From 0dcc1ae5f0be9d4398101faddf62708cd2b6e16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 23 Jul 2023 23:02:06 +0200 Subject: [PATCH] Simplify using lambdas --- UI/GameSettingsScreen.cpp | 65 ++++++++++++++++----------------------- UI/GameSettingsScreen.h | 3 -- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 41006d8114..6f19b9e951 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1413,45 +1413,18 @@ void GameSettingsScreen::TriggerRestart(const char *why) { System_RestartApp(param); } -void GameSettingsScreen::CallbackRenderingBackend(bool yes) { - // If the user ends up deciding not to restart, set the config back to the current backend - // so it doesn't get switched by accident. - if (yes) { - TriggerRestart("GameSettingsScreen::RenderingBackendYes"); - } else { - g_Config.iGPUBackend = (int)GetGPUBackend(); - } -} - -void GameSettingsScreen::CallbackRenderingDevice(bool yes) { - // If the user ends up deciding not to restart, set the config back to the current backend - // so it doesn't get switched by accident. - if (yes) { - TriggerRestart("GameSettingsScreen::RenderingDeviceYes"); - } else { - std::string *deviceNameSetting = GPUDeviceNameSetting(); - if (deviceNameSetting) - *deviceNameSetting = GetGPUBackendDevice(); - // Needed to redraw the setting. - RecreateViews(); - } -} - -void GameSettingsScreen::CallbackInflightFrames(bool yes) { - if (yes) { - TriggerRestart("GameSettingsScreen::InflightFramesYes"); - } else { - g_Config.iInflightFrames = prevInflightFrames_; - } -} - UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) { auto di = GetI18NCategory(I18NCat::DIALOG); // It only makes sense to show the restart prompt if the backend was actually changed. if (g_Config.iGPUBackend != (int)GetGPUBackend()) { - screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), - std::bind(&GameSettingsScreen::CallbackRenderingBackend, this, std::placeholders::_1))); + screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) { + if (yes) { + TriggerRestart("GameSettingsScreen::RenderingBackendYes"); + } else { + g_Config.iGPUBackend = (int)GetGPUBackend(); + } + })); } return UI::EVENT_DONE; } @@ -1462,8 +1435,19 @@ UI::EventReturn GameSettingsScreen::OnRenderingDevice(UI::EventParams &e) { // It only makes sense to show the restart prompt if the device was actually changed. std::string *deviceNameSetting = GPUDeviceNameSetting(); if (deviceNameSetting && *deviceNameSetting != GetGPUBackendDevice()) { - screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), - std::bind(&GameSettingsScreen::CallbackRenderingDevice, this, std::placeholders::_1))); + screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) { + // If the user ends up deciding not to restart, set the config back to the current backend + // so it doesn't get switched by accident. + if (yes) { + TriggerRestart("GameSettingsScreen::RenderingDeviceYes"); + } else { + std::string *deviceNameSetting = GPUDeviceNameSetting(); + if (deviceNameSetting) + *deviceNameSetting = GetGPUBackendDevice(); + // Needed to redraw the setting. + RecreateViews(); + } + })); } return UI::EVENT_DONE; } @@ -1471,8 +1455,13 @@ UI::EventReturn GameSettingsScreen::OnRenderingDevice(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnInflightFramesChoice(UI::EventParams &e) { auto di = GetI18NCategory(I18NCat::DIALOG); if (g_Config.iInflightFrames != prevInflightFrames_) { - screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), - std::bind(&GameSettingsScreen::CallbackInflightFrames, this, std::placeholders::_1))); + screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) { + if (yes) { + TriggerRestart("GameSettingsScreen::InflightFramesYes"); + } else { + g_Config.iInflightFrames = prevInflightFrames_; + } + })); } return UI::EVENT_DONE; } diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 1a46358900..3658874397 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -38,9 +38,6 @@ public: protected: void CallbackRestoreDefaults(bool yes); - void CallbackRenderingBackend(bool yes); - void CallbackRenderingDevice(bool yes); - void CallbackInflightFrames(bool yes); void CallbackMemstickFolder(bool yes); void dialogFinished(const Screen *dialog, DialogResult result) override;