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 "rom/rom.h"
7#include "core/features.h"
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace editor {
12
13// Preset definitions
14const char* RomLoadOptionsDialog::kPresetNames[kNumPresets] = {
15 "Vanilla ROM Hack",
16 "ZSCustomOverworld v2",
17 "ZSCustomOverworld v3 (Recommended)",
18 "Randomizer Compatible"
19};
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 system.",
24 "Full overworld expansion: wide/tall areas, animated GFX, overlays, all features.",
25 "Compatible with ALttP Randomizer. Minimal custom features."
26};
27
35
37 if (rom) {
38 Open(rom, rom->filename());
39 }
40}
41
42void RomLoadOptionsDialog::Draw(bool* p_open) {
43 Show(p_open);
44}
45
46void RomLoadOptionsDialog::Open(Rom* rom, const std::string& rom_filename) {
47 rom_ = rom;
48 rom_filename_ = rom_filename;
49 is_open_ = true;
50 confirmed_ = false;
51
52 // Detect ROM version
53 if (rom_ && rom_->is_loaded()) {
55 } else {
57 }
58
59 // Set default project name from ROM filename
60 size_t last_slash = rom_filename_.find_last_of("/\\");
61 size_t last_dot = rom_filename_.find_last_of('.');
62 std::string base_name;
63 if (last_slash != std::string::npos) {
64 base_name = rom_filename_.substr(last_slash + 1);
65 } else {
66 base_name = rom_filename_;
67 }
68 if (last_dot != std::string::npos && last_dot > last_slash) {
69 base_name = base_name.substr(0, base_name.find_last_of('.'));
70 }
71
72 snprintf(project_name_buffer_, sizeof(project_name_buffer_), "%s_project",
73 base_name.c_str());
74
75 // Auto-select preset based on detected version
76 switch (detected_version_) {
78 selected_preset_index_ = 2; // Recommend v3 upgrade for vanilla
81 break;
84 selected_preset_index_ = 1; // Keep v2 features
85 break;
87 selected_preset_index_ = 2; // Full v3 features
88 break;
89 }
90
92}
93
94bool RomLoadOptionsDialog::Show(bool* p_open) {
95 if (!is_open_) return false;
96
97 ImGui::SetNextWindowSize(ImVec2(600, 500), ImGuiCond_FirstUseEver);
98 ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(),
99 ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
100
101 ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse;
102
103 bool result = false;
104 if (ImGui::Begin(
105 absl::StrFormat("%s ROM Load Options", ICON_MD_SETTINGS).c_str(),
106 &is_open_, flags)) {
108 ImGui::Separator();
109
111 ImGui::Separator();
112
114
115 if (show_advanced_) {
116 ImGui::Separator();
118 }
119
120 ImGui::Separator();
122
123 ImGui::Separator();
125
126 result = confirmed_;
127 }
128 ImGui::End();
129
130 if (p_open) {
131 *p_open = is_open_;
132 }
133
134 return result;
135}
136
138 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
139
140 ImGui::Text("%s ROM Information", ICON_MD_INFO);
141 ImGui::Spacing();
142
143 // ROM filename
144 ImGui::TextColored(gui::ConvertColorToImVec4(theme.text_secondary),
145 "File: %s", rom_filename_.c_str());
146
147 // Detected version with color coding
148 const char* version_name =
150
151 ImVec4 version_color;
152 switch (detected_version_) {
154 version_color = ImVec4(0.8f, 0.8f, 0.2f, 1.0f); // Yellow - needs upgrade
155 break;
158 version_color = 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(ImVec4(0.5f, 0.8f, 0.5f, 1.0f),
226 "%s ROM already has ZSCustomOverworld %s",
230 }
231
232 // Enable custom overworld features toggle
233 ImGui::Spacing();
234 ImGui::Checkbox("Enable custom overworld features in editor",
236
237 if (ImGui::IsItemHovered()) {
238 ImGui::SetTooltip(
239 "Enables ZSCustomOverworld-specific UI elements.\n"
240 "Auto-enabled if ASM is detected in ROM.");
241 }
242}
243
245 ImGui::Text("%s Feature Presets", ICON_MD_TUNE);
246 ImGui::Spacing();
247
248 // Preset selection combo
249 if (ImGui::BeginCombo("##PresetCombo", kPresetNames[selected_preset_index_])) {
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(ImVec4(0.6f, 0.6f, 0.6f, 1.0f),
323 "Project file stores settings, labels, and preferences.");
324
325 ImGui::Unindent();
326 }
327}
328
330 const float button_width = 120.0f;
331 const float spacing = 10.0f;
332 float total_width = button_width * 2 + spacing;
333
334 // Center buttons
335 float avail = ImGui::GetContentRegionAvail().x;
336 ImGui::SetCursorPosX((avail - total_width) * 0.5f + ImGui::GetCursorPosX());
337
338 // Cancel button
339 if (ImGui::Button("Cancel", ImVec2(button_width, 0))) {
340 is_open_ = false;
341 confirmed_ = false;
342 }
343
344 ImGui::SameLine(0, spacing);
345
346 // Confirm button with accent color
347 const auto& theme = gui::ThemeManager::Get().GetCurrentTheme();
348 ImVec4 accent = gui::ConvertColorToImVec4(theme.accent);
349
350 ImGui::PushStyleColor(ImGuiCol_Button, accent);
351 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
352 ImVec4(accent.x * 1.1f, accent.y * 1.1f,
353 accent.z * 1.1f, accent.w));
354 ImGui::PushStyleColor(ImGuiCol_ButtonActive,
355 ImVec4(accent.x * 0.9f, accent.y * 0.9f,
356 accent.z * 0.9f, accent.w));
357
358 if (ImGui::Button(absl::StrFormat("%s Continue", ICON_MD_CHECK).c_str(),
359 ImVec2(button_width, 0))) {
360 // Apply options
363
364 confirmed_ = true;
365 is_open_ = false;
366
367 // Call upgrade callback if needed
370 }
371
372 // Call confirm callback
373 if (confirm_callback_) {
375 }
376 }
377
378 ImGui::PopStyleColor(3);
379}
380
381void RomLoadOptionsDialog::ApplyPreset(const std::string& preset_name) {
382 if (preset_name == "Vanilla ROM Hack") {
392 } else if (preset_name == "ZSCustomOverworld v2") {
404 } else if (preset_name == "ZSCustomOverworld v3 (Recommended)") {
416 } else if (preset_name == "Randomizer Compatible") {
426 }
427}
428
430 auto& flags = core::FeatureFlags::get();
431
432 flags.overworld.kSaveOverworldMaps = options_.save_overworld_maps;
433 flags.overworld.kSaveOverworldEntrances = options_.save_overworld_entrances;
434 flags.overworld.kSaveOverworldExits = options_.save_overworld_exits;
435 flags.overworld.kSaveOverworldItems = options_.save_overworld_items;
436 flags.overworld.kLoadCustomOverworld = options_.enable_custom_overworld;
437 flags.overworld.kEnableSpecialWorldExpansion = options_.enable_tail_expansion;
438 flags.kSaveDungeonMaps = options_.save_dungeon_maps;
439 flags.kSaveAllPalettes = options_.save_all_palettes;
440 flags.kSaveGfxGroups = options_.save_gfx_groups;
441}
442
446
447} // namespace editor
448} // namespace yaze
449
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.