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; } }
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; } } }
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); }
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; } } } }
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(); } } }
public Boolean PasteClipboard(Map map, MapInfo mapInfo, History history, int layerIndex) { if (mapInfo.Selection.StartDrag.X != -1 && mapInfo.Selection.StartDrag.Y != -1 && mapInfo.Selection.StopDrag.X != -1 && mapInfo.Selection.StopDrag.Y != -1) { if (Data.Count < 1) { return(false); } 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; } history.Redo.Clear(); int id = history.UndoNextId; int pasteEndX = mapInfo.Selection.TopLeftX + Width; int pasteEndY = mapInfo.Selection.TopLeftY + Height; //if (mapInfo.Selection.BottomRightX > pasteEndX) // pasteEndX = mapInfo.Selection.BottomRightX - ((mapInfo.Selection.BottomRightX - mapInfo.Selection.TopLeftX) % Width); //if (mapInfo.Selection.BottomRightY > pasteEndY) // pasteEndY = mapInfo.Selection.BottomRightY - ((mapInfo.Selection.BottomRightY - mapInfo.Selection.TopLeftY) % Height); if (pasteEndX > map.Layers[layerIndex].Width) { return(false); } if (pasteEndY > map.Layers[layerIndex].Height) { return(false); } int pos = 0; for (int i = mapInfo.Selection.TopLeftX; i < pasteEndX; i++) { // paste copied tiles for (int j = mapInfo.Selection.TopLeftY; j < pasteEndY; j++) { if (map.Layers[layerIndex].LayerData[i, j] != ((ClipboardNode)Data[pos]).Value) { history.PushUndo(id, map.Layers[layerIndex].LayerId, i, j, map.Layers[layerIndex].LayerData[i, j], ActionType.Paste); map.Layers[layerIndex].LayerData[i, j] = ((ClipboardNode)Data[pos]).Value; } pos++; pos = pos % Data.Count; //pos = pos % ((pasteEndX - i) * Height); } } return(true); } else { MessageBox.Show("No selection", "Paste", MessageBoxButtons.OK, MessageBoxIcon.Stop); } return(false); }