2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-06-01 10:43:33 +03:00
|
|
|
|
2019-01-17 11:50:57 -05:00
|
|
|
#include <chrono>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
2018-10-10 21:49:20 -04:00
|
|
|
#include <QFileDialog>
|
2018-10-09 21:53:04 -04:00
|
|
|
#include <QGraphicsItem>
|
2017-05-06 02:55:51 +02:00
|
|
|
#include <QMessageBox>
|
2021-04-14 16:07:40 -07:00
|
|
|
#include "common/settings.h"
|
2017-02-19 18:37:14 -08:00
|
|
|
#include "core/core.h"
|
2021-10-07 13:29:33 -04:00
|
|
|
#include "core/hle/service/time/time_manager.h"
|
2016-09-21 00:21:23 +09:00
|
|
|
#include "ui_configure_system.h"
|
2020-07-09 22:42:09 -04:00
|
|
|
#include "yuzu/configuration/configuration_shared.h"
|
2018-01-11 20:33:56 -07:00
|
|
|
#include "yuzu/configuration/configure_system.h"
|
|
|
|
|
|
2022-12-28 19:08:31 +00:00
|
|
|
constexpr std::array<u32, 7> LOCALE_BLOCKLIST{
|
|
|
|
|
0b100011100001100000, // Japan
|
|
|
|
|
0b000001101001100100, // Americas
|
|
|
|
|
0b100110100001000010, // Europe
|
|
|
|
|
0b100110100001000010, // Australia
|
|
|
|
|
0b000000000000000000, // China
|
|
|
|
|
0b100111100001000000, // Korea
|
|
|
|
|
0b100111100001000000, // Taiwan
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool IsValidLocale(u32 region_index, u32 language_index) {
|
2022-12-29 14:25:22 +00:00
|
|
|
return ((LOCALE_BLOCKLIST.at(region_index) >> language_index) & 1) == 0;
|
2022-12-28 19:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-02 21:40:55 -04:00
|
|
|
ConfigureSystem::ConfigureSystem(Core::System& system_, QWidget* parent)
|
2021-10-15 15:26:20 -04:00
|
|
|
: QWidget(parent), ui{std::make_unique<Ui::ConfigureSystem>()}, system{system_} {
|
2016-06-01 10:43:33 +03:00
|
|
|
ui->setupUi(this);
|
2017-05-06 02:55:51 +02:00
|
|
|
connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
|
2018-10-25 16:47:09 -04:00
|
|
|
&ConfigureSystem::RefreshConsoleID);
|
2016-09-13 13:04:17 +08:00
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
|
|
|
|
|
ui->rng_seed_edit->setEnabled(state == Qt::Checked);
|
|
|
|
|
if (state != Qt::Checked) {
|
2018-11-13 12:25:43 -05:00
|
|
|
ui->rng_seed_edit->setText(QStringLiteral("00000000"));
|
2019-05-26 00:39:23 -04:00
|
|
|
}
|
2018-11-11 22:34:23 -05:00
|
|
|
});
|
|
|
|
|
|
2020-07-09 22:42:09 -04:00
|
|
|
connect(ui->custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
|
|
|
|
|
ui->custom_rtc_edit->setEnabled(state == Qt::Checked);
|
|
|
|
|
if (state != Qt::Checked) {
|
2018-12-28 18:36:14 -05:00
|
|
|
ui->custom_rtc_edit->setDateTime(QDateTime::currentDateTime());
|
2019-05-26 00:39:23 -04:00
|
|
|
}
|
2018-12-28 18:36:14 -05:00
|
|
|
});
|
|
|
|
|
|
2022-12-28 19:08:31 +00:00
|
|
|
const auto locale_check = [this](int index) {
|
|
|
|
|
const bool valid_locale =
|
|
|
|
|
IsValidLocale(ui->combo_region->currentIndex(), ui->combo_language->currentIndex());
|
|
|
|
|
ui->label_warn_invalid_locale->setVisible(!valid_locale);
|
|
|
|
|
if (!valid_locale) {
|
|
|
|
|
ui->label_warn_invalid_locale->setText(
|
|
|
|
|
tr("Warning: \"%1\" is not a valid language for region \"%2\"")
|
|
|
|
|
.arg(ui->combo_language->currentText())
|
|
|
|
|
.arg(ui->combo_region->currentText()));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
connect(ui->combo_language, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
|
|
|
|
locale_check);
|
|
|
|
|
connect(ui->combo_region, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
|
|
|
|
|
|
2020-11-04 04:16:34 -05:00
|
|
|
ui->label_console_id->setVisible(Settings::IsConfiguringGlobal());
|
|
|
|
|
ui->button_regenerate_console_id->setVisible(Settings::IsConfiguringGlobal());
|
2020-07-09 22:42:09 -04:00
|
|
|
|
|
|
|
|
SetupPerGameUI();
|
|
|
|
|
|
2019-05-26 00:39:23 -04:00
|
|
|
SetConfiguration();
|
2016-06-01 10:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-06 12:58:46 -04:00
|
|
|
ConfigureSystem::~ConfigureSystem() = default;
|
2016-06-01 10:43:33 +03:00
|
|
|
|
2019-06-05 18:39:46 -04:00
|
|
|
void ConfigureSystem::changeEvent(QEvent* event) {
|
|
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
|
RetranslateUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget::changeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigureSystem::RetranslateUI() {
|
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 00:39:23 -04:00
|
|
|
void ConfigureSystem::SetConfiguration() {
|
2021-09-02 21:40:55 -04:00
|
|
|
enabled = !system.IsPoweredOn();
|
2020-07-09 22:42:09 -04:00
|
|
|
const auto rng_seed =
|
|
|
|
|
QStringLiteral("%1")
|
|
|
|
|
.arg(Settings::values.rng_seed.GetValue().value_or(0), 8, 16, QLatin1Char{'0'})
|
|
|
|
|
.toUpper();
|
2021-10-16 02:07:18 -04:00
|
|
|
const auto rtc_time = Settings::values.custom_rtc.value_or(QDateTime::currentSecsSinceEpoch());
|
2018-10-09 21:53:04 -04:00
|
|
|
|
2020-07-13 23:01:18 -04:00
|
|
|
ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value());
|
|
|
|
|
ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() &&
|
|
|
|
|
Settings::values.rng_seed.UsingGlobal());
|
|
|
|
|
ui->rng_seed_edit->setText(rng_seed);
|
|
|
|
|
|
2021-05-16 01:17:18 -04:00
|
|
|
ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value());
|
|
|
|
|
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value());
|
2021-10-16 02:07:18 -04:00
|
|
|
ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time));
|
2022-12-13 17:21:04 -05:00
|
|
|
ui->device_name_edit->setText(
|
|
|
|
|
QString::fromUtf8(Settings::values.device_name.GetValue().c_str()));
|
2020-07-13 23:01:18 -04:00
|
|
|
|
2020-11-04 04:16:34 -05:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
2020-07-09 22:42:09 -04:00
|
|
|
ui->combo_language->setCurrentIndex(Settings::values.language_index.GetValue());
|
|
|
|
|
ui->combo_region->setCurrentIndex(Settings::values.region_index.GetValue());
|
|
|
|
|
ui->combo_time_zone->setCurrentIndex(Settings::values.time_zone_index.GetValue());
|
|
|
|
|
ui->combo_sound->setCurrentIndex(Settings::values.sound_index.GetValue());
|
|
|
|
|
} else {
|
|
|
|
|
ConfigurationShared::SetPerGameSetting(ui->combo_language,
|
|
|
|
|
&Settings::values.language_index);
|
|
|
|
|
ConfigurationShared::SetPerGameSetting(ui->combo_region, &Settings::values.region_index);
|
|
|
|
|
ConfigurationShared::SetPerGameSetting(ui->combo_time_zone,
|
|
|
|
|
&Settings::values.time_zone_index);
|
|
|
|
|
ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index);
|
2020-07-14 00:20:25 -04:00
|
|
|
|
2020-08-14 14:02:37 -04:00
|
|
|
ConfigurationShared::SetHighlight(ui->label_language,
|
2020-07-14 00:36:58 -04:00
|
|
|
!Settings::values.language_index.UsingGlobal());
|
2020-08-14 14:02:37 -04:00
|
|
|
ConfigurationShared::SetHighlight(ui->label_region,
|
2020-07-14 00:36:58 -04:00
|
|
|
!Settings::values.region_index.UsingGlobal());
|
2020-08-14 14:02:37 -04:00
|
|
|
ConfigurationShared::SetHighlight(ui->label_timezone,
|
2020-07-14 00:36:58 -04:00
|
|
|
!Settings::values.time_zone_index.UsingGlobal());
|
2020-08-14 14:02:37 -04:00
|
|
|
ConfigurationShared::SetHighlight(ui->label_sound,
|
2020-07-14 00:36:58 -04:00
|
|
|
!Settings::values.sound_index.UsingGlobal());
|
2020-07-09 22:42:09 -04:00
|
|
|
}
|
2018-10-09 21:53:04 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 20:33:56 -07:00
|
|
|
void ConfigureSystem::ReadSystemSettings() {}
|
2016-06-01 10:43:33 +03:00
|
|
|
|
2019-05-26 00:39:23 -04:00
|
|
|
void ConfigureSystem::ApplyConfiguration() {
|
2020-11-27 10:50:48 -05:00
|
|
|
// Allow setting custom RTC even if system is powered on,
|
|
|
|
|
// to allow in-game time to be fast forwarded
|
2021-05-16 01:17:18 -04:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
2020-10-12 18:09:15 -07:00
|
|
|
if (ui->custom_rtc_checkbox->isChecked()) {
|
2021-10-16 02:07:18 -04:00
|
|
|
Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch();
|
2020-11-27 10:50:48 -05:00
|
|
|
if (system.IsPoweredOn()) {
|
2021-10-16 02:07:18 -04:00
|
|
|
const s64 posix_time{*Settings::values.custom_rtc +
|
2020-10-12 18:09:15 -07:00
|
|
|
Service::Time::TimeManager::GetExternalTimeZoneOffset()};
|
2020-11-27 10:50:48 -05:00
|
|
|
system.GetTimeManager().UpdateLocalSystemClockTime(posix_time);
|
2020-10-12 18:09:15 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
2021-05-16 01:17:18 -04:00
|
|
|
Settings::values.custom_rtc = std::nullopt;
|
2020-10-12 18:09:15 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 17:21:04 -05:00
|
|
|
Settings::values.device_name = ui->device_name_edit->text().toStdString();
|
|
|
|
|
|
2019-05-26 00:39:23 -04:00
|
|
|
if (!enabled) {
|
2016-06-01 10:43:33 +03:00
|
|
|
return;
|
2019-05-26 00:39:23 -04:00
|
|
|
}
|
2018-10-09 21:53:04 -04:00
|
|
|
|
2021-05-15 23:53:36 -04:00
|
|
|
ConfigurationShared::ApplyPerGameSetting(&Settings::values.language_index, ui->combo_language);
|
2021-05-15 22:59:38 -04:00
|
|
|
ConfigurationShared::ApplyPerGameSetting(&Settings::values.region_index, ui->combo_region);
|
|
|
|
|
ConfigurationShared::ApplyPerGameSetting(&Settings::values.time_zone_index,
|
|
|
|
|
ui->combo_time_zone);
|
|
|
|
|
ConfigurationShared::ApplyPerGameSetting(&Settings::values.sound_index, ui->combo_sound);
|
|
|
|
|
|
2020-11-04 04:16:34 -05:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
2020-07-09 22:42:09 -04:00
|
|
|
// Guard if during game and set to game-specific value
|
|
|
|
|
if (Settings::values.rng_seed.UsingGlobal()) {
|
|
|
|
|
if (ui->rng_seed_checkbox->isChecked()) {
|
2022-05-12 07:03:37 -07:00
|
|
|
Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16));
|
2020-07-09 22:42:09 -04:00
|
|
|
} else {
|
|
|
|
|
Settings::values.rng_seed.SetValue(std::nullopt);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-26 00:39:23 -04:00
|
|
|
} else {
|
2020-07-14 15:42:12 -04:00
|
|
|
switch (use_rng_seed) {
|
2020-07-13 23:01:18 -04:00
|
|
|
case ConfigurationShared::CheckState::On:
|
|
|
|
|
case ConfigurationShared::CheckState::Off:
|
2020-07-09 22:42:09 -04:00
|
|
|
Settings::values.rng_seed.SetGlobal(false);
|
2020-07-13 23:01:18 -04:00
|
|
|
if (ui->rng_seed_checkbox->isChecked()) {
|
2022-05-12 07:03:37 -07:00
|
|
|
Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16));
|
2020-07-13 23:01:18 -04:00
|
|
|
} else {
|
|
|
|
|
Settings::values.rng_seed.SetValue(std::nullopt);
|
|
|
|
|
}
|
2020-07-09 22:42:09 -04:00
|
|
|
break;
|
2020-07-13 23:01:18 -04:00
|
|
|
case ConfigurationShared::CheckState::Global:
|
2020-07-09 22:42:09 -04:00
|
|
|
Settings::values.rng_seed.SetGlobal(false);
|
|
|
|
|
Settings::values.rng_seed.SetValue(std::nullopt);
|
|
|
|
|
Settings::values.rng_seed.SetGlobal(true);
|
|
|
|
|
break;
|
2020-07-14 13:40:49 -04:00
|
|
|
case ConfigurationShared::CheckState::Count:
|
|
|
|
|
break;
|
2020-07-09 22:42:09 -04:00
|
|
|
}
|
2019-05-26 00:39:23 -04:00
|
|
|
}
|
2016-06-01 10:43:33 +03:00
|
|
|
}
|
|
|
|
|
|
2018-10-25 16:47:09 -04:00
|
|
|
void ConfigureSystem::RefreshConsoleID() {
|
2017-05-06 02:55:51 +02:00
|
|
|
QMessageBox::StandardButton reply;
|
2018-01-13 23:49:16 +00:00
|
|
|
QString warning_text = tr("This will replace your current virtual Switch with a new one. "
|
|
|
|
|
"Your current virtual Switch will not be recoverable. "
|
2017-05-06 02:55:51 +02:00
|
|
|
"This might have unexpected effects in games. This might fail, "
|
|
|
|
|
"if you use an outdated config savegame. Continue?");
|
|
|
|
|
reply = QMessageBox::critical(this, tr("Warning"), warning_text,
|
|
|
|
|
QMessageBox::No | QMessageBox::Yes);
|
2019-05-26 00:39:23 -04:00
|
|
|
if (reply == QMessageBox::No) {
|
2017-05-06 02:55:51 +02:00
|
|
|
return;
|
2019-05-26 00:39:23 -04:00
|
|
|
}
|
|
|
|
|
|
2017-10-12 21:21:49 -04:00
|
|
|
u64 console_id{};
|
2018-01-17 11:20:46 -05:00
|
|
|
ui->label_console_id->setText(
|
|
|
|
|
tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
|
2017-05-06 02:55:51 +02:00
|
|
|
}
|
2020-07-09 22:42:09 -04:00
|
|
|
|
|
|
|
|
void ConfigureSystem::SetupPerGameUI() {
|
2020-11-04 04:16:34 -05:00
|
|
|
if (Settings::IsConfiguringGlobal()) {
|
2020-07-09 22:42:09 -04:00
|
|
|
ui->combo_language->setEnabled(Settings::values.language_index.UsingGlobal());
|
|
|
|
|
ui->combo_region->setEnabled(Settings::values.region_index.UsingGlobal());
|
|
|
|
|
ui->combo_time_zone->setEnabled(Settings::values.time_zone_index.UsingGlobal());
|
|
|
|
|
ui->combo_sound->setEnabled(Settings::values.sound_index.UsingGlobal());
|
|
|
|
|
ui->rng_seed_checkbox->setEnabled(Settings::values.rng_seed.UsingGlobal());
|
|
|
|
|
ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.UsingGlobal());
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 23:01:18 -04:00
|
|
|
ConfigurationShared::SetColoredComboBox(ui->combo_language, ui->label_language,
|
|
|
|
|
Settings::values.language_index.GetValue(true));
|
2020-08-14 14:02:37 -04:00
|
|
|
ConfigurationShared::SetColoredComboBox(ui->combo_region, ui->label_region,
|
2020-07-13 23:01:18 -04:00
|
|
|
Settings::values.region_index.GetValue(true));
|
|
|
|
|
ConfigurationShared::SetColoredComboBox(ui->combo_time_zone, ui->label_timezone,
|
|
|
|
|
Settings::values.time_zone_index.GetValue(true));
|
2020-08-14 14:02:37 -04:00
|
|
|
ConfigurationShared::SetColoredComboBox(ui->combo_sound, ui->label_sound,
|
2020-07-13 23:01:18 -04:00
|
|
|
Settings::values.sound_index.GetValue(true));
|
|
|
|
|
|
2020-07-18 13:25:07 -04:00
|
|
|
ConfigurationShared::SetColoredTristate(
|
2020-08-14 14:02:37 -04:00
|
|
|
ui->rng_seed_checkbox, Settings::values.rng_seed.UsingGlobal(),
|
2020-07-18 13:25:07 -04:00
|
|
|
Settings::values.rng_seed.GetValue().has_value(),
|
2020-07-14 15:42:12 -04:00
|
|
|
Settings::values.rng_seed.GetValue(true).has_value(), use_rng_seed);
|
2021-05-16 01:17:18 -04:00
|
|
|
|
|
|
|
|
ui->custom_rtc_checkbox->setVisible(false);
|
|
|
|
|
ui->custom_rtc_edit->setVisible(false);
|
2020-07-09 22:42:09 -04:00
|
|
|
}
|