Exemplo n.º 1
0
        public static void Brush(D2DMapEditor d2d, Map map, History history, int layerIndex, int tileIndex)
        {
            history.ClearRedo();
            int id = history.UndoNextId;

            while (InputHelper.OldMapPosition.X != InputHelper.MapPosition.X ||
                   InputHelper.OldMapPosition.Y != InputHelper.MapPosition.Y)
            {
                if (map.Layers[layerIndex].LayerData[InputHelper.OldMapPosition.X, InputHelper.OldMapPosition.Y] != tileIndex)
                {
                    history.PushUndo(id, map.Layers[layerIndex].LayerId,
                                      InputHelper.OldMapPosition.X, InputHelper.OldMapPosition.Y,
                                      map.Layers[layerIndex].LayerData[InputHelper.OldMapPosition.X, InputHelper.OldMapPosition.Y],
                                      ActionType.Brush);
                    map.Layers[layerIndex].LayerData[InputHelper.OldMapPosition.X, InputHelper.OldMapPosition.Y] = tileIndex;
                }

                InputHelper.UpdateOldMapPosition();
            }
            if (map.Layers[layerIndex].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y] != tileIndex)
            {
                history.PushUndo(map.Layers[layerIndex].LayerId,
                                  InputHelper.MapPosition.X, InputHelper.MapPosition.Y,
                                  map.Layers[layerIndex].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y],
                                  ActionType.Brush);
                map.Layers[layerIndex].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y] = tileIndex;
            }
        }
Exemplo n.º 2
0
 public static void Eraser(Map map, MapInfo mapInfo, History history, int layerIndex)
 {
     if (mapInfo.Selection.IsWithinSelection())
     {
         if (map.Layers[layerIndex].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y] != -1)
         {
             history.PushUndo(map.Layers[layerIndex].LayerId, InputHelper.MapPosition.X, InputHelper.MapPosition.Y,
                              map.Layers[layerIndex].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y],
                              ActionType.Erase);
             map.Layers[layerIndex].LayerData[InputHelper.MapPosition.X, InputHelper.MapPosition.Y] = -1;
         }
     }
 }
Exemplo n.º 3
0
        public static void Fill(Map map, MapInfo mapInfo, History history, int layerIndex, int tileIndex)
        {
            if (mapInfo.Selection.IsWithinSelection())
            {
                history.ClearRedo();
                int id = history.UndoNextId;

                mapInfo.Selection.ForceWithinSelection(map.Layers[layerIndex].Width, map.Layers[layerIndex].Height);
                for (int i = mapInfo.Selection.TopLeftX; i < mapInfo.Selection.BottomRightX; i++)
                {   // fill selected tiles
                    for (int j = mapInfo.Selection.TopLeftY; j < mapInfo.Selection.BottomRightY; j++)
                    {
                        history.PushUndo(id, map.Layers[layerIndex].LayerId, i, j, map.Layers[layerIndex].LayerData[i, j], ActionType.Fill);
                        map.Layers[layerIndex].LayerData[i, j] = tileIndex;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void KeyboardShortCut(D2DMapEditor d2d, Map map, MapInfo mapInfo, History history, int layerIndex, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.S)
            {
                d2d.SelectTool(ToolType.selection);
            }
            else if (e.KeyCode == Keys.B)
            {
                d2d.SelectTool(ToolType.brush);
            }
            else if (e.KeyCode == Keys.E)
            {
                d2d.SelectTool(ToolType.eraser);
            }
            else if (e.KeyCode == Keys.F)
            {
                d2d.SelectTool(ToolType.fill);
            }
            else if (e.KeyCode == Keys.T)
            {
                d2d.SelectTool(ToolType.selectTile);
            }
            else if (e.KeyCode == Keys.Delete)
            {
                if (mapInfo.Selection.StartDrag.X != -1 && mapInfo.Selection.StartDrag.Y != -1 && mapInfo.Selection.StopDrag.X != -1 && mapInfo.Selection.StopDrag.Y != -1)
                {   // selection was made
                    history.ClearRedo();
                    int id = history.UndoNextId;

                    mapInfo.Selection.ForceWithinSelection(map.Layers[layerIndex].Width, map.Layers[layerIndex].Height);
                    for (int i = mapInfo.Selection.TopLeftX; i < mapInfo.Selection.BottomRightX; i++)
                    {   // delete selected tiles
                        for (int j = mapInfo.Selection.TopLeftY; j < mapInfo.Selection.BottomRightY; j++)
                        {
                            history.PushUndo(id, map.Layers[layerIndex].LayerId, i, j, map.Layers[layerIndex].LayerData[i, j], ActionType.Erase);
                            map.Layers[layerIndex].LayerData[i, j] = -1;
                        }
                    }

                    d2d.RenderMap();
                }
            }
        }
Exemplo n.º 5
0
        private void Init()
        {
            // add event handlers
            pbMap.MouseDown += new MouseEventHandler(mapPicBox_MouseDown);
            pbMap.MouseMove += new MouseEventHandler(mapPicBox_MouseMove);
            pbMap.MouseUp += new MouseEventHandler(mapPicBox_MouseUp);
            this.KeyDown += new KeyEventHandler(d2dMapEditor_KeyDown);
            this.KeyPreview = true;
            FormClosing += new FormClosingEventHandler(D2DMapEditor_FormClosing);

            // create tooltips for tools
            ToolTip toolTips = new ToolTip();
            toolTips.AutoPopDelay = 5000;
            toolTips.InitialDelay = 500;
            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)");
            toolTips.SetToolTip(btnAddLayer, "Add Layer");
            toolTips.SetToolTip(btnDeleteLayer, "Delete Layer");
            toolTips.SetToolTip(btnLayerMoveUp, "Move Up");
            toolTips.SetToolTip(btnLayerMoveDown, "Move Down");

            cbTileType.DataSource = Tile.TileTypeStr;

            lvTileLibrary.View = View.Tile;

            _map_info = new MapInfo();

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

            _history = new History();
            undoToolStripMenuItem.Enabled = false;
            redoToolStripMenuItem.Enabled = false;

            _clipboard = new Clipboard();
            pasteToolStripMenuItem.Enabled = false;

            saveMapToolStripMenuItem.Enabled = false;

            _tile_library = new Tile[0];
        }