yaze 0.3.2
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 "absl/status/status.h"
5#include "app/editor/editor.h"
12#include "app/gfx/bitmap.h"
14#include "app/gfx/tilemap.h"
15#include "app/gui/canvas.h"
17#include "app/gui/input.h"
18#include "app/rom.h"
20#include "imgui/imgui.h"
21#include <mutex>
22
23namespace yaze {
24namespace editor {
25
26constexpr unsigned int k4BPP = 4;
27constexpr unsigned int kByteSize = 3;
28constexpr unsigned int kMessageIdSize = 5;
29constexpr unsigned int kNumSheetsToLoad = 223;
30constexpr unsigned int kOverworldMapSize = 0x200;
33constexpr ImVec2 kCurrentGfxCanvasSize(0x100 + 1, 0x10 * 0x40 + 1);
34constexpr ImVec2 kBlocksetCanvasSize(0x100 + 1, 0x4000 + 1);
35constexpr ImVec2 kGraphicsBinCanvasSize(0x100 + 1, kNumSheetsToLoad * 0x40 + 1);
36
37constexpr ImGuiTableFlags kOWMapFlags =
38 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable |
39 ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp;
40
41constexpr absl::string_view kWorldList =
42 "Light World\0Dark World\0Extra World\0";
43
44constexpr absl::string_view kGamePartComboString = "Part 0\0Part 1\0Part 2\0";
45
46constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
47
64class OverworldEditor : public Editor, public gfx::GfxContext {
65 public:
66 explicit OverworldEditor(Rom* rom) : rom_(rom) {
69 // MapPropertiesSystem will be initialized after maps_bmp_ and canvas are ready
70 }
71
72 void Initialize(gfx::IRenderer* renderer, Rom* rom);
73 void Initialize() override;
74 absl::Status Load() override;
75 absl::Status Update() final;
76 absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
77 absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
78 absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
79 absl::Status Copy() override;
80 absl::Status Paste() override;
81 absl::Status Find() override { return absl::UnimplementedError("Find"); }
82 absl::Status Save() override;
83 absl::Status Clear() override;
85
89 absl::Status ApplyZSCustomOverworldASM(int target_version);
90
94 absl::Status UpdateROMVersionMarkers(int target_version);
95
96 int jump_to_tab() { return jump_to_tab_; }
97 int jump_to_tab_ = -1;
98
99 // ROM state methods (from Editor base class)
100 bool IsRomLoaded() const override { return rom_ && rom_->is_loaded(); }
101 std::string GetRomStatus() const override {
102 if (!rom_) return "No ROM loaded";
103 if (!rom_->is_loaded()) return "ROM failed to load";
104 return absl::StrFormat("ROM loaded: %s", rom_->title());
105 }
106
107 // Jump-to functionality
108 void set_current_map(int map_id) {
109 if (map_id >= 0 && map_id < zelda3::kNumOverworldMaps) {
110 current_map_ = map_id;
111 current_world_ = map_id / 0x40; // Calculate which world the map belongs to
112 }
113 }
114
122 absl::Status LoadGraphics();
123
124 private:
126 void DrawToolset();
127
128 void RefreshChildMap(int map_index);
129 void RefreshOverworldMap();
130 void RefreshOverworldMapOnDemand(int map_index);
131 void RefreshChildMapOnDemand(int map_index);
132 void RefreshMultiAreaMapsSafely(int map_index, zelda3::OverworldMap* map);
133 absl::Status RefreshMapPalette();
135 absl::Status RefreshTile16Blockset();
136 void ForceRefreshGraphics(int map_index);
137 void RefreshSiblingMapGraphics(int map_index, bool include_self = false);
138
139 void DrawOverworldMaps();
140 void DrawOverworldEdits();
141 void RenderUpdatedMapBitmap(const ImVec2& click_position,
142 const std::vector<uint8_t>& tile_data);
143
153
158
159 // Selected tile IDs for rectangle operations (moved from local static)
160 std::vector<int> selected_tile16_ids_;
161
167 absl::Status CheckForCurrentMap();
168 void CheckForMousePan();
169 void DrawOverworldCanvas();
170
171 absl::Status DrawTile16Selector();
172 void DrawTile8Selector();
173 absl::Status DrawAreaGraphics();
175
176 absl::Status LoadSpriteGraphics();
177
186
193 void EnsureMapTexture(int map_index);
194
197 // SetupOverworldCanvasContextMenu removed (Phase 3B) - now handled by MapPropertiesSystem
198
199 // Canvas pan/zoom helpers (Overworld Refactoring)
200 void HandleOverworldPan();
201 void HandleOverworldZoom();
202 void ResetOverworldView();
203 void CenterOverworldView();
204
205 // Canvas Automation API integration (Phase 4)
208
209 // Tile operations for automation callbacks
210 bool AutomationSetTile(int x, int y, int tile_id);
211 int AutomationGetTile(int x, int y);
212
217
218 // Scratch space canvas methods
219 absl::Status DrawScratchSpace();
220 absl::Status SaveCurrentSelectionToScratch(int slot);
221 absl::Status LoadScratchToSelection(int slot);
222 absl::Status ClearScratchSpace(int slot);
226 void UpdateScratchBitmapTile(int tile_x, int tile_y, int tile_id, int slot = -1);
227
228 absl::Status UpdateUsageStats();
229 void DrawUsageGrid();
230 void DrawDebugWindow();
231
232 enum class EditingMode {
233 MOUSE, // Navigation, selection, entity management via context menu
234 DRAW_TILE // Tile painting mode
235 };
236
239
240 // Entity editing state (managed via context menu now)
241 enum class EntityEditMode {
242 NONE,
243 ENTRANCES,
244 EXITS,
245 ITEMS,
246 SPRITES,
248 MUSIC
249 };
250
252
267
276 int game_state_ = 1;
280
281 bool all_gfx_loaded_ = false;
291 bool current_map_lock_ = false;
297
298 // Card visibility states - Start hidden to prevent crash
301 bool show_area_gfx_ = false;
302 bool show_scratch_ = false;
303 bool show_gfx_groups_ = false;
304 bool show_usage_stats_ = false;
305 bool show_v3_settings_ = false;
306
307 // Map properties system for UI organization
308 std::unique_ptr<MapPropertiesSystem> map_properties_system_;
309 std::unique_ptr<OverworldEntityRenderer> entity_renderer_;
310
311 // Scratch space for large layouts
312 // Scratch space canvas for tile16 drawing (like a mini overworld)
315 std::array<std::array<int, 32>, 32> tile_data; // 32x32 grid of tile16 IDs
316 bool in_use = false;
317 std::string name = "Empty";
318 int width = 16; // Default 16x16 tiles
319 int height = 16;
320 // Independent selection system for scratch space
321 std::vector<ImVec2> selected_tiles;
322 std::vector<ImVec2> selected_points;
323 bool select_rect_active = false;
324 };
325 std::array<ScratchSpaceSlot, 4> scratch_spaces_;
327
329
331
336
338
343
344 std::array<gfx::Bitmap, zelda3::kNumOverworldMaps> maps_bmp_;
346 std::vector<gfx::Bitmap> sprite_previews_;
347
348 // Deferred texture creation for performance optimization
349 // Deferred texture management now handled by gfx::Arena::Get()
350
353
355
360
363
370 std::unique_ptr<gui::TileSelectorWidget> blockset_selector_;
374 gui::Canvas scratch_canvas_{"ScratchSpace", ImVec2(320, 480), gui::CanvasGridSize::k32x32};
375
376 absl::Status status_;
377};
378} // namespace editor
379} // namespace yaze
380
381#endif
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
bool is_loaded() const
Definition rom.h:197
auto title() const
Definition rom.h:201
Interface for editor classes.
Definition editor.h:82
EditorType type_
Definition editor.h:123
Manage graphics group configurations in a Rom.
Manipulates the Overworld and OverworldMap data in a Rom.
absl::Status Clear() override
std::unique_ptr< MapPropertiesSystem > map_properties_system_
zelda3::OverworldItem current_item_
zelda3::OverworldEntranceTileTypes entrance_tiletypes_
zelda3::OverworldEntrance current_entrance_
std::array< ScratchSpaceSlot, 4 > scratch_spaces_
absl::Status ApplyZSCustomOverworldASM(int target_version)
Apply ZSCustomOverworld ASM patch to upgrade ROM version.
absl::Status ClearScratchSpace(int slot)
absl::Status CheckForCurrentMap()
Check for changes to the overworld map. Calls RefreshOverworldMap and RefreshTile16Blockset on the cu...
absl::Status Cut() override
void ForceRefreshGraphics(int map_index)
std::vector< int > selected_tile16_ids_
zelda3::OverworldBlockset refresh_blockset_
absl::Status Undo() override
zelda3::GameEntity * dragged_entity_
std::array< gfx::Bitmap, zelda3::kNumOverworldMaps > maps_bmp_
void CheckForOverworldEdits()
Check for changes to the overworld map.
absl::Status UpdateROMVersionMarkers(int target_version)
Update ROM version markers and feature flags after ASM patching.
zelda3::OverworldExit current_exit_
void RefreshSiblingMapGraphics(int map_index, bool include_self=false)
void RenderUpdatedMapBitmap(const ImVec2 &click_position, const std::vector< uint8_t > &tile_data)
absl::Status SaveCurrentSelectionToScratch(int slot)
void RefreshOverworldMapOnDemand(int map_index)
On-demand map refresh that only updates what's actually needed.
absl::Status Redo() override
bool AutomationSetTile(int x, int y, int tile_id)
void RefreshMultiAreaMapsSafely(int map_index, zelda3::OverworldMap *map)
Safely refresh multi-area maps without recursion.
zelda3::Overworld & overworld()
void CheckForSelectRectangle()
Draw and create the tile16 IDs that are currently selected.
std::unique_ptr< OverworldEntityRenderer > entity_renderer_
absl::Status Load() override
void EnsureMapTexture(int map_index)
Ensure a specific map has its texture created.
absl::Status LoadScratchToSelection(int slot)
void Initialize(gfx::IRenderer *renderer, Rom *rom)
std::vector< gfx::Bitmap > sprite_previews_
std::string GetRomStatus() const override
bool IsRomLoaded() const override
void ProcessDeferredTextures()
Create textures for deferred map bitmaps on demand.
std::unique_ptr< gui::TileSelectorWidget > blockset_selector_
absl::Status Paste() override
void ScrollBlocksetCanvasToCurrentTile()
Scroll the blockset canvas to show the current selected tile16.
absl::Status LoadGraphics()
Load the Bitmap objects for each OverworldMap.
void RefreshChildMapOnDemand(int map_index)
On-demand child map refresh with selective updates.
absl::Status Find() override
zelda3::GameEntity * current_entity_
void UpdateScratchBitmapTile(int tile_x, int tile_y, int tile_id, int slot=-1)
Allows the user to view and edit in game palettes.
Popup window to edit Tile16 data.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:66
Shared graphical context across editors.
Defines an abstract interface for all rendering operations.
Definition irenderer.h:35
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:54
Base class for all overworld and dungeon entities.
Definition common.h:19
Represents a single Overworld map screen.
Represents the full Overworld data, light and dark world.
Definition overworld.h:135
A class for managing sprites in the overworld and underworld.
Definition sprite.h:279
constexpr ImVec2 kOverworldCanvasSize(kOverworldMapSize *8, kOverworldMapSize *8)
constexpr absl::string_view kOWMapTable
constexpr ImGuiTableFlags kOWMapFlags
constexpr unsigned int kOverworldMapSize
constexpr absl::string_view kWorldList
constexpr absl::string_view kGamePartComboString
constexpr unsigned int kNumSheetsToLoad
constexpr ImVec2 kCurrentGfxCanvasSize(0x100+1, 0x10 *0x40+1)
constexpr ImVec2 kBlocksetCanvasSize(0x100+1, 0x4000+1)
constexpr ImVec2 kGraphicsBinCanvasSize(0x100+1, kNumSheetsToLoad *0x40+1)
constexpr unsigned int kByteSize
constexpr unsigned int k4BPP
constexpr unsigned int kMessageIdSize
std::unordered_map< int, gfx::Bitmap > BitmapTable
Definition bitmap.h:333
constexpr int kNumOverworldMaps
Definition overworld.h:119
std::vector< std::vector< uint16_t > > OverworldBlockset
Represents tile32 data for the overworld.
Main namespace for the application.
std::array< std::array< int, 32 >, 32 > tile_data
Tilemap structure for SNES tile-based graphics management.
Definition tilemap.h:109