yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_room_selector.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_format.h"
5#include "imgui/imgui.h"
6#include "util/hex.h"
11
12namespace yaze::editor {
13
14using ImGui::BeginChild;
15using ImGui::EndChild;
16using ImGui::SameLine;
17
19 // Legacy combined view - prefer using DrawRoomSelector() and
20 // DrawEntranceSelector() separately via their own EditorPanels
22}
23
25 if (!rom_ || !rom_->is_loaded()) {
26 ImGui::Text("ROM not loaded");
27 return;
28 }
29
30 gui::InputHexWord("Room ID", &current_room_id_, 50.f, true);
31 ImGui::Separator();
32
33 room_filter_.Draw("Filter", ImGui::GetContentRegionAvail().x);
34
35 if (ImGui::BeginTable("RoomList", 2,
36 ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders |
37 ImGuiTableFlags_RowBg |
38 ImGuiTableFlags_Resizable)) {
39 ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 40.0f);
40 ImGui::TableSetupColumn("Name");
41 ImGui::TableHeadersRow();
42
43 // Use kNumberOfRooms (296) as limit - rooms_ array is 0x128 elements
44 for (int i = 0; i < zelda3::kNumberOfRooms; ++i) {
45 // Use unified ResourceLabelProvider for room names
46 std::string display_name = zelda3::GetRoomLabel(i);
47
48 if (room_filter_.PassFilter(display_name.c_str())) {
49 ImGui::TableNextRow();
50 ImGui::TableNextColumn();
51
52 char label[32];
53 snprintf(label, sizeof(label), "%03X", i);
54 if (ImGui::Selectable(label, current_room_id_ == i,
55 ImGuiSelectableFlags_SpanAllColumns)) {
59 }
60 }
61
62 ImGui::TableNextColumn();
63 ImGui::TextUnformatted(display_name.c_str());
64 }
65 }
66 ImGui::EndTable();
67 }
68}
69
71 if (!rom_ || !rom_->is_loaded()) {
72 ImGui::Text("ROM not loaded");
73 return;
74 }
75
76 if (!entrances_) {
77 ImGui::Text("Entrances not loaded");
78 return;
79 }
80
81 auto current_entrance = (*entrances_)[current_entrance_id_];
82
83 // Organized Properties Table
84 if (ImGui::BeginTable("EntranceProps", 4, ImGuiTableFlags_Borders)) {
85 ImGui::TableSetupColumn("Core", ImGuiTableColumnFlags_WidthStretch);
86 ImGui::TableSetupColumn("Position", ImGuiTableColumnFlags_WidthStretch);
87 ImGui::TableSetupColumn("Camera", ImGuiTableColumnFlags_WidthStretch);
88 ImGui::TableSetupColumn("Scroll", ImGuiTableColumnFlags_WidthStretch);
89 ImGui::TableHeadersRow();
90
91 ImGui::TableNextRow();
92 ImGui::TableNextColumn();
93 gui::InputHexWord("Entr ID", &current_entrance.entrance_id_);
94 gui::InputHexWord("Room ID", &current_entrance.room_);
95 gui::InputHexByte("Dungeon", &current_entrance.dungeon_id_);
96 gui::InputHexByte("Music", &current_entrance.music_);
97
98 ImGui::TableNextColumn();
99 gui::InputHexWord("Player X", &current_entrance.x_position_);
100 gui::InputHexWord("Player Y", &current_entrance.y_position_);
101 gui::InputHexByte("Blockset", &current_entrance.blockset_);
102 gui::InputHexByte("Floor", &current_entrance.floor_);
103
104 ImGui::TableNextColumn();
105 gui::InputHexWord("Cam Trg X", &current_entrance.camera_trigger_x_);
106 gui::InputHexWord("Cam Trg Y", &current_entrance.camera_trigger_y_);
107 gui::InputHexWord("Exit", &current_entrance.exit_);
108
109 ImGui::TableNextColumn();
110 gui::InputHexWord("Scroll X", &current_entrance.camera_x_);
111 gui::InputHexWord("Scroll Y", &current_entrance.camera_y_);
112
113 ImGui::EndTable();
114 }
115
116 ImGui::Separator();
117 if (ImGui::CollapsingHeader("Camera Boundaries")) {
118 ImGui::Text(" North East South West");
119 ImGui::Text("Quadrant ");
120 SameLine();
121 gui::InputHexByte("##QN", &current_entrance.camera_boundary_qn_, 40.f);
122 SameLine();
123 gui::InputHexByte("##QE", &current_entrance.camera_boundary_qe_, 40.f);
124 SameLine();
125 gui::InputHexByte("##QS", &current_entrance.camera_boundary_qs_, 40.f);
126 SameLine();
127 gui::InputHexByte("##QW", &current_entrance.camera_boundary_qw_, 40.f);
128
129 ImGui::Text("Full Room ");
130 SameLine();
131 gui::InputHexByte("##FN", &current_entrance.camera_boundary_fn_, 40.f);
132 SameLine();
133 gui::InputHexByte("##FE", &current_entrance.camera_boundary_fe_, 40.f);
134 SameLine();
135 gui::InputHexByte("##FS", &current_entrance.camera_boundary_fs_, 40.f);
136 SameLine();
137 gui::InputHexByte("##FW", &current_entrance.camera_boundary_fw_, 40.f);
138 }
139 ImGui::Separator();
140
141 entrance_filter_.Draw("Filter", ImGui::GetContentRegionAvail().x);
142
143 // Entrance array layout (from LoadRoomEntrances):
144 // indices 0-6 (0x00-0x06): Spawn points (7 entries)
145 // indices 7-139 (0x07-0x8B): Regular entrances (133 entries, IDs 0x00-0x84)
146 constexpr int kNumSpawnPoints = 7; // 0x07
147 constexpr int kNumEntrances = 133; // 0x85
148 constexpr int kTotalEntries = 140; // 0x8C
149
150 if (ImGui::BeginTable("EntranceList", 3,
151 ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders |
152 ImGuiTableFlags_RowBg |
153 ImGuiTableFlags_Resizable)) {
154 ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed, 40.0f);
155 ImGui::TableSetupColumn("Room", ImGuiTableColumnFlags_WidthFixed, 50.0f);
156 ImGui::TableSetupColumn("Name");
157 ImGui::TableHeadersRow();
158
159 for (int i = 0; i < kTotalEntries; i++) {
160 std::string display_name;
161
162 if (i < kNumSpawnPoints) {
163 // Spawn points are at indices 0-6
164 display_name = absl::StrFormat("Spawn Point %d", i);
165 } else {
166 // Regular entrances are at indices 7-139, mapped to entrance IDs 0-132
167 int entrance_id = i - kNumSpawnPoints;
168 if (entrance_id < kNumEntrances) {
169 // Use unified ResourceLabelProvider for entrance names
170 display_name = zelda3::GetEntranceLabel(entrance_id);
171 } else {
172 display_name = absl::StrFormat("Unknown Entrance %d", i);
173 }
174 }
175
176 // Get room ID for this entrance
177 int room_id = (i < static_cast<int>(entrances_->size()))
178 ? (*entrances_)[i].room_
179 : 0;
180
181 // Include room ID in filter matching
182 char filter_text[256];
183 snprintf(filter_text, sizeof(filter_text), "%s %03X",
184 display_name.c_str(), room_id);
185
186 if (entrance_filter_.PassFilter(filter_text)) {
187 ImGui::TableNextRow();
188 ImGui::TableNextColumn();
189
190 char label[32];
191 snprintf(label, sizeof(label), "%02X", i);
192 if (ImGui::Selectable(label, current_entrance_id_ == i,
193 ImGuiSelectableFlags_SpanAllColumns)) {
195 if (i < static_cast<int>(entrances_->size())) {
196 // Use entrance callback if set, otherwise fall back to room callback
199 } else if (room_selected_callback_) {
201 }
202 }
203 }
204
205 ImGui::TableNextColumn();
206 ImGui::Text("%03X", room_id);
207
208 ImGui::TableNextColumn();
209 ImGui::TextUnformatted(display_name.c_str());
210 }
211 }
212 ImGui::EndTable();
213 }
214}
215
216} // namespace yaze::editor
bool is_loaded() const
Definition rom.h:128
std::array< zelda3::RoomEntrance, 0x8C > * entrances_
std::function< void(int)> room_selected_callback_
std::function< void(int)> entrance_selected_callback_
Editors are the view controllers for the application.
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:344
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:370
std::string GetEntranceLabel(int id)
Convenience function to get an entrance label.
std::string GetRoomLabel(int id)
Convenience function to get a room label.
constexpr int kNumberOfRooms