mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-09 12:05:52 -04:00
decouple generation modal from config menu
This commit is contained in:
@@ -1521,6 +1521,8 @@ set(DUSK_FILES
|
||||
src/dusk/ui/window.hpp
|
||||
src/dusk/ui/rando_config.cpp
|
||||
src/dusk/ui/rando_config.hpp
|
||||
src/dusk/ui/rando_seed_generation.cpp
|
||||
src/dusk/ui/rando_seed_generation.hpp
|
||||
src/dusk/achievements.cpp
|
||||
src/dusk/iso_validate.cpp
|
||||
src/dusk/livesplit.cpp
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "modal.hpp"
|
||||
#include "number_button.hpp"
|
||||
#include "pane.hpp"
|
||||
#include "rando_seed_generation.hpp"
|
||||
#include "string_button.hpp"
|
||||
|
||||
namespace dusk::ui {
|
||||
@@ -24,18 +25,7 @@ struct ConfigBoolProps {
|
||||
std::function<bool()> isDisabled;
|
||||
};
|
||||
|
||||
static std::atomic seedGenStatus = SeedGenerateStatus::Ready;
|
||||
static std::string generationStatusMsg{};
|
||||
|
||||
static void StartSeedGeneration() {
|
||||
if (GenerateAndWriteSeed(generationStatusMsg)) {
|
||||
seedGenStatus.store(SeedGenerateStatus::Success);
|
||||
} else {
|
||||
seedGenStatus.store(SeedGenerateStatus::Error);
|
||||
}
|
||||
|
||||
DuskLog.debug("{}", generationStatusMsg);
|
||||
}
|
||||
|
||||
randomizer::seedgen::settings::Setting* FindSetting(const std::string& key) {
|
||||
if (key.empty()) {
|
||||
@@ -410,27 +400,6 @@ void rando_starting_item_number_toggle(Pane& leftPane, Pane& rightPane, std::str
|
||||
});
|
||||
}
|
||||
|
||||
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 = [this](Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundWindowClose);
|
||||
modal.pop();
|
||||
m_genSeedModal = nullptr;
|
||||
},
|
||||
.icon = "verifying",
|
||||
})));
|
||||
// Allow manual line breaks in this modal for error messages
|
||||
modal->root()->SetProperty("white-space", "pre-line");
|
||||
|
||||
if (auto* doc = top_document()) {
|
||||
doc->focus();
|
||||
}
|
||||
|
||||
return modal;
|
||||
}
|
||||
|
||||
struct ExcludedTabLocData {
|
||||
std::string name {};
|
||||
std::string lowercaseName{};
|
||||
@@ -822,11 +791,7 @@ RandomizerWindow::RandomizerWindow() {
|
||||
DuskLog.info("Created new Seed for generator.");
|
||||
}
|
||||
|
||||
seedGenStatus.store(SeedGenerateStatus::Generating);
|
||||
std::thread randoGenerationThread(StartSeedGeneration);
|
||||
randoGenerationThread.detach();
|
||||
|
||||
m_genSeedModal = show_seed_gen_modal("Generating Seed...");
|
||||
GenerateRandomizerSeed();
|
||||
|
||||
}),rightPane, [](Pane& pane) {
|
||||
pane.clear();
|
||||
@@ -1176,36 +1141,6 @@ RandomizerWindow::RandomizerWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
void RandomizerWindow::update() {
|
||||
Window::update();
|
||||
|
||||
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(escape(generationStatusMsg));
|
||||
m_genSeedModal->add_action({
|
||||
.label = "OK",
|
||||
.onPressed = [this](Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundWindowClose);
|
||||
modal.pop();
|
||||
m_genSeedModal = nullptr;
|
||||
}
|
||||
});
|
||||
m_genSeedModal->focus();
|
||||
|
||||
seedGenStatus.store(SeedGenerateStatus::Ready);
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path GetRandomizerPath() {
|
||||
return data::configured_data_path() / "randomizer";
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace randomizer::seedgen::config {
|
||||
}
|
||||
|
||||
namespace dusk::ui {
|
||||
class Modal;
|
||||
class Pane;
|
||||
|
||||
std::filesystem::path GetRandomizerPath();
|
||||
@@ -16,24 +15,14 @@ class Pane;
|
||||
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:
|
||||
Modal* m_genSeedModal = nullptr;
|
||||
std::string m_excludedLocationsFilter{};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "rando_seed_generation.hpp"
|
||||
|
||||
#include "modal.hpp"
|
||||
#include "dusk/logging.h"
|
||||
#include "dusk/randomizer/game/randomizer_context.hpp"
|
||||
#include "m_Do/m_Do_audio.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace dusk::ui {
|
||||
|
||||
enum class SeedGenerateStatus {
|
||||
Ready,
|
||||
Generating,
|
||||
Success,
|
||||
Error,
|
||||
};
|
||||
|
||||
static std::atomic seedGenStatus = SeedGenerateStatus::Ready;
|
||||
static std::string generationStatusMsg{};
|
||||
|
||||
RandomizerGenerationModal::RandomizerGenerationModal() :
|
||||
Modal({
|
||||
.title = "Randomizer",
|
||||
.bodyRml = "Generating Seed...",
|
||||
.onDismiss = [this](Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundWindowClose);
|
||||
modal.pop();
|
||||
},
|
||||
.icon = "verifying",
|
||||
}) {
|
||||
mRoot->SetProperty("white-space", "pre-line");
|
||||
}
|
||||
|
||||
void RandomizerGenerationModal::update() {
|
||||
Document::update();
|
||||
|
||||
auto curSeedGenStatus = seedGenStatus.load();
|
||||
|
||||
// Change the modal text if we've finished attempting to generate
|
||||
if (curSeedGenStatus == SeedGenerateStatus::Success ||
|
||||
curSeedGenStatus == SeedGenerateStatus::Error)
|
||||
{
|
||||
if (curSeedGenStatus == SeedGenerateStatus::Success) {
|
||||
mDoAud_seStartMenu(kSoundSeedGenerateSuccess);
|
||||
set_icon("celebration");
|
||||
} else {
|
||||
mDoAud_seStartMenu(kSoundSeedGenerateError);
|
||||
set_icon("error");
|
||||
}
|
||||
|
||||
set_body(escape(generationStatusMsg));
|
||||
add_action({
|
||||
.label = "OK",
|
||||
.onPressed = [this](Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundWindowClose);
|
||||
modal.pop();
|
||||
}
|
||||
});
|
||||
|
||||
// Refocus so that we focus the new button
|
||||
focus();
|
||||
|
||||
seedGenStatus.store(SeedGenerateStatus::Ready);
|
||||
}
|
||||
}
|
||||
|
||||
static void StartSeedGeneration() {
|
||||
if (GenerateAndWriteSeed(generationStatusMsg)) {
|
||||
seedGenStatus.store(SeedGenerateStatus::Success);
|
||||
} else {
|
||||
seedGenStatus.store(SeedGenerateStatus::Error);
|
||||
}
|
||||
|
||||
DuskLog.debug("{}", generationStatusMsg);
|
||||
}
|
||||
|
||||
void GenerateRandomizerSeed() {
|
||||
// Start Generation Thread
|
||||
seedGenStatus.store(SeedGenerateStatus::Generating);
|
||||
std::thread randoGenerationThread(StartSeedGeneration);
|
||||
randoGenerationThread.detach();
|
||||
|
||||
// Create Seed Generation Modal
|
||||
push_document(std::make_unique<RandomizerGenerationModal>());
|
||||
|
||||
// Focus Modal
|
||||
if (auto* doc = top_document()) {
|
||||
doc->focus();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "modal.hpp"
|
||||
|
||||
namespace dusk::ui {
|
||||
|
||||
class RandomizerGenerationModal : public Modal {
|
||||
public:
|
||||
explicit RandomizerGenerationModal();
|
||||
|
||||
void update() override;
|
||||
};
|
||||
|
||||
void GenerateRandomizerSeed();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user