yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_OVERWORLDEDITOR_H
2#define YAZE_APP_EDITOR_OVERWORLDEDITOR_H
3
4#include <cmath>
5#include <unordered_map>
6
7#include "absl/container/flat_hash_map.h"
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "absl/strings/str_format.h"
17#include "app/gfx/bitmap.h"
19#include "app/gfx/snes_tile.h"
20#include "app/gui/canvas.h"
21#include "app/gui/icons.h"
22#include "app/gui/zeml.h"
23#include "app/rom.h"
25#include "imgui/imgui.h"
26
27namespace yaze {
28namespace app {
29namespace editor {
30
31constexpr uint k4BPP = 4;
32constexpr uint kByteSize = 3;
33constexpr uint kMessageIdSize = 5;
34constexpr uint kNumSheetsToLoad = 223;
36constexpr uint kOverworldMapSize = 0x200;
37constexpr float kInputFieldSize = 30.f;
40constexpr ImVec2 kCurrentGfxCanvasSize(0x100 + 1, 0x10 * 0x40 + 1);
41constexpr ImVec2 kBlocksetCanvasSize(0x100 + 1, 0x2000 + 1);
42constexpr ImVec2 kGraphicsBinCanvasSize(0x100 + 1, kNumSheetsToLoad * 0x40 + 1);
43
44constexpr ImGuiTableFlags kOWMapFlags =
45 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable;
46constexpr ImGuiTableFlags kToolsetTableFlags = ImGuiTableFlags_SizingFixedFit;
47constexpr ImGuiTableFlags kOWEditFlags =
48 ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
49 ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
50 ImGuiTableFlags_BordersV;
51
52static constexpr absl::string_view kToolsetColumnNames[] = {
53 "#undoTool", "#redoTool", "#separator2", "#zoomOutTool",
54 "#zoomInTool", "#separator", "#drawTool", "#history",
55 "#entranceTool", "#exitTool", "#itemTool", "#spriteTool",
56 "#transportTool", "#musicTool", "#separator3", "#tilemapTool",
57 "propertiesTool", "#separator4", "#experimentalTool", "#properties",
58 "#separator5"};
59
60constexpr absl::string_view kWorldList =
61 "Light World\0Dark World\0Extra World\0";
62
63constexpr absl::string_view kGamePartComboString = "Part 0\0Part 1\0Part 2\0";
64
65constexpr absl::string_view kTileSelectorTab = "##TileSelectorTabBar";
66constexpr absl::string_view kOWEditTable = "##OWEditTable";
67constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
68
70 public:
71 absl::Status LoadEntranceTileTypes(Rom& rom) {
72 int offset_low = 0xDB8BF;
73 int offset_high = 0xDB917;
74
75 for (int i = 0; i < 0x2C; i++) {
76 // Load entrance tile types
77 ASSIGN_OR_RETURN(auto value_low, rom.ReadWord(offset_low + i));
78 entrance_tile_types_low_.push_back(value_low);
79 ASSIGN_OR_RETURN(auto value_high, rom.ReadWord(offset_high + i));
80 entrance_tile_types_low_.push_back(value_high);
81 }
82
83 return absl::OkStatus();
84 }
85
86 private:
87 std::vector<uint16_t> entrance_tile_types_low_;
88 std::vector<uint16_t> entrance_tile_types_high_;
89};
90
107class OverworldEditor : public Editor,
108 public SharedRom,
109 public EntranceContext,
110 public context::GfxContext,
111 public core::ExperimentFlags {
112 public:
114
115 void InitializeZeml();
116
117 absl::Status Update() final;
118 absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
119 absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
120 absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
121 absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
122 absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
123 absl::Status Find() override {
124 return absl::UnimplementedError("Find Unused Tiles");
125 }
126 absl::Status Save();
127
128 auto overworld() { return &overworld_; }
129
133 int jump_to_tab() { return jump_to_tab_; }
134 int jump_to_tab_ = -1;
135
143 absl::Status LoadGraphics();
144
145 private:
150
154 void DrawToolset();
155
161
162 void RefreshChildMap(int i);
163 void RefreshOverworldMap();
164 absl::Status RefreshMapPalette();
166 absl::Status RefreshTile16Blockset();
167
168 void DrawOverworldEntrances(ImVec2 canvas_p, ImVec2 scrolling,
169 bool holes = false);
170 void DrawOverworldExits(ImVec2 zero, ImVec2 scrolling);
171 void DrawOverworldItems();
173
174 void DrawOverworldMaps();
175 void DrawOverworldEdits();
176 void RenderUpdatedMapBitmap(const ImVec2& click_position,
177 const std::vector<uint8_t>& tile_data);
178
188
193
199 absl::Status CheckForCurrentMap();
200 void CheckForMousePan();
201
205 void DrawOverworldCanvas();
206
207 absl::Status DrawTile16Selector();
208 void DrawTile8Selector();
209 absl::Status DrawAreaGraphics();
210 absl::Status DrawTileSelector();
211
212 absl::Status LoadSpriteGraphics();
213
215
216 absl::Status UpdateUsageStats();
217 void DrawUsageGrid();
218 void DrawDebugWindow();
219
220 enum class EditingMode {
221 DRAW_TILE,
222 ENTRANCES,
223 EXITS,
224 ITEMS,
225 SPRITES,
227 MUSIC,
228 PAN
229 };
230
233
248
257 int game_state_ = 1;
261
262 bool all_gfx_loaded_ = false;
269
270 std::vector<uint8_t> selected_tile_data_;
271 std::vector<std::vector<uint8_t>> tile16_individual_data_;
272 std::vector<gfx::Bitmap> tile16_individual_;
273
274 std::vector<std::vector<uint8_t>> tile8_individual_data_;
275 std::vector<gfx::Bitmap> tile8_individual_;
276
280
282
287
291
294
296
300
303
314 absl::Status status_;
315};
316} // namespace editor
317} // namespace app
318} // namespace yaze
319
320#endif
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:145
absl::StatusOr< uint16_t > ReadWord(int offset)
Definition rom.h:264
A class to hold a shared pointer to a Rom object.
Definition rom.h:585
A class to manage experimental feature flags.
Definition common.h:30
Interface for editor classes.
Definition editor.h:39
std::vector< uint16_t > entrance_tile_types_low_
absl::Status LoadEntranceTileTypes(Rom &rom)
std::vector< uint16_t > entrance_tile_types_high_
Manage graphics group configurations in a Rom.
Manipulates the Overworld and OverworldMap data in a Rom.
zelda3::overworld::OverworldItem current_item_
std::vector< gfx::Bitmap > tile16_individual_
std::vector< std::vector< uint8_t > > tile16_individual_data_
void DrawOverworldCanvas()
Allows the user to make changes to the overworld map.
void DrawOverworldEntrances(ImVec2 canvas_p, ImVec2 scrolling, bool holes=false)
void DrawFullscreenCanvas()
Draws the canvas, tile16 selector, and toolset in fullscreen.
absl::Status CheckForCurrentMap()
Check for changes to the overworld map. Calls RefreshOverworldMap and RefreshTile16Blockset on the cu...
void CheckForSelectRectangle()
Draw and create the tile16 IDs that are currently selected.
zelda3::overworld::Overworld overworld_
std::vector< gfx::Bitmap > tile8_individual_
std::vector< std::vector< uint8_t > > tile8_individual_data_
std::vector< uint8_t > selected_tile_data_
zelda3::overworld::OverworldExit current_exit_
zelda3::overworld::OverworldEntrance current_entrance_
void DrawOverworldExits(ImVec2 zero, ImVec2 scrolling)
void RenderUpdatedMapBitmap(const ImVec2 &click_position, const std::vector< uint8_t > &tile_data)
void CheckForOverworldEdits()
Check for changes to the overworld map.
absl::Status LoadGraphics()
Load the Bitmap objects for each OverworldMap.
void DrawToolset()
Toolset for entrances, exits, items, sprites, and transports.
void DrawOverworldMapSettings()
Draws the overworld map settings. Graphics, palettes, etc.
Allows the user to view and edit in game palettes.
Popup window to edit Tile16 data.
Shared graphical context across editors.
Definition gfx_context.h:25
Represents a bitmap image.
Definition bitmap.h:70
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Represents a canvas for drawing and manipulating graphics.
Definition canvas.h:36
Base class for all overworld and dungeon entities.
Definition common.h:31
A class for managing sprites in the overworld and underworld.
Definition sprite.h:285
Represents the full Overworld data, light and dark world.
Definition overworld.h:447
unsigned int uint
Definition constants.h:120
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition constants.h:77
constexpr uint kOverworldMapSize
constexpr absl::string_view kTileSelectorTab
constexpr ImVec2 kOverworldCanvasSize(kOverworldMapSize *8, kOverworldMapSize *8)
constexpr uint k4BPP
constexpr absl::string_view kOWMapTable
constexpr ImGuiTableFlags kOWMapFlags
constexpr uint kByteSize
constexpr absl::string_view kGamePartComboString
constexpr uint kTile8DisplayHeight
constexpr uint kNumSheetsToLoad
constexpr ImVec2 kGraphicsBinCanvasSize(0x100+1, kNumSheetsToLoad *0x40+1)
constexpr uint kMessageIdSize
constexpr ImGuiTableFlags kOWEditFlags
constexpr ImGuiTableFlags kToolsetTableFlags
constexpr absl::string_view kWorldList
constexpr ImVec2 kCurrentGfxCanvasSize(0x100+1, 0x10 *0x40+1)
constexpr float kInputFieldSize
constexpr absl::string_view kOWEditTable
constexpr ImVec2 kBlocksetCanvasSize(0x100+1, 0x2000+1)
std::unordered_map< int, gfx::Bitmap > BitmapTable
Definition bitmap.h:221
std::vector< std::vector< uint16_t > > OWBlockset
Represents tile32 data for the overworld.
Definition common.h:15
Definition common.cc:21
Node for a zeml tree.
Definition zeml.h:127