yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
rom_load_options_dialog.cc
Go to the documentation of this file.
2#include "util/i18n/tr.h"
3
4#include "absl/strings/str_format.h"
9#include "core/features.h"
10#include "imgui/imgui.h"
11#include "rom/rom.h"
12
13namespace yaze {
14namespace editor {
15
16// Preset definitions
17const char* RomLoadOptionsDialog::kPresetNames[kNumPresets] = {
18 "Vanilla ROM Hack", "ZSCustomOverworld v2",
19 "ZSCustomOverworld v3 (Recommended)", "Randomizer Compatible"};
20
21const char* RomLoadOptionsDialog::kPresetDescriptions[kNumPresets] = {
22 "Standard ROM editing without custom ASM. Limited to vanilla features.",
23 "Basic overworld expansion: custom BG colors, main palettes, parent "
24 "system.",
25 "Full overworld expansion: wide/tall areas, animated GFX, overlays, all "
26 "features.",
27 "Compatible with ALttP Randomizer. Minimal custom features."};
28
36
38 if (rom) {
39 Open(rom, rom->filename(), false);
40 }
41}
42
43void RomLoadOptionsDialog::Open(Rom* rom, bool suggest_project_creation) {
44 if (rom) {
45 Open(rom, rom->filename(), suggest_project_creation);
46 }
47}
48
49void RomLoadOptionsDialog::Draw(bool* p_open) {
50 Show(p_open);
51}
52
53void RomLoadOptionsDialog::Open(Rom* rom, const std::string& rom_filename) {
54 Open(rom, rom_filename, false);
55}
56
57void RomLoadOptionsDialog::Open(Rom* rom, const std::string& rom_filename,
58 bool suggest_project_creation) {
59 rom_ = rom;
60 rom_filename_ = rom_filename;
61 is_open_ = true;
62 confirmed_ = false;
63 show_advanced_ = false;
64
65 // Reset options for each open so stale state from previous ROM loads does
66 // not carry over.
72 options_.create_project = suggest_project_creation;
73
74 // Detect ROM version
75 if (rom_ && rom_->is_loaded()) {
77 } else {
79 }
80
81 // Set default project name from ROM filename
82 size_t last_slash = rom_filename_.find_last_of("/\\");
83 size_t last_dot = rom_filename_.find_last_of('.');
84 std::string base_name;
85 if (last_slash != std::string::npos) {
86 base_name = rom_filename_.substr(last_slash + 1);
87 } else {
88 base_name = rom_filename_;
89 }
90 if (last_dot != std::string::npos && last_dot > last_slash) {
91 base_name = base_name.substr(0, base_name.find_last_of('.'));
92 }
93
94 snprintf(project_name_buffer_, sizeof(project_name_buffer_), "%s_project",
95 base_name.c_str());
96
97 // Auto-select preset based on detected version
98 switch (detected_version_) {
100 selected_preset_index_ = 2; // Recommend v3 upgrade for vanilla
103 break;
106 selected_preset_index_ = 1; // Keep v2 features
107 break;
109 selected_preset_index_ = 2; // Full v3 features
110 break;
111 }
112
114 options_.create_project = suggest_project_creation;
115}
116
117bool RomLoadOptionsDialog::Show(bool* p_open) {
118 if (!is_open_)
119 return false;
120
121 ImGui::SetNextWindowSize(ImVec2(600, 500), ImGuiCond_FirstUseEver);
122 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(),
123 ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
124
125 ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse;
126
127 bool result = false;
128 if (ImGui::Begin(
129 absl::StrFormat("%s ROM Load Options", ICON_MD_SETTINGS).c_str(),
130 &is_open_, flags)) {
132 ImGui::Separator();
133
135 ImGui::Separator();
136
138
139 if (show_advanced_) {
140 ImGui::Separator();
142 }
143
144 ImGui::Separator();
146
147 ImGui::Separator();
149
150 result = confirmed_;
151 }
152 ImGui::End();
153
154 if (p_open) {
155 *p_open = is_open_;
156 }
157
158 return result;
159}
160
162 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
163
164 ImGui::Text(tr("%s ROM Information"), ICON_MD_INFO);
165 ImGui::Spacing();
166
167 // ROM filename
168 ImGui::TextColored(gui::ConvertColorToImVec4(theme.text_secondary),
169 tr("File: %s"), rom_filename_.c_str());
170
171 // Detected version with color coding
172 const char* version_name =
174
175 ImVec4 version_color;
176 switch (detected_version_) {
178 version_color = gui::GetWarningColor(); // Vanilla ROM needs an upgrade.
179 break;
182 version_color = gui::GetInfoColor(); // Partial feature support.
183 break;
185 version_color = gui::GetSuccessColor(); // Full feature support.
186 break;
187 default:
188 version_color = gui::GetTextSecondaryVec4();
189 }
190
191 ImGui::TextColored(version_color, tr("%s Detected: %s"), ICON_MD_VERIFIED,
192 version_name);
193
194 // Show feature availability
196 ImGui::TextColored(gui::GetWarningColor(),
197 tr("%s This ROM can be upgraded for expanded features"),
199 }
200}
201
204
205 ImGui::Text(tr("%s ZSCustomOverworld Options"), ICON_MD_AUTO_FIX_HIGH);
206 ImGui::Spacing();
207
208 if (is_vanilla) {
209 ImGui::Checkbox(tr("Upgrade ROM to ZSCustomOverworld"),
211
213 ImGui::Indent();
214
215 ImGui::Text(tr("Target Version:"));
216 ImGui::SameLine();
217
218 if (ImGui::RadioButton(tr("v2 (Basic)"),
221 }
222 ImGui::SameLine();
223 if (ImGui::RadioButton(tr("v3 (Full)"),
226 }
227
228 // Version comparison
229 ImGui::TextColored(gui::GetTextSecondaryVec4(),
230 tr("v2: BG colors, main palettes, parent system"));
231 ImGui::TextColored(gui::GetTextSecondaryVec4(),
232 tr("v3: + wide/tall areas, animated GFX, overlays"));
233
234 // Tail expansion option (only for v3)
235 if (options_.target_zso_version == 3) {
236 ImGui::Spacing();
237 ImGui::TextColored(gui::GetWarningColor(), tr("Experimental:"));
238 ImGui::Checkbox(tr("Enable special world tail (0xA0-0xBF)"),
240 if (ImGui::IsItemHovered()) {
241 ImGui::SetTooltip(
242 tr("Enables access to unused special world map slots.\n"
243 "REQUIRES additional ASM patch for pointer table expansion.\n"
244 "Without the patch, maps will show blank tiles (safe)."));
245 }
246 }
247
248 ImGui::Unindent();
249 }
250 } else {
251 ImGui::TextColored(
252 gui::GetSuccessColor(), tr("%s ROM already has ZSCustomOverworld %s"),
255 }
256
257 // Enable custom overworld features toggle
258 ImGui::Spacing();
259 ImGui::Checkbox(tr("Enable custom overworld features in editor"),
261
262 if (ImGui::IsItemHovered()) {
263 ImGui::SetTooltip(
264 tr("Enables ZSCustomOverworld-specific UI elements.\n"
265 "Auto-enabled if ASM is detected in ROM."));
266 }
267}
268
270 ImGui::Text(tr("%s Feature Presets"), ICON_MD_TUNE);
271 ImGui::Spacing();
272
273 // Preset selection combo
274 if (ImGui::BeginCombo("##PresetCombo",
276 for (int i = 0; i < kNumPresets; i++) {
277 bool is_selected = (selected_preset_index_ == i);
278 if (ImGui::Selectable(kPresetNames[i], is_selected)) {
281 }
282
283 if (ImGui::IsItemHovered()) {
284 ImGui::SetTooltip("%s", kPresetDescriptions[i]);
285 }
286
287 if (is_selected) {
288 ImGui::SetItemDefaultFocus();
289 }
290 }
291 ImGui::EndCombo();
292 }
293
294 // Show preset description
295 ImGui::TextColored(gui::GetTextSecondaryVec4(), "%s",
297
298 // Advanced toggle
299 ImGui::Spacing();
300 if (ImGui::Button(show_advanced_ ? "Hide Advanced Options"
301 : "Show Advanced Options")) {
303 }
304}
305
307 ImGui::Text(tr("%s Feature Flags"), ICON_MD_FLAG);
308 ImGui::Spacing();
309
310 // Overworld flags
311 if (ImGui::TreeNodeEx("Overworld", ImGuiTreeNodeFlags_DefaultOpen)) {
312 ImGui::Checkbox(tr("Save overworld maps"), &options_.save_overworld_maps);
313 ImGui::Checkbox(tr("Save entrances"), &options_.save_overworld_entrances);
314 ImGui::Checkbox(tr("Save exits"), &options_.save_overworld_exits);
315 ImGui::Checkbox(tr("Save items"), &options_.save_overworld_items);
316 ImGui::TreePop();
317 }
318
319 // Dungeon flags
320 if (ImGui::TreeNodeEx("Dungeon")) {
321 ImGui::Checkbox(tr("Save dungeon maps"), &options_.save_dungeon_maps);
322 ImGui::TreePop();
323 }
324
325 // Graphics flags
326 if (ImGui::TreeNodeEx("Graphics")) {
327 ImGui::Checkbox(tr("Save all palettes"), &options_.save_all_palettes);
328 ImGui::Checkbox(tr("Save GFX groups"), &options_.save_gfx_groups);
329 ImGui::TreePop();
330 }
331}
332
334 ImGui::Text(tr("%s Project Options"), ICON_MD_FOLDER);
335 ImGui::Spacing();
336
337 ImGui::Checkbox(tr("Create associated project file"),
339
341 ImGui::Indent();
342
343 ImGui::Text(tr("Project Name:"));
344 ImGui::SetNextItemWidth(-1);
345 ImGui::InputText("##ProjectName", project_name_buffer_,
346 sizeof(project_name_buffer_));
348
349 ImGui::TextColored(
351 tr("Project file stores settings, labels, and preferences."));
352
353 ImGui::Unindent();
354 }
355}
356
358 const float button_width = 120.0f;
359 const float spacing = 10.0f;
360 float total_width = button_width * 2 + spacing;
361
362 // Center buttons
363 float avail = ImGui::GetContentRegionAvail().x;
364 ImGui::SetCursorPosX((avail - total_width) * 0.5f + ImGui::GetCursorPosX());
365
366 // Cancel button
367 if (ImGui::Button(tr("Cancel"), ImVec2(button_width, 0))) {
368 is_open_ = false;
369 confirmed_ = false;
370 }
371
372 ImGui::SameLine(0, spacing);
373
374 // Confirm button with accent color
375 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
376 ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
377
378 {
379 gui::StyleColorGuard btn_guard(
380 {{ImGuiCol_Button, accent},
381 {ImGuiCol_ButtonHovered,
382 ImVec4(accent.x * 1.1f, accent.y * 1.1f, accent.z * 1.1f, accent.w)},
383 {ImGuiCol_ButtonActive, ImVec4(accent.x * 0.9f, accent.y * 0.9f,
384 accent.z * 0.9f, accent.w)}});
385
386 if (ImGui::Button(absl::StrFormat("%s Continue", ICON_MD_CHECK).c_str(),
387 ImVec2(button_width, 0))) {
388 // Apply options
391
392 confirmed_ = true;
393 is_open_ = false;
394
395 // Call upgrade callback if needed
398 }
399
400 // Call confirm callback
401 if (confirm_callback_) {
403 }
404 }
405 }
406}
407
408void RomLoadOptionsDialog::ApplyPreset(const std::string& preset_name) {
409 if (preset_name == "Vanilla ROM Hack") {
419 } else if (preset_name == "ZSCustomOverworld v2") {
431 } else if (preset_name == "ZSCustomOverworld v3 (Recommended)") {
443 } else if (preset_name == "Randomizer Compatible") {
453 }
454}
455
457 auto& flags = core::FeatureFlags::get();
458
459 flags.overworld.kSaveOverworldMaps = options_.save_overworld_maps;
460 flags.overworld.kSaveOverworldEntrances = options_.save_overworld_entrances;
461 flags.overworld.kSaveOverworldExits = options_.save_overworld_exits;
462 flags.overworld.kSaveOverworldItems = options_.save_overworld_items;
463 flags.overworld.kLoadCustomOverworld = options_.enable_custom_overworld;
464 flags.overworld.kEnableSpecialWorldExpansion = options_.enable_tail_expansion;
465 flags.kSaveDungeonMaps = options_.save_dungeon_maps;
466 flags.kSaveAllPalettes = options_.save_all_palettes;
467 flags.kSaveGfxGroups = options_.save_gfx_groups;
468}
469
473
474} // namespace editor
475} // namespace yaze
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
auto filename() const
Definition rom.h:157
bool is_loaded() const
Definition rom.h:144
static Flags & get()
Definition features.h:119
std::function< void(const LoadOptions &) confirm_callback_)
void ApplyPreset(const std::string &preset_name)
void Open(Rom *rom, const std::string &rom_filename)
Open the dialog after ROM detection.
static const char * kPresetNames[kNumPresets]
std::function< absl::Status(int version)> upgrade_callback_
bool Show(bool *p_open)
Show the dialog.
static const char * kPresetDescriptions[kNumPresets]
bool ShouldPromptUpgrade() const
Check if ROM needs upgrade prompt.
void Draw(bool *p_open)
Draw the dialog (wrapper around Show)
RAII guard for ImGui style colors.
Definition style_guard.h:27
const Theme & GetCurrentTheme() const
static ThemeManager & Get()
static OverworldVersion GetVersion(const Rom &rom)
Detect ROM version from ASM marker byte.
static const char * GetVersionName(OverworldVersion version)
Get human-readable version name for display/logging.
#define ICON_MD_SETTINGS
Definition icons.h:1699
#define ICON_MD_INFO
Definition icons.h:993
#define ICON_MD_UPGRADE
Definition icons.h:2047
#define ICON_MD_CHECK
Definition icons.h:397
#define ICON_MD_TUNE
Definition icons.h:2022
#define ICON_MD_VERIFIED
Definition icons.h:2055
#define ICON_MD_AUTO_FIX_HIGH
Definition icons.h:218
#define ICON_MD_CHECK_CIRCLE
Definition icons.h:400
#define ICON_MD_FLAG
Definition icons.h:784
#define ICON_MD_FOLDER
Definition icons.h:809
ImVec4 ConvertColorToImVec4(const Color &color)
Definition color.h:134
ImVec4 GetSuccessColor()
Definition ui_helpers.cc:49
ImVec4 GetTextSecondaryVec4()
ImVec4 GetWarningColor()
Definition ui_helpers.cc:54
ImVec4 GetInfoColor()
Definition ui_helpers.cc:64
@ 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.