From 6c246f2ac5ce2ede656bf0d2def3b32f87e620b3 Mon Sep 17 00:00:00 2001
From: Florian <fl.david.53@gmail.com>
Date: Sat, 26 Aug 2023 21:23:02 +0200
Subject: [PATCH] yuzu: Use new setting method for stop emulation

---
 src/common/settings.cpp                       |  5 +++++
 src/common/settings.h                         |  5 +++++
 src/common/settings_enums.h                   |  2 ++
 src/yuzu/configuration/shared_translation.cpp |  9 ++++++++-
 src/yuzu/main.cpp                             |  8 +++++---
 src/yuzu/uisettings.h                         | 16 +++++++++++-----
 6 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 3fde3cae63..98b43e49c8 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -45,6 +45,7 @@ SWITCHABLE(CpuAccuracy, true);
 SWITCHABLE(FullscreenMode, true);
 SWITCHABLE(GpuAccuracy, true);
 SWITCHABLE(Language, true);
+SWITCHABLE(MemoryLayout, true);
 SWITCHABLE(NvdecEmulation, false);
 SWITCHABLE(Region, true);
 SWITCHABLE(RendererBackend, true);
@@ -61,6 +62,10 @@ SWITCHABLE(u32, false);
 SWITCHABLE(u8, false);
 SWITCHABLE(u8, true);
 
+// Used in UISettings
+// TODO see if we can move this to uisettings.cpp
+SWITCHABLE(ConfirmStop, true);
+
 #undef SETTING
 #undef SWITCHABLE
 #endif
diff --git a/src/common/settings.h b/src/common/settings.h
index 98ab0ec2e4..236e33beea 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -67,6 +67,7 @@ SWITCHABLE(CpuAccuracy, true);
 SWITCHABLE(FullscreenMode, true);
 SWITCHABLE(GpuAccuracy, true);
 SWITCHABLE(Language, true);
+SWITCHABLE(MemoryLayout, true);
 SWITCHABLE(NvdecEmulation, false);
 SWITCHABLE(Region, true);
 SWITCHABLE(RendererBackend, true);
@@ -83,6 +84,10 @@ SWITCHABLE(u32, false);
 SWITCHABLE(u8, false);
 SWITCHABLE(u8, true);
 
+// Used in UISettings
+// TODO see if we can move this to uisettings.h
+SWITCHABLE(ConfirmStop, true);
+
 #undef SETTING
 #undef SWITCHABLE
 #endif
diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h
index 815cafe15e..11429d7a8d 100644
--- a/src/common/settings_enums.h
+++ b/src/common/settings_enums.h
@@ -133,6 +133,8 @@ ENUM(CpuAccuracy, Auto, Accurate, Unsafe, Paranoid);
 
 ENUM(MemoryLayout, Memory_4Gb, Memory_6Gb, Memory_8Gb);
 
+ENUM(ConfirmStop, Ask_Always, Ask_Based_On_Game, Ask_Never);
+
 ENUM(FullscreenMode, Borderless, Exclusive);
 
 ENUM(NvdecEmulation, Off, Cpu, Gpu);
diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp
index 9e65525ca3..3fe448f27d 100644
--- a/src/yuzu/configuration/shared_translation.cpp
+++ b/src/yuzu/configuration/shared_translation.cpp
@@ -157,7 +157,7 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) {
     INSERT(UISettings, select_user_on_boot, "Prompt for user on game boot", "");
     INSERT(UISettings, pause_when_in_background, "Pause emulation when in background", "");
     INSERT(UISettings, confirm_before_closing, "Confirm exit while emulation is running", "");
-    INSERT(UISettings, confirm_before_stopping, "Confirm stopping emulation", "");
+    INSERT(UISettings, confirm_before_stopping, "Confirm before stopping emulation", "");
     INSERT(UISettings, hide_mouse, "Hide mouse on inactivity", "");
     INSERT(UISettings, controller_applet_disabled, "Disable controller applet", "");
 
@@ -384,6 +384,13 @@ std::unique_ptr<ComboboxTranslationMap> ComboboxEnumeration(QWidget* parent) {
     translations->insert(
         {Settings::EnumMetadata<Settings::ConsoleMode>::Index(),
          {PAIR(ConsoleMode, Docked, "Docked"), PAIR(ConsoleMode, Handheld, "Handheld")}});
+    translations->insert(
+        {Settings::EnumMetadata<Settings::ConfirmStop>::Index(),
+         {
+             PAIR(ConfirmStop, Ask_Always, "Always ask (Default)"),
+             PAIR(ConfirmStop, Ask_Based_On_Game, "Only if game specifies not to stop"),
+             PAIR(ConfirmStop, Ask_Never, "Never ask"),
+         }});
 
 #undef PAIR
 #undef CTX_PAIR
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 26fa3e1919..2727f9d062 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -3426,7 +3426,7 @@ void GMainWindow::OnPauseContinueGame() {
 
 void GMainWindow::OnStopGame() {
     // Open (or not) the right confirm dialog based on current setting and game exit lock
-    if (UISettings::values.confirm_before_stopping.GetValue() == UISettings::AskStopIndex::Always) {
+    if (UISettings::values.confirm_before_stopping.GetValue() == ConfirmStop::Ask_Always) {
         if (system->GetExitLocked()) {
             if (!ConfirmForceLockedExit()) {
                 return;
@@ -3438,7 +3438,7 @@ void GMainWindow::OnStopGame() {
         }
     } else {
         if (UISettings::values.confirm_before_stopping.GetValue() ==
-                UISettings::AskStopIndex::Game &&
+                ConfirmStop::Ask_Based_On_Game &&
             system->GetExitLocked()) {
             if (!ConfirmForceLockedExit()) {
                 return;
@@ -4081,13 +4081,15 @@ void GMainWindow::OnLoadAmiibo() {
 bool GMainWindow::question(QWidget* parent, const QString& title, const QString& text,
                            QMessageBox::StandardButtons buttons,
                            QMessageBox::StandardButton defaultButton) {
-    ControllerNavigation* controller_navigation = new ControllerNavigation(system->HIDCore(), this);
 
     QMessageBox* box_dialog = new QMessageBox(parent);
     box_dialog->setWindowTitle(title);
     box_dialog->setText(text);
     box_dialog->setStandardButtons(buttons);
     box_dialog->setDefaultButton(defaultButton);
+
+    ControllerNavigation* controller_navigation =
+        new ControllerNavigation(system->HIDCore(), box_dialog);
     connect(controller_navigation, &ControllerNavigation::TriggerKeyboardEvent,
             [box_dialog](Qt::Key key) {
                 QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier);
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h
index 1216c4efaa..b62ff620ce 100644
--- a/src/yuzu/uisettings.h
+++ b/src/yuzu/uisettings.h
@@ -16,7 +16,9 @@
 #include "common/settings_enums.h"
 
 using Settings::Category;
+using Settings::ConfirmStop;
 using Settings::Setting;
+using Settings::SwitchableSetting;
 
 #ifndef CANNOT_EXPLICITLY_INSTANTIATE
 namespace Settings {
@@ -56,8 +58,6 @@ enum class Theme {
     MidnightBlueColorful,
 };
 
-enum AskStopIndex : int { Always, Game, Never };
-
 using Themes = std::array<std::pair<const char*, const char*>, 6>;
 extern const Themes themes;
 
@@ -96,9 +96,15 @@ struct Values {
     Setting<bool> confirm_before_closing{
         linkage, true, "confirmClose", Category::UiGeneral, Settings::Specialization::Default,
         true,    true};
-    Setting<bool> confirm_before_stopping{
-        linkage, true, "confirmStop", Category::UiGeneral, Settings::Specialization::Default,
-        true,    true};
+
+    SwitchableSetting<ConfirmStop> confirm_before_stopping{linkage,
+                                                           ConfirmStop::Ask_Always,
+                                                           "confirmStop",
+                                                           Category::UiGeneral,
+                                                           Settings::Specialization::Default,
+                                                           true,
+                                                           true};
+
     Setting<bool> first_start{linkage, true, "firstStart", Category::Ui};
     Setting<bool> pause_when_in_background{linkage,
                                            false,