yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
screen_menu_tilemap_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_SCREEN_MENU_TILEMAP_EDITOR_H_
2#define YAZE_APP_EDITOR_GRAPHICS_SCREEN_MENU_TILEMAP_EDITOR_H_
3
4#include <array>
5#include <cstdint>
6#include <string>
7#include <vector>
8
15#include "imgui/imgui.h"
16#include "rom/rom.h"
17#include "zelda3/game_data.h"
19
20namespace yaze {
21namespace project {
22struct YazeProject;
23}
24namespace editor {
25
26class UndoManager;
27
41 public:
42 // `undo_manager` and `rom`/`game_data`/`project` may be null (e.g. no ROM
43 // loaded yet); the panel degrades to "no data source" messaging rather
44 // than crashing.
45 void Draw(Rom* rom, zelda3::GameData* game_data,
46 project::YazeProject* project, UndoManager* undo_manager);
47
48 bool dirty() const { return doc_.dirty(); }
49 bool loaded() const { return loaded_; }
50 const std::string& current_path() const { return doc_.path(); }
51
52 // Test-only hook: loads a file the same way "Open..." does, without a
53 // native file dialog (ImGuiTestEngine can't drive OS dialogs). Mirrors
54 // Controller::LoadRomForTesting's naming convention.
55 absl::Status LoadFileForTesting(const std::string& path) {
56 return LoadFile(path);
57 }
58
60
61 private:
62 enum class Tool { kPaint, kSelect };
63
65 std::string label; // display label (relative path)
66 std::string full_path;
67 bool is_dirty = false; // true if this is the currently-open, dirty doc
68 };
69
70 // --- File / project ---
71 void DrawFileBar(Rom* rom, project::YazeProject* project);
73 absl::Status LoadFile(const std::string& path);
74 absl::Status SaveCurrent();
75 absl::Status SaveCurrentAs();
76 absl::Status RevertCurrent();
78
79 // --- Sources (CHR / palette) ---
80 void DrawSourceBar(Rom* rom, zelda3::GameData* game_data,
81 project::YazeProject* project);
82 absl::Status ResolveSources(Rom* rom, zelda3::GameData* game_data);
83 // Resolves palette_colors_ per palette_source_kind_ and describes the
84 // source that actually supplied it (including an Auto fallback).
85 absl::Status ResolvePaletteSource(Rom* rom, zelda3::GameData* game_data,
86 std::string* description);
88
89 // Owns a small SDL streaming texture for the reference-image overlay
90 // (arbitrary true-color PNG, unlike the indexed gfx::Bitmap used for the
91 // tilemap/picker/WRAM-dump renders).
92 void SetReferenceImage(const std::vector<uint8_t>& rgba, int width,
93 int height);
95
96 // --- Canvas / tools ---
97 void DrawToolbar();
98 void DrawMainCanvas();
99 void DrawTilePicker();
100 void DrawHoverReadout();
101 void DrawOverlayControls();
102 void DrawStatusBar();
103
104 void BeginStroke(const std::string& description);
105 // Pushes the pending stroke onto undo_manager_ (set at the top of
106 // Draw() from its parameter) if it actually changed any bytes; no-ops
107 // if undo_manager_ is null (e.g. a caller that doesn't have one).
108 void CommitStroke();
109 void RestoreSnapshot(const std::string& path,
110 const std::vector<uint8_t>& bytes);
111
112 void PaintCellAt(int row, int col);
113 void EyedropAt(int row, int col);
114
115 // --- Data ---
117 bool loaded_ = false;
118 std::string open_error_;
119
120 std::vector<FileListEntry> project_files_;
122 bool project_has_page3_ = false;
123
124 // Sources
125 enum class ChrSourceKind { kRom, kFile };
126 // kAuto (default): the ROM symbol when it resolves to real data,
127 // otherwise Menu/menu_palette.asm when the project has one (the symbol
128 // reads all zero against a base ROM such as oos168.sfc, where the table
129 // is assembled rather than stored). The other kinds are explicit.
133 std::string palette_label_ = "Oracle_Menu_Palette";
134 std::string chr_file_path_;
138 // Discovered <project>/Menu/menu_palette.asm, or a user-picked override.
139 std::string palette_asm_path_;
141 std::string asm_search_key_; // project path + code folder last searched
142 // Set when an input to the sources changed (kind, path, label, ROM);
143 // ResolveSources() runs once per change instead of every frame, even
144 // when it fails.
145 bool sources_dirty_ = true;
146 const Rom* resolved_rom_ = nullptr;
147 std::vector<uint8_t> chr_sheet_;
148 std::array<gfx::SnesColor, 32> palette_colors_{};
149 std::string source_status_; // last resolve error/status, shown in UI
150 bool sources_ready_ = false;
151 // Cached from Draw()'s parameter so BeginStroke/CommitStroke call sites
152 // elsewhere in this class don't each need it threaded through.
154
155 // Render/textures
158 std::vector<uint8_t> picker_indexed_;
161
162 // Canvas widgets
163 gui::Canvas canvas_{"##MenuTilemapCanvas", ImVec2(256, 256),
165 gui::Canvas picker_canvas_{"##MenuTilemapPicker", ImVec2(128, 448),
167 // Adaptive sheet layout (Fit/1x/2x/4x, matching the room-graphics /
168 // overworld-canvas convention introduced in #262) for the tile picker's
169 // CHR sheet, which can be a few hundred pixels tall (7 sheets * 64px).
170 gui::TileSelectorWidget tile_picker_widget_{"##MenuTilemapPickerWidget"};
173 float zoom_ = 2.0f;
174 bool show_grid_ = true;
176 ImVec2 last_canvas_screen_origin_{0.0f, 0.0f};
177
178 // Tool state
182 bool h_flip_ = false;
183 bool v_flip_ = false;
184 bool priority_ = false;
185 uint16_t erase_word_ = 0x0000;
186
187 // Rect select
188 bool selecting_ = false;
189 bool has_selection_ = false;
190 ImVec2 select_drag_start_{-1, -1};
193 bool has_clipboard_ = false;
194
195 // Stroke/undo
196 bool stroke_active_ = false;
197 std::vector<uint8_t> stroke_before_bytes_;
199
200 // Hover readout
201 bool has_hover_ = false;
202 int hover_row_ = 0;
203 int hover_col_ = 0;
204
205 // Preview overlays
206 bool show_ref_overlay_ = false;
207 float ref_opacity_ = 0.5f;
208 ImVec2 ref_nudge_{0.0f, 0.0f};
209 std::string ref_image_path_;
210 SDL_Texture* ref_texture_ = nullptr;
213 bool ref_loaded_ = false;
214
215 bool show_wram_overlay_ = false;
216 std::string wram_dump_path_;
218 bool wram_loaded_ = false;
219
221
222 // Reload-on-external-change prompt
225};
226
227} // namespace editor
228} // namespace yaze
229
230#endif // YAZE_APP_EDITOR_GRAPHICS_SCREEN_MENU_TILEMAP_EDITOR_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:49
Self-contained ImGui UI for editing a single Oracle-of-Secrets- style 2bpp BG3 menu tilemap file,...
absl::Status ResolvePaletteSource(Rom *rom, zelda3::GameData *game_data, std::string *description)
void BeginStroke(const std::string &description)
gui::AdaptiveSheetScaleMode picker_scale_mode_
zelda3::MenuTilemapDocument::Clipboard clipboard_
void DrawSourceBar(Rom *rom, zelda3::GameData *game_data, project::YazeProject *project)
void RestoreSnapshot(const std::string &path, const std::vector< uint8_t > &bytes)
zelda3::MenuTilemapDocument::Rect selection_
void Draw(Rom *rom, zelda3::GameData *game_data, project::YazeProject *project, UndoManager *undo_manager)
absl::Status LoadFileForTesting(const std::string &path)
void RefreshProjectFileList(project::YazeProject *project)
std::vector< FileListEntry > project_files_
absl::Status ResolveSources(Rom *rom, zelda3::GameData *game_data)
void SetReferenceImage(const std::vector< uint8_t > &rgba, int width, int height)
void DrawFileBar(Rom *rom, project::YazeProject *project)
std::array< gfx::SnesColor, 32 > palette_colors_
absl::Status LoadFile(const std::string &path)
Manages undo/redo stacks for a single editor.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
Reusable tile selector built on top of Canvas.
const std::string & path() const
SDL2/SDL3 compatibility layer.
Modern project structure with comprehensive settings consolidation.
Definition project.h:287