Cannot place a tree on top of a tree
This commit is contained in:
		@@ -502,6 +502,23 @@ namespace EduNetworkBuilder
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool BlockedByTree(Point NetworkLocation)
 | 
			
		||||
        {
 | 
			
		||||
            NetworkDevice tDevice;
 | 
			
		||||
            foreach (NetworkComponent tItem in NetComponents)
 | 
			
		||||
            {
 | 
			
		||||
                if (tItem is NetworkDevice)
 | 
			
		||||
                {
 | 
			
		||||
                    tDevice = (NetworkDevice)tItem;
 | 
			
		||||
                    if (tDevice.GetNetType() != NetworkComponentType.tree) continue; //We only care about trees
 | 
			
		||||
                    Rectangle myRec = tDevice.GetMyRectangle();
 | 
			
		||||
                    if (myRec.Contains(NetworkLocation))
 | 
			
		||||
                        return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public NetworkLink LinkAtPosition(Point NetworkLocation)
 | 
			
		||||
        {
 | 
			
		||||
            NetworkLink tLink;
 | 
			
		||||
 
 | 
			
		||||
@@ -1487,7 +1487,22 @@ namespace EduNetworkBuilder
 | 
			
		||||
                            NC = myNetwork.AddItem(NetworkComponentType.wrepeater, CenteredLocation);
 | 
			
		||||
                            break;
 | 
			
		||||
                        case "btnTree":
 | 
			
		||||
                            NC = myNetwork.AddItem(NetworkComponentType.tree, CenteredLocation);
 | 
			
		||||
                            bool CanDo = true;
 | 
			
		||||
                            Point TopLeft = CenteredLocation;
 | 
			
		||||
                            Point TopRight = new Point(TopLeft.X + myNetwork.itemsize, TopLeft.Y);
 | 
			
		||||
                            Point BottomRight = new Point(TopLeft.X + myNetwork.itemsize, TopLeft.Y + myNetwork.itemsize);
 | 
			
		||||
                            Point BottomLeft = new Point(TopLeft.X, TopLeft.Y + myNetwork.itemsize);
 | 
			
		||||
                            if (myNetwork.BlockedByTree(ClickedLocation)) CanDo = false;
 | 
			
		||||
                            if (myNetwork.BlockedByTree(TopLeft)) CanDo = false;
 | 
			
		||||
                            if (myNetwork.BlockedByTree(TopRight)) CanDo = false;
 | 
			
		||||
                            if (myNetwork.BlockedByTree(BottomRight)) CanDo = false;
 | 
			
		||||
                            if (myNetwork.BlockedByTree(BottomLeft)) CanDo = false;
 | 
			
		||||
                            if(CanDo)
 | 
			
		||||
                                NC = myNetwork.AddItem(NetworkComponentType.tree, CenteredLocation);
 | 
			
		||||
                            else
 | 
			
		||||
                            {
 | 
			
		||||
                                lblStatus.Text = NB.Translate("NB_TreePlacementError");
 | 
			
		||||
                            }
 | 
			
		||||
                            break;
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
 
 | 
			
		||||
@@ -2033,4 +2033,8 @@
 | 
			
		||||
    <value>Add a tree to the network to block wireless signals</value>
 | 
			
		||||
    <comment>NB_BuildBtnTree = Add a tree to the network to block wireless signals</comment>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="NB_TreePlacementError" xml:space="preserve">
 | 
			
		||||
    <value>Cannot place a tree on top of a tree.</value>
 | 
			
		||||
    <comment>NB_TreePlacementError = Cannot place a tree on top of a tree.</comment>
 | 
			
		||||
  </data>
 | 
			
		||||
</root>
 | 
			
		||||
		Reference in New Issue
	
	Block a user