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
7#include "absl/strings/str_format.h"
11#include "app/gui/core/icons.h"
12#include "imgui/imgui.h"
13#include "zelda3/dungeon/room.h"
15
16namespace yaze {
17namespace editor {
18
38 public:
47 DungeonRoomPanel(size_t session_id, int room_id, zelda3::Room* room,
48 DungeonCanvasViewer* canvas_viewer,
49 DungeonRoomLoader* room_loader)
51 room_(room),
52 canvas_viewer_(canvas_viewer),
53 room_loader_(room_loader) {
54 session_id_ = session_id;
55 }
56
57 // ==========================================================================
58 // ResourceWindowContent Identity
59 // ==========================================================================
60
61 int GetResourceId() const override { return room_id_; }
62 std::string GetResourceType() const override { return "room"; }
63
64 std::string GetResourceName() const override {
65 // Use unified ResourceLabelProvider for room names
66 return absl::StrFormat("[%03X] %s", room_id_,
68 }
69
70 std::string GetIcon() const override { return ICON_MD_GRID_ON; }
71 std::string GetEditorCategory() const override { return "Dungeon"; }
72 int GetPriority() const override { return 100 + room_id_; }
73
74 // ==========================================================================
75 // WindowContent Drawing
76 // ==========================================================================
77
78 void Draw(bool* p_open) override {
79 if (!room_ || !canvas_viewer_) {
80 ImGui::TextColored(ImVec4(1, 0, 0, 1), "Room data unavailable");
81 return;
82 }
83
84 // Lazy load room data
85 if (!room_->IsLoaded() && room_loader_) {
86 auto status = room_loader_->LoadRoom(room_id_, *room_);
87 if (!status.ok()) {
88 ImGui::TextColored(ImVec4(1, 0, 0, 1), "Failed to load room: %s",
89 status.message().data());
90 return;
91 }
92 }
93
94 // Initialize room graphics if needed
95 if (room_->IsLoaded()) {
96 bool needs_render = false;
97
98 if (room_->blocks().empty()) {
100 needs_render = true;
101 }
102
103 if (!room_->AreObjectsLoaded()) {
105 needs_render = true;
106 }
107
108 auto& bg1_bitmap = room_->bg1_buffer().bitmap();
109 if (needs_render || !bg1_bitmap.is_active() || bg1_bitmap.width() == 0) {
111 }
112 }
113
114 // Room status header
115 if (room_->IsLoaded()) {
116 ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f),
117 ICON_MD_CHECK " Loaded");
118 } else {
119 ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f),
120 ICON_MD_PENDING " Loading...");
121 }
122 ImGui::SameLine();
123 ImGui::TextDisabled("Objects: %zu", room_->GetTileObjects().size());
124
125 // Room Controls
126 if (ImGui::CollapsingHeader("Room Controls")) {
127 if (ImGui::Button(ICON_MD_REFRESH " Reload Graphics & Objects",
128 ImVec2(-FLT_MIN, 0))) {
130 }
131
132 if (ImGui::Button(ICON_MD_CLEANING_SERVICES " Clear Room Buffers",
133 ImVec2(-FLT_MIN, 0))) {
135 }
136
137 ImGui::Separator();
138 ImGui::Text("Floor Graphics Override:");
139
140 uint8_t floor1 = room_->floor1();
141 uint8_t floor2 = room_->floor2();
142 static uint8_t floor_min = 0;
143 static uint8_t floor_max = 15;
144
145 bool changed = false;
146 if (ImGui::SliderScalar("Floor1", ImGuiDataType_U8, &floor1, &floor_min,
147 &floor_max)) {
148 room_->set_floor1(floor1);
149 changed = true;
150 }
151 if (ImGui::SliderScalar("Floor2", ImGuiDataType_U8, &floor2, &floor_min,
152 &floor_max)) {
153 room_->set_floor2(floor2);
154 changed = true;
155 }
156
157 if (changed && room_->rom() && room_->rom()->is_loaded()) {
159 }
160 }
161
162 ImGui::Separator();
163
164 // Draw the room canvas
166 }
167
168 // ==========================================================================
169 // ResourceWindowContent Lifecycle
170 // ==========================================================================
171
172 void OnResourceModified() override {
173 // Re-render room when modified externally
174 if (room_ && room_->IsLoaded()) {
176 }
177 }
178
179 // ==========================================================================
180 // Panel-Specific Methods
181 // ==========================================================================
182
183 zelda3::Room* room() const { return room_; }
184 int room_id() const { return room_id_; }
185
186 private:
187 int room_id_ = 0;
188 zelda3::Room* room_ = nullptr;
191};
192
193} // namespace editor
194} // namespace yaze
195
196#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.
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:336
uint8_t blockset() const
Definition room.h:602
void LoadRoomGraphics(uint8_t entrance_blockset=0xFF)
Definition room.cc:547
void set_floor2(uint8_t value)
Definition room.h:632
void set_floor1(uint8_t value)
Definition room.h:626
bool IsLoaded() const
Definition room.h:579
void ReloadGraphics(uint8_t entrance_blockset=0xFF)
Definition room.cc:604
uint8_t floor2() const
Definition room.h:625
auto rom() const
Definition room.h:652
void RenderRoomGraphics()
Definition room.cc:739
auto & bg1_buffer()
Definition room.h:669
const std::vector< RoomObject > & GetTileObjects() const
Definition room.h:330
auto blocks() const
Definition room.h:650
void LoadObjects()
Definition room.cc:1355
bool AreObjectsLoaded() const
Definition room.h:581
uint8_t floor1() const
Definition room.h:624
#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.