From 4a3692161b365f9f7936a75ea8bda0e2a1dc29c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 25 Mar 2018 14:26:44 +0200 Subject: [PATCH] Show chosen postshader display name properly, plus some additional bugfixes. Fixes #10790 --- UI/GameSettingsScreen.cpp | 19 ++++++++++++++----- UI/RemoteISOScreen.cpp | 4 ++-- Windows/MainWindowMenu.cpp | 5 +++++ .../src/org/ppsspp/ppsspp/NativeActivity.java | 1 + ext/native/i18n/i18n.h | 7 +++++++ ext/native/ui/ui_screen.cpp | 4 +++- ext/native/ui/ui_screen.h | 15 ++++++++++----- 7 files changed, 42 insertions(+), 13 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index c0a0a33d27..8d803f913b 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -52,6 +52,7 @@ #include "Core/Host.h" #include "Core/System.h" #include "Core/Reporting.h" +#include "GPU/Common/PostShader.h" #include "android/jni/TestRunner.h" #include "GPU/GPUInterface.h" #include "GPU/Common/FramebufferCommon.h" @@ -106,6 +107,14 @@ bool DoesBackendSupportHWTess() { return false; } +static std::string PostShaderTranslateName(const char *value) { + I18NCategory *ps = GetI18NCategory("PostShaders"); + const ShaderInfo *info = GetPostShaderInfo(value); + if (info) { + return ps->T(value, info ? info->name.c_str() : value); + } +} + void GameSettingsScreen::CreateViews() { if (editThenRestore_) { g_Config.loadGameConfig(gameID_); @@ -244,7 +253,7 @@ void GameSettingsScreen::CreateViews() { // Hide postprocess option on unsupported backends to avoid confusion. if (GetGPUBackend() != GPUBackend::DIRECT3D9) { I18NCategory *ps = GetI18NCategory("PostShaders"); - postProcChoice_ = graphicsSettings->Add(new ChoiceWithValueDisplay(&g_Config.sPostShaderName, gr->T("Postprocessing Shader"), ps->GetName())); + postProcChoice_ = graphicsSettings->Add(new ChoiceWithValueDisplay(&g_Config.sPostShaderName, gr->T("Postprocessing Shader"), &PostShaderTranslateName)); postProcChoice_->OnClick.Handle(this, &GameSettingsScreen::OnPostProcShader); postProcEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); postProcChoice_->SetEnabledPtr(&postProcEnable_); @@ -597,12 +606,12 @@ void GameSettingsScreen::CreateViews() { #if !defined(MOBILE_DEVICE) && !defined(USING_QT_UI) networkingSettings->Add(new PopupTextInputChoice(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), "", 255, screenManager())); #elif defined(__ANDROID__) - networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeproAdhocServerAddress); + networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), (const char *)nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeproAdhocServerAddress); #else - networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeproAdhocServerAddress); + networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), (const char *)nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeproAdhocServerAddress); #endif networkingSettings->Add(new CheckBox(&g_Config.bEnableAdhocServer, n->T("Enable built-in PRO Adhoc Server", "Enable built-in PRO Adhoc Server"))); - networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sMACAddress, n->T("Change Mac Address"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeMacAddress); + networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sMACAddress, n->T("Change Mac Address"), (const char *)nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeMacAddress); networkingSettings->Add(new PopupSliderChoice(&g_Config.iPortOffset, 0, 60000, n->T("Port offset", "Port offset(0 = PSP compatibility)"), 100, screenManager())); ViewGroup *toolsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -757,7 +766,7 @@ void GameSettingsScreen::CreateViews() { #elif defined(USING_QT_UI) systemSettings->Add(new Choice(sy->T("Change Nickname")))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname); #elif defined(__ANDROID__) - systemSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Change Nickname"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname); + systemSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Change Nickname"), (const char *)nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname); #endif #if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE)) // Screenshot functionality is not yet available on non-Windows/non-Qt diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index 0ae4fec31c..2767e72761 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -689,7 +689,7 @@ void RemoteISOSettingsScreen::CreateViews() { #if !defined(MOBILE_DEVICE) PopupTextInputChoice *remoteServer = remoteisoSettings->Add(new PopupTextInputChoice(&g_Config.sLastRemoteISOServer, ri->T("Remote Server"), "", 255, screenManager())); #else - ChoiceWithValueDisplay *remoteServer = new ChoiceWithValueDisplay(&g_Config.sLastRemoteISOServer, ri->T("Remote Server"), nullptr); + ChoiceWithValueDisplay *remoteServer = new ChoiceWithValueDisplay(&g_Config.sLastRemoteISOServer, ri->T("Remote Server"), (const char *)nullptr); remoteisoSettings->Add(remoteServer); remoteServer->OnClick.Handle(this, &RemoteISOSettingsScreen::OnClickRemoteServer); #endif @@ -701,7 +701,7 @@ void RemoteISOSettingsScreen::CreateViews() { remoteSubdir->OnChange.Handle(this, &RemoteISOSettingsScreen::OnChangeRemoteISOSubdir); #else ChoiceWithValueDisplay *remoteSubdir = remoteisoSettings->Add( - new ChoiceWithValueDisplay(&g_Config.sRemoteISOSubdir, ri->T("Remote Subdirectory"), nullptr)); + new ChoiceWithValueDisplay(&g_Config.sRemoteISOSubdir, ri->T("Remote Subdirectory"), (const char *)nullptr)); remoteSubdir->OnClick.Handle(this, &RemoteISOSettingsScreen::OnClickRemoteISOSubdir); #endif remoteSubdir->SetEnabledPtr(&g_Config.bRemoteISOManual); diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index dd157d7552..caa5ae5511 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -167,11 +167,16 @@ namespace MainWindow { } bool CreateShadersSubmenu(HMENU menu) { + // NOTE: We do not load this until translations are loaded! + if (!I18NCategoryLoaded("PostShaders")) + return false; + // We only reload this initially and when a menu is actually opened. if (!menuShaderInfoLoaded) { ReloadAllPostShaderInfo(); menuShaderInfoLoaded = true; } + std::vector info = GetAllPostShaderInfo(); if (menuShaderInfo.size() == info.size() && std::equal(info.begin(), info.end(), menuShaderInfo.begin())) { diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 96dadd6cf0..d941d64139 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -546,6 +546,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C recreate(); return; } else if (requestedPortrait == detectedPortrait) { + Log.i(TAG, "Correct orientation detected, resetting orientation counter."); badOrientationCount = 0; } diff --git a/ext/native/i18n/i18n.h b/ext/native/i18n/i18n.h index c57bc81f55..ede7f1e8a6 100644 --- a/ext/native/i18n/i18n.h +++ b/ext/native/i18n/i18n.h @@ -77,6 +77,9 @@ public: std::string LanguageID(); I18NCategory *GetCategory(const char *categoryName); + bool HasCategory(const char *categoryName) const { + return cats_.find(categoryName) != cats_.end(); + } const char *T(const char *category, const char *key, const char *def = 0); private: @@ -101,6 +104,10 @@ inline I18NCategory *GetI18NCategory(const char *categoryName) { return i18nrepo.GetCategory(categoryName); } +inline bool I18NCategoryLoaded(const char *categoryName) { + return i18nrepo.HasCategory(categoryName); +} + inline const char *T(const char *category, const char *key, const char *def = 0) { return i18nrepo.T(category, key, def); } diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index 092eacec1c..d4f5f0f41d 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -836,7 +836,9 @@ void ChoiceWithValueDisplay::Draw(UIContext &dc) { I18NCategory *category = GetI18NCategory(category_); std::ostringstream valueText; - if (sValue_ != nullptr) { + if (translateCallback_ && sValue_) { + valueText << translateCallback_(sValue_->c_str()); + } else if (sValue_ != nullptr) { if (category) valueText << category->T(*sValue_); else diff --git a/ext/native/ui/ui_screen.h b/ext/native/ui/ui_screen.h index 3844cba71a..4daeeb3078 100644 --- a/ext/native/ui/ui_screen.h +++ b/ext/native/ui/ui_screen.h @@ -354,17 +354,22 @@ private: class ChoiceWithValueDisplay : public UI::Choice { public: ChoiceWithValueDisplay(int *value, const std::string &text, LayoutParams *layoutParams = 0) - : Choice(text, layoutParams), iValue_(value), category_(nullptr) { sValue_ = nullptr; } + : Choice(text, layoutParams), iValue_(value) {} ChoiceWithValueDisplay(std::string *value, const std::string &text, const char *category, LayoutParams *layoutParams = 0) - : Choice(text, layoutParams), sValue_(value), category_(category) { iValue_ = nullptr; } + : Choice(text, layoutParams), sValue_(value), category_(category) {} + + ChoiceWithValueDisplay(std::string *value, const std::string &text, std::string (*translateCallback)(const char *value), LayoutParams *layoutParams = 0) + : Choice(text, layoutParams), sValue_(value), translateCallback_(translateCallback) { + } virtual void Draw(UIContext &dc) override; private: - int *iValue_; - std::string *sValue_; - const char *category_; + int *iValue_ = nullptr; + std::string *sValue_ = nullptr; + const char *category_ = nullptr; + std::string(*translateCallback_)(const char *value); }; } // namespace UI