Adds "Randomize on Randomizer Generation" options to Audio and Cosmetics Editors (#5387)

* Add "Randomize on Randomizer Generation" options to Audio and Cosmetics Editors

 * Added "Randomize All Music and Sound Effects on Randomizer Generation" to the Audio Editor.

 * Added "Randomize All on Randomizer Generation" to the Cosmetics Editor.

When enabled, these options randomize audio and/or cosmetics during a new randomizer generation.

* Added "OnRandomizerGeneration" Hook.
 * It is executed on Randomizer Generation.

* Changed AudioEditor and CosmeticsEditor "Randomize all on Randomizer Generation" options to use the "OnRandomizerGeneration" Hook.

* Renamed "OnRandomizerGeneration" to "OnGenerationCompletion.
Renamed "GameInteractor_ExecuteOnRandomizerGeneration" to "GameInteractor_ExecuteOnGenerationCompletion"
Moved "GameInteractor_ExecuteOnGenerationCompletion" from "GenerateRandomizer" to the end of "GenerateRandomizerImgui".

* Removed "GameInteractor_ExecuteOnGenerationCompletion()" from "GameInteractor_Hooks.h" and "GameInteractor_Hooks.cpp"
The "OnGenerationCompletion" hook is now called directly at the end of "GenerateRandomizerImgui" in "randomizer.cpp"

---------

Co-authored-by: Glought <663343+Glought@users.noreply.github.com>
This commit is contained in:
Glought 2025-08-25 12:02:30 -07:00 committed by GitHub
commit bdaf352440
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 0 deletions

View file

@ -468,8 +468,17 @@ void AudioEditorRegisterOnSceneInitHook() {
});
}
void AudioEditorRegisterOnGenerationCompletionHook() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGenerationCompletion>([]() {
if (CVarGetInteger(CVAR_AUDIO("RandomizeAllOnRandoGen"), 0)) {
AudioEditor_RandomizeAll();
}
});
}
void AudioEditor::InitElement() {
AudioEditorRegisterOnSceneInitHook();
AudioEditorRegisterOnGenerationCompletionHook();
}
void AudioEditor::DrawElement() {
@ -573,6 +582,12 @@ void AudioEditor::DrawElement() {
.Color(THEME_COLOR)
.Tooltip(
"Enables randomizing all unlocked music and sound effects when you enter a new scene."));
UIWidgets::CVarCheckbox("Randomize All Music and Sound Effects on Randomizer Generation",
CVAR_AUDIO("RandomizeAllOnRandoGen"),
UIWidgets::CheckboxOptions()
.Color(THEME_COLOR)
.Tooltip("Enables randomizing all unlocked music and sound effects when "
"you generate a new randomizer."));
UIWidgets::CVarCheckbox(
"Lower Octaves of Unplayable High Notes", CVAR_AUDIO("ExperimentalOctaveDrop"),
UIWidgets::CheckboxOptions()

View file

@ -2382,6 +2382,11 @@ void CosmeticsEditorWindow::DrawElement() {
.Color(THEME_COLOR)
.Tooltip("Enables randomizing all unlocked cosmetics when you enter a new scene."));
ImGui::EndDisabled();
UIWidgets::CVarCheckbox(
"Randomize All on Randomizer Generation", CVAR_COSMETIC("RandomizeAllOnRandoGen"),
UIWidgets::CheckboxOptions()
.Color(THEME_COLOR)
.Tooltip("Enables randomizing all unlocked cosmetics when you generate a new randomizer."));
UIWidgets::CVarCheckbox(
"Advanced Mode", CVAR_COSMETIC("AdvancedMode"),
UIWidgets::CheckboxOptions()
@ -2589,6 +2594,14 @@ void Cosmetics_RegisterOnSceneInitHook() {
});
}
void CosmeticsEditorRegisterOnGenerationCompletionHook() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGenerationCompletion>([]() {
if (CVarGetInteger(CVAR_COSMETIC("RandomizeAllOnRandoGen"), 0)) {
CosmeticsEditor_RandomizeAll();
}
});
}
void CosmeticsEditorWindow::InitElement() {
// Convert the `current color` into the format that the ImGui color picker expects
for (auto& [id, cosmeticOption] : cosmeticOptions) {
@ -2608,6 +2621,7 @@ void CosmeticsEditorWindow::InitElement() {
RegisterOnLoadGameHook();
RegisterOnGameFrameUpdateHook();
Cosmetics_RegisterOnSceneInitHook();
CosmeticsEditorRegisterOnGenerationCompletionHook();
}
void CosmeticsEditor_RandomizeAll() {

View file

@ -68,6 +68,7 @@ DEFINE_HOOK(OnUpdateFileBossRushOptionSelection, (uint8_t optionIndex, uint8_t o
DEFINE_HOOK(OnUpdateFileRandomizerOptionSelection, (uint8_t optionIndex));
DEFINE_HOOK(OnUpdateFileNameSelection, (int16_t charCode));
DEFINE_HOOK(OnFileChooseMain, (void* gameState));
DEFINE_HOOK(OnGenerationCompletion, ());
DEFINE_HOOK(OnSetGameLanguage, ());
DEFINE_HOOK(OnFileDropped, (std::string filePath));

View file

@ -3800,6 +3800,8 @@ void GenerateRandomizerImgui(std::string seed = "") {
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
generated = 1;
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnGenerationCompletion>();
}
bool GenerateRandomizer(std::string seed /*= ""*/) {
@ -3809,6 +3811,7 @@ bool GenerateRandomizer(std::string seed /*= ""*/) {
}
if (CVarGetInteger(CVAR_GENERAL("RandoGenerating"), 0) == 0) {
randoThread = std::thread(&GenerateRandomizerImgui, seed);
return true;
}
return false;