From c7180762d9c3055d7de12861a8767ddea84f871f Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 28 Mar 2026 01:52:01 -0500 Subject: [PATCH] Add button to rando all rando settings (#6001) --- soh/soh/Enhancements/randomizer/settings.cpp | 44 ++++++++++++++++++++ soh/soh/Enhancements/randomizer/settings.h | 7 ++++ soh/soh/SohGui/SohMenuRandomizer.cpp | 22 ++++++---- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/settings.cpp b/soh/soh/Enhancements/randomizer/settings.cpp index 35a37451b..cb93319e4 100644 --- a/soh/soh/Enhancements/randomizer/settings.cpp +++ b/soh/soh/Enhancements/randomizer/settings.cpp @@ -2,12 +2,14 @@ #include "soh/Enhancements/randomizer/randomizerTypes.h" #include "trial.h" #include "dungeon.h" +#include "3drando/random.hpp" #include "soh/OTRGlobals.h" #include #include +#include namespace Rando { std::shared_ptr Settings::mInstance; @@ -3475,6 +3477,48 @@ void Settings::SetAllToContext() { } } +void Settings::RandomizeAllSettings() { + // Randomize all settings except tricks + for (int i = 0; i < RSK_MAX; i++) { + switch (static_cast(i)) { + case RSK_STARTING_SKULLTULA_TOKEN: + case RSK_STARTING_HEARTS: + case RSK_STARTING_ZELDAS_LULLABY: + case RSK_STARTING_EPONAS_SONG: + case RSK_STARTING_SARIAS_SONG: + case RSK_STARTING_SUNS_SONG: + case RSK_STARTING_SONG_OF_TIME: + case RSK_STARTING_SONG_OF_STORMS: + case RSK_STARTING_MINUET_OF_FOREST: + case RSK_STARTING_BOLERO_OF_FIRE: + case RSK_STARTING_SERENADE_OF_WATER: + case RSK_STARTING_REQUIEM_OF_SPIRIT: + case RSK_STARTING_NOCTURNE_OF_SHADOW: + case RSK_STARTING_PRELUDE_OF_LIGHT: + continue; + default: + break; + } + + auto key = static_cast(i); + Option& option = mOptions[key]; + + if (option.GetOptionCount() == 0) { + continue; + } + + uint8_t randomIndex = Random(0, static_cast(option.GetOptionCount())); + + option.SetContextIndex(randomIndex); + if (!option.GetCVarName().empty()) { + CVarSetInteger(option.GetCVarName().c_str(), randomIndex); + } + option.RunCallback(); + } + + Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame(); +} + std::shared_ptr Settings::GetInstance() { if (mInstance == nullptr) { mInstance = std::make_shared(); diff --git a/soh/soh/Enhancements/randomizer/settings.h b/soh/soh/Enhancements/randomizer/settings.h index e77d9d864..ecef3bfa0 100644 --- a/soh/soh/Enhancements/randomizer/settings.h +++ b/soh/soh/Enhancements/randomizer/settings.h @@ -135,6 +135,13 @@ class Settings { */ void SetAllToContext(); + /** + * @brief Randomizes all randomizer settings (excluding tricks) to random valid values. + * This function iterates through all options and sets them to a random index within + * their valid range. + */ + void RandomizeAllSettings(); + static std::shared_ptr GetInstance(); private: diff --git a/soh/soh/SohGui/SohMenuRandomizer.cpp b/soh/soh/SohGui/SohMenuRandomizer.cpp index b5b9ece98..be64ac815 100644 --- a/soh/soh/SohGui/SohMenuRandomizer.cpp +++ b/soh/soh/SohGui/SohMenuRandomizer.cpp @@ -585,15 +585,23 @@ void SohMenu::AddMenuRandomizer() { .Options(ButtonOptions() .Size(ImVec2(250.f, 0.f)) .DisabledTooltip("Must be on File Select to generate a randomizer seed.")); - AddWidget(path, "Spoiler File", WIDGET_CUSTOM) - .CustomFunction([](WidgetInfo& info) { - JoinRandoGenerationThread(); - if (!CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) { - std::string spoilerfilepath = CVarGetString(CVAR_GENERAL("SpoilerLog"), ""); - ImGui::Text("Spoiler File: %s", spoilerfilepath.c_str()); - } + AddWidget(path, "Randomize All Settings", WIDGET_BUTTON) + .Callback([](WidgetInfo& info) { Rando::Settings::GetInstance()->RandomizeAllSettings(); }) + .PreFunc([](WidgetInfo& info) { + info.options->disabled = CVarGetInteger(CVAR_GENERAL("RandoGenerating"), 0) || + CVarGetInteger(CVAR_GENERAL("OnFileSelectNameEntry"), 0); }) + .Options(ButtonOptions() + .Size(ImVec2(250.f, 0.f)) + .Tooltip("Randomizes all randomizer settings to random valid values (excludes tricks).")) .SameLine(true); + AddWidget(path, "Spoiler File", WIDGET_CUSTOM).CustomFunction([](WidgetInfo& info) { + JoinRandoGenerationThread(); + if (!CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) { + std::string spoilerfilepath = CVarGetString(CVAR_GENERAL("SpoilerLog"), ""); + ImGui::Text("Spoiler File: %s", spoilerfilepath.c_str()); + } + }); // Enhancements AddWidget(path, "Enhancements", WIDGET_SEPARATOR_TEXT);