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
75 // ==========================================================================
76 // WindowContent Drawing
77 // ==========================================================================
78
79 void Draw(bool* p_open) override {
80 if (!room_ || !canvas_viewer_) {
81 ImGui::TextColored(ImVec4(1, 0, 0, 1), tr("Room data unavailable"));
82 return;
83 }
84
85 // Lazy load room data
86 if (!room_->IsLoaded() && room_loader_) {
87 auto status = room_loader_->LoadRoom(room_id_, *room_);
88 if (!status.ok()) {
89 ImGui::TextColored(ImVec4(1, 0, 0, 1), tr("Failed to load room: %s"),
90 status.message().data());
91 return;
92 }
93 }
94
95 // Initialize room graphics if needed
96 if (room_->IsLoaded()) {
97 bool needs_render = false;
98
99 if (room_->blocks().empty()) {
101 needs_render = true;
102 }
103
104 if (!room_->AreObjectsLoaded()) {
106 needs_render = true;
107 }
108
109 auto& bg1_bitmap = room_->bg1_buffer().bitmap();
110 if (needs_render || !bg1_bitmap.is_active() || bg1_bitmap.width() == 0) {
112 }
113 }
114
115 // Room status header
116 if (room_->IsLoaded()) {
117 ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f),
118 ICON_MD_CHECK " Loaded");
119 } else {
120 ImGui::TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f),
121 ICON_MD_PENDING " Loading...");
122 }
123 ImGui::SameLine();
124 ImGui::TextDisabled(tr("Objects: %zu"), room_->GetTileObjects().size());
125
126 // Room Controls
127 if (ImGui::CollapsingHeader(tr("Room Controls"))) {
128 if (ImGui::Button(ICON_MD_REFRESH " Reload Graphics & Objects",
129 ImVec2(-FLT_MIN, 0))) {
131 }
132
133 if (ImGui::Button(ICON_MD_CLEANING_SERVICES " Clear Room Buffers",
134 ImVec2(-FLT_MIN, 0))) {
136 }
137
138 ImGui::Separator();
139 ImGui::Text(tr("Floor Graphics Override:"));
140
141 uint8_t floor1 = room_->floor1();
142 uint8_t floor2 = room_->floor2();
143 static uint8_t floor_min = 0;
144 static uint8_t floor_max = 15;
145
146 bool changed = false;
147 if (ImGui::SliderScalar("Floor1", ImGuiDataType_U8, &floor1, &floor_min,
148 &floor_max)) {
149 room_->set_floor1(floor1);
150 changed = true;
151 }
152 if (ImGui::SliderScalar("Floor2", ImGuiDataType_U8, &floor2, &floor_min,
153 &floor_max)) {
154 room_->set_floor2(floor2);
155 changed = true;
156 }
157
158 if (changed && room_->rom() && room_->rom()->is_loaded()) {
160 }
161 }
162
163 ImGui::Separator();
164
165 // Draw the room canvas
167 }
168
169 // ==========================================================================
170 // ResourceWindowContent Lifecycle
171 // ==========================================================================
172
173 void OnResourceModified() override {
174 // Re-render room when modified externally
175 if (room_ && room_->IsLoaded()) {
177 }
178 }
179
180 // ==========================================================================
181 // Panel-Specific Methods
182 // ==========================================================================
183
184 zelda3::Room* room() const { return room_; }
185 int room_id() const { return room_id_; }
186
187 private:
188 int room_id_ = 0;
189 zelda3::Room* room_ = nullptr;
192};
193
194} // namespace editor
195} // namespace yaze
196
197#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:388
void set_floor2(uint8_t value)
Definition room.h:935
void set_floor1(uint8_t value)
Definition room.h:928
bool IsLoaded() const
Definition room.h:871
void ReloadGraphics(std::optional< uint8_t > entrance_blockset=std::nullopt)
Definition room.cc:839
uint8_t floor2() const
Definition room.h:927
auto rom() const
Definition room.h:958
void RenderRoomGraphics()
Definition room.cc:987
void LoadRoomGraphics(std::optional< uint8_t > entrance_blockset=std::nullopt)
Definition room.cc:746
auto & bg1_buffer()
Definition room.h:975
const std::vector< RoomObject > & GetTileObjects() const
Definition room.h:382
auto blocks() const
Definition room.h:956
void LoadObjects()
Definition room.cc:1623
bool AreObjectsLoaded() const
Definition room.h:873
uint8_t floor1() const
Definition room.h:926
#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.