public static void Selection(D2DMapEditor d2d, Map map, MapInfo mapInfo, int layerIndex, SelectionState state) { switch (state) { case SelectionState.StartSelection: mapInfo.Selection = new SelectionTool(); mapInfo.Selection.IsDragging = true; mapInfo.Selection.StartDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); mapInfo.Selection.StopDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); break; case SelectionState.Dragging: if (mapInfo.Selection.IsDragging) { mapInfo.Selection.StopDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); d2d.RenderMap(); } break; case SelectionState.EndSelection: mapInfo.Selection.IsDragging = false; mapInfo.Selection.StopDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); d2d.RenderMap(); break; case SelectionState.SelectAll: mapInfo.Selection = new SelectionTool(); mapInfo.Selection.StartDrag = new Point(0, 0); mapInfo.Selection.StopDrag = new Point(map.Layers[layerIndex].Width, map.Layers[layerIndex].Height); d2d.RenderMap(); break; case SelectionState.ClearSelection: mapInfo.Selection = new SelectionTool(); break; default: break; } }
public static void DeleteSelectedTile(D2DMapEditor d2d, Map map, ref Tile[] tileLibrary, Panel pnlTileLibrary, int selectedTileID) { // remove selected tile from tile library if (tileLibrary != null) { // remove that tile int i = 0; for (i = selectedTileID; i < tileLibrary.Length - 1; i++) { tileLibrary[i].TileWidth = tileLibrary[i + 1].TileWidth; tileLibrary[i].TileHeight = tileLibrary[i + 1].TileHeight; tileLibrary[i].TilePath = tileLibrary[i + 1].TilePath; tileLibrary[i].TileWalkable = tileLibrary[i + 1].TileWalkable; tileLibrary[i].TilePictureBox = tileLibrary[i + 1].TilePictureBox; if (tileLibrary[i + 1].TileName == tileLibrary[i + 1].TileID.ToString()) { tileLibrary[i].TileName = tileLibrary[i].TileID.ToString(); } else { tileLibrary[i].TileName = tileLibrary[i + 1].TileName; } //tileLibrary[i].TileID = i; } Array.Clear(tileLibrary, i, 1); Array.Resize(ref tileLibrary, tileLibrary.Length - 1); } // update map foreach (Layer layer in map.Layers) { for (int x = 0; x < layer.Width; x++) { for (int y = 0; y < layer.Height; y++) { if (layer.LayerData[x, y] == selectedTileID) { layer.LayerData[x, y] = -1; } else if (layer.LayerData[x, y] > selectedTileID) { layer.LayerData[x, y] = layer.LayerData[x, y] - 1; } } } } RenderTiles(map, ref tileLibrary, pnlTileLibrary); d2d.RenderMap(); d2d.ClearSelectedTile(); }
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(); } } }
private void btnCreateNewMap_Click(object sender, EventArgs e) { // create new map if (tbNewMapName.Text == "") { MessageBox.Show("Please provide the map name"); } else if (nudNewMapWidth.Value < 1 || nudNewMapHeight.Value < 1 || nudNewTileWidth.Value < 1 || nudNewTileHeight.Value < 1) { MessageBox.Show("Please set the appropriate map size"); } else { _parent_form.SetupMap(tbNewMapName.Text, Convert.ToInt32(nudNewMapWidth.Value), Convert.ToInt32(nudNewMapHeight.Value), Convert.ToInt32(nudNewTileWidth.Value), Convert.ToInt32(nudNewTileHeight.Value)); _parent_form.ClearTiles(); _parent_form.ReloadLayers(0); _parent_form.RenderMap(); this.Close(); } }
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 static void Selection(D2DMapEditor d2d, Map map, MapInfo mapInfo, int layerIndex, SelectionState state) { switch (state) { case SelectionState.StartSelection: mapInfo.Selection = new SelectionTool(); mapInfo.Selection.IsDragging = true; mapInfo.Selection.StartDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); mapInfo.Selection.StopDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); break; case SelectionState.Dragging: if (mapInfo.Selection.IsDragging) { mapInfo.Selection.StopDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); d2d.RenderMap(); } break; case SelectionState.EndSelection: mapInfo.Selection.IsDragging = false; mapInfo.Selection.StopDrag = new Point(InputHelper.MapPosition.X, InputHelper.MapPosition.Y); d2d.RenderMap(); break; case SelectionState.SelectAll: mapInfo.Selection = new SelectionTool(); mapInfo.Selection.StartDrag = new Point(0, 0); mapInfo.Selection.StopDrag = new Point(map.Layers[layerIndex].Width, map.Layers[layerIndex].Height); d2d.RenderMap(); break; case SelectionState.ClearSelection: mapInfo.Selection = new SelectionTool(); break; default: break; } }
public static void DeleteSelectedTile(D2DMapEditor d2d, Map map, ref Tile[] tileLibrary, ListView lvTileLibrary, ImageList ilTileImages, int selectedTileID) { // remove selected tile from tile library if (tileLibrary != null) { // remove that tile int i = 0; for (i = selectedTileID; i < tileLibrary.Length - 1; i++) { tileLibrary[i].TileWidth = tileLibrary[i + 1].TileWidth; tileLibrary[i].TileHeight = tileLibrary[i + 1].TileHeight; tileLibrary[i].TilePath = tileLibrary[i + 1].TilePath; tileLibrary[i].TileWalkable = tileLibrary[i + 1].TileWalkable; tileLibrary[i].TilePictureBox = tileLibrary[i + 1].TilePictureBox; tileLibrary[i].TilePictureBox.Name = tileLibrary[i].TileName; //if (tileLibrary[i + 1].TileName == tileLibrary[i + 1].TileID.ToString()) // tileLibrary[i].TileName = tileLibrary[i].TileID.ToString(); //else // tileLibrary[i].TileName = tileLibrary[i + 1].TileName; //tileLibrary[i].TileID = i; } Array.Clear(tileLibrary, i, 1); Array.Resize(ref tileLibrary, tileLibrary.Length - 1); //ilTileImages.Images.RemoveAt(selectedTileID); lvTileLibrary.Items.RemoveAt(selectedTileID); } // update map foreach (Layer layer in map.Layers) { for (int x = 0; x < layer.Width; x++) { for (int y = 0; y < layer.Height; y++) { if (layer.LayerData[x, y] == selectedTileID) { layer.LayerData[x, y] = -1; } else if (layer.LayerData[x, y] > selectedTileID) { layer.LayerData[x, y] = layer.LayerData[x, y] - 1; } } } } //RenderTiles(map, ref tileLibrary, lvTileLibrary); lvTileLibrary.Refresh(); d2d.RenderMap(); d2d.ClearSelectedTile(); }