diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 860aab64d..4f46e7791 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -25,6 +25,7 @@ #include "Lib/Fast3D/gfx_rendering_api.h" #include "Lib/spdlog/include/spdlog/common.h" #include "Utils/StringHelper.h" +#include #ifdef ENABLE_OPENGL #include "Lib/ImGui/backends/imgui_impl_opengl3.h" @@ -60,6 +61,8 @@ OSContPad* pads; std::map DefaultAssets; +std::thread randoThread; + SpoilerData gSpoilerData; namespace SohImGui { @@ -419,6 +422,11 @@ namespace SohImGui { pads = cont_pad; }); Game::InitSettings(); + + CVar_SetS32("gRandomizer", 0); + CVar_SetS32("gRandoGenerating", 0); + CVar_SetS32("gDroppedNewSpoilerFile", 0); + Game::SaveSettings(); } void Update(EventImpl event) { @@ -1033,11 +1041,10 @@ namespace SohImGui { if (ImGui::BeginMenu("Randomizer")) { - EnhancementCheckbox("Enable Randomizer", "gRandomizer"); - if (ImGui::Button("Generate Seed")) { - RandoMain::GenerateRando(); - Game::LoadSettings(); + if (CVar_GetS32("gRandoGenerating", 0) == 0) { + randoThread = std::thread(&SohImGui::GenerateRandomizerImgui); + } } ImGui::EndMenu(); @@ -1261,6 +1268,18 @@ namespace SohImGui { overlay->Draw(); } + void GenerateRandomizerImgui() { + CVar_SetS32("gRandoGenerating", 1); + Game::SaveSettings(); + + RandoMain::GenerateRando(); + + CVar_SetS32("gRandoGenerating", 0); + Game::SaveSettings(); + + Game::LoadSettings(); + } + void DrawFramebufferAndGameInput(void) { const ImVec2 main_pos = ImGui::GetWindowPos(); ImVec2 size = ImGui::GetContentRegionAvail(); diff --git a/libultraship/libultraship/SohImGuiImpl.h b/libultraship/libultraship/SohImGuiImpl.h index 421c71778..850c740e5 100644 --- a/libultraship/libultraship/SohImGuiImpl.h +++ b/libultraship/libultraship/SohImGuiImpl.h @@ -74,6 +74,7 @@ namespace SohImGui { void DrawMainMenuAndCalculateGameSize(void); + void GenerateRandomizerImgui(); void DrawFramebufferAndGameInput(void); void Render(void); void CancelFrame(void); diff --git a/soh/include/randomizer/rando_main.cpp b/soh/include/randomizer/rando_main.cpp index fc47e1ebd..94c4accb4 100644 --- a/soh/include/randomizer/rando_main.cpp +++ b/soh/include/randomizer/rando_main.cpp @@ -17,6 +17,7 @@ void RandoMain::GenerateRando() { std::string fileName = GenerateRandomizer(); CVar_SetString("gSpoilerLog", fileName.c_str()); - CVar_SetS32("gDroppedNewSpoilerFile", 1); Game::SaveSettings(); + Game::LoadSettings(); + CVar_SetS32("gDroppedNewSpoilerFile", 1); } \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer.cpp b/soh/soh/Enhancements/randomizer.cpp index 55ccec417..90fe9d517 100644 --- a/soh/soh/Enhancements/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer.cpp @@ -1159,7 +1159,7 @@ void Randomizer::ParseItemLocationsFile(const char* spoilerFileName) { } if (success) { - CVar_SetS32("gDroppedNewSpoilerFile", 0); + CVar_SetS32("gRandomizer", 1); Game::SaveSettings(); } } diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index e0b9fc2fb..01a71ec2a 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -227,6 +227,9 @@ void DrawSeedHashSprites(FileChooseContext* this) { * Lastly, set any warning labels if appropriate. * Update function for `CM_MAIN_MENU` */ + +u8 generating; + void FileChoose_UpdateMainMenu(GameState* thisx) { static u8 emptyName[] = { 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E }; FileChooseContext* this = (FileChooseContext*)thisx; @@ -234,7 +237,21 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { Input* input = &this->state.input[0]; bool dpad = CVar_GetS32("gDpadPauseName", 0); - if (CVar_GetS32("gDroppedNewSpoilerFile", 0) != 0) { + if (CVar_GetS32("gRandoGenerating", 0) != 0 && generating == 0) { + generating = 1; + func_800F5E18(SEQ_PLAYER_BGM_MAIN, NA_BGM_HORSE, 0, 7, 1); + return; + } else if (CVar_GetS32("gRandoGenerating", 0) == 0 && generating) { + Audio_PlayFanfare(NA_BGM_HORSE_GOAL); + func_800F5E18(SEQ_PLAYER_BGM_MAIN, NA_BGM_FILE_SELECT, 0, 7, 1); + generating = 0; + return; + } else if (generating) { + return; + } + + if (CVar_GetS32("gDroppedNewSpoilerFile", 0) != 0 && !generating) { + CVar_SetS32("gDroppedNewSpoilerFile", 0); const char* fileLoc = CVar_GetString("gSpoilerLog", ""); LoadItemLocations(fileLoc); }