Esempio n. 1
0
        private void overWriteSinglesWithWalls(int[] p_mapPos)
        {
            ModifyTile[] changeSingles = new ModifyTile[9];
            changeSingles[0] = new ModifyTile(world.SystemManager);
            changeSingles[0].col = p_mapPos[0] - 1;
            changeSingles[0].row = p_mapPos[1] - 1;
            changeSingles[0].state = -1;
            changeSingles[0].affectedTilemap = singlesTilemap.getType();

            changeSingles[1] = new ModifyTile(world.SystemManager);
            changeSingles[1].col = p_mapPos[0];
            changeSingles[1].row = p_mapPos[1] - 1;
            changeSingles[1].state = -1;
            changeSingles[1].affectedTilemap = singlesTilemap.getType();

            changeSingles[2] = new ModifyTile(world.SystemManager);
            changeSingles[2].col = p_mapPos[0] + 1;
            changeSingles[2].row = p_mapPos[1] - 1;
            changeSingles[2].state = -1;
            changeSingles[2].affectedTilemap = singlesTilemap.getType();

            changeSingles[3] = new ModifyTile(world.SystemManager);
            changeSingles[3].col = p_mapPos[0] + 1;
            changeSingles[3].row = p_mapPos[1];
            changeSingles[3].state = -1;
            changeSingles[3].affectedTilemap = singlesTilemap.getType();

            changeSingles[4] = new ModifyTile(world.SystemManager);
            changeSingles[4].col = p_mapPos[0] + 1;
            changeSingles[4].row = p_mapPos[1] + 1;
            changeSingles[4].state = -1;
            changeSingles[4].affectedTilemap = singlesTilemap.getType();

            changeSingles[5] = new ModifyTile(world.SystemManager);
            changeSingles[5].col = p_mapPos[0];
            changeSingles[5].row = p_mapPos[1] + 1;
            changeSingles[5].state = -1;
            changeSingles[5].affectedTilemap = singlesTilemap.getType();

            changeSingles[6] = new ModifyTile(world.SystemManager);
            changeSingles[6].col = p_mapPos[0] - 1;
            changeSingles[6].row = p_mapPos[1] + 1;
            changeSingles[6].state = -1;
            changeSingles[6].affectedTilemap = singlesTilemap.getType();

            changeSingles[7] = new ModifyTile(world.SystemManager);
            changeSingles[7].col = p_mapPos[0] - 1;
            changeSingles[7].row = p_mapPos[1];
            changeSingles[7].state = -1;
            changeSingles[7].affectedTilemap = singlesTilemap.getType();

            changeSingles[8] = new ModifyTile(world.SystemManager);
            changeSingles[8].col = p_mapPos[0];
            changeSingles[8].row = p_mapPos[1];
            changeSingles[8].state = -1;
            changeSingles[8].affectedTilemap = singlesTilemap.getType();

            ActionSystem actionSys = ((ActionSystem)world.SystemManager.GetSystem<ActionSystem>()[0]);
            for (int i = 0; i < 9; i++)
            {
                actionSys.EnqueueAction(changeSingles[i]);
            }
        }
Esempio n. 2
0
        public void canvasWindow_MouseMove(object sender, MouseEventArgs e)
        {
            Vector2 mousePos = new Vector2(e.Position.X, e.Position.Y);
            Entity camera = world.TagManager.GetEntity("mainCamera");
            if (camera != null)
            {
                Transform camTransform = camera.GetComponent<Transform>();
                if (camTransform != null)
                {
                    mousePos = Vector2.Transform(mousePos, Matrix.Invert(camTransform.getMatrix()));
                    if (m_horizontalLock > 0.0f) {
                        mousePos.Y = m_horizontalLock;
                    }
                    else if (m_verticalLock > 0.0f) {
                        mousePos.X = m_verticalLock;
                    }
                    m_drawCanvasSys.setLastMousePos(mousePos);
                }
            }

            if (mousePos.X >= 0.0f &&
                mousePos.X < mainTilemap.getColumns() * 32.0f &&
                mousePos.Y >= 0.0f &&
                mousePos.Y < mainTilemap.getRows() * 32.0f)
            {
                if (m_lmbPressed)
                {
                    Tool currentTool = m_toolSys.GetCurrentTool();
                    if (mainTilemap != null && roadTilemap != null && wallTilemap != null &&
                        canvasTransform != null)
                    {

                        if (currentTool == Tool.ROAD_TOOL)
                        {
                            if (!m_haveShownRoadToolMessage)
                            {
                                NotificationBarSystem noteSys = (NotificationBarSystem)world.SystemManager.GetSystem<NotificationBarSystem>()[0];

                                List<Paragraph> paragraphs = new List<Paragraph>();
                                paragraphs.Add(new Paragraph("You just used the road tool. The road tool is a pen you can use to draw roads free hand."));
                                paragraphs.Add(new Paragraph("By pressing and holding the left shift key before starting to draw you can limit your movement to either the horizontal or vertical axis. Try it out!"));

                                Notification note = new Notification("Want more information about the road tool? Press more.", NotificationType.INFO, paragraphs, "Road Tool");
                                noteSys.AddNotification(note);
                                m_haveShownRoadToolMessage = true;
                            }

                            int[] mapPos = roadTilemap.getTilePosition(mousePos);
                            ModifyTile changeTile = new ModifyTile(world.SystemManager);
                            changeTile.col = mapPos[0];
                            changeTile.row = mapPos[1];
                            changeTile.state = 0;
                            changeTile.affectedTilemap = roadTilemap.getType();

                            if (roadTilemap.getState(mapPos[0], mapPos[1]) != 0)
                            {
                                ActionSystem actionSys = ((ActionSystem)world.SystemManager.GetSystem<ActionSystem>()[0]);
                                actionSys.EnqueueAction(changeTile);
                                overWriteSinglesWithWalls(mapPos);
                            }
                        }
                        else if (currentTool == Tool.PAINT_TOOL)
                        {
                            int[] mapPos = roadTilemap.getTilePosition(mousePos);

                            IntPair indexPair = m_toolSys.GetCurrentDrawTileIndex();
                            Vector2 min = new Vector2(indexPair.i1 - 30 * (indexPair.i1 / 30), indexPair.i1 / 30);
                            Vector2 max = new Vector2(indexPair.i2 - 30 * (indexPair.i2 / 30), indexPair.i2 / 30);

                            for (int i = (int)min.X; i <= max.X; i++)
                            {
                                for (int j = (int)min.Y; j <= max.Y; j++)
                                {
                                    int index = j * 30 + i;
                                    if (singlesTilemap.getState(mapPos[0]+i-(int)min.X, mapPos[1]+j-(int)min.Y) != index)
                                    {
                                        ActionSystem actionSys = ((ActionSystem)world.SystemManager.GetSystem<ActionSystem>()[0]);

                                        //actionSys.StartGroupingActions();
                                        ModifyTile changeTile = new ModifyTile(world.SystemManager);
                                        changeTile.col = mapPos[0] + i - (int)min.X;
                                        changeTile.row = mapPos[1] + j - (int)min.Y;
                                        changeTile.state = index;
                                        changeTile.affectedTilemap = singlesTilemap.getType();
                                        actionSys.EnqueueAction(changeTile);

                                        //ModifyTile roadChangeTile = new ModifyTile(world.SystemManager);
                                        //roadChangeTile.col = changeTile.col;
                                        //roadChangeTile.row = changeTile.row;
                                        //roadChangeTile.state = -1;
                                        //roadChangeTile.affectedTilemap = roadTilemap.getType();
                                        //actionSys.EnqueueAction(roadChangeTile);
                                    }
                                }
                            }
                        }
                        else if (currentTool == Tool.ERASE_TOOL)
                        {
                            int[] mapPos = roadTilemap.getTilePosition(mousePos);

                            ModifyTile roadModify = new ModifyTile(world.SystemManager);
                            roadModify.affectedTilemap = roadTilemap.getType();
                            roadModify.col = mapPos[0];
                            roadModify.row = mapPos[1];
                            roadModify.state = -1;

                            ModifyTile singlesModify = new ModifyTile(world.SystemManager);
                            singlesModify.affectedTilemap = singlesTilemap.getType();
                            singlesModify.col = mapPos[0];
                            singlesModify.row = mapPos[1];
                            singlesModify.state = -1;

                            ActionSystem actionSys = ((ActionSystem)world.SystemManager.GetSystem<ActionSystem>()[0]);
                            actionSys.EnqueueAction(roadModify);
                            actionSys.EnqueueAction(singlesModify);
                        }
                    }
                }
            }
        }