yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_workbench_room_inspector.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <cstdint>
5#include <cstdio>
6#include <string>
7
8#include "absl/strings/str_format.h"
20#include "app/gui/core/icons.h"
21#include "app/gui/core/input.h"
22#include "imgui/imgui.h"
23#include "rom/rom.h"
24#include "util/i18n/tr.h"
27
28namespace yaze::editor {
29
31 DungeonCanvasViewer& viewer) {
32 const auto& theme = AgentUI::GetTheme();
33
34 int room_id = viewer.current_room_id();
35 if (room_id < 0 && current_room_id_) {
36 room_id = *current_room_id_;
37 }
38
39 const std::string room_label =
40 (room_id >= 0)
42 : std::string("None");
43
44 bool room_dirty = false;
45 if (auto* rooms = viewer.rooms(); rooms && room_id >= 0) {
46 if (const auto* room = rooms->GetIfMaterialized(room_id)) {
47 room_dirty = room->HasUnsavedChanges();
48 }
49 }
50
51 // Room badge: hex ID + copy button (only for valid room IDs).
52 if (room_id >= 0) {
53 ImGui::AlignTextToFramePadding();
54 ImGui::Text(tr("Room 0x%03X"), room_id);
55 ImGui::SameLine();
56 if (ImGui::SmallButton(ICON_MD_CONTENT_COPY "##CopyRoomId")) {
57 char buf[16];
58 snprintf(buf, sizeof(buf), "0x%03X", room_id);
59 ImGui::SetClipboardText(buf);
60 }
61 if (ImGui::IsItemHovered()) {
62 ImGui::SetTooltip(tr("Copy room ID (0x%03X) to clipboard"), room_id);
63 }
64 if (room_dirty) {
65 ImGui::SameLine();
66 ImGui::TextColored(theme.status_warning, "Unsaved");
67 }
68
69 if (auto* rooms = viewer.rooms();
70 rooms && room_id < static_cast<int>(rooms->size())) {
71 auto& objects = (*rooms)[room_id].GetTileObjects();
72 if (!objects.empty()) {
73 const auto selected_indices =
75 int requested_object_index =
76 selected_indices.size() == 1
77 ? static_cast<int>(selected_indices.front())
78 : 0;
79 ImGui::AlignTextToFramePadding();
80 ImGui::TextUnformatted(tr("Object"));
81 ImGui::SameLine();
82 ImGui::SetNextItemWidth(74.0f);
83 bool object_index_changed = false;
84 {
85 gui::AutoWidgetScope automation_scope("Dungeon/Workbench");
86 object_index_changed = gui::InputScalarDeferred(
87 "##WorkbenchObjectIndex", ImGuiDataType_S32,
88 &requested_object_index, "%d", 0,
89 {reinterpret_cast<uintptr_t>(rooms),
90 static_cast<uint64_t>(room_id)});
91 gui::AutoRegisterLastItem("input_int", "object_index",
92 "Select and locate a room object by index");
93 }
94 if (object_index_changed) {
95 const size_t target_index = static_cast<size_t>(std::clamp(
96 requested_object_index, 0, static_cast<int>(objects.size()) - 1));
97 viewer.object_interaction().SetSelectedObjects({target_index});
98 viewer.ScrollToTile(objects[target_index].x(),
99 objects[target_index].y());
101 }
102 if (ImGui::IsItemHovered()) {
103 ImGui::SetTooltip(tr("Select object index 0-%zu"),
104 objects.size() - 1);
105 }
106 }
107 }
108 } else {
109 ImGui::TextUnformatted(tr("Room: None"));
110 }
111
112 // Dungeon group context: prefer ROM entrance-based lookup (accurate for
113 // custom Oracle dungeons); fall back to blockset-derived name.
116 }
117 ImGui::PushTextWrapPos(0.0f);
118 if (room_id >= 0) {
119 std::string project_group_name =
121 room_id);
122 const char* group_name =
123 project_group_name.empty() ? nullptr : project_group_name.c_str();
124 if (!group_name) {
125 auto cache_it = room_dungeon_cache_.find(room_id);
126 if (cache_it != room_dungeon_cache_.end() && !cache_it->second.empty()) {
127 group_name = cache_it->second.c_str();
128 }
129 }
130 if (!group_name) {
131 auto* rooms = viewer.rooms();
132 if (rooms && room_id < static_cast<int>(rooms->size())) {
134 (*rooms)[room_id].blockset());
135 }
136 }
137 if (group_name) {
138 ImGui::TextDisabled(ICON_MD_CASTLE " %s – %s", group_name,
139 room_label.c_str());
140 } else {
141 ImGui::TextDisabled("%s", room_label.c_str());
142 }
143 } else {
144 ImGui::TextDisabled("%s", room_label.c_str());
145 }
146 ImGui::PopTextWrapPos();
147
148 // Room properties share the editor's validated metadata edit boundary. Raw
149 // graphics IDs remain available alongside named behavior choices.
150 if (auto* rooms = viewer.rooms();
151 rooms && room_id >= 0 && room_id < static_cast<int>(rooms->size())) {
152 auto& room = (*rooms)[room_id];
153 DrawDungeonRoomPropertyFields(viewer, room, room_id,
155
156 DrawPitDamageControls(room_id);
159 if (viewer.current_room_id() != room_id)
160 return;
161
163 ImGui::PushID("InspectedEntrance");
165 const std::string id = entrance_navigator_content_->GetId();
167 ImGui::TextDisabled(
168 "Entrance properties are open in a separate window.");
169 if (ImGui::Button("Show entrance window") &&
172 } else {
173 ImGui::BeginDisabled(viewer.header_read_only() ||
176 ImGui::EndDisabled();
177 }
178 ImGui::PopID();
179 if (viewer.current_room_id() != room_id)
180 return;
181 }
182
184 false)) {
185 DrawDungeonChestEditor(room_id, room, viewer);
186 }
187 } else {
188 ImGui::TextDisabled(tr("Room properties unavailable"));
189 }
190
192 ICON_MD_CONTENT_COPY " Clone / Import Room", false)) {
193 if (viewer.room_transfer_state().popup_open) {
194 ImGui::TextWrapped("Room transfer is open in the canvas dialog.");
195 } else {
197 }
198 }
199}
200
201} // namespace yaze::editor
bool is_loaded() const
Definition rom.h:187
DungeonObjectInteraction & object_interaction()
DungeonRoomTransferEditorState & room_transfer_state()
const project::YazeProject * project() const
void ScrollToTile(int tile_x, int tile_y)
std::string GetId() const override
Unique identifier for this panel.
void SetSelectedObjects(const std::vector< size_t > &indices)
std::vector< size_t > GetSelectedObjectIndices() const
static const char * GetBlocksetGroupName(uint8_t blockset)
std::function< bool(const std::string &) is_standalone_tool_open_)
void DrawInspectorShelfRoom(DungeonCanvasViewer &viewer)
std::unordered_map< int, std::string > room_dungeon_cache_
std::function< bool(const std::string &) open_and_focus_standalone_tool_)
RAII scope that enables automatic widget registration.
#define ICON_MD_CASTLE
Definition icons.h:380
#define ICON_MD_CONTENT_COPY
Definition icons.h:465
#define ICON_MD_INVENTORY_2
Definition icons.h:1012
const AgentUITheme & GetTheme()
std::string GetRoomLabel(const project::YazeProject *project, int room_id)
std::string GetDungeonNameForRoom(const project::YazeProject *project, int room_id)
bool BeginInspectorSection(const char *label, bool default_open)
Editors are the view controllers for the application.
void DrawDungeonRoomTransferEditor(DungeonCanvasViewer &viewer)
void DrawDungeonDestinationEditor(DungeonCanvasViewer &viewer)
void DrawDungeonRoomPropertyFields(DungeonCanvasViewer &viewer, zelda3::Room &room, int room_id, RoomPropertyLayout layout)
void DrawDungeonChestEditor(int room_id, zelda3::Room &room, DungeonCanvasViewer &viewer)
void AutoRegisterLastItem(const std::string &widget_type, const std::string &explicit_label, const std::string &description)
Automatically register the last ImGui item.
bool InputScalarDeferred(const char *label, ImGuiDataType data_type, void *data, const char *format, ImGuiInputTextFlags flags, InputScalarTargetIdentity target_identity)
Definition input.cc:392
Automatic widget registration helpers for ImGui Test Engine integration.