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 // ResourcePanel 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 // EditorPanel 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_->GetTileObjects().empty()) {
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", 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("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 // ResourcePanel 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)
ResourcePanel 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 panels that edit specific ROM resources.
size_t session_id_
Session ID for multi-ROM editing (0 = single session)
void ClearTileObjects()
Definition room.h:352
void LoadRoomGraphics(uint8_t entrance_blockset=0xFF)
Definition room.cc:370
void set_floor2(uint8_t value)
Definition room.h:508
void set_floor1(uint8_t value)
Definition room.h:502
bool IsLoaded() const
Definition room.h:478
uint8_t floor2() const
Definition room.h:501
uint8_t blockset
Definition room.h:490
void RenderRoomGraphics()
Definition room.cc:518
auto & bg1_buffer()
Definition room.h:542
const std::vector< RoomObject > & GetTileObjects() const
Definition room.h:346
auto blocks() const
Definition room.h:525
void LoadObjects()
Definition room.cc:1140
uint8_t floor1() const
Definition room.h:500
#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.