configure_general.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <functional>
  5. #include <utility>
  6. #include <QCheckBox>
  7. #include <QMessageBox>
  8. #include <QSpinBox>
  9. #include "common/settings.h"
  10. #include "core/core.h"
  11. #include "ui_configure_general.h"
  12. #include "yuzu/configuration/config.h"
  13. #include "yuzu/configuration/configuration_shared.h"
  14. #include "yuzu/configuration/configure_general.h"
  15. #include "yuzu/uisettings.h"
  16. ConfigureGeneral::ConfigureGeneral(const Core::System& system_, QWidget* parent)
  17. : QWidget(parent), ui{std::make_unique<Ui::ConfigureGeneral>()}, system{system_} {
  18. ui->setupUi(this);
  19. SetupPerGameUI();
  20. SetConfiguration();
  21. if (Settings::IsConfiguringGlobal()) {
  22. connect(ui->toggle_speed_limit, &QCheckBox::clicked, ui->speed_limit,
  23. [this]() { ui->speed_limit->setEnabled(ui->toggle_speed_limit->isChecked()); });
  24. }
  25. connect(ui->button_reset_defaults, &QPushButton::clicked, this,
  26. &ConfigureGeneral::ResetDefaults);
  27. ui->fps_cap_label->setVisible(Settings::IsConfiguringGlobal());
  28. ui->fps_cap_combobox->setVisible(!Settings::IsConfiguringGlobal());
  29. }
  30. ConfigureGeneral::~ConfigureGeneral() = default;
  31. void ConfigureGeneral::SetConfiguration() {
  32. const bool runtime_lock = !system.IsPoweredOn();
  33. ui->use_multi_core->setEnabled(runtime_lock);
  34. ui->use_multi_core->setChecked(Settings::values.use_multi_core.GetValue());
  35. ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing.GetValue());
  36. ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot.GetValue());
  37. ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background.GetValue());
  38. ui->toggle_background_mute->setChecked(UISettings::values.mute_when_in_background.GetValue());
  39. ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse.GetValue());
  40. ui->toggle_speed_limit->setChecked(Settings::values.use_speed_limit.GetValue());
  41. ui->speed_limit->setValue(Settings::values.speed_limit.GetValue());
  42. ui->fps_cap->setValue(Settings::values.fps_cap.GetValue());
  43. ui->button_reset_defaults->setEnabled(runtime_lock);
  44. if (Settings::IsConfiguringGlobal()) {
  45. ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue());
  46. } else {
  47. ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue() &&
  48. use_speed_limit != ConfigurationShared::CheckState::Global);
  49. ui->fps_cap_combobox->setCurrentIndex(Settings::values.fps_cap.UsingGlobal() ? 0 : 1);
  50. ui->fps_cap->setEnabled(!Settings::values.fps_cap.UsingGlobal());
  51. ConfigurationShared::SetHighlight(ui->fps_cap_layout,
  52. !Settings::values.fps_cap.UsingGlobal());
  53. }
  54. }
  55. // Called to set the callback when resetting settings to defaults
  56. void ConfigureGeneral::SetResetCallback(std::function<void()> callback) {
  57. reset_callback = std::move(callback);
  58. }
  59. void ConfigureGeneral::ResetDefaults() {
  60. QMessageBox::StandardButton answer = QMessageBox::question(
  61. this, tr("yuzu"),
  62. tr("This reset all settings and remove all per-game configurations. This will not delete "
  63. "game directories, profiles, or input profiles. Proceed?"),
  64. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  65. if (answer == QMessageBox::No) {
  66. return;
  67. }
  68. UISettings::values.reset_to_defaults = true;
  69. UISettings::values.is_game_list_reload_pending.exchange(true);
  70. reset_callback();
  71. }
  72. void ConfigureGeneral::ApplyConfiguration() {
  73. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core,
  74. use_multi_core);
  75. if (Settings::IsConfiguringGlobal()) {
  76. UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
  77. UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked();
  78. UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
  79. UISettings::values.mute_when_in_background = ui->toggle_background_mute->isChecked();
  80. UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
  81. Settings::values.fps_cap.SetValue(ui->fps_cap->value());
  82. // Guard if during game and set to game-specific value
  83. if (Settings::values.use_speed_limit.UsingGlobal()) {
  84. Settings::values.use_speed_limit.SetValue(ui->toggle_speed_limit->checkState() ==
  85. Qt::Checked);
  86. Settings::values.speed_limit.SetValue(ui->speed_limit->value());
  87. }
  88. } else {
  89. bool global_speed_limit = use_speed_limit == ConfigurationShared::CheckState::Global;
  90. Settings::values.use_speed_limit.SetGlobal(global_speed_limit);
  91. Settings::values.speed_limit.SetGlobal(global_speed_limit);
  92. if (!global_speed_limit) {
  93. Settings::values.use_speed_limit.SetValue(ui->toggle_speed_limit->checkState() ==
  94. Qt::Checked);
  95. Settings::values.speed_limit.SetValue(ui->speed_limit->value());
  96. }
  97. if (ui->fps_cap_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  98. Settings::values.fps_cap.SetGlobal(true);
  99. } else {
  100. Settings::values.fps_cap.SetGlobal(false);
  101. Settings::values.fps_cap.SetValue(ui->fps_cap->value());
  102. }
  103. }
  104. }
  105. void ConfigureGeneral::changeEvent(QEvent* event) {
  106. if (event->type() == QEvent::LanguageChange) {
  107. RetranslateUI();
  108. }
  109. QWidget::changeEvent(event);
  110. }
  111. void ConfigureGeneral::RetranslateUI() {
  112. ui->retranslateUi(this);
  113. }
  114. void ConfigureGeneral::SetupPerGameUI() {
  115. if (Settings::IsConfiguringGlobal()) {
  116. // Disables each setting if:
  117. // - A game is running (thus settings in use), and
  118. // - A non-global setting is applied.
  119. ui->toggle_speed_limit->setEnabled(Settings::values.use_speed_limit.UsingGlobal());
  120. ui->speed_limit->setEnabled(Settings::values.speed_limit.UsingGlobal());
  121. return;
  122. }
  123. ui->toggle_check_exit->setVisible(false);
  124. ui->toggle_user_on_boot->setVisible(false);
  125. ui->toggle_background_pause->setVisible(false);
  126. ui->toggle_hide_mouse->setVisible(false);
  127. ui->button_reset_defaults->setVisible(false);
  128. ConfigurationShared::SetColoredTristate(ui->toggle_speed_limit,
  129. Settings::values.use_speed_limit, use_speed_limit);
  130. ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core,
  131. use_multi_core);
  132. connect(ui->toggle_speed_limit, &QCheckBox::clicked, ui->speed_limit, [this]() {
  133. ui->speed_limit->setEnabled(ui->toggle_speed_limit->isChecked() &&
  134. (use_speed_limit != ConfigurationShared::CheckState::Global));
  135. });
  136. connect(ui->fps_cap_combobox, qOverload<int>(&QComboBox::activated), this, [this](int index) {
  137. ui->fps_cap->setEnabled(index == 1);
  138. ConfigurationShared::SetHighlight(ui->fps_cap_layout, index == 1);
  139. });
  140. }