Simplify using lambdas

This commit is contained in:
Henrik Rydgård
2023-07-23 23:02:06 +02:00
parent 386976b123
commit 0dcc1ae5f0
2 changed files with 27 additions and 41 deletions
+27 -38
View File
@@ -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;
}
-3
View File
@@ -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;