diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 708dd1033c..a6bfec6411 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1158,10 +1158,7 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) { systemSettings->Add(new ChoiceWithValueDisplay(&g_Config.sLanguageIni, sy->T("Language"), langCodeToName))->OnClick.Add([&](UI::EventParams &e) { auto sy = GetI18NCategory(I18NCat::SYSTEM); auto langScreen = new NewLanguageScreen(sy->T("Language")); - langScreen->OnChoice.Add([&](UI::EventParams &e) { - screenManager()->RecreateAllViews(); - System_Notify(SystemNotification::UI); - }); + // The actual switching is handled in OnCompleted in NewLanguageScreen. if (e.v) langScreen->SetPopupOrigin(e.v); screenManager()->push(langScreen); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index d910929fcb..c2197565b6 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -40,6 +40,7 @@ #include "Common/TimeUtil.h" #include "Common/File/FileUtil.h" #include "Common/Render/ManagedTexture.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/System.h" @@ -329,13 +330,10 @@ void NewLanguageScreen::OnCompleted(DialogResult result) { std::string oldLang = g_Config.sLanguageIni; std::string iniFile = langs_[listView_->GetSelected()].name; - size_t dot = iniFile.find('.'); - std::string code; - if (dot != std::string::npos) - code = iniFile.substr(0, dot); - - if (code.empty()) + std::string_view code, part2; + if (!SplitStringOnce(iniFile, &code, &part2, '.')) { return; + } g_Config.sLanguageIni = code; @@ -352,6 +350,7 @@ void NewLanguageScreen::OnCompleted(DialogResult result) { if (iniLoadedSuccessfully) { RecreateViews(); + System_Notify(SystemNotification::UI); } else { // Failed to load the language ini. Shouldn't really happen, but let's just switch back to the old language. g_Config.sLanguageIni = oldLang; diff --git a/UI/MiscViews.cpp b/UI/MiscViews.cpp index b1b3715b4e..f863592352 100644 --- a/UI/MiscViews.cpp +++ b/UI/MiscViews.cpp @@ -66,7 +66,6 @@ TopBar::TopBar(const UIContext &ctx, bool usePortraitLayout, std::string_view ti // If using HCENTER, to balance the centering, add a spacer on the right. // Add(new Spacer(50.0f)); } - SetBG(ctx.GetTheme().itemDownStyle.background); } SettingInfoMessage::SettingInfoMessage(int align, float cutOffY, UI::AnchorLayoutParams *lp) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 10d46a7adf..25d3c2832c 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1384,6 +1384,24 @@ bool NativeKey(const KeyInput &key) { } #endif +#ifdef _DEBUG + // Debug hack: Randomize the language with F9! + if (false && (key.keyCode == NKCODE_F9 && (key.flags & KEY_DOWN))) { + std::vector tempLangs; + g_VFS.GetFileListing("lang", &tempLangs, "ini"); + int x = rand() % tempLangs.size(); + std::string_view code, part2; + if (SplitStringOnce(tempLangs[x].name, &code, &part2, '.')) { + g_Config.sLanguageIni = code; + INFO_LOG(Log::System, "Switching to random language: %s", g_Config.sLanguageIni.c_str()); + if (g_i18nrepo.LoadIni(g_Config.sLanguageIni)) { + g_screenManager->RecreateAllViews(); + System_Notify(SystemNotification::UI); + } + } + } +#endif + if (!g_screenManager) { return false; }