Files
eden/src/yuzu/configuration/configure_system.cpp
T

191 lines
6.6 KiB
C++
Raw Normal View History

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
#include <chrono>
2023-05-10 17:57:25 -04:00
#include <forward_list>
#include <optional>
2023-05-10 17:57:25 -04:00
#include <QDateTimeEdit>
#include <QFileDialog>
#include <QGraphicsItem>
2023-05-10 17:57:25 -04:00
#include <QLineEdit>
2017-05-06 02:55:51 +02:00
#include <QMessageBox>
2021-04-14 16:07:40 -07:00
#include "common/settings.h"
#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"
2023-05-10 17:57:25 -04:00
#include "yuzu/configuration/config.h"
#include "yuzu/configuration/configuration_shared.h"
#include "yuzu/configuration/configure_system.h"
2023-05-10 17:57:25 -04:00
#include "yuzu/configuration/shared_widget.h"
constexpr std::array<u32, 7> LOCALE_BLOCKLIST{
// pzzefezrpnkzeidfej
// thhsrnhutlohsternp
// BHH4CG U
// Raa1AB S
// nn9
// ts
0b0100011100001100000, // Japan
0b0000001101001100100, // Americas
0b0100110100001000010, // Europe
0b0100110100001000010, // Australia
0b0000000000000000000, // China
0b0100111100001000000, // Korea
0b0100111100001000000, // Taiwan
};
static bool IsValidLocale(u32 region_index, u32 language_index) {
2023-01-22 01:35:28 -06:00
if (region_index >= LOCALE_BLOCKLIST.size()) {
return false;
}
return ((LOCALE_BLOCKLIST.at(region_index) >> language_index) & 1) == 0;
}
2023-05-05 23:30:59 -04:00
ConfigureSystem::ConfigureSystem(
Core::System& system_, std::shared_ptr<std::forward_list<ConfigurationShared::Tab*>> group,
2023-05-10 17:57:25 -04:00
ConfigurationShared::TranslationMap& translations_, QWidget* parent)
: Tab(group, parent), ui{std::make_unique<Ui::ConfigureSystem>()}, system{system_},
translations{translations_} {
2016-06-01 10:43:33 +03:00
ui->setupUi(this);
2016-09-13 13:04:17 +08:00
2023-05-10 17:57:25 -04:00
Setup();
connect(rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
rng_seed_edit->setEnabled(state == Qt::Checked);
if (state != Qt::Checked) {
2023-05-10 17:57:25 -04:00
rng_seed_edit->setText(QStringLiteral("00000000"));
}
2018-11-11 22:34:23 -05:00
});
2023-05-10 17:57:25 -04:00
connect(custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
custom_rtc_edit->setEnabled(state == Qt::Checked);
if (state != Qt::Checked) {
2023-05-10 17:57:25 -04:00
custom_rtc_edit->setDateTime(QDateTime::currentDateTime());
}
2018-12-28 18:36:14 -05:00
});
const auto locale_check = [this](int index) {
2023-05-10 17:57:25 -04:00
const auto region_index = combo_region->currentIndex();
const auto language_index = combo_language->currentIndex();
2023-01-22 01:35:28 -06:00
const bool valid_locale = IsValidLocale(region_index, language_index);
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\"")
2023-05-10 17:57:25 -04:00
.arg(combo_language->currentText())
.arg(combo_region->currentText()));
}
};
2023-05-10 17:57:25 -04:00
connect(combo_language, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
connect(combo_region, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check);
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
void ConfigureSystem::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
RetranslateUI();
}
QWidget::changeEvent(event);
}
void ConfigureSystem::RetranslateUI() {
ui->retranslateUi(this);
}
2023-05-10 17:57:25 -04:00
void ConfigureSystem::Setup() {
const bool runtime_lock = !system.IsPoweredOn();
auto& core_layout = *ui->core_widget->layout();
auto& system_layout = *ui->system_widget->layout();
2023-05-10 17:57:25 -04:00
std::map<std::string, QWidget*> core_hold{};
std::map<bool, std::map<std::string, QWidget*>> system_hold{};
2016-06-01 10:43:33 +03:00
2023-05-10 17:57:25 -04:00
std::forward_list<Settings::BasicSetting*> settings;
auto push = [&settings](std::forward_list<Settings::BasicSetting*>& list) {
for (auto setting : list) {
settings.push_front(setting);
}
2023-05-10 17:57:25 -04:00
};
2023-05-10 17:57:25 -04:00
push(Settings::values.linkage.by_category[Settings::Category::Core]);
push(Settings::values.linkage.by_category[Settings::Category::System]);
for (auto setting : settings) {
2023-06-09 16:53:26 -04:00
[[maybe_unused]] std::string label = setting->GetLabel();
2023-05-10 17:57:25 -04:00
ConfigurationShared::Widget* widget = [=]() {
2023-06-09 16:53:26 -04:00
if (setting->Id() == Settings::values.custom_rtc.Id()) {
2023-05-10 17:57:25 -04:00
return new ConfigurationShared::Widget(
setting, translations, this, runtime_lock, apply_funcs,
ConfigurationShared::RequestType::DateTimeEdit, true, 1.0f,
2023-06-09 16:53:26 -04:00
&Settings::values.custom_rtc_enabled);
} else if (setting->Id() == Settings::values.rng_seed.Id()) {
return new ConfigurationShared::Widget(
setting, translations, this, runtime_lock, apply_funcs,
ConfigurationShared::RequestType::HexEdit, true, 1.0f,
&Settings::values.rng_seed_enabled);
2023-05-10 17:57:25 -04:00
} else {
return new ConfigurationShared::Widget(setting, translations, this, runtime_lock,
apply_funcs);
}
}();
2022-12-13 17:21:04 -05:00
2023-05-10 17:57:25 -04:00
if (!widget->Valid()) {
delete widget;
continue;
}
2023-06-09 16:53:26 -04:00
if (setting->Id() == Settings::values.rng_seed.Id()) {
2023-05-10 17:57:25 -04:00
rng_seed_checkbox = widget->checkbox;
rng_seed_edit = widget->line_edit;
2023-06-09 16:53:26 -04:00
rng_seed_edit->setEnabled(Settings::values.rng_seed_enabled.GetValue());
} else if (setting->Id() == Settings::values.custom_rtc.Id()) {
2023-05-10 17:57:25 -04:00
custom_rtc_checkbox = widget->checkbox;
custom_rtc_edit = widget->date_time_edit;
custom_rtc_edit->setEnabled(Settings::values.custom_rtc_enabled.GetValue());
} else if (setting->Id() == Settings::values.region_index.Id()) {
combo_region = widget->combobox;
} else if (setting->Id() == Settings::values.language_index.Id()) {
combo_language = widget->combobox;
}
2023-05-10 17:57:25 -04:00
switch (setting->Category()) {
case Settings::Category::Core:
core_hold[setting->GetLabel()] = widget;
break;
2023-05-10 17:57:25 -04:00
case Settings::Category::System:
system_hold[setting->IsEnum()].insert(std::pair{setting->GetLabel(), widget});
break;
2023-05-10 17:57:25 -04:00
default:
delete widget;
}
}
2023-05-10 17:57:25 -04:00
for (const auto& [label, widget] : core_hold) {
core_layout.addWidget(widget);
}
for (const auto& [label, widget] : system_hold[true]) {
system_layout.addWidget(widget);
}
for (const auto& [label, widget] : system_hold[false]) {
system_layout.addWidget(widget);
}
2016-06-01 10:43:33 +03:00
}
2023-05-10 17:57:25 -04:00
void ConfigureSystem::SetConfiguration() {}
2023-05-10 17:57:25 -04:00
void ConfigureSystem::ApplyConfiguration() {
const bool powered_on = system.IsPoweredOn();
for (const auto& func : apply_funcs) {
func(powered_on);
}
}