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
3#include "absl/strings/str_format.h"
7#include "core/features.h"
8#include "imgui/imgui.h"
9#include "rom/rom.h"
10
11namespace yaze {
12namespace editor {
13
14// Preset definitions
15const char* RomLoadOptionsDialog::kPresetNames[kNumPresets] = {
16 "Vanilla ROM Hack", "ZSCustomOverworld v2",
17 "ZSCustomOverworld v3 (Recommended)", "Randomizer Compatible"};
18
19const char* RomLoadOptionsDialog::kPresetDescriptions[kNumPresets] = {
20 "Standard ROM editing without custom ASM. Limited to vanilla features.",
21 "Basic overworld expansion: custom BG colors, main palettes, parent "
22 "system.",
23 "Full overworld expansion: wide/tall areas, animated GFX, overlays, all "
24 "features.",
25 "Compatible with ALttP Randomizer. Minimal custom features."};
26
34
36 if (rom) {
37 Open(rom, rom->filename(), false);
38 }
39}
40
41void RomLoadOptionsDialog::Open(Rom* rom, bool suggest_project_creation) {
42 if (rom) {
43 Open(rom, rom->filename(), suggest_project_creation);
44 }
45}
46
47void RomLoadOptionsDialog::Draw(bool* p_open) {
48 Show(p_open);
49}
50
51void RomLoadOptionsDialog::Open(Rom* rom, const std::string& rom_filename) {
52 Open(rom, rom_filename, false);
53}
54
55void RomLoadOptionsDialog::Open(Rom* rom, const std::string& rom_filename,
56 bool suggest_project_creation) {
57 rom_ = rom;
58 rom_filename_ = rom_filename;
59 is_open_ = true;
60 confirmed_ = false;
61 show_advanced_ = false;
62
63 // Reset options for each open so stale state from previous ROM loads does
64 // not carry over.
70 options_.create_project = suggest_project_creation;
71
72 // Detect ROM version
73 if (rom_ && rom_->is_loaded()) {
75 } else {
77 }
78
79 // Set default project name from ROM filename
80 size_t last_slash = rom_filename_.find_last_of("/\\");
81 size_t last_dot = rom_filename_.find_last_of('.');
82 std::string base_name;
83 if (last_slash != std::string::npos) {
84 base_name = rom_filename_.substr(last_slash + 1);
85 } else {
86 base_name = rom_filename_;
87 }
88 if (last_dot != std::string::npos && last_dot > last_slash) {
89 base_name = base_name.substr(0, base_name.find_last_of('.'));
90 }
91
92 snprintf(project_name_buffer_, sizeof(project_name_buffer_), "%s_project",
93 base_name.c_str());
94
95 // Auto-select preset based on detected version
96 switch (detected_version_) {
98 selected_preset_index_ = 2; // Recommend v3 upgrade for vanilla
101 break;
104 selected_preset_index_ = 1; // Keep v2 features
105 break;
107 selected_preset_index_ = 2; // Full v3 features
108 break;
109 }
110
112 options_.create_project = suggest_project_creation;
113}
114
115bool RomLoadOptionsDialog::Show(bool* p_open) {
116 if (!is_open_)
117 return false;
118
119 ImGui::SetNextWindowSize(ImVec2(600, 500), ImGuiCond_FirstUseEver);
120 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(),
121 ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
122
123 ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse;
124
125 bool result = false;
126 if (ImGui::Begin(
127 absl::StrFormat("%s ROM Load Options", ICON_MD_SETTINGS).c_str(),
128 &is_open_, flags)) {
130 ImGui::Separator();
131
133 ImGui::Separator();
134
136
137 if (show_advanced_) {
138 ImGui::Separator();
140 }
141
142 ImGui::Separator();
144
145 ImGui::Separator();
147
148 result = confirmed_;
149 }
150 ImGui::End();
151
152 if (p_open) {
153 *p_open = is_open_;
154 }
155
156 return result;
157}
158
160 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
161
162 ImGui::Text("%s ROM Information", ICON_MD_INFO);
163 ImGui::Spacing();
164
165 // ROM filename
166 ImGui::TextColored(gui::ConvertColorToImVec4(theme.text_secondary),
167 "File: %s", rom_filename_.c_str());
168
169 // Detected version with color coding
170 const char* version_name =
172
173 ImVec4 version_color;
174 switch (detected_version_) {
176 version_color = ImVec4(0.8f, 0.8f, 0.2f, 1.0f); // Yellow - needs upgrade
177 break;
180 version_color =
181 ImVec4(0.2f, 0.6f, 0.8f, 1.0f); // Blue - partial features
182 break;
184 version_color = ImVec4(0.2f, 0.8f, 0.4f, 1.0f); // Green - full features
185 break;
186 default:
187 version_color = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
188 }
189
190 ImGui::TextColored(version_color, "%s Detected: %s", ICON_MD_VERIFIED,
191 version_name);
192
193 // Show feature availability
195 ImGui::TextColored(ImVec4(1.0f, 0.6f, 0.2f, 1.0f),
196 "%s This ROM can be upgraded for expanded features",
198 }
199}
200
203
204 ImGui::Text("%s ZSCustomOverworld Options", ICON_MD_AUTO_FIX_HIGH);
205 ImGui::Spacing();
206
207 if (is_vanilla) {
208 ImGui::Checkbox("Upgrade ROM to ZSCustomOverworld",
210
212 ImGui::Indent();
213
214 ImGui::Text("Target Version:");
215 ImGui::SameLine();
216
217 if (ImGui::RadioButton("v2 (Basic)", options_.target_zso_version == 2)) {
219 }
220 ImGui::SameLine();
221 if (ImGui::RadioButton("v3 (Full)", options_.target_zso_version == 3)) {
223 }
224
225 // Version comparison
226 ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1.0f),
227 "v2: BG colors, main palettes, parent system");
228 ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1.0f),
229 "v3: + wide/tall areas, animated GFX, overlays");
230
231 // Tail expansion option (only for v3)
232 if (options_.target_zso_version == 3) {
233 ImGui::Spacing();
234 ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.2f, 1.0f), "Experimental:");
235 ImGui::Checkbox("Enable special world tail (0xA0-0xBF)",
237 if (ImGui::IsItemHovered()) {
238 ImGui::SetTooltip(
239 "Enables access to unused special world map slots.\n"
240 "REQUIRES additional ASM patch for pointer table expansion.\n"
241 "Without the patch, maps will show blank tiles (safe).");
242 }
243 }
244
245 ImGui::Unindent();
246 }
247 } else {
248 ImGui::TextColored(
249 ImVec4(0.5f, 0.8f, 0.5f, 1.0f),
250 "%s ROM already has ZSCustomOverworld %s", ICON_MD_CHECK_CIRCLE,
252 }
253
254 // Enable custom overworld features toggle
255 ImGui::Spacing();
256 ImGui::Checkbox("Enable custom overworld features in editor",
258
259 if (ImGui::IsItemHovered()) {
260 ImGui::SetTooltip(
261 "Enables ZSCustomOverworld-specific UI elements.\n"
262 "Auto-enabled if ASM is detected in ROM.");
263 }
264}
265
267 ImGui::Text("%s Feature Presets", ICON_MD_TUNE);
268 ImGui::Spacing();
269
270 // Preset selection combo
271 if (ImGui::BeginCombo("##PresetCombo",
273 for (int i = 0; i < kNumPresets; i++) {
274 bool is_selected = (selected_preset_index_ == i);
275 if (ImGui::Selectable(kPresetNames[i], is_selected)) {
278 }
279
280 if (ImGui::IsItemHovered()) {
281 ImGui::SetTooltip("%s", kPresetDescriptions[i]);
282 }
283
284 if (is_selected) {
285 ImGui::SetItemDefaultFocus();
286 }
287 }
288 ImGui::EndCombo();
289 }
290
291 // Show preset description
292 ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1.0f), "%s",
294
295 // Advanced toggle
296 ImGui::Spacing();
297 if (ImGui::Button(show_advanced_ ? "Hide Advanced Options"
298 : "Show Advanced Options")) {
300 }
301}
302
304 ImGui::Text("%s Feature Flags", ICON_MD_FLAG);
305 ImGui::Spacing();
306
307 // Overworld flags
308 if (ImGui::TreeNodeEx("Overworld", ImGuiTreeNodeFlags_DefaultOpen)) {
309 ImGui::Checkbox("Save overworld maps", &options_.save_overworld_maps);
310 ImGui::Checkbox("Save entrances", &options_.save_overworld_entrances);
311 ImGui::Checkbox("Save exits", &options_.save_overworld_exits);
312 ImGui::Checkbox("Save items", &options_.save_overworld_items);
313 ImGui::TreePop();
314 }
315
316 // Dungeon flags
317 if (ImGui::TreeNodeEx("Dungeon")) {
318 ImGui::Checkbox("Save dungeon maps", &options_.save_dungeon_maps);
319 ImGui::TreePop();
320 }
321
322 // Graphics flags
323 if (ImGui::TreeNodeEx("Graphics")) {
324 ImGui::Checkbox("Save all palettes", &options_.save_all_palettes);
325 ImGui::Checkbox("Save GFX groups", &options_.save_gfx_groups);
326 ImGui::TreePop();
327 }
328}
329
331 ImGui::Text("%s Project Options", ICON_MD_FOLDER);
332 ImGui::Spacing();
333
334 ImGui::Checkbox("Create associated project file", &options_.create_project);
335
337 ImGui::Indent();
338
339 ImGui::Text("Project Name:");
340 ImGui::SetNextItemWidth(-1);
341 ImGui::InputText("##ProjectName", project_name_buffer_,
342 sizeof(project_name_buffer_));
344
345 ImGui::TextColored(
346 ImVec4(0.6f, 0.6f, 0.6f, 1.0f),
347 "Project file stores settings, labels, and preferences.");
348
349 ImGui::Unindent();
350 }
351}
352
354 const float button_width = 120.0f;
355 const float spacing = 10.0f;
356 float total_width = button_width * 2 + spacing;
357
358 // Center buttons
359 float avail = ImGui::GetContentRegionAvail().x;
360 ImGui::SetCursorPosX((avail - total_width) * 0.5f + ImGui::GetCursorPosX());
361
362 // Cancel button
363 if (ImGui::Button("Cancel", ImVec2(button_width, 0))) {
364 is_open_ = false;
365 confirmed_ = false;
366 }
367
368 ImGui::SameLine(0, spacing);
369
370 // Confirm button with accent color
371 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
372 ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
373
374 {
375 gui::StyleColorGuard btn_guard(
376 {{ImGuiCol_Button, accent},
377 {ImGuiCol_ButtonHovered,
378 ImVec4(accent.x * 1.1f, accent.y * 1.1f, accent.z * 1.1f, accent.w)},
379 {ImGuiCol_ButtonActive, ImVec4(accent.x * 0.9f, accent.y * 0.9f,
380 accent.z * 0.9f, accent.w)}});
381
382 if (ImGui::Button(absl::StrFormat("%s Continue", ICON_MD_CHECK).c_str(),
383 ImVec2(button_width, 0))) {
384 // Apply options
387
388 confirmed_ = true;
389 is_open_ = false;
390
391 // Call upgrade callback if needed
394 }
395
396 // Call confirm callback
397 if (confirm_callback_) {
399 }
400 }
401 }
402}
403
404void RomLoadOptionsDialog::ApplyPreset(const std::string& preset_name) {
405 if (preset_name == "Vanilla ROM Hack") {
415 } else if (preset_name == "ZSCustomOverworld v2") {
427 } else if (preset_name == "ZSCustomOverworld v3 (Recommended)") {
439 } else if (preset_name == "Randomizer Compatible") {
449 }
450}
451
453 auto& flags = core::FeatureFlags::get();
454
455 flags.overworld.kSaveOverworldMaps = options_.save_overworld_maps;
456 flags.overworld.kSaveOverworldEntrances = options_.save_overworld_entrances;
457 flags.overworld.kSaveOverworldExits = options_.save_overworld_exits;
458 flags.overworld.kSaveOverworldItems = options_.save_overworld_items;
459 flags.overworld.kLoadCustomOverworld = options_.enable_custom_overworld;
460 flags.overworld.kEnableSpecialWorldExpansion = options_.enable_tail_expansion;
461 flags.kSaveDungeonMaps = options_.save_dungeon_maps;
462 flags.kSaveAllPalettes = options_.save_all_palettes;
463 flags.kSaveGfxGroups = options_.save_gfx_groups;
464}
465
469
470} // namespace editor
471} // 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:145
bool is_loaded() const
Definition rom.h:132
static Flags & get()
Definition features.h:118
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
@ 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.