yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_entrances_panel.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ENTRANCES_PANEL_H_
2#define YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ENTRANCES_PANEL_H_
3
4#include <algorithm>
5#include <array>
6#include <cstdio>
7#include <functional>
8#include <memory>
9#include <optional>
10#include <string>
11#include <utility>
12
13#include "absl/status/status.h"
14#include "absl/strings/str_format.h"
21#include "app/gui/core/icons.h"
22#include "app/gui/core/input.h"
23#include "imgui/imgui.h"
24#include "util/i18n/tr.h"
25#include "zelda3/common.h"
28
29namespace yaze {
30namespace editor {
31
42 public:
44 std::array<zelda3::RoomEntrance, zelda3::kNumDungeonEntranceSlots>*
45 entrances,
46 std::array<zelda3::DungeonSpawnPoint, zelda3::kNumDungeonSpawnPoints>*
47 spawn_points,
48 int* current_entrance_id, std::function<void(int)> on_entrance_selected)
49 : entrances_(entrances),
50 spawn_points_(spawn_points),
51 current_entrance_id_(current_entrance_id),
52 on_entrance_selected_(std::move(on_entrance_selected)) {}
53
54 // ==========================================================================
55 // WindowContent Identity
56 // ==========================================================================
57
58 std::string GetId() const override { return "dungeon.entrance_properties"; }
59 std::string GetDisplayName() const override { return "Entrances"; }
60 std::string GetIcon() const override { return ICON_MD_DOOR_FRONT; }
61 std::string GetEditorCategory() const override { return "Dungeon"; }
62 int GetPriority() const override { return 26; }
63 std::string GetWorkflowGroup() const override { return "Core"; }
64
66 std::function<std::optional<DungeonEntranceCameraState>(int)>;
67 using CameraRepairCallback = std::function<absl::Status(int)>;
68 using EntrancePropertyEditCallback = std::function<void(
69 int, const zelda3::RoomEntrance&, const zelda3::RoomEntrance&)>;
70 using SpawnPropertyEditCallback = std::function<void(
72
74 SpawnPropertyEditCallback spawn_callback) {
75 entrance_property_edit_callback_ = std::move(entrance_callback);
76 spawn_property_edit_callback_ = std::move(spawn_callback);
77 }
78
79 std::shared_ptr<const int> property_edit_gesture() const {
81 }
82
84 CameraRepairCallback repair_callback,
85 std::function<void()> data_changed_callback = {}) {
86 camera_state_provider_ = std::move(state_provider);
87 camera_repair_callback_ = std::move(repair_callback);
88 camera_data_changed_callback_ = std::move(data_changed_callback);
89 }
91 if (!navigation_shortcut_focus_ || ImGui::GetCurrentContext() == nullptr) {
92 return false;
93 }
94 return navigation_shortcut_last_draw_frame_ >= ImGui::GetFrameCount() - 1;
95 }
96
97 void SetGraphicsPreview(std::function<DungeonRenderContext()> context,
98 std::function<bool()> automatic,
99 std::function<void(int)> select) {
100 preview_context_ = std::move(context);
101 preview_automatic_ = std::move(automatic);
102 select_preview_ = std::move(select);
103 }
104
105 void SetProject(const project::YazeProject* project) { project_ = project; }
106
107 // Shared preview selector: regular IDs are not the combined list slots,
108 // whose first entries are dedicated spawn points.
109 void DrawGraphicsContext(float width = -1.0f) {
111 return;
112 if (*current_entrance_id_ < 0 ||
113 *current_entrance_id_ >= static_cast<int>(entrances_->size()))
115 const int selected = *current_entrance_id_;
116 const uint8_t main_gfx = selected < zelda3::kNumDungeonSpawnPoints
117 ? (*spawn_points_)[selected].main_gfx
118 : (*entrances_)[selected].blockset_;
119 std::string preview = absl::StrFormat(
120 "%s / GFX %02X", DungeonEntrancePreviewLabel(selected), main_gfx);
121 const bool automatic = preview_automatic_ && preview_automatic_();
122 if (preview_context_) {
123 const auto context = preview_context_();
124 const std::string name =
125 automatic && !context.owner_name.empty() ? context.owner_name
126 : context.entrance_slot >= zelda3::kNumDungeonSpawnPoints
127 ? EntranceLabel(context.entrance_slot)
128 : DungeonEntrancePreviewLabel(context.entrance_slot);
129 preview =
130 context.uses_entrance()
131 ? absl::StrFormat(
132 "%s: %s / %s", automatic ? "Auto" : "Manual", name,
133 DungeonEntrancePreviewLabel(context.entrance_slot))
134 : absl::StrFormat(
135 "Auto: %s / GFX %02X",
137 ? "Choose entrance"
138 : "Room fallback",
139 context.effective_blockset());
140 }
141 ImGui::SetNextItemWidth(width);
142 const bool open = ImGui::BeginCombo(
143 "##GraphicsEntrance", preview.c_str(),
144 select_preview_ ? ImGuiComboFlags_HeightLarge : ImGuiComboFlags_None);
145 gui::AutoRegisterLastItem("combo", "Graphics entrance");
146 if (ImGui::IsItemHovered())
147 ImGui::SetTooltip(
148 "Auto follows the room's dungeon. Choosing an entrance pins its "
149 "graphics until you choose Auto again. This changes only the "
150 "preview.");
151 if (open) {
152 if (select_preview_) {
153 if (ImGui::Selectable("Auto (follow room)", automatic))
154 select_preview_(-1);
155 gui::AutoRegisterLastItem("selectable", "Auto (follow room)");
156 ImGui::Separator();
157 // Keep Auto visible while the entrance list scrolls to a manual choice.
158 ImGui::BeginChild("##EntranceChoices",
159 ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 8));
160 }
161 for (int slot = 0; slot < static_cast<int>(entrances_->size()); ++slot) {
162 const std::string entry = DungeonEntrancePreviewLabel(slot);
163 const std::string label = slot >= zelda3::kNumDungeonSpawnPoints
164 ? entry + " - " + EntranceLabel(slot)
165 : entry;
166 if (ImGui::Selectable(label.c_str(), !automatic && slot == selected)) {
167 if (select_preview_) {
168 select_preview_(slot);
169 ImGui::CloseCurrentPopup();
170 } else {
171 *current_entrance_id_ = slot;
174 }
175 }
176 gui::AutoRegisterLastItem("selectable", entry);
177 if (ImGui::IsItemHovered() && slot >= zelda3::kNumDungeonSpawnPoints)
178 ImGui::SetTooltip("%s", EntranceLabel(slot).c_str());
179 if (slot == selected) {
180 ImGui::SetItemDefaultFocus();
181 if (select_preview_ && ImGui::IsWindowAppearing())
182 ImGui::SetScrollHereY(0.5f);
183 }
184 }
185 if (select_preview_)
186 ImGui::EndChild();
187 ImGui::EndCombo();
188 }
189 }
190
193 !preview_context_().uses_entrance()) {
194 ImGui::TextWrapped("Choose an entrance to edit its properties.");
195 return;
196 }
198 *current_entrance_id_ >= 0 &&
199 *current_entrance_id_ < static_cast<int>(entrances_->size()))
201 }
202
203 // Navigation-only embedding: reuse the list and selection callback without
204 // duplicating the entrance property editor in the Workbench inspector.
206 if (PrepareNavigation())
208 }
209
210 // ==========================================================================
211 // WindowContent Drawing
212 // ==========================================================================
213
214 void Draw(bool* p_open) override {
215 (void)p_open;
216 if (!PrepareNavigation())
217 return;
218
219 const bool split_layout = ImGui::GetContentRegionAvail().x >= 620.0f;
220 if (split_layout &&
221 ImGui::BeginTable("##EntranceNavigator", 2,
222 ImGuiTableFlags_Resizable |
223 ImGuiTableFlags_BordersInnerV |
224 ImGuiTableFlags_SizingStretchProp)) {
225 ImGui::TableSetupColumn("Entrances", ImGuiTableColumnFlags_WidthFixed,
226 300.0f);
227 ImGui::TableSetupColumn("Properties", ImGuiTableColumnFlags_WidthStretch);
228 ImGui::TableNextRow();
229 ImGui::TableNextColumn();
231 ImGui::TableNextColumn();
233 ImGui::EndTable();
234 return;
235 }
236
237 if (ImGui::BeginTabBar("##EntranceNavigatorTabs")) {
238 if (ImGui::BeginTabItem(ICON_MD_DOOR_FRONT " Entrances")) {
240 ImGui::EndTabItem();
241 }
242 if (ImGui::BeginTabItem(ICON_MD_TUNE " Properties")) {
244 ImGui::EndTabItem();
245 }
246 ImGui::EndTabBar();
247 }
248 }
249
250 private:
253 return false;
254 if (*current_entrance_id_ < 0 ||
255 *current_entrance_id_ >= static_cast<int>(entrances_->size()))
257 navigation_shortcut_last_draw_frame_ = ImGui::GetFrameCount();
259 ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
260 return true;
261 }
262
263 float HexPropertyWidth(int digits) const {
264 constexpr char hexadecimal[] = "0123456789ABCDEF";
265 float glyph_width = 0.0f;
266 for (int index = 0; index < 16; ++index) {
267 const char glyph[] = {hexadecimal[index], '\0'};
268 glyph_width = std::max(glyph_width, ImGui::CalcTextSize(glyph).x);
269 }
270 return glyph_width * digits + ImGui::GetStyle().FramePadding.x * 2.0f +
271 2.0f;
272 }
273
274 void ContinuePropertyRow(const char* label, int digits) const {
275 const float right =
276 ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x;
277 const float spacing = ImGui::GetStyle().ItemSpacing.x;
278 const float next_width =
279 ImGui::CalcTextSize(label).x + spacing + HexPropertyWidth(digits);
280 if (ImGui::GetItemRectMax().x + spacing + next_width <= right)
281 ImGui::SameLine();
282 }
283
284 template <typename T>
285 bool DrawHexProperty(const char* label, T* value, const char* widget_label,
286 bool continue_row = false) {
287 constexpr int digits = sizeof(T) == 1 ? 2 : 4;
288 if (continue_row)
289 ContinuePropertyRow(label, digits);
290 const float width = HexPropertyWidth(digits);
291 // InputScalarLeft draws its label with Text(), so wrapping the label keeps
292 // the existing input ID and wheel/typing behavior even for a long label.
293 const float label_width =
294 std::max(1.0f, ImGui::GetContentRegionAvail().x - width -
295 ImGui::GetStyle().ItemSpacing.x);
296 ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + label_width);
297 bool changed = false;
298 if constexpr (sizeof(T) == 1)
299 changed = gui::InputHexByte(label, value, width, true);
300 else
301 changed = gui::InputHexWord(label, value, width, true);
302 ImGui::PopTextWrapPos();
303 RegisterPropertyInput(label, widget_label);
304 return changed;
305 }
306
307 std::string EntranceLabel(int slot) const {
308 const int entrance_id = slot - zelda3::kNumDungeonSpawnPoints;
309 if (!entrances_ || entrance_id < 0 ||
310 slot >= static_cast<int>(entrances_->size()))
311 return DungeonEntrancePreviewLabel(slot);
313 (*entrances_)[slot].room_);
314 }
315
317 if (!camera_repair_preview_.has_value()) {
318 return;
319 }
320 const auto validation =
322 if (!ImGui::BeginPopupModal("Camera Repair Preview##DungeonEntrance",
323 nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
324 return;
325 }
326
327 ImGui::TextWrapped(
328 "Review the derived camera values before changing this entrance. "
329 "The repair is one undoable action.");
330 ImGui::Separator();
331 if (ImGui::BeginTable(
332 "##CameraRepairValues", 3,
333 ImGuiTableFlags_BordersInner | ImGuiTableFlags_SizingFixedFit)) {
334 ImGui::TableSetupColumn("Field");
335 ImGui::TableSetupColumn("Current");
336 ImGui::TableSetupColumn("Derived");
337 ImGui::TableHeadersRow();
338 const auto draw_word_row = [](const char* label, uint16_t current,
339 uint16_t derived) {
340 ImGui::TableNextRow();
341 ImGui::TableNextColumn();
342 ImGui::TextUnformatted(label);
343 ImGui::TableNextColumn();
344 ImGui::Text("0x%04X", current);
345 ImGui::TableNextColumn();
346 ImGui::Text("0x%04X", derived);
347 };
348 draw_word_row("Scroll X", camera_repair_preview_->camera_x,
349 validation.expected.camera_x);
350 draw_word_row("Scroll Y", camera_repair_preview_->camera_y,
351 validation.expected.camera_y);
352 draw_word_row("Trigger X", camera_repair_preview_->trigger_x,
353 validation.expected.trigger_x);
354 draw_word_row("Trigger Y", camera_repair_preview_->trigger_y,
355 validation.expected.trigger_y);
356 ImGui::TableNextRow();
357 ImGui::TableNextColumn();
358 ImGui::TextUnformatted("Quadrant");
359 ImGui::TableNextColumn();
360 ImGui::Text("0x%02X", camera_repair_preview_->quadrant);
361 ImGui::TableNextColumn();
362 if (validation.quadrant_repair_safe) {
363 ImGui::Text("0x%02X", validation.expected.quadrant);
364 } else {
365 ImGui::TextUnformatted("Preserved");
366 }
367 ImGui::EndTable();
368 }
369 ImGui::TextWrapped(
370 "Boundary pages: [%02X %02X %02X %02X | %02X %02X %02X %02X] "
371 "-> [%02X %02X %02X %02X | %02X %02X %02X %02X]",
372 camera_repair_preview_->boundaries[0],
373 camera_repair_preview_->boundaries[1],
374 camera_repair_preview_->boundaries[2],
375 camera_repair_preview_->boundaries[3],
376 camera_repair_preview_->boundaries[4],
377 camera_repair_preview_->boundaries[5],
378 camera_repair_preview_->boundaries[6],
379 camera_repair_preview_->boundaries[7],
380 validation.expected.boundaries[0], validation.expected.boundaries[1],
381 validation.expected.boundaries[2], validation.expected.boundaries[3],
382 validation.expected.boundaries[4], validation.expected.boundaries[5],
383 validation.expected.boundaries[6], validation.expected.boundaries[7]);
384 if (!camera_repair_error_.empty()) {
385 ImGui::TextWrapped("Repair failed: %s", camera_repair_error_.c_str());
386 }
387
388 ImGui::BeginDisabled(!validation.can_repair() || !camera_repair_callback_);
389 if (ImGui::Button("Apply Safe Repair")) {
390 const absl::Status status =
393 : absl::FailedPreconditionError(
394 "Camera repair callback is unavailable");
395 if (status.ok()) {
398 camera_repair_error_.clear();
399 ImGui::CloseCurrentPopup();
400 } else {
401 camera_repair_error_ = std::string(status.message());
402 }
403 }
404 gui::AutoRegisterLastItem("button", "ApplyCameraRepair");
405 ImGui::EndDisabled();
406 ImGui::SameLine();
407 if (ImGui::Button("Cancel")) {
410 camera_repair_error_.clear();
411 ImGui::CloseCurrentPopup();
412 }
413 ImGui::EndPopup();
414 }
415
416 void DrawCameraSafety(int slot_index) {
418 return;
419 }
420 const auto state = camera_state_provider_(slot_index);
421 if (!state.has_value()) {
422 ImGui::TextDisabled("Camera validation unavailable.");
423 return;
424 }
425 const auto validation = ValidateDungeonEntranceCamera(*state);
426 ImGui::SeparatorText("Camera safety");
427 ImGui::PushTextWrapPos(0.0f);
428 if (!validation.geometry_valid()) {
429 ImGui::TextColored(ImVec4(0.95f, 0.35f, 0.30f, 1.0f),
430 "Unsafe camera geometry");
431 for (const auto& error : validation.errors) {
432 ImGui::Bullet();
433 ImGui::SameLine();
434 ImGui::TextWrapped("%s", error.c_str());
435 }
436 if (validation.can_repair()) {
437 ImGui::TextWrapped(
438 "The room and player position are valid, so a previewed repair "
439 "can replace these derived fields.");
440 }
441 } else if (validation.matches_derived()) {
442 ImGui::TextColored(ImVec4(0.35f, 0.80f, 0.45f, 1.0f),
443 "Camera values match the player position.");
444 } else {
445 ImGui::TextWrapped(
446 "Camera geometry is safe, but %zu derived value group(s) differ.",
447 validation.differences.size());
448 for (const auto& difference : validation.differences) {
449 ImGui::Bullet();
450 ImGui::SameLine();
451 ImGui::TextWrapped("%s", difference.c_str());
452 }
453 }
454
455 ImGui::PopTextWrapPos();
456 ImGui::BeginDisabled(!validation.can_repair() || !camera_repair_callback_);
457 if (ImGui::Button("Preview Camera Repair", ImVec2(-1, 0))) {
458 camera_repair_preview_ = *state;
459 camera_repair_slot_ = slot_index;
460 camera_repair_error_.clear();
461 ImGui::OpenPopup("Camera Repair Preview##DungeonEntrance");
462 }
463 gui::AutoRegisterLastItem("button", "PreviewCameraRepair");
464 ImGui::EndDisabled();
466 }
467
479
480 bool DrawCameraBoundaries(const char* table_id,
481 const std::array<uint8_t*, 8>& boundaries) {
482 bool changed = false;
483 const float value_width = HexPropertyWidth(2);
484 const float mode_width = ImGui::CalcTextSize("Full room").x;
485 const float column_width =
486 std::max(value_width, ImGui::CalcTextSize("North").x);
487 const bool narrow = ImGui::GetContentRegionAvail().x <
488 mode_width + column_width * 4.0f +
489 ImGui::GetStyle().CellPadding.x * 10.0f;
490 if (!ImGui::BeginTable(table_id, narrow ? 2 : 5,
491 ImGuiTableFlags_BordersInnerV |
492 ImGuiTableFlags_SizingStretchProp)) {
493 return false;
494 }
495 if (narrow) {
496 ImGui::TableSetupColumn("Boundary", ImGuiTableColumnFlags_WidthStretch);
497 ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_WidthFixed,
498 value_width);
499 } else {
500 ImGui::TableSetupColumn("Mode", ImGuiTableColumnFlags_WidthFixed,
501 mode_width);
502 for (const auto* direction : {"North", "East", "South", "West"})
503 ImGui::TableSetupColumn(direction);
504 ImGui::TableHeadersRow();
505 }
506 constexpr std::array<int, 4> kQuadrantOrder = {0, 6, 2, 4};
507 constexpr std::array<int, 4> kFullRoomOrder = {1, 7, 3, 5};
508 const auto draw_row = [&changed, &boundaries, narrow, value_width, this](
509 const char* label,
510 const std::array<int, 4>& order) {
511 if (!narrow) {
512 ImGui::TableNextRow();
513 ImGui::TableNextColumn();
514 ImGui::TextUnformatted(label);
515 }
516 constexpr const char* directions[] = {"North", "East", "South", "West"};
517 for (size_t direction = 0; direction < order.size(); ++direction) {
518 const int index = order[direction];
519 if (narrow) {
520 ImGui::TableNextRow();
521 ImGui::TableNextColumn();
522 ImGui::TextWrapped("%s %s", label, directions[direction]);
523 }
524 ImGui::TableNextColumn();
525 ImGui::PushID(index);
526 changed |= gui::InputHexByte("##Boundary", boundaries[index],
527 value_width, true);
529 "##Boundary", absl::StrFormat("CameraBoundary%d", index).c_str());
530 ImGui::PopID();
531 }
532 };
533 draw_row("Quadrant", kQuadrantOrder);
534 draw_row("Full room", kFullRoomOrder);
535 ImGui::EndTable();
536 return changed;
537 }
538
540 entrance_filter_.Draw(ICON_MD_SEARCH " Filter",
541 ImGui::GetContentRegionAvail().x);
542 constexpr int kNumSpawnPoints = zelda3::kNumDungeonSpawnPoints;
543 constexpr int kNumEntrances = zelda3::kNumRegularDungeonEntrances;
544 constexpr int kTotalEntries = zelda3::kNumDungeonEntranceSlots;
545
546 if (ImGui::BeginChild("##EntrancesList", ImVec2(0, 0), true,
547 ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
548 for (int i = 0; i < kTotalEntries; i++) {
549 std::string entrance_name;
550 if (i < kNumSpawnPoints) {
551 entrance_name = absl::StrFormat("Spawn Point %d", i);
552 } else {
553 const int entrance_id = i - kNumSpawnPoints;
554 entrance_name = entrance_id < kNumEntrances
555 ? EntranceLabel(i)
556 : absl::StrFormat("Unknown %d", i);
557 }
558
559 const int room_id = i < kNumSpawnPoints ? (*spawn_points_)[i].room_id
560 : (*entrances_)[i].room_;
561 const std::string room_name =
563 const std::string label = absl::StrFormat(
564 "%s - %s -> %s (%03X)", DungeonEntrancePreviewLabel(i),
565 entrance_name, room_name, room_id);
566 if (!entrance_filter_.PassFilter(label.c_str())) {
567 continue;
568 }
569
570 const bool is_selected = (*current_entrance_id_ == i);
571 if (ImGui::Selectable(label.c_str(), is_selected)) {
575 }
576 }
577 gui::AutoRegisterLastItem("selectable",
578 absl::StrFormat("entrance_%03X", i));
579 if (ImGui::IsItemHovered())
580 ImGui::SetTooltip("%s", label.c_str());
581 }
582 }
583 ImGui::EndChild();
584 }
585
586 void DrawSpawnPointProperties(int slot_index) {
587 auto& spawn = (*spawn_points_)[slot_index];
588 const auto before = spawn;
589 const bool properties_editable =
590 CanEditDungeonSpawnPoint(slot_index, spawn);
591 bool changed = false;
592
593 ImGui::Text(tr("Spawn Point %d"), slot_index);
594 if (!properties_editable) {
595 ImGui::TextWrapped(tr(
596 "Spawn point data is unavailable; reload the ROM before editing."));
597 }
598 ImGui::BeginDisabled(!properties_editable);
599
600 changed |=
601 DrawHexProperty("Entrance ID", &spawn.entrance_id, "SpawnEntranceId");
602 changed |= DrawHexProperty("Room ID", &spawn.room_id, "SpawnRoomId");
603 changed |= DrawHexProperty("Dungeon ID", &spawn.dungeon_id,
604 "SpawnDungeonId", true);
605 changed |= DrawHexProperty("Main GFX", &spawn.main_gfx, "SpawnMainGfx");
606 changed |= DrawHexProperty("Song", &spawn.song, "SpawnSong", true);
607 changed |= DrawHexProperty("Floor", &spawn.floor, "SpawnFloor", true);
608
609 ImGui::Separator();
610 changed |= DrawHexProperty("Player X", &spawn.x_coordinate, "SpawnPlayerX");
611 changed |=
612 DrawHexProperty("Player Y", &spawn.y_coordinate, "SpawnPlayerY", true);
613 changed |=
614 DrawHexProperty("Overworld Door Tilemap", &spawn.overworld_door_tilemap,
615 "SpawnDoorTilemap");
616 ImGui::EndDisabled();
617
618 CommitSpawnPropertyEdit(slot_index, before, changed);
619 DrawCameraSafety(slot_index);
620
621 const auto camera_before = spawn;
622 changed = false;
623 const bool camera_open = ImGui::CollapsingHeader("Advanced camera data");
624 gui::AutoRegisterLastItem("header", "AdvancedCameraData");
625 if (camera_open) {
626 ImGui::BeginDisabled(!properties_editable);
627 changed |= DrawHexProperty("Camera Trigger X", &spawn.camera_trigger_x,
628 "SpawnCameraTriggerX");
629 changed |= DrawHexProperty("Camera Trigger Y", &spawn.camera_trigger_y,
630 "SpawnCameraTriggerY", true);
631 changed |= DrawHexProperty("Horizontal Scroll", &spawn.horizontal_scroll,
632 "SpawnHorizontalScroll");
633 changed |= DrawHexProperty("Vertical Scroll", &spawn.vertical_scroll,
634 "SpawnVerticalScroll", true);
635 changed |= DrawHexProperty("Layer", &spawn.layer, "SpawnLayer");
636 changed |= DrawHexProperty("Spawn Quadrant", &spawn.quadrant,
637 "SpawnQuadrant", true);
638 changed |=
639 DrawHexProperty("Scroll Controller", &spawn.camera_scroll_controller,
640 "SpawnScrollController", true);
641
642 ImGui::SeparatorText(tr("Camera Boundaries"));
643 changed |= DrawCameraBoundaries("##SpawnCameraBoundaries",
644 {&spawn.camera_scroll_boundaries[0],
645 &spawn.camera_scroll_boundaries[1],
646 &spawn.camera_scroll_boundaries[2],
647 &spawn.camera_scroll_boundaries[3],
648 &spawn.camera_scroll_boundaries[4],
649 &spawn.camera_scroll_boundaries[5],
650 &spawn.camera_scroll_boundaries[6],
651 &spawn.camera_scroll_boundaries[7]});
652 ImGui::EndDisabled();
653 }
654
655 CommitSpawnPropertyEdit(slot_index, camera_before, changed);
656 }
657
658 void DrawRegularEntranceProperties(int slot_index) {
659 auto& entrance = (*entrances_)[slot_index];
660 const auto before = entrance;
661 const bool properties_editable =
662 CanEditDungeonEntrance(slot_index, entrance);
663 bool changed = false;
664
665 ImGui::Text(tr("Entrance ID: %04X"), entrance.entrance_id_);
666 ImGui::BeginDisabled(!properties_editable);
667 changed |= DrawHexProperty("Room ID", &entrance.room_, "RegularRoomId");
668 changed |= DrawHexProperty("Dungeon ID", &entrance.dungeon_id_,
669 "RegularDungeonId", true);
670 changed |=
671 DrawHexProperty("Blockset", &entrance.blockset_, "RegularBlockset");
672 changed |= DrawHexProperty("Music", &entrance.music_, "RegularMusic", true);
673 changed |= DrawHexProperty("Floor", &entrance.floor_, "RegularFloor", true);
674
675 ImGui::Separator();
676 changed |=
677 DrawHexProperty("Player X ", &entrance.x_position_, "RegularPlayerX");
678 changed |= DrawHexProperty("Player Y ", &entrance.y_position_,
679 "RegularPlayerY", true);
680 changed |= DrawHexProperty("Exit", &entrance.exit_, "RegularExit");
681 ImGui::EndDisabled();
682
683 CommitEntrancePropertyEdit(slot_index, before, changed);
684 DrawCameraSafety(slot_index);
685
686 const auto camera_before = entrance;
687 changed = false;
688 const bool camera_open = ImGui::CollapsingHeader("Advanced camera data");
689 gui::AutoRegisterLastItem("header", "AdvancedCameraData");
690 if (camera_open) {
691 ImGui::BeginDisabled(!properties_editable);
692 changed |=
693 DrawHexProperty("Camera Trigger X", &entrance.camera_trigger_x_,
694 "RegularCameraTriggerX");
695 changed |=
696 DrawHexProperty("Camera Trigger Y", &entrance.camera_trigger_y_,
697 "RegularCameraTriggerY", true);
698 changed |=
699 DrawHexProperty("Scroll X", &entrance.camera_x_, "RegularScrollX");
700 changed |= DrawHexProperty("Scroll Y", &entrance.camera_y_,
701 "RegularScrollY", true);
702 changed |= DrawHexProperty("Scroll Quadrant", &entrance.scroll_quadrant_,
703 "RegularScrollQuadrant");
704
705 ImGui::SeparatorText(tr("Camera Boundaries"));
706 changed |= DrawCameraBoundaries(
707 "##RegularCameraBoundaries",
708 {&entrance.camera_boundary_qn_, &entrance.camera_boundary_fn_,
709 &entrance.camera_boundary_qs_, &entrance.camera_boundary_fs_,
710 &entrance.camera_boundary_qw_, &entrance.camera_boundary_fw_,
711 &entrance.camera_boundary_qe_, &entrance.camera_boundary_fe_});
712 ImGui::EndDisabled();
713 }
714
715 CommitEntrancePropertyEdit(slot_index, camera_before, changed);
716 }
717
718 void CommitEntrancePropertyEdit(int slot_index,
719 const zelda3::RoomEntrance& before,
720 bool changed) {
721 auto& entrance = (*entrances_)[slot_index];
722 if (!MarkDungeonEntranceDirtyIfEditable(slot_index, entrance, changed)) {
723 return;
724 }
727 entrance_property_edit_callback_(slot_index, before, entrance);
728 }
731 }
732 }
733
734 void CommitSpawnPropertyEdit(int slot_index,
735 const zelda3::DungeonSpawnPoint& before,
736 bool changed) {
737 auto& spawn = (*spawn_points_)[slot_index];
738 if (!MarkDungeonSpawnPointDirtyIfEditable(slot_index, spawn, changed)) {
739 return;
740 }
743 spawn_property_edit_callback_(slot_index, before, spawn);
744 }
747 }
748 }
749
751 void RegisterPropertyInput(const char* field_label, const char* widget_label);
752
753 std::array<zelda3::RoomEntrance, zelda3::kNumDungeonEntranceSlots>*
754 entrances_ = nullptr;
755 std::array<zelda3::DungeonSpawnPoint, zelda3::kNumDungeonSpawnPoints>*
756 spawn_points_ = nullptr;
757 int* current_entrance_id_ = nullptr;
759 std::function<void(int)> on_entrance_selected_;
761 std::function<bool()> preview_automatic_;
762 std::function<void(int)> select_preview_;
768 std::shared_ptr<const int> property_edit_gesture_;
769 std::function<void()> camera_data_changed_callback_;
770 std::optional<DungeonEntranceCameraState> camera_repair_preview_;
775 ImGuiTextFilter entrance_filter_;
776};
777
778} // namespace editor
779} // namespace yaze
780
781#endif // YAZE_APP_EDITOR_DUNGEON_PANELS_DUNGEON_ENTRANCES_PANEL_H_
WindowContent for displaying and editing dungeon entrances.
void SetPropertyEditCallbacks(EntrancePropertyEditCallback entrance_callback, SpawnPropertyEditCallback spawn_callback)
DungeonEntrancesPanel(std::array< zelda3::RoomEntrance, zelda3::kNumDungeonEntranceSlots > *entrances, std::array< zelda3::DungeonSpawnPoint, zelda3::kNumDungeonSpawnPoints > *spawn_points, int *current_entrance_id, std::function< void(int)> on_entrance_selected)
std::optional< DungeonEntranceCameraState > camera_repair_preview_
void Draw(bool *p_open) override
Draw the panel content.
std::function< void(int)> on_entrance_selected_
void SetCameraTools(CameraStateProvider state_provider, CameraRepairCallback repair_callback, std::function< void()> data_changed_callback={})
int GetPriority() const override
Get display priority for menu ordering.
SpawnPropertyEditCallback spawn_property_edit_callback_
void RegisterPropertyInput(const char *field_label, const char *widget_label)
std::function< std::optional< DungeonEntranceCameraState >(int)> CameraStateProvider
void CommitEntrancePropertyEdit(int slot_index, const zelda3::RoomEntrance &before, bool changed)
bool DrawHexProperty(const char *label, T *value, const char *widget_label, bool continue_row=false)
std::array< zelda3::DungeonSpawnPoint, zelda3::kNumDungeonSpawnPoints > * spawn_points_
void SetProject(const project::YazeProject *project)
std::function< void( int, const zelda3::DungeonSpawnPoint &, const zelda3::DungeonSpawnPoint &)> SpawnPropertyEditCallback
std::string GetDisplayName() const override
Human-readable name shown in menus and title bars.
std::string GetWorkflowGroup() const override
Optional workflow group for hack-centric actions.
std::array< zelda3::RoomEntrance, zelda3::kNumDungeonEntranceSlots > * entrances_
std::shared_ptr< const int > property_edit_gesture() const
std::string GetEditorCategory() const override
Editor category this panel belongs to.
EntrancePropertyEditCallback entrance_property_edit_callback_
std::string GetId() const override
Unique identifier for this panel.
std::string GetIcon() const override
Material Design icon for this panel.
std::function< DungeonRenderContext()> preview_context_
void SetGraphicsPreview(std::function< DungeonRenderContext()> context, std::function< bool()> automatic, std::function< void(int)> select)
void ContinuePropertyRow(const char *label, int digits) const
std::function< absl::Status(int)> CameraRepairCallback
std::function< void( int, const zelda3::RoomEntrance &, const zelda3::RoomEntrance &)> EntrancePropertyEditCallback
std::shared_ptr< const int > property_edit_gesture_
bool DrawCameraBoundaries(const char *table_id, const std::array< uint8_t *, 8 > &boundaries)
void CommitSpawnPropertyEdit(int slot_index, const zelda3::DungeonSpawnPoint &before, bool changed)
Base interface for all logical window content components.
RAII scope that enables automatic widget registration.
Dungeon Room Entrance or Spawn Point.
#define ICON_MD_SEARCH
Definition icons.h:1673
#define ICON_MD_TUNE
Definition icons.h:2022
#define ICON_MD_DOOR_FRONT
Definition icons.h:613
std::string GetEntranceLabel(const project::YazeProject *project, int entrance_id, int room_id)
std::string GetRoomLabel(const project::YazeProject *project, int room_id)
std::string DungeonEntrancePreviewLabel(int slot)
bool CanEditDungeonEntrance(int slot_index, const zelda3::RoomEntrance &entrance)
bool CanEditDungeonSpawnPoint(int slot_index, const zelda3::DungeonSpawnPoint &spawn)
bool MarkDungeonEntranceDirtyIfEditable(int slot_index, zelda3::RoomEntrance &entrance, bool properties_changed)
bool MarkDungeonSpawnPointDirtyIfEditable(int slot_index, zelda3::DungeonSpawnPoint &spawn, bool properties_changed)
DungeonEntranceCameraValidation ValidateDungeonEntranceCamera(const DungeonEntranceCameraState &state)
void AutoRegisterLastItem(const std::string &widget_type, const std::string &explicit_label, const std::string &description)
Automatically register the last ImGui item.
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
Definition input.cc:462
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
Definition input.cc:483
constexpr int kNumRegularDungeonEntrances
constexpr int kNumDungeonSpawnPoints
constexpr int kNumDungeonEntranceSlots
Modern project structure with comprehensive settings consolidation.
Definition project.h:290
Automatic widget registration helpers for ImGui Test Engine integration.