diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index 7cf6bbe7cd..c7a6a18222 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -261,10 +261,12 @@ void DisplayLayoutScreen::CreateViews() { static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" }; rotation_ = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, local_dp_yres - 64 - 10)); - rotation_->SetEnabledPtr(&displayRotEnable_); - displayRotEnable_ = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); + rotation_->SetEnabledFunc([] { + return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; + }); + bool displayRotEnable = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); bRotated = false; - if (displayRotEnable_ && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) { + if (displayRotEnable && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) { bRotated = true; } displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom diff --git a/UI/DisplayLayoutScreen.h b/UI/DisplayLayoutScreen.h index 725131fab3..45d0906930 100644 --- a/UI/DisplayLayoutScreen.h +++ b/UI/DisplayLayoutScreen.h @@ -44,7 +44,6 @@ private: UI::ChoiceStrip *mode_; UI::PopupMultiChoice *zoom_; UI::PopupMultiChoice *rotation_; - bool displayRotEnable_; bool bRotated; bool stickToEdgeX; bool stickToEdgeY; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 10801c1610..e4dd17d0c1 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -225,7 +225,7 @@ void GameSettingsScreen::CreateViews() { } } - static const char *renderingMode[] = { "Non-Buffered Rendering", "Buffered Rendering"}; + static const char *renderingMode[] = { "Non-Buffered Rendering", "Buffered Rendering" }; PopupMultiChoice *renderingModeChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iRenderingMode, gr->T("Mode"), renderingMode, 0, ARRAY_SIZE(renderingMode), gr->GetName(), screenManager())); renderingModeChoice->OnChoice.Add([=](EventParams &e) { switch (g_Config.iRenderingMode) { @@ -289,8 +289,9 @@ void GameSettingsScreen::CreateViews() { auto ps = GetI18NCategory("PostShaders"); 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_); + postProcChoice_->SetEnabledFunc([] { + return !g_Config.bSoftwareRendering && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; + }); } #if !defined(MOBILE_DEVICE) @@ -315,14 +316,15 @@ void GameSettingsScreen::CreateViews() { graphicsSettings->Add(new ItemHeader(gr->T("Performance"))); #ifndef MOBILE_DEVICE - static const char *internalResolutions[] = {"Auto (1:1)", "1x PSP", "2x PSP", "3x PSP", "4x PSP", "5x PSP", "6x PSP", "7x PSP", "8x PSP", "9x PSP", "10x PSP" }; + static const char *internalResolutions[] = { "Auto (1:1)", "1x PSP", "2x PSP", "3x PSP", "4x PSP", "5x PSP", "6x PSP", "7x PSP", "8x PSP", "9x PSP", "10x PSP" }; #else - static const char *internalResolutions[] = {"Auto (1:1)", "1x PSP", "2x PSP", "3x PSP", "4x PSP", "5x PSP" }; + static const char *internalResolutions[] = { "Auto (1:1)", "1x PSP", "2x PSP", "3x PSP", "4x PSP", "5x PSP" }; #endif resolutionChoice_ = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iInternalResolution, gr->T("Rendering Resolution"), internalResolutions, 0, ARRAY_SIZE(internalResolutions), gr->GetName(), screenManager())); resolutionChoice_->OnChoice.Handle(this, &GameSettingsScreen::OnResolutionChange); - resolutionEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); - resolutionChoice_->SetEnabledPtr(&resolutionEnable_); + resolutionChoice_->SetEnabledFunc([] { + return !g_Config.bSoftwareRendering && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; + }); #ifdef __ANDROID__ if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) != DEVICE_TYPE_TV) { @@ -344,6 +346,9 @@ void GameSettingsScreen::CreateViews() { }); #endif CheckBox *frameDuplication = graphicsSettings->Add(new CheckBox(&g_Config.bRenderDuplicateFrames, gr->T("Render duplicate frames to 60hz"))); + frameDuplication->SetEnabledFunc([] { + return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE || (g_Config.bSoftwareRendering && g_Config.iFrameSkip != 0); + }); frameDuplication->OnClick.Add([=](EventParams &e) { settingInfo_->Show(gr->T("RenderDuplicateFrames Tip", "Can make framerate smoother in games that run at lower framerates"), e.v); return UI::EVENT_CONTINUE; @@ -371,8 +376,9 @@ void GameSettingsScreen::CreateViews() { settingInfo_->Show(gr->T("VertexCache Tip", "Faster, but may cause temporary flicker"), e.v); return UI::EVENT_CONTINUE; }); - vtxCacheEnable_ = !g_Config.bSoftwareRendering && g_Config.bHardwareTransform; - vtxCache->SetEnabledPtr(&vtxCacheEnable_); + vtxCache->SetEnabledFunc([] { + return !g_Config.bSoftwareRendering && g_Config.bHardwareTransform; + }); CheckBox *texBackoff = graphicsSettings->Add(new CheckBox(&g_Config.bTextureBackoffCache, gr->T("Lazy texture caching", "Lazy texture caching (speedup)"))); texBackoff->SetDisabledPtr(&g_Config.bSoftwareRendering); @@ -394,7 +400,7 @@ void GameSettingsScreen::CreateViews() { vtxJit->SetEnabled(false); }*/ - static const char *quality[] = { "Low", "Medium", "High"}; + static const char *quality[] = { "Low", "Medium", "High" }; PopupMultiChoice *beziersChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iSplineBezierQuality, gr->T("LowCurves", "Spline/Bezier curves quality"), quality, 0, ARRAY_SIZE(quality), gr->GetName(), screenManager())); beziersChoice->OnChoice.Add([=](EventParams &e) { if (g_Config.iSplineBezierQuality != 0) { @@ -481,8 +487,9 @@ void GameSettingsScreen::CreateViews() { static const char *bloomHackOptions[] = { "Off", "Safe", "Balanced", "Aggressive" }; PopupMultiChoice *bloomHack = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iBloomHack, gr->T("Lower resolution for effects (reduces artifacts)"), bloomHackOptions, 0, ARRAY_SIZE(bloomHackOptions), gr->GetName(), screenManager())); - bloomHackEnable_ = !g_Config.bSoftwareRendering && (g_Config.iInternalResolution != 1); - bloomHack->SetEnabledPtr(&bloomHackEnable_); + bloomHack->SetEnabledFunc([] { + return !g_Config.bSoftwareRendering && g_Config.iInternalResolution != 1; + }); graphicsSettings->Add(new ItemHeader(gr->T("Overlay Information"))); static const char *fpsChoices[] = { "None", "Speed", "FPS", "Both" }; @@ -563,12 +570,14 @@ void GameSettingsScreen::CreateViews() { #if defined(MOBILE_DEVICE) controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, co->T("HapticFeedback", "Haptic Feedback (vibration)"))); - static const char *tiltTypes[] = { "None (Disabled)", "Analog Stick", "D-PAD", "PSP Action Buttons", "L/R Trigger Buttons"}; + static const char *tiltTypes[] = { "None (Disabled)", "Analog Stick", "D-PAD", "PSP Action Buttons", "L/R Trigger Buttons" }; controlsSettings->Add(new PopupMultiChoice(&g_Config.iTiltInputType, co->T("Tilt Input Type"), tiltTypes, 0, ARRAY_SIZE(tiltTypes), co->GetName(), screenManager()))->OnClick.Handle(this, &GameSettingsScreen::OnTiltTypeChange); Choice *customizeTilt = controlsSettings->Add(new Choice(co->T("Customize tilt"))); customizeTilt->OnClick.Handle(this, &GameSettingsScreen::OnTiltCustomize); - customizeTilt->SetEnabledPtr((bool *)&g_Config.iTiltInputType); //<- dirty int-to-bool cast + customizeTilt->SetEnabledFunc([] { + return g_Config.iTiltInputType != 0; + }); #endif // TVs don't have touch control, at least not yet. @@ -768,6 +777,10 @@ void GameSettingsScreen::CreateViews() { View *ioTimingMethod = systemSettings->Add(new PopupMultiChoice(&g_Config.iIOTimingMethod, sy->T("IO timing method"), ioTimingMethods, 0, ARRAY_SIZE(ioTimingMethods), sy->GetName(), screenManager())); systemSettings->Add(new CheckBox(&g_Config.bForceLagSync, sy->T("Force real clock sync (slower, less lag)"))); PopupSliderChoice *lockedMhz = systemSettings->Add(new PopupSliderChoice(&g_Config.iLockedCPUSpeed, 0, 1000, sy->T("Change CPU Clock", "Change CPU Clock (unstable)"), screenManager(), sy->T("MHz, 0:default"))); + lockedMhz->OnChange.Add([&](UI::EventParams &) { + enableReportsCheckbox_->SetEnabled(Reporting::IsSupported()); + return UI::EVENT_CONTINUE; + }); lockedMhz->SetZeroLabel(sy->T("Auto")); PopupSliderChoice *rewindFreq = systemSettings->Add(new PopupSliderChoice(&g_Config.iRewindFlipFrequency, 0, 1800, sy->T("Rewind Snapshot Frequency", "Rewind Snapshot Frequency (mem hog)"), screenManager(), sy->T("frames, 0:off"))); rewindFreq->SetZeroLabel(sy->T("Off")); @@ -864,10 +877,12 @@ void GameSettingsScreen::CreateViews() { systemSettings->Add(new CheckBox(&g_Config.bCacheFullIsoInRam, sy->T("Cache ISO in RAM", "Cache full ISO in RAM"))); #endif -//#ifndef __ANDROID__ systemSettings->Add(new ItemHeader(sy->T("Cheats", "Cheats (experimental, see forums)"))); - systemSettings->Add(new CheckBox(&g_Config.bEnableCheats, sy->T("Enable Cheats"))); -//#endif + CheckBox *enableCheats = systemSettings->Add(new CheckBox(&g_Config.bEnableCheats, sy->T("Enable Cheats"))); + enableCheats->OnClick.Add([&](UI::EventParams &) { + enableReportsCheckbox_->SetEnabled(Reporting::IsSupported()); + return UI::EVENT_CONTINUE; + }); systemSettings->SetSpacing(0); systemSettings->Add(new ItemHeader(sy->T("PSP Settings"))); @@ -910,16 +925,11 @@ UI::EventReturn GameSettingsScreen::OnAutoFrameskip(UI::EventParams &e) { } UI::EventReturn GameSettingsScreen::OnSoftwareRendering(UI::EventParams &e) { - vtxCacheEnable_ = !g_Config.bSoftwareRendering && g_Config.bHardwareTransform; - postProcEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); - resolutionEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); - bloomHackEnable_ = !g_Config.bSoftwareRendering && (g_Config.iInternalResolution != 1); tessHWEnable_ = DoesBackendSupportHWTess() && !g_Config.bSoftwareRendering && g_Config.bHardwareTransform; return UI::EVENT_DONE; } UI::EventReturn GameSettingsScreen::OnHardwareTransform(UI::EventParams &e) { - vtxCacheEnable_ = !g_Config.bSoftwareRendering && g_Config.bHardwareTransform; tessHWEnable_ = DoesBackendSupportHWTess() && !g_Config.bSoftwareRendering && g_Config.bHardwareTransform; return UI::EVENT_DONE; } @@ -969,9 +979,6 @@ UI::EventReturn GameSettingsScreen::OnRenderingMode(UI::EventParams &e) { enableReports_ = Reporting::IsEnabled(); enableReportsCheckbox_->SetEnabled(Reporting::IsSupported()); - postProcEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); - resolutionEnable_ = !g_Config.bSoftwareRendering && (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); - if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE) { g_Config.bAutoFrameSkip = false; } @@ -1114,7 +1121,6 @@ UI::EventReturn GameSettingsScreen::OnResolutionChange(UI::EventParams &e) { if (g_Config.iAndroidHwScale == 1) { RecreateActivity(); } - bloomHackEnable_ = !g_Config.bSoftwareRendering && g_Config.iInternalResolution != 1; Reporting::UpdateConfig(); return UI::EVENT_DONE; } diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 7a82b7f463..2cf38a3a36 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -121,22 +121,16 @@ private: UI::EventReturn OnSavedataManager(UI::EventParams &e); UI::EventReturn OnSysInfo(UI::EventParams &e); - // Temporaries to convert setting types. + // Temporaries to convert setting types, cache enabled, etc. int iAlternateSpeedPercent1_; int iAlternateSpeedPercent2_; + int prevInflightFrames_; bool enableReports_; + bool tessHWEnable_; //edit the game-specific settings and restore the global settings after exiting bool editThenRestore_; - // Cached booleans - bool vtxCacheEnable_; - bool postProcEnable_; - bool resolutionEnable_; - bool bloomHackEnable_; - bool tessHWEnable_; - int prevInflightFrames_; - #if PPSSPP_PLATFORM(ANDROID) std::string pendingMemstickFolder_; #endif diff --git a/ext/native/ui/view.h b/ext/native/ui/view.h index 9bd45d8757..5cf1ad275c 100644 --- a/ext/native/ui/view.h +++ b/ext/native/ui/view.h @@ -401,15 +401,34 @@ public: return GetFocusedView() == this; } - void SetEnabled(bool enabled) { enabled_ = enabled; enabledMeansDisabled_ = false; } + void SetEnabled(bool enabled) { + enabledFunc_ = nullptr; + enabledPtr_ = nullptr; + enabled_ = enabled; + enabledMeansDisabled_ = false; + } bool IsEnabled() const { + if (enabledFunc_) + return enabledFunc_() != enabledMeansDisabled_; if (enabledPtr_) return *enabledPtr_ != enabledMeansDisabled_; - else - return enabled_ != enabledMeansDisabled_; + return enabled_ != enabledMeansDisabled_; + } + void SetEnabledFunc(std::function func) { + enabledFunc_ = func; + enabledPtr_ = nullptr; + enabledMeansDisabled_ = false; + } + void SetEnabledPtr(bool *enabled) { + enabledFunc_ = nullptr; + enabledPtr_ = enabled; + enabledMeansDisabled_ = false; + } + void SetDisabledPtr(bool *disabled) { + enabledFunc_ = nullptr; + enabledPtr_ = disabled; + enabledMeansDisabled_ = true; } - void SetEnabledPtr(bool *enabled) { enabledPtr_ = enabled; enabledMeansDisabled_ = false; } - void SetDisabledPtr(bool *disabled) { enabledPtr_ = disabled; enabledMeansDisabled_ = true; } virtual void SetVisibility(Visibility visibility) { visibility_ = visibility; } Visibility GetVisibility() const { return visibility_; } @@ -445,6 +464,7 @@ protected: std::vector tweens_; private: + std::function enabledFunc_; bool *enabledPtr_; bool enabled_; bool enabledMeansDisabled_;