diff options
| author | 2021-06-04 21:07:39 -0700 | |
|---|---|---|
| committer | 2021-06-04 21:07:39 -0700 | |
| commit | fefc76e5da03b646715454fc57179578babe8881 (patch) | |
| tree | 654ff3d979661bc358be6ca381686d75ad466660 /src | |
| parent | Merge pull request #6411 from clementgallet/yuzu-cmd-touch-button (diff) | |
| parent | yuzu qt: Use lambda and std::function for reset callback (diff) | |
| download | yuzu-fefc76e5da03b646715454fc57179578babe8881.tar.gz yuzu-fefc76e5da03b646715454fc57179578babe8881.tar.xz yuzu-fefc76e5da03b646715454fc57179578babe8881.zip | |
Merge pull request #6362 from lat9nq/reset-to-defaults
yuzu qt: Add settings reset button to general configuration
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_dialog.cpp | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.cpp | 30 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.h | 7 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_general.ui | 41 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 44 | ||||
| -rw-r--r-- | src/yuzu/uisettings.h | 1 |
6 files changed, 122 insertions, 3 deletions
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 6028135c5..371bc01b1 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp | |||
| @@ -27,6 +27,8 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, | |||
| 27 | 27 | ||
| 28 | ui->inputTab->Initialize(input_subsystem); | 28 | ui->inputTab->Initialize(input_subsystem); |
| 29 | 29 | ||
| 30 | ui->generalTab->SetResetCallback([&] { this->close(); }); | ||
| 31 | |||
| 30 | SetConfiguration(); | 32 | SetConfiguration(); |
| 31 | PopulateSelectionList(); | 33 | PopulateSelectionList(); |
| 32 | 34 | ||
diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 55a6a37bd..38edb4d8d 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp | |||
| @@ -2,11 +2,15 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <functional> | ||
| 6 | #include <utility> | ||
| 5 | #include <QCheckBox> | 7 | #include <QCheckBox> |
| 8 | #include <QMessageBox> | ||
| 6 | #include <QSpinBox> | 9 | #include <QSpinBox> |
| 7 | #include "common/settings.h" | 10 | #include "common/settings.h" |
| 8 | #include "core/core.h" | 11 | #include "core/core.h" |
| 9 | #include "ui_configure_general.h" | 12 | #include "ui_configure_general.h" |
| 13 | #include "yuzu/configuration/config.h" | ||
| 10 | #include "yuzu/configuration/configuration_shared.h" | 14 | #include "yuzu/configuration/configuration_shared.h" |
| 11 | #include "yuzu/configuration/configure_general.h" | 15 | #include "yuzu/configuration/configure_general.h" |
| 12 | #include "yuzu/uisettings.h" | 16 | #include "yuzu/uisettings.h" |
| @@ -23,6 +27,9 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) | |||
| 23 | connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, | 27 | connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, |
| 24 | [this]() { ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); }); | 28 | [this]() { ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); }); |
| 25 | } | 29 | } |
| 30 | |||
| 31 | connect(ui->button_reset_defaults, &QPushButton::clicked, this, | ||
| 32 | &ConfigureGeneral::ResetDefaults); | ||
| 26 | } | 33 | } |
| 27 | 34 | ||
| 28 | ConfigureGeneral::~ConfigureGeneral() = default; | 35 | ConfigureGeneral::~ConfigureGeneral() = default; |
| @@ -41,6 +48,8 @@ void ConfigureGeneral::SetConfiguration() { | |||
| 41 | ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue()); | 48 | ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue()); |
| 42 | ui->frame_limit->setValue(Settings::values.frame_limit.GetValue()); | 49 | ui->frame_limit->setValue(Settings::values.frame_limit.GetValue()); |
| 43 | 50 | ||
| 51 | ui->button_reset_defaults->setEnabled(runtime_lock); | ||
| 52 | |||
| 44 | if (Settings::IsConfiguringGlobal()) { | 53 | if (Settings::IsConfiguringGlobal()) { |
| 45 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue()); | 54 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue()); |
| 46 | } else { | 55 | } else { |
| @@ -49,6 +58,25 @@ void ConfigureGeneral::SetConfiguration() { | |||
| 49 | } | 58 | } |
| 50 | } | 59 | } |
| 51 | 60 | ||
| 61 | // Called to set the callback when resetting settings to defaults | ||
| 62 | void ConfigureGeneral::SetResetCallback(std::function<void()> callback) { | ||
| 63 | reset_callback = std::move(callback); | ||
| 64 | } | ||
| 65 | |||
| 66 | void ConfigureGeneral::ResetDefaults() { | ||
| 67 | QMessageBox::StandardButton answer = QMessageBox::question( | ||
| 68 | this, tr("yuzu"), | ||
| 69 | tr("This reset all settings and remove all per-game configurations. This will not delete " | ||
| 70 | "game directories, profiles, or input profiles. Proceed?"), | ||
| 71 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No); | ||
| 72 | if (answer == QMessageBox::No) { | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | UISettings::values.reset_to_defaults = true; | ||
| 76 | UISettings::values.is_game_list_reload_pending.exchange(true); | ||
| 77 | reset_callback(); | ||
| 78 | } | ||
| 79 | |||
| 52 | void ConfigureGeneral::ApplyConfiguration() { | 80 | void ConfigureGeneral::ApplyConfiguration() { |
| 53 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core, | 81 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core, |
| 54 | use_multi_core); | 82 | use_multi_core); |
| @@ -105,6 +133,8 @@ void ConfigureGeneral::SetupPerGameUI() { | |||
| 105 | ui->toggle_background_pause->setVisible(false); | 133 | ui->toggle_background_pause->setVisible(false); |
| 106 | ui->toggle_hide_mouse->setVisible(false); | 134 | ui->toggle_hide_mouse->setVisible(false); |
| 107 | 135 | ||
| 136 | ui->button_reset_defaults->setVisible(false); | ||
| 137 | |||
| 108 | ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit, | 138 | ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit, |
| 109 | Settings::values.use_frame_limit, use_frame_limit); | 139 | Settings::values.use_frame_limit, use_frame_limit); |
| 110 | ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core, | 140 | ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core, |
diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 323ffbd8f..a0fd52492 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h | |||
| @@ -4,9 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <functional> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <QWidget> | 9 | #include <QWidget> |
| 9 | 10 | ||
| 11 | class ConfigureDialog; | ||
| 12 | |||
| 10 | namespace ConfigurationShared { | 13 | namespace ConfigurationShared { |
| 11 | enum class CheckState; | 14 | enum class CheckState; |
| 12 | } | 15 | } |
| @@ -24,6 +27,8 @@ public: | |||
| 24 | explicit ConfigureGeneral(QWidget* parent = nullptr); | 27 | explicit ConfigureGeneral(QWidget* parent = nullptr); |
| 25 | ~ConfigureGeneral() override; | 28 | ~ConfigureGeneral() override; |
| 26 | 29 | ||
| 30 | void SetResetCallback(std::function<void()> callback); | ||
| 31 | void ResetDefaults(); | ||
| 27 | void ApplyConfiguration(); | 32 | void ApplyConfiguration(); |
| 28 | 33 | ||
| 29 | private: | 34 | private: |
| @@ -34,6 +39,8 @@ private: | |||
| 34 | 39 | ||
| 35 | void SetupPerGameUI(); | 40 | void SetupPerGameUI(); |
| 36 | 41 | ||
| 42 | std::function<void()> reset_callback; | ||
| 43 | |||
| 37 | std::unique_ptr<Ui::ConfigureGeneral> ui; | 44 | std::unique_ptr<Ui::ConfigureGeneral> ui; |
| 38 | 45 | ||
| 39 | ConfigurationShared::CheckState use_frame_limit; | 46 | ConfigurationShared::CheckState use_frame_limit; |
diff --git a/src/yuzu/configuration/configure_general.ui b/src/yuzu/configuration/configure_general.ui index 2711116a2..bc7041090 100644 --- a/src/yuzu/configuration/configure_general.ui +++ b/src/yuzu/configuration/configure_general.ui | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>300</width> | 9 | <width>329</width> |
| 10 | <height>407</height> | 10 | <height>407</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| @@ -104,6 +104,45 @@ | |||
| 104 | </property> | 104 | </property> |
| 105 | </spacer> | 105 | </spacer> |
| 106 | </item> | 106 | </item> |
| 107 | <item> | ||
| 108 | <layout class="QHBoxLayout" name="layout_reset"> | ||
| 109 | <property name="spacing"> | ||
| 110 | <number>6</number> | ||
| 111 | </property> | ||
| 112 | <property name="leftMargin"> | ||
| 113 | <number>5</number> | ||
| 114 | </property> | ||
| 115 | <property name="topMargin"> | ||
| 116 | <number>5</number> | ||
| 117 | </property> | ||
| 118 | <property name="rightMargin"> | ||
| 119 | <number>5</number> | ||
| 120 | </property> | ||
| 121 | <property name="bottomMargin"> | ||
| 122 | <number>5</number> | ||
| 123 | </property> | ||
| 124 | <item> | ||
| 125 | <widget class="QPushButton" name="button_reset_defaults"> | ||
| 126 | <property name="text"> | ||
| 127 | <string>Reset All Settings</string> | ||
| 128 | </property> | ||
| 129 | </widget> | ||
| 130 | </item> | ||
| 131 | <item> | ||
| 132 | <spacer name="spacer_reset"> | ||
| 133 | <property name="orientation"> | ||
| 134 | <enum>Qt::Horizontal</enum> | ||
| 135 | </property> | ||
| 136 | <property name="sizeHint" stdset="0"> | ||
| 137 | <size> | ||
| 138 | <width>40</width> | ||
| 139 | <height>20</height> | ||
| 140 | </size> | ||
| 141 | </property> | ||
| 142 | </spacer> | ||
| 143 | </item> | ||
| 144 | </layout> | ||
| 145 | </item> | ||
| 107 | </layout> | 146 | </layout> |
| 108 | </item> | 147 | </item> |
| 109 | </layout> | 148 | </layout> |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 237e26829..e683fb920 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -2596,13 +2596,53 @@ void GMainWindow::OnConfigure() { | |||
| 2596 | &GMainWindow::OnLanguageChanged); | 2596 | &GMainWindow::OnLanguageChanged); |
| 2597 | 2597 | ||
| 2598 | const auto result = configure_dialog.exec(); | 2598 | const auto result = configure_dialog.exec(); |
| 2599 | if (result != QDialog::Accepted && !UISettings::values.configuration_applied) { | 2599 | if (result != QDialog::Accepted && !UISettings::values.configuration_applied && |
| 2600 | !UISettings::values.reset_to_defaults) { | ||
| 2601 | // Runs if the user hit Cancel or closed the window, and did not ever press the Apply button | ||
| 2602 | // or `Reset to Defaults` button | ||
| 2600 | return; | 2603 | return; |
| 2601 | } else if (result == QDialog::Accepted) { | 2604 | } else if (result == QDialog::Accepted) { |
| 2605 | // Only apply new changes if user hit Okay | ||
| 2606 | // This is here to avoid applying changes if the user hit Apply, made some changes, then hit | ||
| 2607 | // Cancel | ||
| 2602 | configure_dialog.ApplyConfiguration(); | 2608 | configure_dialog.ApplyConfiguration(); |
| 2603 | controller_dialog->refreshConfiguration(); | 2609 | } else if (UISettings::values.reset_to_defaults) { |
| 2610 | LOG_INFO(Frontend, "Resetting all settings to defaults"); | ||
| 2611 | if (!Common::FS::RemoveFile(config->GetConfigFilePath())) { | ||
| 2612 | LOG_WARNING(Frontend, "Failed to remove configuration file"); | ||
| 2613 | } | ||
| 2614 | if (!Common::FS::RemoveDirContentsRecursively( | ||
| 2615 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "custom")) { | ||
| 2616 | LOG_WARNING(Frontend, "Failed to remove custom configuration files"); | ||
| 2617 | } | ||
| 2618 | if (!Common::FS::RemoveDirRecursively( | ||
| 2619 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "game_list")) { | ||
| 2620 | LOG_WARNING(Frontend, "Failed to remove game metadata cache files"); | ||
| 2621 | } | ||
| 2622 | |||
| 2623 | // Explicitly save the game directories, since reinitializing config does not explicitly do | ||
| 2624 | // so. | ||
| 2625 | QVector<UISettings::GameDir> old_game_dirs = std::move(UISettings::values.game_dirs); | ||
| 2626 | QVector<u64> old_favorited_ids = std::move(UISettings::values.favorited_ids); | ||
| 2627 | |||
| 2628 | Settings::values.disabled_addons.clear(); | ||
| 2629 | |||
| 2630 | config = std::make_unique<Config>(); | ||
| 2631 | UISettings::values.reset_to_defaults = false; | ||
| 2632 | |||
| 2633 | UISettings::values.game_dirs = std::move(old_game_dirs); | ||
| 2634 | UISettings::values.favorited_ids = std::move(old_favorited_ids); | ||
| 2635 | |||
| 2636 | InitializeRecentFileMenuActions(); | ||
| 2637 | |||
| 2638 | SetDefaultUIGeometry(); | ||
| 2639 | RestoreUIState(); | ||
| 2640 | |||
| 2641 | ShowTelemetryCallout(); | ||
| 2604 | } | 2642 | } |
| 2643 | controller_dialog->refreshConfiguration(); | ||
| 2605 | InitializeHotkeys(); | 2644 | InitializeHotkeys(); |
| 2645 | |||
| 2606 | if (UISettings::values.theme != old_theme) { | 2646 | if (UISettings::values.theme != old_theme) { |
| 2607 | UpdateUITheme(); | 2647 | UpdateUITheme(); |
| 2608 | } | 2648 | } |
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h index 49122ec32..cdcb83f9f 100644 --- a/src/yuzu/uisettings.h +++ b/src/yuzu/uisettings.h | |||
| @@ -97,6 +97,7 @@ struct Values { | |||
| 97 | bool cache_game_list; | 97 | bool cache_game_list; |
| 98 | 98 | ||
| 99 | bool configuration_applied; | 99 | bool configuration_applied; |
| 100 | bool reset_to_defaults; | ||
| 100 | }; | 101 | }; |
| 101 | 102 | ||
| 102 | extern Values values; | 103 | extern Values values; |