Example #1
0
        private void TilesetTool()
        {
            //Vector2 _worldPosition = new Vector2()
            //{
            //    X = mouseWorldPosition.X - (EditorHandler.SelectedGameObjects[0] as Tileset).OffsetX - EditorHandler.BrushControl.CurrentSelectionXNA.Width / 2,
            //    Y = mouseWorldPosition.Y - (EditorHandler.SelectedGameObjects[0] as Tileset).OffsetY - EditorHandler.BrushControl.CurrentSelectionXNA.Height / 2
            //};

            if (tilesetMode == TilesetModes.Pencil)
            {
                if (LeftMouseKeyDown)
                {
                    if (!tilesetDragStarted)
                    {
                        memTiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();
                    }

                    (EditorHandler.SelectedGameObjects[0] as Tileset).PlaceTiles(EditorHandler.BrushControl.CurrentSelectionXNA, SnapToTilesetGrid(mouseWorldPosition));

                    tilesetDragStarted = true;
                }
                else
                {
                    if (tilesetDragStarted)
                    {
                        TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, memTiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                        EditorHandler.UnDoRedo.InsertUndoRedo(tc);

                        tilesetDragStarted = false;
                    }
                }
            }
            else if (tilesetMode == TilesetModes.Rectangle)
            {
                if (LeftMouseKeyDown)
                {
                    if (tilesetDragStarted)
                    {
                        Vector2 releasePos = SnapToTilesetGrid(mouseWorldPosition);
                        tilesetSelectedArea = MathExtension.RectangleFromVectors(tilesetMouseDownPos, releasePos);

                        tilesetSelectedArea = new Rectangle()
                        {
                            X = tilesetSelectedArea.X,
                            Y = tilesetSelectedArea.Y,
                            Width = tilesetSelectedArea.Width + (EditorHandler.SelectedGameObjects[0] as Tileset).TileWidth,
                            Height = tilesetSelectedArea.Height + (EditorHandler.SelectedGameObjects[0] as Tileset).TileHeight
                        };
                    }
                    else
                    {
                        tilesetDragStarted = true;
                        tilesetMouseDownPos = SnapToTilesetGrid(mouseWorldPosition);
                    }
                }
                else
                {
                    if (tilesetDragStarted)
                    {
                        if (EditorHandler.BrushControl.CurrentSelectionXNA != Rectangle.Empty)
                        {
                            Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

                            (EditorHandler.SelectedGameObjects[0] as Tileset).PlaceTiles(EditorHandler.BrushControl.CurrentSelectionXNA, tilesetSelectedArea);

                            TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                            EditorHandler.UnDoRedo.InsertUndoRedo(tc);
                        }
                    }

                    tilesetSelectedArea = Rectangle.Empty;
                    tilesetDragStarted = false;
                }
            }
            else if (tilesetMode == TilesetModes.Eraser)
            {
                if (LeftMouseKeyDown)
                {
                    if (tilesetDragStarted)
                    {
                        Vector2 releasePos = SnapToTilesetGrid(mouseWorldPosition);
                        tilesetSelectedArea = MathExtension.RectangleFromVectors(tilesetMouseDownPos, releasePos);

                        tilesetSelectedArea = new Rectangle()
                        {
                            X = tilesetSelectedArea.X,
                            Y = tilesetSelectedArea.Y,
                            Width = tilesetSelectedArea.Width + (EditorHandler.SelectedGameObjects[0] as Tileset).TileWidth,
                            Height = tilesetSelectedArea.Height + (EditorHandler.SelectedGameObjects[0] as Tileset).TileHeight
                        };
                    }
                    else
                    {
                        tilesetDragStarted = true;
                        tilesetMouseDownPos = SnapToTilesetGrid(mouseWorldPosition);
                    }
                }
                else
                {
                    if (tilesetDragStarted)
                    {
                        Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

                        (EditorHandler.SelectedGameObjects[0] as Tileset).RemoveTiles(tilesetSelectedArea);

                        TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                        EditorHandler.UnDoRedo.InsertUndoRedo(tc);
                    }

                    tilesetSelectedArea = Rectangle.Empty;
                    tilesetDragStarted = false;
                }
            }
            else if (tilesetMode == TilesetModes.AddColumn)
            {
                if (LeftMouseKeyPressed)
                {
                    Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

                    (EditorHandler.SelectedGameObjects[0] as Tileset).AddColumn((int)mouseWorldPosition.X);

                    TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                    EditorHandler.UnDoRedo.InsertUndoRedo(tc);
                }
            }
            else if (tilesetMode == TilesetModes.AddRow)
            {
                if (LeftMouseKeyPressed)
                {
                    Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

                    (EditorHandler.SelectedGameObjects[0] as Tileset).AddRow((int)mouseWorldPosition.Y);

                    TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                    EditorHandler.UnDoRedo.InsertUndoRedo(tc);
                }
            }
            else if (tilesetMode == TilesetModes.RemoveColumn)
            {
                if (LeftMouseKeyPressed)
                {
                    Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

                    (EditorHandler.SelectedGameObjects[0] as Tileset).RemoveColumn((int)mouseWorldPosition.X);

                    TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                    EditorHandler.UnDoRedo.InsertUndoRedo(tc);
                }
            }
            else if (tilesetMode == TilesetModes.RemoveRow)
            {
                if (LeftMouseKeyPressed)
                {
                    Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

                    (EditorHandler.SelectedGameObjects[0] as Tileset).RemoveRow((int)mouseWorldPosition.Y);

                    TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
                    EditorHandler.UnDoRedo.InsertUndoRedo(tc);
                }
            }
        }
Example #2
0
        private void shiftLeftBtn_Click(object sender, EventArgs e)
        {
            Tile[,] _tiles = (EditorHandler.SelectedGameObjects[0] as Tileset).DeepCopy();

            (EditorHandler.SelectedGameObjects[0] as Tileset).ShiftLeft(1);

            TilesetCommand tc = new TilesetCommand((EditorHandler.SelectedGameObjects[0] as Tileset).Tiles, _tiles, (EditorHandler.SelectedGameObjects[0] as Tileset));
            EditorHandler.UnDoRedo.InsertUndoRedo(tc);
        }