diff --git a/UnleashedRecomp/app.cpp b/UnleashedRecomp/app.cpp index aa0daaa8..b2f83b8c 100644 --- a/UnleashedRecomp/app.cpp +++ b/UnleashedRecomp/app.cpp @@ -5,11 +5,14 @@ #include #include -void App::Exit(std::vector restartArgs) +void App::Restart(std::vector restartArgs) { - if (restartArgs.size()) - os::process::StartProcess(os::process::GetExecutablePath(), restartArgs, os::process::GetWorkingDirectory()); + os::process::StartProcess(os::process::GetExecutablePath(), restartArgs, os::process::GetWorkingDirectory()); + Exit(); +} +void App::Exit() +{ #if _WIN32 ExitProcess(0); #endif @@ -21,6 +24,7 @@ PPC_FUNC(sub_824EB490) { App::s_isInit = true; App::s_isMissingDLC = !Installer::checkAllDLC(GetGamePath()); + App::s_language = Config::Language; __imp__sub_824EB490(ctx, base); } diff --git a/UnleashedRecomp/app.h b/UnleashedRecomp/app.h index 89849a69..2b7bc9aa 100644 --- a/UnleashedRecomp/app.h +++ b/UnleashedRecomp/app.h @@ -1,12 +1,17 @@ #pragma once +#include + class App { public: inline static bool s_isInit; inline static bool s_isMissingDLC; + inline static ELanguage s_language; + inline static double s_deltaTime; - static void Exit(std::vector restartArgs = {}); + static void Restart(std::vector restartArgs = {}); + static void Exit(); }; diff --git a/UnleashedRecomp/locale/locale.h b/UnleashedRecomp/locale/locale.h index 3be2f541..a59c8921 100644 --- a/UnleashedRecomp/locale/locale.h +++ b/UnleashedRecomp/locale/locale.h @@ -66,6 +66,12 @@ inline static std::unordered_map #include #include +#include #include #include #include @@ -31,7 +32,7 @@ static bool ProcessInstallMessage() switch (g_installMessageResult) { case 0: - Fader::FadeOut(1, []() { App::Exit({ "--install-dlc" }); }); + Fader::FadeOut(1, []() { App::Restart({ "--install-dlc" }); }); g_installMessageFaderBegun = true; break; @@ -58,7 +59,14 @@ PPC_FUNC(sub_825882B8) if (!OptionsMenu::s_isVisible && isOptionsIndex) { - if (isAccepted) + if (OptionsMenu::s_isRestartRequired) + { + static int result = -1; + + if (MessageWindow::Open(Localise("Options_Message_Restart"), &result) == MSG_CLOSED) + Fader::FadeOut(1, []() { App::Restart(); }); + } + else if (isAccepted) { Game_PlaySound("sys_worldmap_window"); Game_PlaySound("sys_worldmap_decide"); @@ -71,7 +79,7 @@ PPC_FUNC(sub_825882B8) g_installMessageOpen = true; } - if (!OptionsMenu::s_isVisible && !ProcessInstallMessage()) + if (!OptionsMenu::s_isVisible && !OptionsMenu::s_isRestartRequired && !ProcessInstallMessage()) __imp__sub_825882B8(ctx, base); if (isOptionsIndex) diff --git a/UnleashedRecomp/ui/fader.cpp b/UnleashedRecomp/ui/fader.cpp index bd3cd034..18a37aac 100644 --- a/UnleashedRecomp/ui/fader.cpp +++ b/UnleashedRecomp/ui/fader.cpp @@ -2,6 +2,7 @@ #include "imgui_utils.h" #include +static bool g_isFading; static bool g_isFadeIn; static float g_startTime; @@ -21,8 +22,13 @@ void Fader::Draw() if (time >= g_duration) { - if (g_endCallback && time >= g_duration + g_endCallbackDelay) - g_endCallback(); + if (time >= g_duration + g_endCallbackDelay) + { + if (g_endCallback) + g_endCallback(); + + g_isFading = false; + } } else { @@ -36,9 +42,14 @@ void Fader::Draw() ImGui::GetForegroundDrawList()->AddRectFilled({ 0, 0 }, ImGui::GetIO().DisplaySize, colour); } -static void DoFade(float duration, std::function endCallback, float endCallbackDelay) +static void DoFade(bool isFadeIn, float duration, std::function endCallback, float endCallbackDelay) { + if (g_isFading) + return; + Fader::s_isVisible = true; + g_isFading = true; + g_isFadeIn = isFadeIn; g_startTime = ImGui::GetTime(); g_duration = duration; g_endCallback = endCallback; @@ -52,12 +63,10 @@ void Fader::SetFadeColour(ImU32 colour) void Fader::FadeIn(float duration, std::function endCallback, float endCallbackDelay) { - g_isFadeIn = true; - DoFade(duration, endCallback, endCallbackDelay); + DoFade(true, duration, endCallback, endCallbackDelay); } void Fader::FadeOut(float duration, std::function endCallback, float endCallbackDelay) { - g_isFadeIn = false; - DoFade(duration, endCallback, endCallbackDelay); + DoFade(false, duration, endCallback, endCallbackDelay); } diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index f3c9bc2d..f7741791 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -66,6 +67,7 @@ static std::string* g_inaccessibleReason; static bool g_isEnterKeyBuffered = false; static bool g_canReset = false; +static bool g_isLanguageOptionChanged = false; static double g_appearTime = 0.0; @@ -475,6 +477,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf { g_leftWasHeld = false; g_rightWasHeld = false; + // remember value s_oldValue = config->Value; @@ -493,6 +496,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef* conf { // released lock, restore old value config->Value = s_oldValue; + g_lockedOnOption = false; Game_PlaySound("sys_worldmap_cansel"); @@ -1012,6 +1016,8 @@ void OptionsMenu::Draw() DrawScanlineBars(); DrawSettingsPanel(); DrawInfoPanel(); + + s_isRestartRequired = Config::Language != App::s_language; } void OptionsMenu::Open(bool isPause, SWA::EMenuType pauseMenuType) diff --git a/UnleashedRecomp/ui/options_menu.h b/UnleashedRecomp/ui/options_menu.h index 85268806..f0a32e59 100644 --- a/UnleashedRecomp/ui/options_menu.h +++ b/UnleashedRecomp/ui/options_menu.h @@ -7,6 +7,7 @@ class OptionsMenu public: inline static bool s_isVisible = false; inline static bool s_isPause = false; + inline static bool s_isRestartRequired = false; inline static SWA::EMenuType s_pauseMenuType;