mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-09 12:05:52 -04:00
update seed generation modal when generation finishes
This commit is contained in:
@@ -1303,17 +1303,14 @@ static void DeleteFailedGenerationFiles(randomizer::Randomizer& rando) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates a seed and writes the necessary seed files to the players seed directory
|
||||
*/
|
||||
void GenerateAndWriteSeed(std::string& generationStatusMsg) {
|
||||
bool GenerateAndWriteSeed(std::string& generationStatusMsg) {
|
||||
auto r = randomizer::Randomizer{dusk::ui::GetRandomizerPath()};
|
||||
|
||||
auto generationResult = r.Generate();
|
||||
if (generationResult.has_value()) {
|
||||
generationStatusMsg = fmt::format("Seed Generation failed. Reason:\n{}", generationResult.value());
|
||||
generationStatusMsg = fmt::format("Failed to generate seed. Reason:\n{}", generationResult.value());
|
||||
DeleteFailedGenerationFiles(r);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto world = r.GetWorld();
|
||||
@@ -1324,7 +1321,7 @@ void GenerateAndWriteSeed(std::string& generationStatusMsg) {
|
||||
generationStatusMsg =
|
||||
fmt::format("Failed to write seed data. Reason:\n{}", e.what());
|
||||
DeleteFailedGenerationFiles(r);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
randoData.mHash = r.GetConfig().GetHash();
|
||||
@@ -1333,8 +1330,9 @@ void GenerateAndWriteSeed(std::string& generationStatusMsg) {
|
||||
generationStatusMsg =
|
||||
fmt::format("Failed to write seed data to file. Reason:\n{}", writeToFileResult.value());
|
||||
DeleteFailedGenerationFiles(r);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
generationStatusMsg = fmt::format("Seed generated! Hash: {}", randoData.mHash);
|
||||
return true;
|
||||
}
|
||||
@@ -255,6 +255,10 @@ u32 getActorPatchesCurrentStageKey(u8 roomNo);
|
||||
*/
|
||||
u32 getStageObjCRC32(u8* data, size_t size);
|
||||
|
||||
void GenerateAndWriteSeed(std::string& generationStatusMsg);
|
||||
/*
|
||||
* Generates a seed and writes the necessary seed files to the players seed directory
|
||||
* Returns true if generation was successful, false otherwise.
|
||||
*/
|
||||
bool GenerateAndWriteSeed(std::string& generationStatusMsg);
|
||||
|
||||
#endif //DUSK_RANDOMIZER_CONTEXT_HPP
|
||||
|
||||
+23
-8
@@ -27,14 +27,7 @@ Modal::Modal(Props props) : WindowSmall("modal", "modal-dialog"), mProps(std::mo
|
||||
actions->SetClass("modal-actions", true);
|
||||
|
||||
for (auto& action : mProps.actions) {
|
||||
auto btn = std::make_unique<Button>(actions, action.label);
|
||||
btn->root()->SetClass("modal-btn", true);
|
||||
btn->on_pressed([this, callback = std::move(action.onPressed)] {
|
||||
if (callback) {
|
||||
callback(*this);
|
||||
}
|
||||
});
|
||||
mButtons.push_back(std::move(btn));
|
||||
add_action(action);
|
||||
}
|
||||
|
||||
mDoAud_seStartMenu(kSoundWindowOpen);
|
||||
@@ -47,6 +40,28 @@ bool Modal::focus() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Modal::add_action(ModalAction action) {
|
||||
auto actions = mDialog->QuerySelector(".modal-actions");
|
||||
auto btn = std::make_unique<Button>(actions, action.label);
|
||||
btn->root()->SetClass("modal-btn", true);
|
||||
btn->on_pressed([this, callback = std::move(action.onPressed)] {
|
||||
if (callback) {
|
||||
callback(*this);
|
||||
}
|
||||
});
|
||||
mButtons.push_back(std::move(btn));
|
||||
}
|
||||
|
||||
void Modal::set_body(const Rml::String& bodyRml) {
|
||||
auto body = mDialog->QuerySelector(".modal-body");
|
||||
body->SetInnerRML(bodyRml);
|
||||
}
|
||||
|
||||
void Modal::set_icon(const Rml::String& iconStr) {
|
||||
auto icon = mDialog->QuerySelector("icon");
|
||||
icon->SetClassNames({iconStr});
|
||||
}
|
||||
|
||||
void Modal::dismiss() {
|
||||
if (mProps.onDismiss) {
|
||||
mProps.onDismiss(*this);
|
||||
|
||||
@@ -25,6 +25,9 @@ public:
|
||||
explicit Modal(Props props);
|
||||
|
||||
bool focus() override;
|
||||
void add_action(ModalAction action);
|
||||
void set_body(const Rml::String& bodyRml);
|
||||
void set_icon(const Rml::String& icon);
|
||||
|
||||
protected:
|
||||
bool handle_nav_command(Rml::Event& event, NavCommand cmd) override;
|
||||
|
||||
@@ -24,12 +24,16 @@ struct ConfigBoolProps {
|
||||
std::function<bool()> isDisabled;
|
||||
};
|
||||
|
||||
static bool generatingSeed = false;
|
||||
static std::atomic seedGenStatus = SeedGenerateStatus::Ready;
|
||||
static std::string generationStatusMsg{};
|
||||
|
||||
static void StartSeedGeneration() {
|
||||
GenerateAndWriteSeed(generationStatusMsg);
|
||||
generatingSeed = false;
|
||||
if (GenerateAndWriteSeed(generationStatusMsg)) {
|
||||
seedGenStatus.store(SeedGenerateStatus::Success);
|
||||
} else {
|
||||
seedGenStatus.store(SeedGenerateStatus::Error);
|
||||
}
|
||||
|
||||
DuskLog.debug("{}", generationStatusMsg);
|
||||
}
|
||||
|
||||
@@ -406,16 +410,17 @@ void rando_starting_item_number_toggle(Pane& leftPane, Pane& rightPane, std::str
|
||||
});
|
||||
}
|
||||
|
||||
Document* show_seed_gen_modal(std::string_view message) {
|
||||
auto* modal = &push_document(std::make_unique<Modal>(Modal::Props{
|
||||
Modal* RandomizerWindow::show_seed_gen_modal(std::string_view message) {
|
||||
auto* modal = dynamic_cast<Modal*>(&push_document(std::make_unique<Modal>(Modal::Props{
|
||||
.title = "Randomizer",
|
||||
.bodyRml = escape(message),
|
||||
.onDismiss = [](Modal& modal) {
|
||||
.onDismiss = [this](Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundWindowClose);
|
||||
modal.pop();
|
||||
m_genSeedModal = nullptr;
|
||||
},
|
||||
.icon = "verifying",
|
||||
}));
|
||||
})));
|
||||
|
||||
if (auto* doc = top_document()) {
|
||||
doc->focus();
|
||||
@@ -815,10 +820,10 @@ RandomizerWindow::RandomizerWindow() {
|
||||
DuskLog.info("Created new Seed for generator.");
|
||||
}
|
||||
|
||||
seedGenStatus.store(SeedGenerateStatus::Generating);
|
||||
std::thread randoGenerationThread(StartSeedGeneration);
|
||||
randoGenerationThread.detach();
|
||||
|
||||
generatingSeed = true;
|
||||
m_genSeedModal = show_seed_gen_modal("Generating Seed...");
|
||||
|
||||
}),rightPane, [](Pane& pane) {
|
||||
@@ -1172,9 +1177,29 @@ RandomizerWindow::RandomizerWindow() {
|
||||
void RandomizerWindow::update() {
|
||||
Window::update();
|
||||
|
||||
if (m_genSeedModal && !generatingSeed) {
|
||||
m_genSeedModal->pop();
|
||||
m_genSeedModal = nullptr;
|
||||
auto curSeedGenStatus = seedGenStatus.load();
|
||||
if (curSeedGenStatus == SeedGenerateStatus::Success ||
|
||||
curSeedGenStatus == SeedGenerateStatus::Error)
|
||||
{
|
||||
if (curSeedGenStatus == SeedGenerateStatus::Success) {
|
||||
mDoAud_seStartMenu(kSoundSeedGenerateSuccess);
|
||||
m_genSeedModal->set_icon("celebration");
|
||||
} else {
|
||||
mDoAud_seStartMenu(kSoundSeedGenerateError);
|
||||
m_genSeedModal->set_icon("error");
|
||||
}
|
||||
|
||||
m_genSeedModal->set_body(generationStatusMsg);
|
||||
m_genSeedModal->add_action({
|
||||
.label = "OK",
|
||||
.onPressed = [this](Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundWindowClose);
|
||||
modal.pop();
|
||||
m_genSeedModal = nullptr;
|
||||
}
|
||||
});
|
||||
|
||||
seedGenStatus.store(SeedGenerateStatus::Ready);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace randomizer::seedgen::config {
|
||||
}
|
||||
|
||||
namespace dusk::ui {
|
||||
class Pane;
|
||||
class Modal;
|
||||
class Pane;
|
||||
|
||||
std::filesystem::path GetRandomizerPath();
|
||||
std::filesystem::path GetRandomizerSettingsPath();
|
||||
@@ -15,14 +16,24 @@ namespace dusk::ui {
|
||||
std::filesystem::path GetRandomizerSeedsPath();
|
||||
randomizer::seedgen::config::Config& GetRandomizerConfig();
|
||||
|
||||
enum class SeedGenerateStatus {
|
||||
Ready,
|
||||
Generating,
|
||||
Success,
|
||||
Error,
|
||||
};
|
||||
|
||||
class RandomizerWindow : public Window {
|
||||
public:
|
||||
|
||||
|
||||
RandomizerWindow();
|
||||
void update() override;
|
||||
Modal* show_seed_gen_modal(std::string_view message);
|
||||
void rando_excluded_locations_update_left_pane(Pane& innerLeftPane, Pane& rightPane, bool forceUpdate = false);
|
||||
auto& get_locations_for_left_pane();
|
||||
private:
|
||||
Document* m_genSeedModal = nullptr;
|
||||
std::string m_excludedLocationsFilter = "";
|
||||
Modal* m_genSeedModal = nullptr;
|
||||
std::string m_excludedLocationsFilter{};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,6 +54,11 @@ constexpr u32 kSoundAchievementUnlock = Z2SE_NAVI_FLY;
|
||||
// Warning prompt
|
||||
constexpr u32 kSoundWarning = Z2SE_SY_COW_GET_IN;
|
||||
|
||||
// Randomizer Seed Generation Success
|
||||
constexpr u32 kSoundSeedGenerateSuccess = Z2SE_SY_FILE_SAVE_OK;
|
||||
// Randomizer Seed Generation Error
|
||||
constexpr u32 kSoundSeedGenerateError = Z2SE_SYS_RESULT_WRONG;
|
||||
|
||||
struct Insets {
|
||||
float top = 0.0f;
|
||||
float right = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user