Add button to rando all rando settings (#6001)

This commit is contained in:
Garrett Cox 2026-03-28 01:52:01 -05:00 committed by GitHub
parent 178471bf20
commit c7180762d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 7 deletions

View file

@ -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 <spdlog/spdlog.h>
#include <libultraship/bridge/consolevariablebridge.h>
#include <libultraship/libultraship.h>
namespace Rando {
std::shared_ptr<Settings> 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<RandomizerSettingKey>(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<RandomizerSettingKey>(i);
Option& option = mOptions[key];
if (option.GetOptionCount() == 0) {
continue;
}
uint8_t randomIndex = Random(0, static_cast<uint32_t>(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> Settings::GetInstance() {
if (mInstance == nullptr) {
mInstance = std::make_shared<Settings>();

View file

@ -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<Settings> GetInstance();
private:

View file

@ -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);