yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_room_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ROOM_PANEL_H_
2#define YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ROOM_PANEL_H_
3
4#include <functional>
5#include <string>
6#include "util/i18n/tr.h"
7
8#include "absl/strings/str_format.h"
12#include "app/gui/core/icons.h"
13#include "imgui/imgui.h"
14#include "zelda3/dungeon/room.h"
16
17namespace yaze {
18namespace editor {
19
39 public:
48 DungeonRoomPanel(size_t session_id, int room_id, zelda3::Room* room,
49 DungeonCanvasViewer* canvas_viewer,
50 DungeonRoomLoader* room_loader)
52 room_(room),
53 canvas_viewer_(canvas_viewer),
54 room_loader_(room_loader) {
55 session_id_ = session_id;
56 }
57
58 // ==========================================================================
59 // ResourceWindowContent Identity
60 // ==========================================================================
61
62 int GetResourceId() const override { return room_id_; }
63 std::string GetResourceType() const override { return "room"; }
64
65 std::string GetResourceName() const override {
66 // Use unified ResourceLabelProvider for room names
67 return absl::StrFormat("[%03X] %s", room_id_,
69 }
70
71 std::string GetIcon() const override { return ICON_MD_GRID_ON; }
72 std::string GetEditorCategory() const override { return "Dungeon"; }
73 int GetPriority() const override { return 100 + room_id_; }
74 std::string GetWorkflowGroup() const override { return "Rooms"; }
75
76 // ==========================================================================
77 // WindowContent Drawing
78 // ==========================================================================
79
80 void Draw(bool* p_open) override {
81 if (!room_ || !canvas_viewer_) {
82 ImGui::TextColored(ImVec4(1, 0, 0, 1), tr("Room data unavailable"));
83 return;
84 }
85
86 // Lazy load room data
87 if (!room_->IsLoaded() && room_loader_) {
88 auto status = room_loader_->LoadRoom(room_id_, *room_);
89 if (!status.ok()) {
90 ImGui::TextColored(ImVec4(1, 0, 0, 1), tr("Failed to load room: %s"),
91 status.message().data());
92 return;
93 }
94 }
95
96 // Initialize room graphics if needed
97 if (room_->IsLoaded()) {
98 bool needs_render = false;
99
100 if (room_->blocks().empty()) {
102 needs_render = true;
103 }
104
105 if (!room_->AreObjectsLoaded()) {
107 needs_render = true;
108 }
109
110 auto& bg1_bitmap = room_->bg1_buffer().bitmap();
111 if (needs_render || !bg1_bitmap.is_active() || bg1_bitmap.width() == 0) {
113 }
114 }
115
116 // Room status header
117 if (room_->IsLoaded()) {
118 ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f),
119 ICON_MD_CHECK " Loaded");
120 } else {
121 ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f),
122 ICON_MD_PENDING " Loading...");
123 }
124 ImGui::SameLine();
125 ImGui::TextDisabled(tr("Objects: %zu"), room_->GetTileObjects().size());
126
127 // Room Controls
128 if (ImGui::CollapsingHeader(tr("Room Controls"))) {
129 if (ImGui::Button(ICON_MD_REFRESH " Reload Graphics & Objects",
130 ImVec2(-FLT_MIN, 0))) {
132 }
133
134 if (ImGui::Button(ICON_MD_CLEANING_SERVICES " Clear Room Buffers",
135 ImVec2(-FLT_MIN, 0))) {
137 }
138
139 ImGui::Separator();
140 ImGui::Text(tr("Floor Graphics Override:"));
141
142 uint8_t floor1 = room_->floor1();
143 uint8_t floor2 = room_->floor2();
144 static uint8_t floor_min = 0;
145 static uint8_t floor_max = 15;
146
147 bool changed = false;
148 if (ImGui::SliderScalar("Floor1", ImGuiDataType_U8, &floor1, &floor_min,
149 &floor_max)) {
150 room_->set_floor1(floor1);
151 changed = true;
152 }
153 if (ImGui::SliderScalar("Floor2", ImGuiDataType_U8, &floor2, &floor_min,
154 &floor_max)) {
155 room_->set_floor2(floor2);
156 changed = true;
157 }
158
159 if (changed && room_->rom() && room_->rom()->is_loaded()) {
161 }
162 }
163
164 ImGui::Separator();
165
166 // Draw the room canvas
168 }
169
170 // ==========================================================================
171 // ResourceWindowContent Lifecycle
172 // ==========================================================================
173
174 void OnResourceModified() override {
175 // Re-render room when modified externally
176 if (room_ && room_->IsLoaded()) {
178 }
179 }
180
181 // ==========================================================================
182 // Panel-Specific Methods
183 // ==========================================================================
184
185 zelda3::Room* room() const { return room_; }
186 int room_id() const { return room_id_; }
187
188 private:
189 int room_id_ = 0;
190 zelda3::Room* room_ = nullptr;
193};
194
195} // namespace editor
196} // namespace yaze
197
198#endif // YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ROOM_PANEL_H_
Manages loading and saving of dungeon room data.
absl::Status LoadRoom(int room_id, zelda3::Room &room)
ResourceWindowContent for editing individual dungeon rooms.
std::string GetIcon() const override
Material Design icon for this panel.
std::string GetResourceName() const override
Human-readable resource name.
std::string GetWorkflowGroup() const override
Optional workflow group for hack-centric actions.
int GetResourceId() const override
The numeric ID of the resource.
std::string GetResourceType() const override
The resource type name.
DungeonRoomPanel(size_t session_id, int room_id, zelda3::Room *room, DungeonCanvasViewer *canvas_viewer, DungeonRoomLoader *room_loader)
Construct a room panel.
DungeonCanvasViewer * canvas_viewer_
void OnResourceModified() override
Called when resource data changes externally.
int GetPriority() const override
Get display priority for menu ordering.
std::string GetEditorCategory() const override
Editor category this panel belongs to.
void Draw(bool *p_open) override
Draw the panel content.
Base class for windows that edit specific ROM resources.
size_t session_id_
Session ID for multi-ROM editing (0 = single session)
void ClearTileObjects()
Definition room.h:411
void set_floor2(uint8_t value)
Definition room.h:984
void set_floor1(uint8_t value)
Definition room.h:977
bool IsLoaded() const
Definition room.h:919
void ReloadGraphics(std::optional< uint8_t > entrance_blockset=std::nullopt)
Definition room.cc:969
uint8_t floor2() const
Definition room.h:976
auto rom() const
Definition room.h:1007
void RenderRoomGraphics()
Definition room.cc:1122
void LoadRoomGraphics(std::optional< uint8_t > entrance_blockset=std::nullopt)
Definition room.cc:876
auto & bg1_buffer()
Definition room.h:1039
const std::vector< RoomObject > & GetTileObjects() const
Definition room.h:405
auto blocks() const
Definition room.h:1005
void LoadObjects()
Definition room.cc:1755
bool AreObjectsLoaded() const
Definition room.h:921
uint8_t floor1() const
Definition room.h:975
#define ICON_MD_CHECK
Definition icons.h:397
#define ICON_MD_REFRESH
Definition icons.h:1572
#define ICON_MD_GRID_ON
Definition icons.h:896
#define ICON_MD_CLEANING_SERVICES
Definition icons.h:415
#define ICON_MD_PENDING
Definition icons.h:1398
std::string GetRoomLabel(int id)
Convenience function to get a room label.