// When an object purchased from the shop is placed on the DropGrid private void objectPlaced(object sender, DragEventArgs e) { DragPictureBox dragPictureBox = (sender as DropGrid).activeDragPB; // Store the dropped DragPictureBox SnappingRegion snappingRegion = new SnappingRegion((sender as DropGrid).GetSnappingRegion()); // Store the snapping region of the DropGrid snappingRegion.AddImageOffsets(dragPictureBox); // Add Image offsets to the snapping region for interrogation purposes if (!snappingRegion.IsSnappingRegion(dragPictureBox.Location.X, dragPictureBox.Location.Y) || snappingRegion.CheckIfOccupied(dragPictureBox.Location.X, dragPictureBox.Location.Y, dragPictureBox.Width, dragPictureBox.Height)) // If the DragPictureBox cannot be placed here { return; // Stop this method here } points -= dragPictureBox.getHeldValue("cost"); // Reduce the player's points by the cost of the item PointsLabel.Text = "Points: " + points; // Update the text of the points label (sender as DropGrid).AddOccupyingPB(dragPictureBox); // Add this DragPictureBox as an occupying PictureBox on the DropGrid that no other DragPictureBox can be dropped on dragPictureBox.Parent = ViewTabControl.TabPages[0]; // Set the parent of the newly dropped DragPictureBox to the TabControl Mars view TabPage dragPictureBox.Location = new Point(dragPictureBox.Location.X - ViewTabControl.Location.X - 4, dragPictureBox.Location.Y - ViewTabControl.Location.Y - 22); // Correct the location of the dropped DragPictureBox dragPictureBox.BringToFront(); // Ensure that the DragPictureBox is at the front of the TapControl's page switch (dragPictureBox.Tag + "") // Inspect the tag of the DragPictureBox { case "Plant": // If the tag is Plant PlantPurchased(); // Carry out the PlantPurchased functionality break; case "Tap": // If the tag is Tap TapPurchased(); // Carry out the TapPurchased functionality break; case "FoodMachine": // If the tag is FoodMachine FoodMachinePurchased(); // Carry out the FoodMachinePurchased functionality break; case "Torch": // If the tag is Torch TorchPurchased(); // Carry out the TorchPurchased functionality break; } }
private void objectPlaced(object sender, DragEventArgs e) { DragPictureBox dragPictureBox = (sender as DropGrid).activeDragPB; SnappingRegion snappingRegion = new SnappingRegion((sender as DropGrid).GetSnappingRegion()); snappingRegion.AddImageOffsets(dragPictureBox); if (!snappingRegion.IsSnappingRegion(dragPictureBox.Location.X, dragPictureBox.Location.Y) || snappingRegion.CheckIfOccupied(dragPictureBox.Location.X, dragPictureBox.Location.Y, dragPictureBox.Width, dragPictureBox.Height)) { return; } points -= dragPictureBox.getHeldValue("cost"); PointsLabel.Text = "Points: " + points; (sender as DropGrid).AddOccupyingPB(dragPictureBox); dragPictureBox.Parent = tabControl1.TabPages[0]; dragPictureBox.Location = new Point(dragPictureBox.Location.X - tabControl1.Location.X - 4, dragPictureBox.Location.Y - tabControl1.Location.Y - 22); dragPictureBox.BringToFront(); switch (dragPictureBox.Tag + "") { case "Plant" : PlantPurchased(); break; case "Tap" : TapPurchased(); break; case "FoodMachine": FoodMachinePurchased(); break; case "Torch": TorchPurchased(); break; } }
// When a DragPictureBox is dropped on this DropGrid private void DropGrid_DragDrop(object sender, DragEventArgs e) { Point dragPBlocation = activeDragPB.Location; // Store the location of the Dropped (active) DragPictureBox SetGridVisibility(false); // Set the visibility of the grid to false activeDragPB.followMouse.Stop(); // Stop the following timer on the Dropped DragPictureBox SnappingRegion tempSnappingRegion = new SnappingRegion(snappingRegion); // Temporarily store the state the current DropGrid tempSnappingRegion.AddImageOffsets(activeDragPB); // Add the image offsets of the Dropped DragPictureBox to the Snapping Region for reading purposes if (!tempSnappingRegion.IsSnappingRegion(dragPBlocation.X, dragPBlocation.Y) || tempSnappingRegion.CheckIfOccupied(dragPBlocation.X, dragPBlocation.Y, activeDragPB.Width, activeDragPB.Height)) // If the DragPictureBox cannot be placed here becasue there is another component in it's way { activeDragPB.Dispose(); // Dispose of the Dropped DragPictureBox } }