configure_general.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "core/core.h"
  7. #include "core/settings.h"
  8. #include "ui_configure_general.h"
  9. #include "yuzu/configuration/configuration_shared.h"
  10. #include "yuzu/configuration/configure_general.h"
  11. #include "yuzu/uisettings.h"
  12. ConfigureGeneral::ConfigureGeneral(QWidget* parent)
  13. : QWidget(parent), ui(new Ui::ConfigureGeneral) {
  14. ui->setupUi(this);
  15. SetupPerGameUI();
  16. SetConfiguration();
  17. if (Settings::configuring_global) {
  18. connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit,
  19. [this]() { ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); });
  20. }
  21. }
  22. ConfigureGeneral::~ConfigureGeneral() = default;
  23. void ConfigureGeneral::SetConfiguration() {
  24. const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
  25. ui->use_multi_core->setEnabled(runtime_lock);
  26. ui->use_multi_core->setChecked(Settings::values.use_multi_core.GetValue());
  27. ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing);
  28. ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot);
  29. ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background);
  30. ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse);
  31. ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue());
  32. ui->frame_limit->setValue(Settings::values.frame_limit.GetValue());
  33. if (Settings::configuring_global) {
  34. ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue());
  35. } else {
  36. ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue() &&
  37. trackers.use_frame_limit !=
  38. ConfigurationShared::CheckState::Global);
  39. }
  40. }
  41. void ConfigureGeneral::ApplyConfiguration() {
  42. if (Settings::configuring_global) {
  43. UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
  44. UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked();
  45. UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
  46. UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
  47. // Guard if during game and set to game-specific value
  48. if (Settings::values.use_frame_limit.UsingGlobal()) {
  49. Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() ==
  50. Qt::Checked);
  51. Settings::values.frame_limit.SetValue(ui->frame_limit->value());
  52. }
  53. if (Settings::values.use_multi_core.UsingGlobal()) {
  54. Settings::values.use_multi_core.SetValue(ui->use_multi_core->isChecked());
  55. }
  56. } else {
  57. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core,
  58. ui->use_multi_core,
  59. trackers.use_multi_core);
  60. bool global_frame_limit = trackers.use_frame_limit ==
  61. ConfigurationShared::CheckState::Global;
  62. Settings::values.use_frame_limit.SetGlobal(global_frame_limit);
  63. Settings::values.frame_limit.SetGlobal(global_frame_limit);
  64. if (!global_frame_limit) {
  65. Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() ==
  66. Qt::Checked);
  67. Settings::values.frame_limit.SetValue(ui->frame_limit->value());
  68. }
  69. }
  70. }
  71. void ConfigureGeneral::changeEvent(QEvent* event) {
  72. if (event->type() == QEvent::LanguageChange) {
  73. RetranslateUI();
  74. }
  75. QWidget::changeEvent(event);
  76. }
  77. void ConfigureGeneral::RetranslateUI() {
  78. ui->retranslateUi(this);
  79. }
  80. void ConfigureGeneral::SetupPerGameUI() {
  81. if (Settings::configuring_global) {
  82. ui->toggle_frame_limit->setEnabled(Settings::values.use_frame_limit.UsingGlobal());
  83. ui->frame_limit->setEnabled(Settings::values.frame_limit.UsingGlobal());
  84. return;
  85. }
  86. ui->toggle_check_exit->setVisible(false);
  87. ui->toggle_user_on_boot->setVisible(false);
  88. ui->toggle_background_pause->setVisible(false);
  89. ui->toggle_hide_mouse->setVisible(false);
  90. ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit, "toggle_frame_limit",
  91. Settings::values.use_frame_limit,
  92. trackers.use_frame_limit);
  93. ConfigurationShared::SetColoredTristate(ui->use_multi_core, "use_multi_core",
  94. Settings::values.use_multi_core,
  95. trackers.use_multi_core);
  96. connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, [this]() {
  97. ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked() &&
  98. (trackers.use_frame_limit !=
  99. ConfigurationShared::CheckState::Global));
  100. });
  101. }