2016-01-24 17:34:05 +00:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2022-07-07 02:51:01 +00:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QFileDialog>
|
2018-10-27 20:43:29 +00:00
|
|
|
#include <QMessageBox>
|
2022-07-07 02:51:01 +00:00
|
|
|
#include <QUrl>
|
2022-12-08 11:27:25 +00:00
|
|
|
#include "citra_qt/configuration/configuration_shared.h"
|
2016-12-22 04:49:36 +00:00
|
|
|
#include "citra_qt/configuration/configure_general.h"
|
2019-08-15 04:38:54 +00:00
|
|
|
#include "citra_qt/uisettings.h"
|
2022-12-08 11:27:25 +00:00
|
|
|
#include "common/file_util.h"
|
|
|
|
#include "common/settings.h"
|
2016-09-20 15:21:23 +00:00
|
|
|
#include "ui_configure_general.h"
|
2016-01-24 17:34:05 +00:00
|
|
|
|
2020-06-20 18:52:14 +00:00
|
|
|
// The QSlider doesn't have an easy way to set a custom step amount,
|
|
|
|
// so we can just convert from the sliders range (0 - 198) to the expected
|
|
|
|
// settings range (5 - 995) with simple math.
|
|
|
|
static constexpr int SliderToSettings(int value) {
|
|
|
|
return 5 * value + 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr int SettingsToSlider(int value) {
|
|
|
|
return (value - 5) / 5;
|
|
|
|
}
|
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
ConfigureGeneral::ConfigureGeneral(QWidget* parent)
|
2020-10-01 01:23:01 +00:00
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureGeneral>()) {
|
2016-09-19 01:01:46 +00:00
|
|
|
|
2016-01-24 17:34:05 +00:00
|
|
|
ui->setupUi(this);
|
2016-09-02 03:30:01 +00:00
|
|
|
|
2020-06-20 18:52:14 +00:00
|
|
|
// Set a minimum width for the label to prevent the slider from changing size.
|
|
|
|
// This scales across DPIs, and is acceptable for uncapitalized strings.
|
|
|
|
ui->emulation_speed_display_label->setMinimumWidth(tr("unthrottled").size() * 6);
|
2022-12-08 11:27:25 +00:00
|
|
|
ui->emulation_speed_combo->setVisible(!Settings::IsConfiguringGlobal());
|
|
|
|
ui->screenshot_combo->setVisible(!Settings::IsConfiguringGlobal());
|
2023-02-12 06:45:43 +00:00
|
|
|
ui->updateBox->setVisible(UISettings::values.updater_found);
|
2020-06-20 18:52:14 +00:00
|
|
|
|
2022-12-08 11:27:25 +00:00
|
|
|
SetupPerGameUI();
|
2020-06-20 18:52:14 +00:00
|
|
|
SetConfiguration();
|
2019-08-10 09:13:17 +00:00
|
|
|
|
2018-10-27 20:43:29 +00:00
|
|
|
connect(ui->button_reset_defaults, &QPushButton::clicked, this,
|
|
|
|
&ConfigureGeneral::ResetDefaults);
|
2020-06-20 18:52:14 +00:00
|
|
|
|
2022-12-08 11:27:25 +00:00
|
|
|
connect(ui->frame_limit, &QSlider::valueChanged, this, [&](int value) {
|
2020-06-20 18:52:14 +00:00
|
|
|
if (value == ui->frame_limit->maximum()) {
|
|
|
|
ui->emulation_speed_display_label->setText(tr("unthrottled"));
|
|
|
|
} else {
|
|
|
|
ui->emulation_speed_display_label->setText(
|
|
|
|
QStringLiteral("%1%")
|
|
|
|
.arg(SliderToSettings(value))
|
|
|
|
.rightJustified(tr("unthrottled").size()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-07-07 02:51:01 +00:00
|
|
|
connect(ui->change_screenshot_dir, &QToolButton::clicked, this, [this] {
|
|
|
|
const QString dir_path = QFileDialog::getExistingDirectory(
|
|
|
|
this, tr("Select Screenshot Directory"), ui->screenshot_dir_path->text(),
|
|
|
|
QFileDialog::ShowDirsOnly);
|
|
|
|
if (!dir_path.isEmpty()) {
|
|
|
|
ui->screenshot_dir_path->setText(dir_path);
|
|
|
|
}
|
|
|
|
});
|
2016-01-24 17:34:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 15:14:09 +00:00
|
|
|
ConfigureGeneral::~ConfigureGeneral() = default;
|
2016-01-24 17:34:05 +00:00
|
|
|
|
2019-05-26 04:39:23 +00:00
|
|
|
void ConfigureGeneral::SetConfiguration() {
|
2022-12-08 11:27:25 +00:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing.GetValue());
|
|
|
|
ui->toggle_background_pause->setChecked(
|
|
|
|
UISettings::values.pause_when_in_background.GetValue());
|
|
|
|
ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse.GetValue());
|
|
|
|
|
|
|
|
ui->toggle_update_check->setChecked(
|
|
|
|
UISettings::values.check_for_update_on_start.GetValue());
|
|
|
|
ui->toggle_auto_update->setChecked(UISettings::values.update_on_close.GetValue());
|
|
|
|
}
|
2019-08-10 09:13:17 +00:00
|
|
|
|
2022-12-08 11:27:25 +00:00
|
|
|
if (Settings::values.frame_limit.GetValue() == 0) {
|
2020-06-20 18:52:14 +00:00
|
|
|
ui->frame_limit->setValue(ui->frame_limit->maximum());
|
|
|
|
} else {
|
2022-12-08 11:27:25 +00:00
|
|
|
ui->frame_limit->setValue(SettingsToSlider(Settings::values.frame_limit.GetValue()));
|
2020-06-20 18:52:14 +00:00
|
|
|
}
|
|
|
|
if (ui->frame_limit->value() == ui->frame_limit->maximum()) {
|
|
|
|
ui->emulation_speed_display_label->setText(tr("unthrottled"));
|
|
|
|
} else {
|
|
|
|
ui->emulation_speed_display_label->setText(
|
|
|
|
QStringLiteral("%1%")
|
|
|
|
.arg(SliderToSettings(ui->frame_limit->value()))
|
|
|
|
.rightJustified(tr("unthrottled").size()));
|
|
|
|
}
|
|
|
|
|
2022-12-08 11:27:25 +00:00
|
|
|
if (!Settings::IsConfiguringGlobal()) {
|
|
|
|
if (Settings::values.frame_limit.UsingGlobal()) {
|
|
|
|
ui->emulation_speed_combo->setCurrentIndex(0);
|
|
|
|
ui->frame_limit->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui->emulation_speed_combo->setCurrentIndex(1);
|
|
|
|
ui->frame_limit->setEnabled(true);
|
|
|
|
}
|
|
|
|
if (UISettings::values.screenshot_path.UsingGlobal()) {
|
|
|
|
ui->screenshot_combo->setCurrentIndex(0);
|
|
|
|
ui->screenshot_dir_path->setEnabled(false);
|
|
|
|
ui->change_screenshot_dir->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui->screenshot_combo->setCurrentIndex(1);
|
|
|
|
ui->screenshot_dir_path->setEnabled(true);
|
|
|
|
ui->change_screenshot_dir->setEnabled(true);
|
|
|
|
}
|
|
|
|
ConfigurationShared::SetHighlight(ui->widget_screenshot,
|
|
|
|
!UISettings::values.screenshot_path.UsingGlobal());
|
|
|
|
ConfigurationShared::SetHighlight(ui->emulation_speed_layout,
|
|
|
|
!Settings::values.frame_limit.UsingGlobal());
|
|
|
|
ConfigurationShared::SetHighlight(ui->widget_region,
|
|
|
|
!Settings::values.region_value.UsingGlobal());
|
|
|
|
const bool is_region_global = Settings::values.region_value.UsingGlobal();
|
|
|
|
ui->region_combobox->setCurrentIndex(
|
|
|
|
is_region_global ? ConfigurationShared::USE_GLOBAL_INDEX
|
|
|
|
: static_cast<int>(Settings::values.region_value.GetValue()) +
|
|
|
|
ConfigurationShared::USE_GLOBAL_OFFSET + 1);
|
2020-06-20 18:52:14 +00:00
|
|
|
} else {
|
2022-12-08 11:27:25 +00:00
|
|
|
// The first item is "auto-select" with actual value -1, so plus one here will do the trick
|
|
|
|
ui->region_combobox->setCurrentIndex(Settings::values.region_value.GetValue() + 1);
|
2020-06-20 18:52:14 +00:00
|
|
|
}
|
2022-07-07 02:51:01 +00:00
|
|
|
|
2022-12-08 11:27:25 +00:00
|
|
|
UISettings::values.screenshot_path.SetGlobal(ui->screenshot_combo->currentIndex() ==
|
|
|
|
ConfigurationShared::USE_GLOBAL_INDEX);
|
|
|
|
std::string screenshot_path = UISettings::values.screenshot_path.GetValue();
|
|
|
|
if (screenshot_path.empty()) {
|
|
|
|
screenshot_path = FileUtil::GetUserPath(FileUtil::UserPath::UserDir) + "screenshots/";
|
|
|
|
FileUtil::CreateFullPath(screenshot_path);
|
2022-07-07 02:51:01 +00:00
|
|
|
UISettings::values.screenshot_path = screenshot_path;
|
|
|
|
}
|
2022-12-08 11:27:25 +00:00
|
|
|
ui->screenshot_dir_path->setText(QString::fromStdString(screenshot_path));
|
2016-01-24 17:34:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 20:43:29 +00:00
|
|
|
void ConfigureGeneral::ResetDefaults() {
|
|
|
|
QMessageBox::StandardButton answer = QMessageBox::question(
|
|
|
|
this, tr("Citra"),
|
|
|
|
tr("Are you sure you want to <b>reset your settings</b> and close Citra?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
|
|
|
|
2022-12-17 15:04:31 +00:00
|
|
|
if (answer == QMessageBox::No) {
|
2018-10-27 20:43:29 +00:00
|
|
|
return;
|
2022-12-17 15:04:31 +00:00
|
|
|
}
|
2018-10-27 20:43:29 +00:00
|
|
|
|
|
|
|
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini");
|
2022-12-17 15:04:31 +00:00
|
|
|
FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "custom");
|
2018-10-27 20:43:29 +00:00
|
|
|
std::exit(0);
|
|
|
|
}
|
|
|
|
|
2019-05-26 04:39:23 +00:00
|
|
|
void ConfigureGeneral::ApplyConfiguration() {
|
2022-12-08 11:27:25 +00:00
|
|
|
ConfigurationShared::ApplyPerGameSetting(&Settings::values.region_value, ui->region_combobox,
|
|
|
|
[](s32 index) { return index - 1; });
|
|
|
|
|
|
|
|
ConfigurationShared::ApplyPerGameSetting(
|
|
|
|
&Settings::values.frame_limit, ui->emulation_speed_combo, [this](s32) {
|
|
|
|
const bool is_maximum = ui->frame_limit->value() == ui->frame_limit->maximum();
|
|
|
|
return is_maximum ? 0 : SliderToSettings(ui->frame_limit->value());
|
|
|
|
});
|
|
|
|
|
|
|
|
ConfigurationShared::ApplyPerGameSetting(
|
|
|
|
&UISettings::values.screenshot_path, ui->screenshot_combo,
|
|
|
|
[this](s32) { return ui->screenshot_dir_path->text().toStdString(); });
|
|
|
|
|
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
|
|
|
|
UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
|
|
|
|
UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
|
|
|
|
|
|
|
|
UISettings::values.check_for_update_on_start = ui->toggle_update_check->isChecked();
|
|
|
|
UISettings::values.update_on_close = ui->toggle_auto_update->isChecked();
|
2020-06-20 18:52:14 +00:00
|
|
|
}
|
2016-01-24 17:34:05 +00:00
|
|
|
}
|
2017-09-23 13:13:59 +00:00
|
|
|
|
2019-05-26 04:39:23 +00:00
|
|
|
void ConfigureGeneral::RetranslateUI() {
|
2017-09-23 13:13:59 +00:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
2022-12-08 11:27:25 +00:00
|
|
|
|
|
|
|
void ConfigureGeneral::SetupPerGameUI() {
|
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
|
|
|
ui->region_combobox->setEnabled(Settings::values.region_value.UsingGlobal());
|
|
|
|
ui->frame_limit->setEnabled(Settings::values.frame_limit.UsingGlobal());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui->emulation_speed_combo, qOverload<int>(&QComboBox::activated), this,
|
|
|
|
[this](int index) {
|
|
|
|
ui->frame_limit->setEnabled(index == 1);
|
|
|
|
ConfigurationShared::SetHighlight(ui->emulation_speed_layout, index == 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->screenshot_combo, qOverload<int>(&QComboBox::activated), this, [this](int index) {
|
|
|
|
ui->screenshot_dir_path->setEnabled(index == 1);
|
|
|
|
ui->change_screenshot_dir->setEnabled(index == 1);
|
|
|
|
ConfigurationShared::SetHighlight(ui->widget_screenshot, index == 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
ui->general_group->setVisible(false);
|
|
|
|
ui->updateBox->setVisible(false);
|
|
|
|
ui->button_reset_defaults->setVisible(false);
|
|
|
|
|
|
|
|
ConfigurationShared::SetColoredComboBox(
|
|
|
|
ui->region_combobox, ui->widget_region,
|
|
|
|
static_cast<u32>(Settings::values.region_value.GetValue(true) + 1));
|
|
|
|
}
|