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