configure_general.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QCheckBox>
  5. #include <QSpinBox>
  6. #include <QMessageBox>
  7. #include "common/settings.h"
  8. #include "core/core.h"
  9. #include "ui_configure_general.h"
  10. #include "yuzu/configuration/configuration_shared.h"
  11. #include "yuzu/configuration/configure_general.h"
  12. #include "yuzu/configuration/config.h"
  13. #include "yuzu/uisettings.h"
  14. ConfigureGeneral::ConfigureGeneral(QWidget* parent)
  15. : QWidget(parent), ui(new Ui::ConfigureGeneral) {
  16. ui->setupUi(this);
  17. SetupPerGameUI();
  18. SetConfiguration();
  19. if (Settings::IsConfiguringGlobal()) {
  20. connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit,
  21. [this]() { ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); });
  22. }
  23. connect(ui->button_reset_defaults, &QPushButton::clicked, this,
  24. &ConfigureGeneral::ResetDefaults);
  25. }
  26. ConfigureGeneral::~ConfigureGeneral() = default;
  27. void ConfigureGeneral::SetConfiguration() {
  28. const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
  29. ui->use_multi_core->setEnabled(runtime_lock);
  30. ui->use_multi_core->setChecked(Settings::values.use_multi_core.GetValue());
  31. ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing);
  32. ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot);
  33. ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background);
  34. ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse);
  35. ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue());
  36. ui->frame_limit->setValue(Settings::values.frame_limit.GetValue());
  37. if (Settings::IsConfiguringGlobal()) {
  38. ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue());
  39. } else {
  40. ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue() &&
  41. use_frame_limit != ConfigurationShared::CheckState::Global);
  42. }
  43. }
  44. void ConfigureGeneral::ResetDefaults() {
  45. QMessageBox::StandardButton answer = QMessageBox::question(
  46. this, tr("yuzu"), tr("Are you sure you want to <b>reset your settings</b>?"),
  47. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  48. if (answer == QMessageBox::No)
  49. return;
  50. UISettings::values.
  51. }
  52. void ConfigureGeneral::ApplyConfiguration() {
  53. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core,
  54. use_multi_core);
  55. if (Settings::IsConfiguringGlobal()) {
  56. UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
  57. UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked();
  58. UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
  59. UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
  60. // Guard if during game and set to game-specific value
  61. if (Settings::values.use_frame_limit.UsingGlobal()) {
  62. Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() ==
  63. Qt::Checked);
  64. Settings::values.frame_limit.SetValue(ui->frame_limit->value());
  65. }
  66. } else {
  67. bool global_frame_limit = use_frame_limit == ConfigurationShared::CheckState::Global;
  68. Settings::values.use_frame_limit.SetGlobal(global_frame_limit);
  69. Settings::values.frame_limit.SetGlobal(global_frame_limit);
  70. if (!global_frame_limit) {
  71. Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() ==
  72. Qt::Checked);
  73. Settings::values.frame_limit.SetValue(ui->frame_limit->value());
  74. }
  75. }
  76. }
  77. void ConfigureGeneral::changeEvent(QEvent* event) {
  78. if (event->type() == QEvent::LanguageChange) {
  79. RetranslateUI();
  80. }
  81. QWidget::changeEvent(event);
  82. }
  83. void ConfigureGeneral::RetranslateUI() {
  84. ui->retranslateUi(this);
  85. }
  86. void ConfigureGeneral::SetupPerGameUI() {
  87. if (Settings::IsConfiguringGlobal()) {
  88. // Disables each setting if:
  89. // - A game is running (thus settings in use), and
  90. // - A non-global setting is applied.
  91. ui->toggle_frame_limit->setEnabled(Settings::values.use_frame_limit.UsingGlobal());
  92. ui->frame_limit->setEnabled(Settings::values.frame_limit.UsingGlobal());
  93. return;
  94. }
  95. ui->toggle_check_exit->setVisible(false);
  96. ui->toggle_user_on_boot->setVisible(false);
  97. ui->toggle_background_pause->setVisible(false);
  98. ui->toggle_hide_mouse->setVisible(false);
  99. ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit,
  100. Settings::values.use_frame_limit, use_frame_limit);
  101. ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core,
  102. use_multi_core);
  103. connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, [this]() {
  104. ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked() &&
  105. (use_frame_limit != ConfigurationShared::CheckState::Global));
  106. });
  107. }