Ejemplo 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;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        public Boolean CopyToClipboard(Map map, MapInfo mapInfo, History history, int layerIndex, bool isCut)
        {   // return true if
            if (mapInfo.Selection.StartDrag.X != -1 && mapInfo.Selection.StartDrag.Y != -1 && mapInfo.Selection.StopDrag.X != -1 && mapInfo.Selection.StopDrag.Y != -1)
            {
                ClearClipboard();

                if (mapInfo.Selection.BottomRightX > map.Layers[layerIndex].Width)
                {
                    mapInfo.Selection.BottomRightX = map.Layers[layerIndex].Width;
                }
                if (mapInfo.Selection.BottomRightY > map.Layers[layerIndex].Height)
                {
                    mapInfo.Selection.BottomRightY = map.Layers[layerIndex].Height;
                }

                int newX = 0;
                int newY = 0;

                int id = -1;
                if (isCut)
                {
                    history.ClearRedo();
                    id = history.UndoNextId;
                }

                for (int i = mapInfo.Selection.TopLeftX; i < mapInfo.Selection.BottomRightX; i++)
                {   // copy selected tiles
                    for (int j = mapInfo.Selection.TopLeftY; j < mapInfo.Selection.BottomRightY; j++)
                    {
                        Data.Add(new ClipboardNode(map.Layers[layerIndex].LayerId, newX, newY, map.Layers[layerIndex].LayerData[i, j]));

                        if (isCut)
                        {   // cut tile
                            history.PushUndo(id, map.Layers[layerIndex].LayerId, i, j, map.Layers[layerIndex].LayerData[i, j], ActionType.Cut);
                            map.Layers[layerIndex].LayerData[i, j] = -1;
                        }

                        newY++;
                    }
                    newX++;
                }

                Width  = mapInfo.Selection.BottomRightX - mapInfo.Selection.TopLeftX;
                Height = mapInfo.Selection.BottomRightY - mapInfo.Selection.TopLeftY;

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
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;
                    }
                }
            }
        }
Ejemplo n.º 5
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;
                    }
                }
            }
        }
Ejemplo n.º 6
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();
                }
            }
        }
Ejemplo n.º 7
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();
                }
            }
        }