yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
rom_load_options_dialog.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SHELL_DIALOGS_ROM_LOAD_OPTIONS_DIALOG_H_
2#define YAZE_APP_EDITOR_SHELL_DIALOGS_ROM_LOAD_OPTIONS_DIALOG_H_
3
4#include <functional>
5#include <optional>
6#include <string>
7#include <string_view>
8#include <utility>
9
10#include "absl/status/status.h"
11#include "core/features.h"
12#include "imgui/imgui.h"
14
15namespace yaze {
16
17class Rom;
18
19namespace editor {
20
34 public:
35 struct LoadOptions {
36 // Overworld load options. Both are read when the overworld loads.
38 bool enable_tail_expansion = false; // Special world tail (0xA0-0xBF)
39
40 // Save flags to apply
46 bool save_dungeon_maps = false;
47 bool save_all_palettes = false;
48 bool save_gfx_groups = false;
49
50 // Project integration
51 bool create_project = false;
52 std::string project_name;
53 std::string project_path;
54
55 // Preset name if selected
56 std::string selected_preset;
57
58 // Skip this dialog the next time this ROM file opens. UserSettings keeps
59 // the choice beside its encoding; the encoding never stores this field.
60 bool remember_for_rom = true;
61 };
62
63 // A decoded remembered choice. zso_version_byte is the ZSCustomOverworld
64 // ASM byte the ROM had when the choice was made.
69
72
78 void Open(Rom* rom, const std::string& rom_filename);
79 void Open(Rom* rom, const std::string& rom_filename,
80 bool suggest_project_creation);
81
86 void Open(Rom* rom);
87 void Open(Rom* rom, bool suggest_project_creation);
88
95 void OpenForReview(Rom* rom, const core::FeatureFlags::Flags& active,
96 const std::string& preset_name, bool remembered);
97
103 bool Show(bool* p_open);
104
109 void Draw(bool* p_open);
110
114 const LoadOptions& GetOptions() const { return options_; }
115
119 bool WasConfirmed() const { return confirmed_; }
120
124 void ResetConfirmation() { confirmed_ = false; }
125
129 void SetConfirmCallback(std::function<void(const LoadOptions&)> callback) {
130 confirm_callback_ = callback;
131 }
132
136 void SetCancelCallback(std::function<void()> callback) {
137 cancel_callback_ = std::move(callback);
138 }
139
140 // Checked before any flag mutation, including the dialog's own application.
141 void SetApplyGuard(std::function<bool()> guard) {
142 apply_guard_ = std::move(guard);
143 }
144 void Close() {
145 is_open_ = false;
146 confirmed_ = false;
147 }
148
155
156 const std::string& rom_filename() const { return rom_filename_; }
157 // ZSCustomOverworld ASM byte of the open ROM; -1 when no ROM is loaded.
158 int zso_version_byte() const { return zso_version_byte_; }
159 // True when opened through OpenForReview().
160 bool reviewing() const { return reviewing_; }
161 // True when an overworld load option differs from the flag in effect when
162 // the dialog opened. The open ROM's overworld loaded with that flag, so the
163 // change needs a reopen.
164 bool OverworldLoadOptionsChanged() const;
165
166 // Remembered choices are stored as "key=value;" text so UserSettings can
167 // keep them as opaque strings in both settings.json and the legacy INI.
168 static std::string EncodeRememberedChoice(const LoadOptions& options,
169 int zso_version_byte);
170 // Returns nullopt for any version, byte, or flag it does not understand.
171 static std::optional<RememberedChoice> DecodeRememberedChoice(
172 std::string_view encoded);
173 // Settings key for a ROM path: absolute and lexically normal. Symlinks are
174 // not resolved, so two links to one file remember separately.
175 static std::string RomChoiceKey(const std::string& rom_path);
176
177 static void ApplyToFeatureFlags(const LoadOptions& options,
179 static LoadOptions OptionsFromFeatureFlags(
180 const core::FeatureFlags::Flags& flags);
181
182 private:
183 void DrawVersionInfo();
187 void DrawProjectOptions();
188 void DrawActionButtons();
189
190 void ApplyPreset(const std::string& preset_name);
192
193 // State
194 Rom* rom_ = nullptr;
195 std::string rom_filename_;
198 bool is_open_ = false;
199 bool confirmed_ = false;
200 bool show_advanced_ = false;
201 bool reviewing_ = false;
203 // Overworld load flags in effect when the dialog opened.
206
207 // Options
209
210 // Available presets
211 static constexpr int kNumPresets = 4;
212 static const char* kPresetNames[kNumPresets];
213 static const char* kPresetDescriptions[kNumPresets];
215
216 // Callbacks
217 std::function<void(const LoadOptions&)> confirm_callback_;
218 std::function<void()> cancel_callback_;
219 std::function<bool()> apply_guard_;
220
221 // UI state
222 char project_name_buffer_[256] = {};
223 char project_path_buffer_[512] = {};
224};
225
226} // namespace editor
227} // namespace yaze
228
229#endif // YAZE_APP_EDITOR_SHELL_DIALOGS_ROM_LOAD_OPTIONS_DIALOG_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:52
std::function< void(const LoadOptions &) confirm_callback_)
void ApplyPreset(const std::string &preset_name)
const LoadOptions & GetOptions() const
Get the selected load options.
void Open(Rom *rom, const std::string &rom_filename)
Open the dialog after ROM detection.
static const char * kPresetNames[kNumPresets]
void OpenForReview(Rom *rom, const core::FeatureFlags::Flags &active, const std::string &preset_name, bool remembered)
Reopen the dialog for a ROM that is already loaded.
void SetApplyGuard(std::function< bool()> guard)
static LoadOptions OptionsFromFeatureFlags(const core::FeatureFlags::Flags &flags)
static std::optional< RememberedChoice > DecodeRememberedChoice(std::string_view encoded)
static std::string RomChoiceKey(const std::string &rom_path)
bool Show(bool *p_open)
Show the dialog.
void SetCancelCallback(std::function< void()> callback)
Set callback for Cancel or the title-bar close button.
void ResetConfirmation()
Reset confirmation state.
static void ApplyToFeatureFlags(const LoadOptions &options, core::FeatureFlags::Flags &flags)
static std::string EncodeRememberedChoice(const LoadOptions &options, int zso_version_byte)
void SetConfirmCallback(std::function< void(const LoadOptions &)> callback)
Set callback for when options are confirmed.
zelda3::OverworldVersion GetDetectedVersion() const
Get detected ROM version.
static const char * kPresetDescriptions[kNumPresets]
bool WasConfirmed() const
Check if dialog resulted in confirmation.
void Draw(bool *p_open)
Draw the dialog (wrapper around Show)
OverworldVersion
ROM version detection for overworld features.
@ kVanilla
0xFF in ROM, no ZScream ASM applied