yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_toolbar.cc
Go to the documentation of this file.
2
10
11namespace yaze::editor {
12
13using ImGui::BeginTable;
14using ImGui::TableNextColumn;
15
16void OverworldToolbar::Draw(int& current_world, int& current_map,
17 bool& current_map_lock, EditingMode& current_mode,
18 EntityEditMode& entity_edit_mode,
19 WorkspaceWindowManager* window_manager, bool has_selection,
20 bool scratch_has_data, Rom* rom,
21 zelda3::Overworld* overworld) {
22 if (!overworld || !overworld->is_loaded() || !window_manager)
23 return;
24
25 gui::StyleVarGuard toolbar_style_guard(
26 {{ImGuiStyleVar_FramePadding, ImVec2(6.0f, 5.0f)},
27 {ImGuiStyleVar_CellPadding, ImVec2(6.0f, 5.0f)}});
28
29 // Simplified canvas toolbar - Navigation and Mode controls
30 if (BeginTable("CanvasToolbar", 8,
31 ImGuiTableFlags_Borders | ImGuiTableFlags_SizingStretchProp,
32 ImVec2(0, 0), -1)) {
33 ImGui::TableSetupColumn("World", ImGuiTableColumnFlags_WidthFixed,
35 ImGui::TableSetupColumn("Map", ImGuiTableColumnFlags_WidthFixed,
37 ImGui::TableSetupColumn("Area Size", ImGuiTableColumnFlags_WidthFixed,
39 ImGui::TableSetupColumn("Lock", ImGuiTableColumnFlags_WidthFixed,
41 ImGui::TableSetupColumn("Mode", ImGuiTableColumnFlags_WidthFixed,
42 124.0f); // Mouse/Brush/Fill
43 ImGui::TableSetupColumn("Context", ImGuiTableColumnFlags_WidthStretch);
44 ImGui::TableSetupColumn("Panels", ImGuiTableColumnFlags_WidthStretch);
45 ImGui::TableSetupColumn("Sidebar", ImGuiTableColumnFlags_WidthFixed, 44.0f);
46
47 TableNextColumn();
48 ImGui::SetNextItemWidth(kComboWorldWidth);
49 int selected_world = current_world;
50 if (ImGui::Combo("##world", &selected_world, kWorldNames, 3)) {
51 current_world = selected_world;
52 if (on_world_changed) {
53 on_world_changed(selected_world);
54 } else {
55 current_map = selected_world * 0x40 + (current_map & 0x3F);
56 }
57 }
58
59 TableNextColumn();
60 ImGui::Text("%d (0x%02X)", current_map, current_map);
61
62 TableNextColumn();
63 // Use centralized version detection
64 auto rom_version = zelda3::OverworldVersionHelper::GetVersion(*rom);
65
66 // ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
67 int current_area_size =
68 static_cast<int>(overworld->overworld_map(current_map)->area_size());
69 ImGui::SetNextItemWidth(kComboAreaSizeWidth);
70
72 // v3+ ROM: Show all 4 area size options
73 if (ImGui::Combo("##AreaSize", &current_area_size, kAreaSizeNames, 4)) {
74 auto status = overworld->ConfigureMultiAreaMap(
75 current_map, static_cast<zelda3::AreaSizeEnum>(current_area_size));
76 if (status.ok()) {
81 }
82 }
83 } else {
84 // Vanilla/v1/v2 ROM: Show only Small/Large (first 2 options)
85 const char* limited_names[] = {"Small (1x1)", "Large (2x2)"};
86 int limited_size = (current_area_size == 0 || current_area_size == 1)
87 ? current_area_size
88 : 0;
89
90 if (ImGui::Combo("##AreaSize", &limited_size, limited_names, 2)) {
91 // limited_size is 0 (Small) or 1 (Large)
92 auto size = (limited_size == 1) ? zelda3::AreaSizeEnum::LargeArea
94 auto status = overworld->ConfigureMultiAreaMap(current_map, size);
95 if (status.ok()) {
100 }
101 }
102
103 if (rom_version == zelda3::OverworldVersion::kVanilla ||
105 HOVER_HINT("Small (1x1) and Large (2x2) maps. Wide/Tall require v3+");
106 }
107 }
108
109 TableNextColumn();
111 current_map_lock ? ICON_MD_LOCK : ICON_MD_LOCK_OPEN,
112 current_map_lock ? "Unlock Map" : "Lock Map")) {
113 current_map_lock = !current_map_lock;
114 }
115
116 TableNextColumn();
117 // Mode Controls
118 {
121 "Mouse Mode (1)\nNavigate, pan, and manage entities",
122 current_mode == EditingMode::MOUSE)) {
123 current_mode = EditingMode::MOUSE;
124 }
125
126 ImGui::SameLine(0, 2);
129 "Brush Mode (2/B)\nDraw tiles on the map\nRight-click or I to "
130 "sample tile16 under cursor",
131 current_mode == EditingMode::DRAW_TILE)) {
132 current_mode = EditingMode::DRAW_TILE;
133 }
134
135 ImGui::SameLine(0, 2);
138 "Fill Screen Mode (F)\nFill the 32x32 screen under the cursor "
139 "with the selected tile\nRight-click or I to sample tile16 under "
140 "cursor",
141 current_mode == EditingMode::FILL_TILE)) {
142 current_mode = EditingMode::FILL_TILE;
143 }
144 }
145
146 TableNextColumn();
147 // Entity status / ROM version plus a small amount of high-value map info.
148 const auto& theme = AgentUI::GetTheme();
149 const zelda3::OverworldMap* map = overworld->overworld_map(current_map);
150 const float context_width = ImGui::GetContentRegionAvail().x;
151 const bool show_map_summary = map != nullptr && context_width >= 188.0f;
152 const bool show_overlay_toggle = context_width >= 132.0f;
153
154 if (entity_edit_mode != EntityEditMode::NONE) {
155 const char* entity_icon = "";
156 const char* entity_label = "";
157 switch (entity_edit_mode) {
159 entity_icon = ICON_MD_DOOR_FRONT;
160 entity_label = "Entrances";
161 break;
163 entity_icon = ICON_MD_DOOR_BACK;
164 entity_label = "Exits";
165 break;
167 entity_icon = ICON_MD_GRASS;
168 entity_label = "Items";
169 break;
171 entity_icon = ICON_MD_PEST_CONTROL_RODENT;
172 entity_label = "Sprites";
173 break;
175 entity_icon = ICON_MD_ADD_LOCATION;
176 entity_label = "Transports";
177 break;
179 entity_icon = ICON_MD_MUSIC_NOTE;
180 entity_label = "Music";
181 break;
182 default:
183 break;
184 }
185 ImGui::TextColored(theme.selection_secondary, "%s %s", entity_icon,
186 entity_label);
187 } else {
188 // Show ROM version badge when no entity mode is active
189 const char* version_label = "Vanilla";
190 ImVec4 version_color = theme.status_inactive;
191 bool show_upgrade = false;
192
193 switch (rom_version) {
195 version_label = "Vanilla";
196 version_color = theme.text_warning_yellow;
197 show_upgrade = true;
198 break;
200 version_label = "ZSC v1";
201 version_color = theme.status_active;
202 break;
204 version_label = "ZSC v2";
205 version_color = theme.status_active;
206 break;
208 version_label = "ZSC v3";
209 version_color = theme.status_success;
210 break;
211 default:
212 break;
213 }
214
215 ImGui::TextColored(version_color, ICON_MD_INFO " %s", version_label);
216 if (ImGui::IsItemHovered()) {
217 ImGui::SetTooltip(
218 "ROM version determines available overworld features.\n"
219 "v2+: Custom BG colors, main palettes\n"
220 "v3+: Wide/Tall maps, custom tile GFX, animated GFX");
221 }
222
223 if (show_upgrade && on_upgrade_rom_version) {
224 ImGui::SameLine();
225 if (gui::PrimaryButton(ICON_MD_UPGRADE " Upgrade")) {
226 on_upgrade_rom_version(3); // Upgrade to v3
227 }
229 "Upgrade ROM to ZSCustomOverworld v3\n"
230 "Enables all advanced features");
231 }
232 }
233
234 if (show_map_summary) {
235 ImGui::TextDisabled("Parent %02X Pal %02X Msg %04X", map->parent(),
236 map->area_palette(), map->message_id());
237 } else if (show_overlay_toggle && on_toggle_overlay_preview &&
239 const bool overlay_preview_enabled = is_overlay_preview_enabled();
242 overlay_preview_enabled ? "Hide overlay preview"
243 : "Show overlay preview",
244 overlay_preview_enabled)) {
246 }
247 }
248
249 TableNextColumn();
250 // Panel Toggle Controls - using WorkspaceWindowManager for visibility
251 const size_t session_id = window_manager->GetActiveSessionId();
252 const float panel_width = ImGui::GetContentRegionAvail().x;
253 const bool compact_panel_controls = panel_width < 320.0f;
254 const auto toggle_window = [&](const char* panel_id) {
255 window_manager->ToggleWindow(session_id, panel_id);
256 };
257 const auto popup_toggle_item =
258 [&](const char* label, const char* panel_id, const char* shortcut = nullptr) {
259 const bool open = window_manager->IsWindowOpen(panel_id);
260 if (ImGui::MenuItem(label, shortcut, open)) {
261 toggle_window(panel_id);
262 }
263 };
264 {
265 gui::StyleVarGuard panel_spacing_guard(ImGuiStyleVar_ItemSpacing,
266 ImVec2(4, 0));
267
268 if (compact_panel_controls) {
270 "Overworld Windows\nOpen panel toggle menu")) {
271 ImGui::OpenPopup("OverworldWindowsPopup");
272 }
273
274 if (ImGui::BeginPopup("OverworldWindowsPopup")) {
275 popup_toggle_item("Tile16 Editor", OverworldPanelIds::kTile16Editor,
276 "Ctrl+T");
277 popup_toggle_item("Tile16 Selector", OverworldPanelIds::kTile16Selector);
278 popup_toggle_item("Tile8 Selector", OverworldPanelIds::kTile8Selector);
279 popup_toggle_item("Area Graphics", OverworldPanelIds::kAreaGraphics);
280 popup_toggle_item("GFX Groups", OverworldPanelIds::kGfxGroups);
281 popup_toggle_item("Usage Statistics", OverworldPanelIds::kUsageStats);
282 popup_toggle_item("Item List", OverworldPanelIds::kItemList,
283 "Ctrl+Shift+I");
284 popup_toggle_item("Scratch Workspace",
286 ImGui::EndPopup();
287 }
288 } else {
289 // Tile16 Editor toggle (Ctrl+T)
290 if (gui::ToolbarIconButton(ICON_MD_EDIT, "Tile16 Editor (Ctrl+T)",
291 window_manager->IsWindowOpen(
294 }
295
296 ImGui::SameLine();
297 if (gui::ToolbarIconButton(ICON_MD_GRID_ON, "Tile16 Selector",
298 window_manager->IsWindowOpen(
301 }
302
303 ImGui::SameLine();
304 if (gui::ToolbarIconButton(ICON_MD_GRID_VIEW, "Tile8 Selector",
305 window_manager->IsWindowOpen(
308 }
309
310 ImGui::SameLine();
311 if (gui::ToolbarIconButton(ICON_MD_IMAGE, "Area Graphics",
312 window_manager->IsWindowOpen(
315 }
316
317 ImGui::SameLine();
319 ICON_MD_LAYERS, "GFX Groups",
321 toggle_window(OverworldPanelIds::kGfxGroups);
322 }
323
324 ImGui::SameLine();
326 ICON_MD_ANALYTICS, "Usage Statistics",
328 toggle_window(OverworldPanelIds::kUsageStats);
329 }
330
331 ImGui::SameLine();
334 "Overworld Item List (Ctrl+Shift+I)\nFilter/select items and use "
335 "duplicate/nudge shortcuts",
336 window_manager->IsWindowOpen(OverworldPanelIds::kItemList))) {
337 toggle_window(OverworldPanelIds::kItemList);
338 }
339
340 ImGui::SameLine();
341 if (gui::ToolbarIconButton(ICON_MD_AUTO_FIX_HIGH, "Scratch Workspace",
342 window_manager->IsWindowOpen(
345 }
346 }
347 }
348
349 TableNextColumn();
350 // Sidebar Toggle (Map Properties)
352 ICON_MD_TUNE, "Toggle Map Properties Sidebar",
354 window_manager->ToggleWindow(window_manager->GetActiveSessionId(),
356 }
357
358 ImGui::EndTable();
359 }
360}
361
362} // namespace yaze::editor
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
std::function< void()> on_refresh_map
std::function< void()> on_refresh_graphics
std::function< void(int)> on_upgrade_rom_version
std::function< bool()> is_overlay_preview_enabled
std::function< void(int)> on_world_changed
void Draw(int &current_world, int &current_map, bool &current_map_lock, EditingMode &current_mode, EntityEditMode &entity_edit_mode, WorkspaceWindowManager *window_manager, bool has_selection, bool scratch_has_data, Rom *rom, zelda3::Overworld *overworld)
std::function< void()> on_toggle_overlay_preview
Central registry for all editor cards with session awareness and dependency injection.
bool IsWindowOpen(size_t session_id, const std::string &base_window_id) const
bool ToggleWindow(size_t session_id, const std::string &base_window_id)
RAII guard for ImGui style vars.
Definition style_guard.h:68
Represents a single Overworld map screen.
static OverworldVersion GetVersion(const Rom &rom)
Detect ROM version from ASM marker byte.
static bool SupportsAreaEnum(OverworldVersion version)
Check if ROM supports area enum system (v3+ only)
Represents the full Overworld data, light and dark world.
Definition overworld.h:261
auto is_loaded() const
Definition overworld.h:597
auto overworld_map(int i) const
Definition overworld.h:531
absl::Status ConfigureMultiAreaMap(int parent_index, AreaSizeEnum size)
Configure a multi-area map structure (Large/Wide/Tall)
Definition overworld.cc:309
#define ICON_MD_GRID_VIEW
Definition icons.h:897
#define ICON_MD_APPS
Definition icons.h:168
#define ICON_MD_INFO
Definition icons.h:993
#define ICON_MD_UPGRADE
Definition icons.h:2047
#define ICON_MD_LOCK_OPEN
Definition icons.h:1142
#define ICON_MD_LOCK
Definition icons.h:1140
#define ICON_MD_DRAW
Definition icons.h:625
#define ICON_MD_TUNE
Definition icons.h:2022
#define ICON_MD_VISIBILITY
Definition icons.h:2101
#define ICON_MD_GRASS
Definition icons.h:891
#define ICON_MD_FORMAT_COLOR_FILL
Definition icons.h:830
#define ICON_MD_EDIT
Definition icons.h:645
#define ICON_MD_DOOR_BACK
Definition icons.h:612
#define ICON_MD_AUTO_FIX_HIGH
Definition icons.h:218
#define ICON_MD_MUSIC_NOTE
Definition icons.h:1264
#define ICON_MD_GRID_ON
Definition icons.h:896
#define ICON_MD_LIST
Definition icons.h:1094
#define ICON_MD_LAYERS
Definition icons.h:1068
#define ICON_MD_DOOR_FRONT
Definition icons.h:613
#define ICON_MD_IMAGE
Definition icons.h:982
#define ICON_MD_ADD_LOCATION
Definition icons.h:100
#define ICON_MD_MOUSE
Definition icons.h:1251
#define ICON_MD_PEST_CONTROL_RODENT
Definition icons.h:1430
#define ICON_MD_ANALYTICS
Definition icons.h:154
#define HOVER_HINT(string)
Definition macro.h:24
const AgentUITheme & GetTheme()
Editors are the view controllers for the application.
constexpr const char * kAreaSizeNames[]
constexpr float kTableColumnWorld
constexpr const char * kWorldNames[]
constexpr float kComboWorldWidth
constexpr float kTableColumnMap
constexpr float kTableColumnAreaSize
constexpr float kComboAreaSizeWidth
constexpr float kTableColumnLock
bool PrimaryButton(const char *label, const ImVec2 &size, const char *panel_id, const char *anim_id)
Draw a primary action button (accented color).
bool ToolbarIconButton(const char *icon, const char *tooltip, bool is_active)
Convenience wrapper for toolbar-sized icon buttons.
AreaSizeEnum
Area size enumeration for v3+ ROMs.
@ kZSCustomV2
Parent system, BG colors, main palettes.
@ kZSCustomV1
Basic features, expanded pointers.
@ kVanilla
0xFF in ROM, no ZScream ASM applied
@ kZSCustomV3
Area enum, wide/tall areas, all features.
static constexpr const char * kMapProperties
static constexpr const char * kTile8Selector
static constexpr const char * kAreaGraphics
static constexpr const char * kItemList
static constexpr const char * kScratchSpace
static constexpr const char * kTile16Editor
static constexpr const char * kTile16Selector
static constexpr const char * kGfxGroups
static constexpr const char * kUsageStats