yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
screen_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SCREEN_EDITOR_H
2#define YAZE_APP_EDITOR_SCREEN_EDITOR_H
3
4#include <array>
5#include <memory>
6
7#include "absl/status/status.h"
8#include "app/editor/editor.h"
12#include "app/gfx/core/bitmap.h"
17#include "imgui/imgui.h"
18#include "rom/rom.h"
23
24namespace yaze {
25namespace editor {
26
39class ScreenEditor : public Editor {
40 public:
41 explicit ScreenEditor(Rom* rom = nullptr) : rom_(rom) {
42 screen_canvas_.SetCanvasSize(ImVec2(512, 512));
44 }
45
46 void Initialize() override;
47 absl::Status Load() override;
48 absl::Status Update() override;
49 absl::Status Undo() override { return undo_manager_.Undo(); }
50 absl::Status Redo() override { return undo_manager_.Redo(); }
51 absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
52 absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
53 absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
54 absl::Status Find() override { return absl::UnimplementedError("Find"); }
55 absl::Status Save() override;
56 // Pure preflight, also used before any coordinated serializer runs. Only
57 // pending map records are admitted; a clean editor produces no writes.
58 absl::StatusOr<zelda3::DungeonMapWritePlan> PrepareDungeonMapSave() const;
59 absl::Status BeginSaveTransaction() override;
60 void RollbackSaveTransaction() override;
61 void CommitSaveTransaction() override;
62 void set_rom(Rom* rom) { rom_ = rom; }
63 Rom* rom() const { return rom_; }
64
65 // Cheap contribution: just the currently-open menu tilemap file name and
66 // dirty state, appended to the base Screen category snapshot. Skips
67 // entirely (falls through to Editor::BuildContextSnapshot()) when no
68 // tilemap is loaded, so this never does I/O or ROM work.
70
71 // Test-only hook (see MenuTilemapEditorUI::LoadFileForTesting): loads a
72 // tilemap file directly, bypassing the native "Open..." file dialog that
73 // ImGuiTestEngine can't drive.
74 absl::Status LoadMenuTilemapForTesting(const std::string& path) {
76 }
79 return menu_tilemap_ui_.loaded();
80 }
81
101 absl::Status RefreshRomBackedState();
103 // Opens the selected ROM-backed Dungeon Map / Tiles Gfx tile in Graphics.
104 // BIN graphics and unavailable same-session sheets fail without navigation.
105 absl::Status OpenDungeonMapTileGraphics();
106
107 std::vector<zelda3::DungeonMap> dungeon_maps_;
108
109 private:
114
118
122 void DrawToolset();
125
126 // Title screen layer editing
131
132 absl::Status LoadDungeonMapTile16(const std::vector<uint8_t>& gfx_data,
133 bool bin_mode = false);
134
135 void DrawDungeonMapScreen(int i);
136 void DrawDungeonMapsTabs();
140
141 void LoadBinaryGfx();
142 gfx::Bitmap* GetOrCreateSheet(int index);
144 bool HasValidDungeonSelection() const;
145 bool HasValidDungeonFloorSelection(int floor) const;
146
147 absl::Status ChangeDungeonMapFloorCount(bool basement, bool add);
148
149 // Undo/redo helpers
152 void SaveDungeonMapUndoState(const std::string& description);
153 void SaveTile16CompUndoState(const std::string& description);
156 void RestoreFromSnapshot(const ScreenSnapshot& snapshot);
167 absl::Status SaveTitleScreenToRom();
168 absl::Status SaveOverworldMapToRom();
169
170 enum class EditingMode { DRAW, EDIT };
171
173
174 bool binary_gfx_loaded_ = false;
175
176 uint8_t selected_room = 0;
177
182 bool select_floor_tab_ = true;
183
186
188
192 gfx::Tilemap tile8_tilemap_; // Tilemap for 8x8 tiles with on-demand caching
193 std::array<gfx::TileInfo, 4> current_tile16_info;
194
195 gui::Canvas current_tile_canvas_{"##CurrentTileCanvas", ImVec2(32, 32),
199 gui::Canvas tilemap_canvas_{"##TilemapCanvas", ImVec2(128 + 2, (192) + 4),
201
202 // Title screen canvases
203 // Title screen is 32x32 tiles at 8x8 pixels = 256x256 pixels total
204 gui::Canvas title_bg1_canvas_{"##TitleBG1Canvas", ImVec2(256, 256),
206 gui::Canvas title_bg2_canvas_{"##TitleBG2Canvas", ImVec2(256, 256),
208 // Blockset is 128 pixels wide x 512 pixels tall (16x64 8x8 tiles)
209 gui::Canvas title_blockset_canvas_{"##TitleBlocksetCanvas", ImVec2(128, 512),
211
212 std::unique_ptr<zelda3::Inventory> inventory_ =
213 std::make_unique<zelda3::Inventory>();
214 bool inventory_loaded_ = false;
218
219 // Title screen state
222 bool title_h_flip_ = false;
223 bool title_v_flip_ = false;
225 bool show_title_bg1_ = true;
226 bool show_title_bg2_ = true;
227
228 // Overworld map screen state
230 bool ow_map_loaded_ = false;
232
233 // Overworld map canvases
234 gui::Canvas ow_map_canvas_{"##OWMapCanvas", ImVec2(512, 512),
236 gui::Canvas ow_tileset_canvas_{"##OWTilesetCanvas", ImVec2(128, 128),
238
239 // Undo/redo pending state
248 Rom* loaded_rom_ = nullptr;
256
258 absl::Status status_;
259};
260
261} // namespace editor
262} // namespace yaze
263
264#endif
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
Interface for editor classes.
Definition editor.h:249
UndoManager undo_manager_
Definition editor.h:371
EditorType type_
Definition editor.h:369
Self-contained ImGui UI for editing a single Oracle-of-Secrets- style 2bpp BG3 menu tilemap file,...
absl::Status LoadFileForTesting(const std::string &path)
The ScreenEditor class allows the user to edit a variety of screens in the game or create a custom me...
absl::Status LoadDungeonMapTile16(const std::vector< uint8_t > &gfx_data, bool bin_mode=false)
void DrawDungeonMapsRoomGfx()
Draw dungeon room graphics editor with enhanced tile16 editing.
absl::Status RefreshRomBackedState()
void RollbackSaveTransaction() override
absl::Status Undo() override
ScreenSnapshot CaptureTile16CompSnapshot() const
absl::Status SaveOverworldMapToRom()
gfx::Bitmap * GetOrCreateSheet(int index)
friend class ScreenEditorSaveStoplossTestPeer
absl::Status ChangeDungeonMapFloorCount(bool basement, bool add)
ScreenSnapshot pending_dungeon_before_
bool HasPendingOverworldMapChanges() const
absl::Status OpenDungeonMapTileGraphics()
absl::Status Paste() override
bool HasPendingDungeonMapChanges() const
absl::Status Cut() override
MenuTilemapEditorUI menu_tilemap_ui_
std::array< gfx::TileInfo, 4 > current_tile16_info
absl::Status Save() override
absl::Status Load() override
void SaveDungeonMapUndoState(const std::string &description)
absl::Status Update() override
bool HasValidDungeonFloorSelection(int floor) const
absl::Status Copy() override
friend class ScreenGraphicsContextTestPeer
absl::Status Find() override
void RestoreFromSnapshot(const ScreenSnapshot &snapshot)
zelda3::OverworldMapScreen ow_map_screen_
ScreenSnapshot pending_tile16_before_
absl::Status LoadMenuTilemapForTesting(const std::string &path)
ScreenSnapshot CaptureDungeonMapSnapshot() const
void DrawDungeonMapsEditor()
Draw dungeon maps editor with enhanced ROM hacking features.
absl::StatusOr< zelda3::DungeonMapWritePlan > PrepareDungeonMapSave() const
zelda3::GameData * loaded_game_data_
absl::Status Redo() override
absl::Status BeginSaveTransaction() override
void SaveTile16CompUndoState(const std::string &description)
bool HasPendingDungeonMapTile16Changes() const
bool IsMenuTilemapLoadedForTesting() const
friend class ScreenFloorMutationTestPeer
ScreenEditor(Rom *rom=nullptr)
absl::Status SaveTitleScreenToRom()
bool HasPendingTitleScreenChanges() const
zelda3::TitleScreen title_screen_
bool IsMenuTilemapDirtyForTesting() const
std::unique_ptr< zelda3::Inventory > inventory_
zelda3::DungeonMapLabels dungeon_map_labels_
bool HasPendingScreenChanges() const
friend class AuthoringSaveWorkflowTestPeer
EditorContextSnapshot BuildContextSnapshot() const override
void RefreshTileCacheForReload(gfx::Tilemap &tilemap)
void CommitSaveTransaction() override
std::vector< zelda3::DungeonMap > dungeon_maps_
absl::Status Redo()
Redo the top action. Returns error if stack is empty.
absl::Status Undo()
Undo the top action. Returns error if stack is empty.
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:70
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Modern, robust canvas for drawing and manipulating graphics.
Definition canvas.h:64
void SetCanvasSize(ImVec2 canvas_size)
Definition canvas.h:388
OverworldMapScreen manages the overworld map (pause menu) graphics.
TitleScreen manages the title screen graphics and tilemap data.
std::unordered_map< int, std::unique_ptr< gfx::Bitmap > > BitmapTable
Definition bitmap.h:549
std::array< std::vector< std::array< std::string, kNumRooms > >, kNumDungeons > DungeonMapLabels
Definition dungeon_map.h:72
Unified screen editor snapshot.
Tilemap structure for SNES tile-based graphics management.
Definition tilemap.h:118