configure_general.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. use_frame_limit != ConfigurationShared::CheckState::Global);
  38. }
  39. }
  40. void ConfigureGeneral::ApplyConfiguration() {
  41. if (Settings::configuring_global) {
  42. UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
  43. UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked();
  44. UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
  45. UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
  46. // Guard if during game and set to game-specific value
  47. if (Settings::values.use_frame_limit.UsingGlobal()) {
  48. Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() ==
  49. Qt::Checked);
  50. Settings::values.frame_limit.SetValue(ui->frame_limit->value());
  51. }
  52. if (Settings::values.use_multi_core.UsingGlobal()) {
  53. Settings::values.use_multi_core.SetValue(ui->use_multi_core->isChecked());
  54. }
  55. } else {
  56. ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core,
  57. ui->use_multi_core, use_multi_core);
  58. bool global_frame_limit = use_frame_limit == ConfigurationShared::CheckState::Global;
  59. Settings::values.use_frame_limit.SetGlobal(global_frame_limit);
  60. Settings::values.frame_limit.SetGlobal(global_frame_limit);
  61. if (!global_frame_limit) {
  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. }
  67. }
  68. void ConfigureGeneral::changeEvent(QEvent* event) {
  69. if (event->type() == QEvent::LanguageChange) {
  70. RetranslateUI();
  71. }
  72. QWidget::changeEvent(event);
  73. }
  74. void ConfigureGeneral::RetranslateUI() {
  75. ui->retranslateUi(this);
  76. }
  77. void ConfigureGeneral::SetupPerGameUI() {
  78. if (Settings::configuring_global) {
  79. ui->toggle_frame_limit->setEnabled(Settings::values.use_frame_limit.UsingGlobal());
  80. ui->frame_limit->setEnabled(Settings::values.frame_limit.UsingGlobal());
  81. return;
  82. }
  83. ui->toggle_check_exit->setVisible(false);
  84. ui->toggle_user_on_boot->setVisible(false);
  85. ui->toggle_background_pause->setVisible(false);
  86. ui->toggle_hide_mouse->setVisible(false);
  87. ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit,
  88. Settings::values.use_frame_limit, use_frame_limit);
  89. ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core,
  90. use_multi_core);
  91. connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, [this]() {
  92. ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked() &&
  93. (use_frame_limit != ConfigurationShared::CheckState::Global));
  94. });
  95. }