private void Map_GridBox_MouseMove(object sender, MouseEventArgs e) { if (Tileset_GridBox.SelectionIsEmpty()) { Map_GridBox.Hover = new bool[1, 1] { { false } }; } else if (Tool_Tile_Button.Checked) { Rectangle selection = Tileset_GridBox.GetSelectionRectangle(); Map_GridBox.Hover = new bool[selection.Width, selection.Height]; for (int y = 0; y < selection.Height; y++) { for (int x = 0; x < selection.Width; x++) { Map_GridBox.Hover[x, y] = Tileset_GridBox.Selection[selection.X + x, selection.Y + y]; } } } else { Map_GridBox.Hover = new bool[1, 1] { { true } }; } }
void Core_TileTool() { Rectangle selection = Tileset_GridBox.GetSelectionRectangle(); if (Changes_CheckBox.Checked) { for (int y = 0; y < selection.Height; y++) { for (int x = 0; x < selection.Width; x++) { if (Map_GridBox.Hovered.X + x < 0 || Map_GridBox.Hovered.X + x >= CurrentMap.WidthTiles || Map_GridBox.Hovered.Y + y < 0 || Map_GridBox.Hovered.Y + y >= CurrentMap.HeightTiles) { continue; } if (Map_GridBox.Hover[x, y]) { CurrentMap.Changes.SetTile( Changes_NumBox.Value, Map_GridBox.Hovered.X + x, Map_GridBox.Hovered.Y + y, (selection.X + x) + (selection.Y + y) * 32); } } } Core.SuspendUpdate(); Core_WriteMapChanges(); Core.ResumeUpdate(); } else if (Map_GridBox.Hover != null) { for (int y = 0; y < selection.Height; y++) { for (int x = 0; x < selection.Width; x++) { if (Map_GridBox.Hovered.X + x < 0 || Map_GridBox.Hovered.X + x >= CurrentMap.WidthTiles || Map_GridBox.Hovered.Y + y < 0 || Map_GridBox.Hovered.Y + y >= CurrentMap.HeightTiles) { continue; } if (Map_GridBox.Hover[x, y]) { CurrentMap.Layout[Map_GridBox.Hovered.X + x, Map_GridBox.Hovered.Y + y] = (selection.X + x) + (selection.Y + y) * 32; } } } } }
void Core_LoadTerrainValues() { Tileset_GridBox.SelectionChanged -= Tileset_GridBox_SelectionChanged; Terrain_Name_ShortBox.ValueChanged -= Terrain_Name_ShortBox_ValueChanged; Terrain_Stat_ByteBox.ValueChanged -= Terrain_Stat_ByteBox_ValueChanged; Terrain_Class_ByteBox.ValueChanged -= Terrain_Class_ByteBox_ValueChanged; try { int entry = Terrain_ArrayBox.Value; Terrain_Name_ShortBox.Value = CurrentTerrainNames[entry]; Terrain_Stat_ByteBox.Value = Core.ReadByte(Terrain_Stat_PointerArrayBox.Value + entry); Terrain_Class_ByteBox.Value = Core.ReadByte(Terrain_Class_PointerArrayBox.Value + entry); int x = 0; int y = 0; for (int i = 0; i < CurrentTileset.Terrain.Length; i++) { if (CurrentTileset.Terrain[i] == entry) { Tileset_GridBox.Selection[x, y] = true; } else { Tileset_GridBox.Selection[x, y] = false; } x++; if (x == 32) { x = 0; y++; } } Tileset_GridBox.Invalidate(); } catch (Exception ex) { Program.ShowError("There has been an error trying to load the terrain values.", ex); } Tileset_GridBox.SelectionChanged += Tileset_GridBox_SelectionChanged; Terrain_Name_ShortBox.ValueChanged += Terrain_Name_ShortBox_ValueChanged; Terrain_Stat_ByteBox.ValueChanged += Terrain_Stat_ByteBox_ValueChanged; Terrain_Class_ByteBox.ValueChanged += Terrain_Class_ByteBox_ValueChanged; Terrain_Name_MagicButton.EntryToSelect = Terrain_Name_ShortBox.Value; }
void Core_LoadTileset() { try { CurrentTileset = new MapTileset( Core.ReadData(Palette_PointerBox.Value, Map.PALETTES * Palette.LENGTH), Core.ReadData(Tileset1_PointerBox.Value, 0), Core.ReadData(Tileset2_PointerBox.Value, 0), Core.ReadData(TilesetTSA_PointerBox.Value, 0)); Tileset_GridBox.SelectionChanged -= Tileset_GridBox_SelectionChanged; Tileset_GridBox.Load(CurrentTileset); Tileset_GridBox.SelectionChanged += Tileset_GridBox_SelectionChanged; } catch (Exception ex) { Program.ShowError("Could not load the map tileset.", ex); } }
void Core_LoadTileset() { try { byte[] palette_data = Core.ReadData(Palette_PointerBox.Value, Map.PALETTES * GBA.Palette.LENGTH); CurrentTileset = new MapTileset(palette_data, Core.ReadData(Tileset1_PointerBox.Value, 0), Core.ReadData(Tileset2_PointerBox.Value, 0), Core.ReadData(TilesetTSA_PointerBox.Value, 0)); Tileset_GridBox.Load(CurrentTileset); Palette_PaletteBox.Load(new GBA.Palette(palette_data, Map.PALETTES * GBA.Palette.MAX)); } catch (Exception ex) { CurrentTileset = null; Program.ShowError("Could not load the the tileset for this chapter.", ex); } }
void Core_FillTool() { Rectangle selection = Tileset_GridBox.GetSelectionRectangle(); int[] tiles = new int[Tileset_GridBox.GetSelectionAmount()]; int index = 0; for (int y = 0; y < selection.Height; y++) { for (int x = 0; x < selection.Width; x++) { if (Tileset_GridBox.Selection[selection.X + x, selection.Y + y]) { tiles[index++] = (selection.X + x) + (selection.Y + y) * 32; } } } if (tiles.Length == 0) { Program.ShowMessage("No tile is selected in the tileset."); } else { Point start = Map_GridBox.Hovered; bool[,] map = new bool[CurrentMap.WidthTiles, CurrentMap.HeightTiles]; int tile = CurrentMap.Layout[start.X, start.Y]; Core_FillHelper(ref map, ref tile, start.X, start.Y); Random random = new Random(); for (int y = 0; y < CurrentMap.HeightTiles; y++) { for (int x = 0; x < CurrentMap.WidthTiles; x++) { if (map[x, y]) { CurrentMap.Layout[x, y] = tiles[random.Next(tiles.Length)]; } } } } }