Exemple #1
0
 private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     selection           = new Controller.SelectionTool();
     selection.StartDrag = new Point(0, 0);
     selection.StopDrag  = new Point(map_width, map_height);
     RenderMap();
 }
Exemple #2
0
        private void Init()
        {
            // add event handlers
            pbMap.MouseDown  += new MouseEventHandler(mapPicBox_MouseDown);
            pbMap.MouseMove  += new MouseEventHandler(mapPicBox_MouseMove);
            pbMap.MouseHover += new EventHandler(mapPicBox_MouseHover);
            pbMap.MouseUp    += new MouseEventHandler(mapPicBox_MouseUp);
            this.KeyDown     += new KeyEventHandler(MapEditor_KeyDown);
            this.KeyPreview   = true;
            FormClosing      += new FormClosingEventHandler(MapEditor_FormClosing);

            // create tooltips for tools
            ToolTip toolTips = new ToolTip();

            toolTips.AutoPopDelay = 5000;
            toolTips.InitialDelay = 1000;
            toolTips.ReshowDelay  = 500;
            toolTips.ShowAlways   = true;
            toolTips.SetToolTip(btnToolSelection, "Selection(S)");
            toolTips.SetToolTip(btnToolBrush, "Brush(B)");
            toolTips.SetToolTip(btnToolEraser, "Eraser(E)");
            toolTips.SetToolTip(btnToolFill, "Fill(F)");
            toolTips.SetToolTip(btnToolSelectTile, "Select Tile(T)");

            // initialized some variables
            grid_on          = true;
            show_walkable_on = false;
            isIsometric      = false;
            choosingPlayer   = false;
            choosingPlayer   = false;
            choosingBomb     = false;
            choosingCoin     = false;
            choosingBullet   = false;

            selected_tile = null;
            selection     = new Controller.SelectionTool();

            // select brush as default tool
            SelectTool(ToolType.selection);

            backup_map = new Model.Map();

            undo = new Stack <Model.HistoryNode>();
            undoToolStripMenuItem.Enabled = false;

            redo = new Stack <Model.HistoryNode>();
            redoToolStripMenuItem.Enabled = false;

            clipboard = new Model.Clipboard();
            pasteToolStripMenuItem.Enabled = false;

            saveMapToolStripMenuItem.Enabled = false;

            tile_library = new Model.Tile[0];

            playerCount   = 0;
            monstersCount = 0;
            bombsCount    = 0;
            coinsCount    = 0;
            bulletsCount  = 0;

            player   = new Model.Player();
            monsters = new List <Model.MapMonster>();
            bombs    = new List <Model.MapBomb>();
            coins    = new List <Model.MapCoinGift>();
            bullets  = new List <Model.MapBulletGift>();

            codesGenerator = new Controller.CodesGenerator(map, map_name, map_width, map_height,
                                                           tile_library, tile_width, tile_height,
                                                           tbCode,
                                                           player, monsters, coins, bullets, bombs);
        }
Exemple #3
0
        private void mapPicBox_MouseDown(object sender, MouseEventArgs e)
        {   // mouse click over map
            Point myMouse  = PointToClient(MousePosition);
            int   clickedX = myMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 8;
            int   clickedY = myMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 26;

            int mapX = clickedX / tile_width;
            int mapY = clickedY / tile_height;

            if (mapX < 0 || mapY < 0 || mapX >= map_width || mapY >= map_height)
            {
                return;
            }

            this.lblMapCoordinate.Text = "Map Coordinate: " + mapX + ", " + mapY;
            this.lblMouse.Text         = "Mouse Position: " + clickedX + ", " + clickedY;

            if (e.Button == MouseButtons.Left)
            {
                if (selected_tool == ToolType.selection)
                {   // selection tool
                    selection            = new Controller.SelectionTool();
                    selection.IsDragging = true;
                    selection.StartDrag  = new Point(mapX, mapY);
                    selection.StopDrag   = new Point(mapX, mapY);
                }
                else if (selected_tool == ToolType.brush)
                {   // brush tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        if (map[mapX, mapY] != Convert.ToInt32(pbSelectedTile.Name))
                        {
                            redo.Clear();

                            int id = 0;
                            if (undo.Count > 0)
                            {
                                id = undo.Peek().Id + 1;
                            }

                            undo.Push(new Model.HistoryNode(id, mapX, mapY, map[mapX, mapY]));
                            map[mapX, mapY] = Convert.ToInt32(pbSelectedTile.Name);
                        }
                    }
                }
                else if (selected_tool == ToolType.fill)
                {   // fill tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        if (mapX >= selection.TopLeftX && mapX < selection.BottomRightX && mapY >= selection.TopLeftY && mapY < selection.BottomRightY)
                        {
                            redo.Clear();

                            int id = 0;
                            if (undo.Count > 0)
                            {
                                id = undo.Peek().Id + 1;
                            }

                            if (selection.BottomRightX > map_width)
                            {
                                selection.BottomRightX = map_width;
                            }
                            if (selection.BottomRightY > map_height)
                            {
                                selection.BottomRightY = map_height;
                            }

                            for (int i = selection.TopLeftX; i < selection.BottomRightX; i++)
                            {   // fill selected tiles
                                for (int j = selection.TopLeftY; j < selection.BottomRightY; j++)
                                {
                                    undo.Push(new Model.HistoryNode(id, i, j, map[i, j]));
                                    map[i, j] = Convert.ToInt32(pbSelectedTile.Name);
                                }
                            }
                        }
                    }
                }
                else if (selected_tool == ToolType.selectTile)
                {   // select color tool
                    if (map[mapX, mapY] > -1)
                    {
                        Model.Tile selectedTile = tile_library[map[mapX, mapY]];

                        selected_tile            = selectedTile.TilePictureBox;
                        lblTileIDValue.Text      = selected_tile.Name;
                        tbTileName.Text          = selectedTile.TileName;
                        cbTileWalkable.Checked   = selectedTile.TileWalkable;
                        pbSelectedTile.Image     = selected_tile.Image;
                        pbSelectedTile.Name      = selected_tile.Name;
                        gbTileProperties.Enabled = true;
                    }
                    else
                    {
                        ClearSelectedTile();
                    }
                }
                else if (selected_tool == ToolType.eraser)
                {     // eraser tool
                    if (selection.StartDrag.X != -1 && selection.StartDrag.Y != -1 && selection.StopDrag.X != -1 && selection.StopDrag.Y != -1)
                    { // selection was made
                        if (mapX >= selection.TopLeftX && mapX < selection.BottomRightX && mapY >= selection.TopLeftY && mapY < selection.BottomRightY)
                        {
                            // is in selection
                        }
                        else
                        {
                            return;
                        }
                    }

                    if (map[mapX, mapY] != -1)
                    {
                        redo.Clear();

                        int id = 0;
                        if (undo.Count > 0)
                        {
                            id = undo.Peek().Id + 1;
                        }

                        undo.Push(new Model.HistoryNode(id, mapX, mapY, map[mapX, mapY]));
                        map[mapX, mapY] = -1;
                    }
                }

                RenderMap();

                if (choosingPlayer)
                {
                    player.StartPoint = new Point(mapX, mapY);
                    choosingPlayer    = false;
                    MessageBox.Show("Player Start Point x: " + player.StartPoint.X + ", y: " + player.StartPoint.Y);
                    return;
                }

                if (choosingMonster)
                {
                    int index = monsters.Count - 1;
                    if (monsters[index].Start)
                    {
                        monsters[index].StartPoint = new Point(mapX, mapY);
                        monsters[index].Start      = false;
                        monsters[index].End        = true;
                        return;
                    }
                    if (monsters[index].End)
                    {
                        monsters[index].EndPoint = new Point(mapX, mapY);
                        monsters[index].End      = false;
                        choosingMonster          = false;
                        MessageBox.Show("Monster " + (index + 1) + " Start Point x: " + monsters[index].StartPoint.X + ", y: " + monsters[index].StartPoint.Y + "\n" +
                                        "Monster " + (index + 1) + " End Point x: " + monsters[index].EndPoint.X + ", y: " + monsters[index].EndPoint.Y);
                        return;
                    }
                }

                if (choosingBomb)
                {
                    bombs[bombs.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingBomb = false;
                    MessageBox.Show("Bomb " + bombs.Count + " Point x: " + bombs[bombs.Count - 1].StartPoint.X + ", y: " + bombs[bombs.Count - 1].StartPoint.Y);
                    return;
                }

                if (choosingCoin)
                {
                    coins[coins.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingCoin = false;
                    MessageBox.Show("Coin " + coins.Count + " Point x: " + coins[coins.Count - 1].StartPoint.X + ", y: " + coins[coins.Count - 1].StartPoint.Y);
                    return;
                }

                if (choosingBullet)
                {
                    bullets[bullets.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingBullet = false;
                    MessageBox.Show("Bullet " + bullets.Count + " Point x: " + bullets[bullets.Count - 1].StartPoint.X + ", y: " + bullets[bullets.Count - 1].StartPoint.Y);
                    return;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                selection = new Controller.SelectionTool();
                RenderMap();
            }

            if (undo.Count > 0)
            {
                undoToolStripMenuItem.Enabled = true;
            }
            else
            {
                undoToolStripMenuItem.Enabled = false;
            }
        }
        private void Init()
        {
            // add event handlers
            pbMap.MouseDown += new MouseEventHandler(mapPicBox_MouseDown);
            pbMap.MouseMove += new MouseEventHandler(mapPicBox_MouseMove);
            pbMap.MouseHover += new EventHandler(mapPicBox_MouseHover);
            pbMap.MouseUp += new MouseEventHandler(mapPicBox_MouseUp);
            this.KeyDown += new KeyEventHandler(MapEditor_KeyDown);
            this.KeyPreview = true;
            FormClosing += new FormClosingEventHandler(MapEditor_FormClosing);

            // create tooltips for tools
            ToolTip toolTips = new ToolTip();
            toolTips.AutoPopDelay = 5000;
            toolTips.InitialDelay = 1000;
            toolTips.ReshowDelay = 500;
            toolTips.ShowAlways = true;
            toolTips.SetToolTip(btnToolSelection, "Selection(S)");
            toolTips.SetToolTip(btnToolBrush, "Brush(B)");
            toolTips.SetToolTip(btnToolEraser, "Eraser(E)");
            toolTips.SetToolTip(btnToolFill, "Fill(F)");
            toolTips.SetToolTip(btnToolSelectTile, "Select Tile(T)");

            // initialized some variables
            grid_on = true;
            show_walkable_on = false;
            isIsometric = false;
            choosingPlayer = false;
            choosingPlayer = false;
            choosingBomb = false;
            choosingCoin = false;
            choosingBullet = false;

            selected_tile = null;
            selection = new Controller.SelectionTool();

            // select brush as default tool
            SelectTool(ToolType.selection);

            backup_map = new Model.Map();

            undo = new Stack<Model.HistoryNode>();
            undoToolStripMenuItem.Enabled = false;

            redo = new Stack<Model.HistoryNode>();
            redoToolStripMenuItem.Enabled = false;

            clipboard = new Model.Clipboard();
            pasteToolStripMenuItem.Enabled = false;

            saveMapToolStripMenuItem.Enabled = false;

            tile_library = new Model.Tile[0];

            playerCount = 0;
            monstersCount = 0;
            bombsCount = 0;
            coinsCount = 0;
            bulletsCount = 0;

            player = new Model.Player();
            monsters = new List<Model.Monster>();
            bombs = new List<Model.Bomb>();
            coins = new List<Model.CoinGift>();
            bullets = new List<Model.BulletGift>();

            codesGenerator = new Controller.CodesGenerator(map, map_name, map_width, map_height,
                tile_library, tile_width, tile_height,
                tbCode,
                player, monsters, coins, bullets, bombs);
        }
        private void mapPicBox_MouseDown(object sender, MouseEventArgs e)
        {   // mouse click over map
            Point myMouse = PointToClient(MousePosition);
            int clickedX = myMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 8;
            int clickedY = myMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 26;

            int mapX = clickedX / tile_width;
            int mapY = clickedY / tile_height;

            if (mapX < 0 || mapY < 0 || mapX >= map_width || mapY >= map_height)
                return;

            this.lblMapCoordinate.Text = "Map Coordinate: " + mapX + ", " + mapY;
            this.lblMouse.Text = "Mouse Position: " + clickedX + ", " + clickedY;

            if (e.Button == MouseButtons.Left)
            {
                if (selected_tool == ToolType.selection)
                {   // selection tool
                    selection = new Controller.SelectionTool();
                    selection.IsDragging = true;
                    selection.StartDrag = new Point(mapX, mapY);
                    selection.StopDrag = new Point(mapX, mapY);
                }
                else if (selected_tool == ToolType.brush)
                {   // brush tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        if (map[mapX, mapY] != Convert.ToInt32(pbSelectedTile.Name))
                        {
                            redo.Clear();

                            int id = 0;
                            if (undo.Count > 0)
                                id = undo.Peek().Id + 1;

                            undo.Push(new Model.HistoryNode(id, mapX, mapY, map[mapX, mapY]));
                            map[mapX, mapY] = Convert.ToInt32(pbSelectedTile.Name);
                        }
                    }
                }
                else if (selected_tool == ToolType.fill)
                {   // fill tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        if (mapX >= selection.TopLeftX && mapX < selection.BottomRightX && mapY >= selection.TopLeftY && mapY < selection.BottomRightY)
                        {
                            redo.Clear();

                            int id = 0;
                            if (undo.Count > 0)
                                id = undo.Peek().Id + 1;

                            if (selection.BottomRightX > map_width)
                                selection.BottomRightX = map_width;
                            if (selection.BottomRightY > map_height)
                                selection.BottomRightY = map_height;

                            for (int i = selection.TopLeftX; i < selection.BottomRightX; i++)
                            {   // fill selected tiles
                                for (int j = selection.TopLeftY; j < selection.BottomRightY; j++)
                                {
                                    undo.Push(new Model.HistoryNode(id, i, j, map[i, j]));
                                    map[i, j] = Convert.ToInt32(pbSelectedTile.Name);
                                }
                            }
                        }
                    }
                }
                else if (selected_tool == ToolType.selectTile)
                {   // select color tool
                    if (map[mapX, mapY] > -1)
                    {
                        Model.Tile selectedTile = tile_library[map[mapX, mapY]];

                        selected_tile = selectedTile.TilePictureBox;
                        lblTileIDValue.Text = selected_tile.Name;
                        tbTileName.Text = selectedTile.TileName;
                        cbTileWalkable.Checked = selectedTile.TileWalkable;
                        pbSelectedTile.Image = selected_tile.Image;
                        pbSelectedTile.Name = selected_tile.Name;
                        gbTileProperties.Enabled = true;
                    }
                    else
                    {
                        ClearSelectedTile();
                    }
                }
                else if (selected_tool == ToolType.eraser)
                {   // eraser tool
                    if (selection.StartDrag.X != -1 && selection.StartDrag.Y != -1 && selection.StopDrag.X != -1 && selection.StopDrag.Y != -1)
                    {   // selection was made
                        if (mapX >= selection.TopLeftX && mapX < selection.BottomRightX && mapY >= selection.TopLeftY && mapY < selection.BottomRightY)
                        {
                            // is in selection
                        }
                        else
                        {
                            return;
                        }
                    }

                    if (map[mapX, mapY] != -1)
                    {
                        redo.Clear();

                        int id = 0;
                        if (undo.Count > 0)
                            id = undo.Peek().Id + 1;

                        undo.Push(new Model.HistoryNode(id, mapX, mapY, map[mapX, mapY]));
                        map[mapX, mapY] = -1;
                    }
                }

                RenderMap();

                if (choosingPlayer)
                {
                    player.StartPoint = new Point(mapX, mapY);
                    choosingPlayer = false;
                    MessageBox.Show("Player Start Point x: " + player.StartPoint.X + ", y: " + player.StartPoint.Y);
                    return;
                }

                if (choosingMonster)
                {
                    int index = monsters.Count - 1;
                    if (monsters[index].Start)
                    {
                        monsters[index].StartPoint = new Point(mapX, mapY);
                        monsters[index].Start = false;
                        monsters[index].End = true;
                        return;
                    }
                    if (monsters[index].End)
                    {
                        monsters[index].EndPoint = new Point(mapX, mapY);
                        monsters[index].End = false;
                        choosingMonster = false;
                        MessageBox.Show("Monster " + (index + 1) + " Start Point x: " + monsters[index].StartPoint.X + ", y: " + monsters[index].StartPoint.Y + "\n" +
                                        "Monster " + (index + 1) + " End Point x: " + monsters[index].EndPoint.X + ", y: " + monsters[index].EndPoint.Y);
                        return;
                    }
                }

                if (choosingBomb)
                {
                    bombs[bombs.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingBomb = false;
                    MessageBox.Show("Bomb " + bombs.Count + " Point x: " + bombs[bombs.Count - 1].StartPoint.X + ", y: " + bombs[bombs.Count - 1].StartPoint.Y);
                    return;
                }

                if (choosingCoin)
                {
                    coins[coins.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingCoin = false;
                    MessageBox.Show("Coin " + coins.Count + " Point x: " + coins[coins.Count - 1].StartPoint.X + ", y: " + coins[coins.Count - 1].StartPoint.Y);
                    return;
                }

                if (choosingBullet)
                {
                    bullets[bullets.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingBullet = false;
                    MessageBox.Show("Bullet " + bullets.Count + " Point x: " + bullets[bullets.Count - 1].StartPoint.X + ", y: " + bullets[bullets.Count - 1].StartPoint.Y);
                    return;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                selection = new Controller.SelectionTool();
                RenderMap();
            }

            if (undo.Count > 0)
                undoToolStripMenuItem.Enabled = true;
            else
                undoToolStripMenuItem.Enabled = false;
        }
Exemple #6
0
 private void deselectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     selection = new Controller.SelectionTool();
     RenderMap();
 }
Exemple #7
0
 private void deselectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     selection = new Controller.SelectionTool();
     RenderMap();
 }
Exemple #8
0
 private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     selection = new Controller.SelectionTool();
     selection.StartDrag = new Point(0, 0);
     selection.StopDrag = new Point(map_width, map_height);
     RenderMap();
 }