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