fix more logic errors

Fixed the frame limit would set the global setting from the game properties
dialog. Also strengthened the Settings::Setting member variables and simplified
the logic in config reading (ReadSettingGlobal).
This commit is contained in:
lat9nq
2020-06-25 02:30:30 -04:00
parent c39112299a
commit 3b62d75257
6 changed files with 35 additions and 25 deletions

View File

@@ -144,6 +144,11 @@ bool IsGPULevelHigh() {
}
void RestoreGlobalState() {
// If a game is running, DO NOT restore the global settings state
if (!Core::System::GetInstance().IsPoweredOn()) {
return;
}
// Audio
Settings::values.enable_audio_stretching.SetGlobal(true);
Settings::values.volume.SetGlobal(true);

View File

@@ -423,9 +423,9 @@ public:
};
private:
bool use_global;
Type global;
Type local;
bool use_global{};
Type global{};
Type local{};
};
struct Values {

View File

@@ -1263,10 +1263,9 @@ QVariant Config::ReadSetting(const QString& name, const QVariant& default_value)
template <typename Type>
void Config::ReadSettingGlobal(Settings::Setting<Type>& setting, const QString& name) {
bool use_global =
global || qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
setting.SetGlobal(use_global);
if ((!global && !use_global) || global) {
bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
setting.SetGlobal(use_global || global);
if (global || !use_global) {
setting.SetValue(ReadSetting(name).value<Type>());
}
}
@@ -1274,10 +1273,9 @@ void Config::ReadSettingGlobal(Settings::Setting<Type>& setting, const QString&
template <typename Type>
void Config::ReadSettingGlobal(Settings::Setting<Type>& setting, const QString& name,
const QVariant& default_value) {
bool use_global =
global || qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
setting.SetGlobal(use_global);
if ((!global && !use_global) || global) {
if (global || !use_global) {
setting.SetValue(ReadSetting(name, default_value).value<Type>());
}
}
@@ -1285,9 +1283,8 @@ void Config::ReadSettingGlobal(Settings::Setting<Type>& setting, const QString&
template <typename Type>
void Config::ReadSettingGlobal(Type& setting, const QString& name,
const QVariant& default_value) const {
bool use_global =
global || qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
if ((!global && !use_global) || global) {
bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool();
if (global || !use_global) {
setting = ReadSetting(name, default_value).value<Type>();
} else {
setting = default_value.value<Type>();

View File

@@ -39,8 +39,10 @@ void ConfigureGeneral::SetConfiguration() {
ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit);
ui->frame_limit->setValue(Settings::values.frame_limit);
if (!Settings::configuring_global && Settings::values.use_frame_limit.UsingGlobal()) {
ui->toggle_frame_limit->setCheckState(Qt::PartiallyChecked);
if (!Settings::configuring_global) {
if (Settings::values.use_frame_limit.UsingGlobal()) {
ui->toggle_frame_limit->setCheckState(Qt::PartiallyChecked);
}
}
ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked &&
@@ -67,12 +69,13 @@ void ConfigureGeneral::ApplyConfiguration() {
Settings::values.frame_limit = ui->frame_limit->value();
}
} else {
Settings::values.use_frame_limit.SetGlobal(ui->toggle_frame_limit->checkState() ==
Qt::PartiallyChecked);
Settings::values.frame_limit.SetGlobal(ui->toggle_frame_limit->checkState() ==
Qt::PartiallyChecked);
Settings::values.use_frame_limit = ui->toggle_frame_limit->checkState() == Qt::Checked;
Settings::values.frame_limit = ui->frame_limit->value();
bool global_frame_limit = ui->toggle_frame_limit->checkState() == Qt::PartiallyChecked;
Settings::values.use_frame_limit.SetGlobal(global_frame_limit);
Settings::values.frame_limit.SetGlobal(global_frame_limit);
if (!global_frame_limit) {
Settings::values.use_frame_limit = ui->toggle_frame_limit->checkState() == Qt::Checked;
Settings::values.frame_limit = ui->frame_limit->value();
}
}
}

View File

@@ -15,6 +15,7 @@
#include "common/common_paths.h"
#include "common/file_util.h"
#include "core/core.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/xts_archive.h"
#include "core/loader/loader.h"
@@ -57,6 +58,8 @@ ConfigurePerGameAddons::ConfigurePerGameAddons(QWidget* parent)
ui->scrollArea->setLayout(layout);
ui->scrollArea->setEnabled(!Core::System::GetInstance().IsPoweredOn());
connect(item_model, &QStandardItemModel::itemChanged,
[] { UISettings::values.is_game_list_reload_pending.exchange(true); });
}

View File

@@ -1550,11 +1550,13 @@ void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) {
game_list->PopulateAsync(UISettings::values.game_dirs);
}
config->Save();
}
// Do not cause the global config to write local settings
Settings::RestoreGlobalState();
// If a game is running, DO NOT restore the global settings state
if (!Core::System::GetInstance().IsPoweredOn()) {
if (!Core::System::GetInstance().IsPoweredOn()) {
config->Save();
}
} else {
Settings::RestoreGlobalState();
}
}