Example #1
0
        /**
         * // I intended to comment these methods to explain them
         * // I also hoped I would be able to make the code better
         * // I did not plan my time well
         * // - Boris Georgiev
         **/
        private void AnimationBox_MouseDown(object sender, MouseEventArgs e)
        {
            var      mouseClick = e as MouseEventArgs;
            GridTile t          = thisGrid.FindTileInPixelCoordinates(mouseClick.X, mouseClick.Y);

            SelectTile(t);

            if (buildModeActive)
            {
                //here we build the different elements
                if (t is EmptyTile && t.Unselectable == false && deleteMode == false)
                {
                    //because a single conveyor can consist of many tiles, we do not add the nodes when we begin building it, unlike the other elements
                    if (buildModeType == "Conveyor")
                    {
                        SelectTile(thisGrid.AddConveyorLineAtCoordinates(t));
                        conveyorBuilding.Add((ConveyorTile)selectedTile);

                        isBuildingConveyor = true;
                    }
                    else if (buildModeType == "CheckIn")
                    {
                        CheckIn checkin = new CheckIn();
                        SelectTile(thisGrid.AddCheckInAtCoordinates(t, checkin));
                        engine.AddCheckIn(checkin);
                        RefreshCheckInCombobox();

                        GridTile temp = thisGrid.AutoConnectToNext(selectedTile, thisGrid.GetBottomNeighbour);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(selectedTile.nodeInGrid, temp.nodeInGrid);
                        }
                    }
                    else if (buildModeType == "Security Scanner")
                    {
                        Security security = new Security();
                        SelectTile(thisGrid.AddSecurityAtCoordinates(t, security));
                        engine.AddSecurity(security);

                        GridTile temp = thisGrid.AutoConnectToPrev(selectedTile, thisGrid.GetNeighboursIn4Directions);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(temp.nodeInGrid, selectedTile.nodeInGrid);
                        }

                        temp = thisGrid.AutoConnectToNext(selectedTile, thisGrid.GetNeighboursIn4Directions);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(selectedTile.nodeInGrid, temp.nodeInGrid);
                        }
                    }
                    else if (buildModeType == "DropOff")
                    {
                        DropOff dropoff = new DropOff();
                        SelectTile(thisGrid.AddDropOffAtCoordinates(t, dropoff));
                        engine.AddDropOff(dropoff);
                        RefreshDropOffCombobox();
                        if (btnAddFlight.Enabled != true)
                        {
                            btnAddFlight.Enabled = true;
                        }

                        GridTile temp = thisGrid.AutoConnectToPrev(selectedTile, thisGrid.GetTopNeighbour);
                        if (temp != null)
                        {
                            engine.LinkTwoNodes(temp.nodeInGrid, selectedTile.nodeInGrid);
                            //each conveyor can contain the destination gate of the drop off it is connected too
                            //here we assign the destination gate to the previous conveyor
                            if (temp is ConveyorTile)
                            {
                                Conveyor selectedConveyor = temp.nodeInGrid as Conveyor;
                                DropOff  selectedDropOff  = selectedTile.nodeInGrid as DropOff;
                                selectedConveyor.DestinationGate = selectedDropOff.DestinationGate;
                            }
                        }
                    }

                    else if (buildModeType == "MPA")
                    {
                        MPA mpa = new MPA();
                        // AddMPA() first checks if there is available space to build it from the selected starting point
                        if (thisGrid.AddMPA(t, mpa))
                        {
                            engine.AddMPA(mpa);

                            SelectTile(thisGrid.FindTileInRowColumnCoordinates(t.Column, t.Row));
                            List <GridTile> tempMPA = thisGrid.GetMPA(selectedTile);
                            foreach (GridTile m in tempMPA)
                            {
                                GridTile temp = thisGrid.AutoConnectToPrev(m, thisGrid.GetNeighboursIn4Directions);
                                if (temp != null)
                                {
                                    engine.LinkTwoNodes(temp.nodeInGrid, m.nodeInGrid);
                                }
                                temp = thisGrid.AutoConnectToNext(m, thisGrid.GetNeighboursIn4Directions);
                                if (temp != null && temp.nodeInGrid is Conveyor)
                                {
                                    mpa.AddNextNode(temp.nodeInGrid as Conveyor);
                                }
                            }
                            // we disable the ability to create another MPA
                            rbMPA.Visible     = false;
                            rbCheckIn.Checked = true;
                        }
                    }
                }

                /**
                 * // isConnectingTiles is used in the MouseMove Event
                 * // since delete mode is enabled only if build mode is enabled,
                 * // we must ensure delete mode is not enabled when attempting to connect elements
                 **/
                else if (!(t is EmptyTile) && deleteMode == false)
                {
                    isConnectingTiles = true;
                }
                //here we delete tiles
                else if (!(t is EmptyTile) && deleteMode == true)
                {
                    if (t is ConveyorTile)
                    {
                        ConveyorTile first = thisGrid.RemoveConveyorLine(t);
                        engine.Remove(t.nodeInGrid);
                        if (engine.mainProcessArea != null)
                        {
                            //here we check if the main process area is linked to the deleted conveyor and remove any connections
                            foreach (Conveyor c in engine.mainProcessArea.nextNodes.ToList())
                            {
                                if (c == first.nodeInGrid)
                                {
                                    engine.mainProcessArea.nextNodes.Remove(c);
                                }
                            }
                        }
                    }
                    else if (t is MPATile)
                    {
                        thisGrid.RemoveMPA(t);
                        engine.Remove(t.nodeInGrid);
                        rbMPA.Visible = true;
                    }
                    else
                    {
                        engine.Remove(t.nodeInGrid);
                        thisGrid.RemoveNode(t);
                    }
                    RefreshCheckInCombobox();
                    RefreshDropOffCombobox();
                }
            }
            //getting information about the clicked tile when not building (buildModeActive == false)
            else
            {
                if (!(t is EmptyTile))
                {
                    Node n = thisGrid.ReturnNodeOnPosition(t);
                    lblNodeType.Text  = n.GetType().Name;
                    lblBagStatus.Text = n.Status.ToString();
                    if (t.nodeInGrid.NextNode == null)
                    {
                        lblNextNode.Text = "null";
                    }
                    else
                    {
                        lblNextNode.Text = t.nodeInGrid.NextNode.ToString();
                    }
                }
            }
            lblColRow.Text = t.Column + " " + t.Row;

            //accessing special options for dropoffs
            if (selectedTile is DropOffTile)
            {
                selectedDropOffForSettings = selectedTile.nodeInGrid as DropOff;
                cbCapacity.Text            = Convert.ToString(selectedDropOffForSettings.baggages.Capacity);
                cbEmployees.Text           = Convert.ToString(selectedDropOffForSettings.EmployeeSpeed);
                gbDropOffSettings.Text     = $"DropOff {selectedDropOffForSettings.DestinationGate} Settings";
                gbDropOffSettings.Visible  = true;
            }
            else
            {
                gbDropOffSettings.Visible = false;
            }
            animationBox.Invalidate();
        }