configure_general.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_hide_mouse->setChecked(UISettings::values.hide_mouse.GetValue());
  39. ui->toggle_speed_limit->setChecked(Settings::values.use_speed_limit.GetValue());
  40. ui->speed_limit->setValue(Settings::values.speed_limit.GetValue());
  41. ui->fps_cap->setValue(Settings::values.fps_cap.GetValue());
  42. ui->button_reset_defaults->setEnabled(runtime_lock);
  43. if (Settings::IsConfiguringGlobal()) {
  44. ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue());
  45. } else {
  46. ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue() &&
  47. use_speed_limit != ConfigurationShared::CheckState::Global);
  48. ui->fps_cap_combobox->setCurrentIndex(Settings::values.fps_cap.UsingGlobal() ? 0 : 1);
  49. ui->fps_cap->setEnabled(!Settings::values.fps_cap.UsingGlobal());
  50. ConfigurationShared::SetHighlight(ui->fps_cap_layout,
  51. !Settings::values.fps_cap.UsingGlobal());
  52. }
  53. }
  54. // Called to set the callback when resetting settings to defaults
  55. void ConfigureGeneral::SetResetCallback(std::function<void()> callback) {
  56. reset_callback = std::move(callback);
  57. }
  58. void ConfigureGeneral::ResetDefaults() {
  59. QMessageBox::StandardButton answer = QMessageBox::question(
  60. this, tr("yuzu"),
  61. tr("This reset all settings and remove all per-game configurations. This will not delete "
  62. "game directories, profiles, or input profiles. Proceed?"),
  63. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  64. if (answer == QMessageBox::No) {
  65. return;
  66. }
  67. UISettings::values.reset_to_defaults = true;
  68. UISettings::values.is_game_list_reload_pending.exchange(true);
  69. reset_callback();
  70. }
  71. void ConfigureGeneral::ApplyConfiguration() {
  72. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core,
  73. use_multi_core);
  74. if (Settings::IsConfiguringGlobal()) {
  75. UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
  76. UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked();
  77. UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
  78. UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
  79. Settings::values.fps_cap.SetValue(ui->fps_cap->value());
  80. // Guard if during game and set to game-specific value
  81. if (Settings::values.use_speed_limit.UsingGlobal()) {
  82. Settings::values.use_speed_limit.SetValue(ui->toggle_speed_limit->checkState() ==
  83. Qt::Checked);
  84. Settings::values.speed_limit.SetValue(ui->speed_limit->value());
  85. }
  86. } else {
  87. bool global_speed_limit = use_speed_limit == ConfigurationShared::CheckState::Global;
  88. Settings::values.use_speed_limit.SetGlobal(global_speed_limit);
  89. Settings::values.speed_limit.SetGlobal(global_speed_limit);
  90. if (!global_speed_limit) {
  91. Settings::values.use_speed_limit.SetValue(ui->toggle_speed_limit->checkState() ==
  92. Qt::Checked);
  93. Settings::values.speed_limit.SetValue(ui->speed_limit->value());
  94. }
  95. if (ui->fps_cap_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
  96. Settings::values.fps_cap.SetGlobal(true);
  97. } else {
  98. Settings::values.fps_cap.SetGlobal(false);
  99. Settings::values.fps_cap.SetValue(ui->fps_cap->value());
  100. }
  101. }
  102. }
  103. void ConfigureGeneral::changeEvent(QEvent* event) {
  104. if (event->type() == QEvent::LanguageChange) {
  105. RetranslateUI();
  106. }
  107. QWidget::changeEvent(event);
  108. }
  109. void ConfigureGeneral::RetranslateUI() {
  110. ui->retranslateUi(this);
  111. }
  112. void ConfigureGeneral::SetupPerGameUI() {
  113. if (Settings::IsConfiguringGlobal()) {
  114. // Disables each setting if:
  115. // - A game is running (thus settings in use), and
  116. // - A non-global setting is applied.
  117. ui->toggle_speed_limit->setEnabled(Settings::values.use_speed_limit.UsingGlobal());
  118. ui->speed_limit->setEnabled(Settings::values.speed_limit.UsingGlobal());
  119. return;
  120. }
  121. ui->toggle_check_exit->setVisible(false);
  122. ui->toggle_user_on_boot->setVisible(false);
  123. ui->toggle_background_pause->setVisible(false);
  124. ui->toggle_hide_mouse->setVisible(false);
  125. ui->button_reset_defaults->setVisible(false);
  126. ConfigurationShared::SetColoredTristate(ui->toggle_speed_limit,
  127. Settings::values.use_speed_limit, use_speed_limit);
  128. ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core,
  129. use_multi_core);
  130. connect(ui->toggle_speed_limit, &QCheckBox::clicked, ui->speed_limit, [this]() {
  131. ui->speed_limit->setEnabled(ui->toggle_speed_limit->isChecked() &&
  132. (use_speed_limit != ConfigurationShared::CheckState::Global));
  133. });
  134. connect(ui->fps_cap_combobox, qOverload<int>(&QComboBox::activated), this, [this](int index) {
  135. ui->fps_cap->setEnabled(index == 1);
  136. ConfigurationShared::SetHighlight(ui->fps_cap_layout, index == 1);
  137. });
  138. }