private void animationBox_MouseDown(object sender, MouseEventArgs e)
        {
            //for drawing the checkins, drop-off, mda,...
            GridTile t = this._grid.FindTileInPixelCoordinates(e.X, e.Y);
            GridTile currentTile;

            if (this.buildType == BuildType.CheckIn)
            {
                currentTile = new CheckInTile(t.Column, t.Row, this._grid.GetTileWidth(), this._grid.GetTileHeight());
                this.ConnectComponentHelper(currentTile, t);
            }
            else if (this.buildType == BuildType.Conveyor)
            {
                currentTile = new ConveyorTile(t.Column, t.Row, this._grid.GetTileWidth(), this._grid.GetTileHeight());
                this.ConnectComponentHelper(currentTile, t);
            }
            else if (this.buildType == BuildType.Mda)
            {
                //mda later on
                currentTile = new MDATile(t.Column, t.Row, this._grid.GetTileWidth(), this._grid.GetTileHeight());
                this.ConnectComponentHelper(currentTile, t);
                //enable other component
                btnCheckin.Enabled  = true;
                btnConveyor.Enabled = true;
                btnDropoff.Enabled  = true;
                btnSecurity.Enabled = true;
            }
            else if (this.buildType == BuildType.Security)
            {
                currentTile = new SecurityTile(t.Column, t.Row, this._grid.GetTileWidth(), this._grid.GetTileHeight());
                this.ConnectComponentHelper(currentTile, t);
            }
            else if (this.buildType == BuildType.DropOff)
            {
                currentTile = new DropOffTile(t.Column, t.Row, this._grid.GetTileWidth(), this._grid.GetTileHeight());
                this.ConnectComponentHelper(currentTile, t);
                if (currentTile.NextTiles != null)
                {
                    gbSettings.Enabled              = true;
                    gbFlightInfo.Enabled            = true;
                    MapImportExportgroupBox.Enabled = true;
                    comboBoxCurrentDropOffs.Items.Add(currentTile.NodeId.ToString());
                }
            }
            else if (this.buildType == BuildType.Delete)
            {
                this._grid.DeleteNode(t);
            }

            //redraw the grid
            this.animationBox.Invalidate();
        }
Ejemplo n.º 2
0
        private void AnimationBox_MouseMove(object sender, MouseEventArgs e)
        {
            var      mouseClick = e as MouseEventArgs;
            GridTile t          = thisGrid.FindTileInPixelCoordinates(mouseClick.X, mouseClick.Y);

            //each conveyor can consist of multiple tiles with one node, as opposed to the other elements(checkin, security, dropoff)
            //which all take a single position on the grid, with the exception of the MPA
            if (isBuildingConveyor)
            {
                if ((Math.Abs(t.Column - selectedTile.Column) == 1 && Math.Abs(t.Row - selectedTile.Row) == 0) || (Math.Abs(t.Column - selectedTile.Column) == 0 && Math.Abs(t.Row - selectedTile.Row) == 1))
                {
                    if (t is EmptyTile && t.Unselectable == false)
                    {
                        GridTile created = thisGrid.AddConveyorLineAtCoordinates(t);
                        conveyorBuilding.Add((ConveyorTile)created);

                        thisGrid.ConnectTiles(selectedTile, t);
                        SelectTile(created);
                    }
                }
            }
            if (isConnectingTiles)
            {
                if ((Math.Abs(t.Column - selectedTile.Column) == 1 && Math.Abs(t.Row - selectedTile.Row) == 0) || (Math.Abs(t.Column - selectedTile.Column) == 0 && Math.Abs(t.Row - selectedTile.Row) == 1))
                {
                    /**
                     * //it is impossible to connect one conveyor to the middle of the other
                     * //you must connect the end of the conveyor with the beginning of the next one
                     * //that is why we have special checks
                     **/
                    if (selectedTile is ConveyorTile && t is ConveyorTile)
                    {
                        ConveyorTile tempEnd = selectedTile as ConveyorTile;
                        ConveyorTile tempBeg = t as ConveyorTile;
                        if (tempEnd.isLastTile && tempBeg.PositionInLine == 0)
                        {
                            thisGrid.ConnectTiles(selectedTile, t);
                            engine.LinkTwoNodes(selectedTile.nodeInGrid, t.nodeInGrid);
                        }
                    }
                    //here we must ensure that the selected conveyor tile is the last tile in the conveyor
                    else if (selectedTile is ConveyorTile && !(t is EmptyTile) && !(t is CheckInTile))
                    {
                        ConveyorTile temp = (ConveyorTile)selectedTile;
                        if (temp.isLastTile)
                        {
                            engine.LinkTwoNodes(selectedTile.nodeInGrid, t.nodeInGrid);
                            thisGrid.ConnectTiles(selectedTile, t);
                            if (t is DropOffTile)
                            {
                                var selectedConveyor = selectedTile.nodeInGrid as Conveyor;
                                var tNode            = t.nodeInGrid as DropOff;
                                selectedConveyor.DestinationGate = tNode.DestinationGate;
                            }
                        }
                    }
                    else if (selectedTile is CheckInTile && t is ConveyorTile)
                    {
                        engine.LinkTwoNodes(selectedTile.nodeInGrid, t.nodeInGrid);
                        thisGrid.ConnectTiles(selectedTile, t);
                    }
                    else if (selectedTile is SecurityTile && t is ConveyorTile)
                    {
                        engine.LinkTwoNodes(selectedTile.nodeInGrid, t.nodeInGrid);
                        thisGrid.ConnectTiles(selectedTile, t);
                    }
                    //since the mpa is the only element that can have multiple nextNodes, special checking needs to be performed
                    else if (selectedTile is MPATile && t is ConveyorTile)
                    {
                        var selectedMPA = selectedTile.nodeInGrid as MPA;
                        selectedMPA.AddNextNode(t.nodeInGrid as Conveyor);
                        engine.LinkTwoNodes(selectedTile.nodeInGrid, t.nodeInGrid);
                        thisGrid.ConnectTiles(selectedTile, t);
                    }
                }
            }

            animationBox.Invalidate();
        }
Ejemplo n.º 3
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();
        }