From d3b94d64d492407dcd43acf79cd1e94d57630109 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Fri, 5 May 2023 23:30:59 -0400 Subject: configuration: Add base class to tabs Tabs that largely configure SwitchableSetting's are now Tabs and grouped together. --- src/yuzu/configuration/configure_dialog.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index bdf83ebfe..2cc9f3621 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -32,21 +32,21 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, std::vector& vk_device_records, Core::System& system_, bool enable_web_config) : QDialog(parent), ui{std::make_unique()}, - registry(registry_), system{system_}, audio_tab{std::make_unique(system_, - this)}, - cpu_tab{std::make_unique(system_, this)}, + registry(registry_), system{system_}, audio_tab{std::make_unique( + system_, nullptr, this)}, + cpu_tab{std::make_unique(system_, nullptr, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, - general_tab{std::make_unique(system_, this)}, - graphics_advanced_tab{std::make_unique(system_, this)}, + general_tab{std::make_unique(system_, nullptr, this)}, + graphics_advanced_tab{std::make_unique(system_, nullptr, this)}, graphics_tab{std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - this)}, + nullptr, this)}, hotkeys_tab{std::make_unique(system_.HIDCore(), this)}, input_tab{std::make_unique(system_, this)}, network_tab{std::make_unique(system_, this)}, profile_tab{std::make_unique(system_, this)}, - system_tab{std::make_unique(system_, this)}, + system_tab{std::make_unique(system_, nullptr, this)}, ui_tab{std::make_unique(system_, this)}, web_tab{std::make_unique( this)} { Settings::SetConfiguringGlobal(true); -- cgit v1.2.3 From a007ac6b9ccc23861f5a5c6967d535220ed794b0 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sun, 7 May 2023 09:48:26 -0400 Subject: configure_graphics_advance: Generate UI at runtime We can iterate through the AdvancedGraphics settings and generate the UI during runtime. This doesn't help runtime efficiency, but it helps a ton in reducing the amount of work a developer needs in order to add a new setting. --- src/common/settings.h | 53 +++-- src/core/telemetry_session.cpp | 2 + src/video_core/textures/texture.cpp | 4 +- src/yuzu/CMakeLists.txt | 2 + src/yuzu/configuration/configuration_shared.cpp | 153 ++++++++++++++ src/yuzu/configuration/configuration_shared.h | 6 + src/yuzu/configuration/configure_dialog.cpp | 8 +- src/yuzu/configuration/configure_dialog.h | 1 + .../configuration/configure_graphics_advanced.cpp | 172 ++++----------- .../configuration/configure_graphics_advanced.h | 20 +- .../configuration/configure_graphics_advanced.ui | 234 +-------------------- src/yuzu/configuration/configure_per_game.cpp | 9 +- src/yuzu/configuration/configure_per_game.h | 1 + src/yuzu/configuration/shared_translation.cpp | 170 +++++++++++++++ src/yuzu/configuration/shared_translation.h | 18 ++ 15 files changed, 451 insertions(+), 402 deletions(-) create mode 100644 src/yuzu/configuration/shared_translation.cpp create mode 100644 src/yuzu/configuration/shared_translation.h (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/common/settings.h b/src/common/settings.h index df4bcb053..48f86d0aa 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -20,6 +20,15 @@ namespace Settings { +enum class AnisotropyMode : u32 { + Automatic = 0, + Default = 1, + X2 = 2, + X4 = 3, + X8 = 4, + X16 = 5, +}; + enum class AstcDecodeMode : u32 { CPU = 0, GPU = 1, @@ -49,6 +58,7 @@ enum class GPUAccuracy : u32 { Normal = 0, High = 1, Extreme = 2, + MaxEnum = 3, }; enum class CPUAccuracy : u32 { @@ -166,11 +176,16 @@ public: virtual Category Category() const = 0; virtual constexpr bool Switchable() const = 0; virtual std::string ToString() const = 0; + virtual std::string ToStringGlobal() const { + return {}; + } virtual void LoadString(const std::string& load) = 0; virtual const std::string& GetLabel() const = 0; virtual std::string DefaultToString() const = 0; virtual bool Save() const = 0; virtual std::type_index TypeId() const = 0; + virtual bool IsEnum() const = 0; + virtual bool RuntimeModfiable() const = 0; virtual void SetGlobal(bool global) {} virtual bool UsingGlobal() const { return false; @@ -188,7 +203,7 @@ public: * configurations. Specifying a default value and label is required. A minimum and maximum range * can be specified for sanitization. */ -template +template class Setting : public BasicSetting { protected: Setting() = default; @@ -282,6 +297,14 @@ public: return category; } + [[nodiscard]] bool RuntimeModfiable() const override { + return runtime_modifiable; + } + + [[nodiscard]] bool IsEnum() const override { + return std::is_enum::value; + } + /** * Returns whether the current setting is Switchable. * @@ -291,7 +314,7 @@ public: return false; } -private: +protected: std::string ToString(const Type& value_) const { if constexpr (std::is_same()) { return value_; @@ -408,8 +431,8 @@ protected: * * By default, the global setting is used. */ -template -class SwitchableSetting : virtual public Setting { +template +class SwitchableSetting : virtual public Setting { public: /** * Sets a default value, label, and setting value. @@ -422,7 +445,7 @@ public: explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, Category category) requires(!ranged) - : Setting{linkage, default_val, name, category} { + : Setting{linkage, default_val, name, category} { linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); } virtual ~SwitchableSetting() = default; @@ -440,7 +463,8 @@ public: explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, const Type& max_val, const std::string& name, Category category) requires(ranged) - : Setting{linkage, default_val, min_val, max_val, name, category} { + : Setting{linkage, default_val, min_val, + max_val, name, category} { linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); } @@ -502,6 +526,10 @@ public: return true; } + [[nodiscard]] virtual std::string ToStringGlobal() const override { + return this->ToString(this->value); + } + /** * Assigns the current setting value depending on the global state. * @@ -667,15 +695,16 @@ struct Values { "fullscreen_mode", Category::Renderer}; SwitchableSetting aspect_ratio{linkage, 0, 0, 4, "aspect_ratio", Category::Renderer}; - SwitchableSetting max_anisotropy{ - linkage, 0, 0, 5, "max_anisotropy", Category::AdvancedGraphics}; + SwitchableSetting max_anisotropy{ + linkage, AnisotropyMode::Automatic, AnisotropyMode::Automatic, AnisotropyMode::X16, + "max_anisotropy", Category::AdvancedGraphics}; SwitchableSetting use_speed_limit{linkage, true, "use_speed_limit", Category::Renderer}; SwitchableSetting speed_limit{linkage, 100, 0, 9999, "speed_limit", Category::Renderer}; SwitchableSetting use_disk_shader_cache{linkage, true, "use_disk_shader_cache", Category::Renderer}; - SwitchableSetting gpu_accuracy{ + SwitchableSetting gpu_accuracy{ linkage, GPUAccuracy::High, GPUAccuracy::Normal, GPUAccuracy::Extreme, "gpu_accuracy", Category::AdvancedGraphics}; SwitchableSetting use_asynchronous_gpu_emulation{ @@ -698,9 +727,9 @@ struct Values { "shader_backend", Category::Renderer}; SwitchableSetting use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders", Category::Renderer}; - SwitchableSetting use_fast_gpu_time{linkage, true, "use_fast_gpu_time", - Category::AdvancedGraphics}; - SwitchableSetting use_vulkan_driver_pipeline_cache{ + SwitchableSetting use_fast_gpu_time{linkage, true, "use_fast_gpu_time", + Category::AdvancedGraphics}; + SwitchableSetting use_vulkan_driver_pipeline_cache{ linkage, true, "use_vulkan_driver_pipeline_cache", Category::AdvancedGraphics}; SwitchableSetting enable_compute_pipelines{linkage, false, "enable_compute_pipelines", Category::AdvancedGraphics}; diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 665ffe3a2..a3505a505 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -69,6 +69,8 @@ static const char* TranslateGPUAccuracyLevel(Settings::GPUAccuracy backend) { return "High"; case Settings::GPUAccuracy::Extreme: return "Extreme"; + case Settings::GPUAccuracy::MaxEnum: + break; } return "Unknown"; } diff --git a/src/video_core/textures/texture.cpp b/src/video_core/textures/texture.cpp index d8b88d9bc..39c08b5ae 100644 --- a/src/video_core/textures/texture.cpp +++ b/src/video_core/textures/texture.cpp @@ -72,12 +72,12 @@ float TSCEntry::MaxAnisotropy() const noexcept { } const auto anisotropic_settings = Settings::values.max_anisotropy.GetValue(); s32 added_anisotropic{}; - if (anisotropic_settings == 0) { + if (anisotropic_settings == Settings::AnisotropyMode::Automatic) { added_anisotropic = Settings::values.resolution_info.up_scale >> Settings::values.resolution_info.down_shift; added_anisotropic = std::max(added_anisotropic - 1, 0); } else { - added_anisotropic = Settings::values.max_anisotropy.GetValue() - 1U; + added_anisotropic = static_cast(Settings::values.max_anisotropy.GetValue()) - 1U; } return static_cast(1U << (max_anisotropy + added_anisotropic)); } diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index fe98e3605..8b54e1268 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -143,6 +143,8 @@ add_executable(yuzu configuration/configure_web.ui configuration/input_profiles.cpp configuration/input_profiles.h + configuration/shared_translation.cpp + configuration/shared_translation.h debugger/console.cpp debugger/console.h debugger/controller.cpp diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp index 72b7957e0..44222718c 100644 --- a/src/yuzu/configuration/configuration_shared.cpp +++ b/src/yuzu/configuration/configuration_shared.cpp @@ -3,14 +3,167 @@ #include #include +#include +#include #include #include #include +#include #include "common/settings.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_per_game.h" +#include "yuzu/configuration/shared_translation.h" namespace ConfigurationShared { +static std::pair> CreateCheckBox(Settings::BasicSetting* setting, + const QString& label, + QWidget* parent, + std::list& trackers) { + QCheckBox* checkbox = new QCheckBox(label, parent); + checkbox->setObjectName(QString::fromStdString(setting->GetLabel())); + checkbox->setCheckState(setting->ToString() == "true" ? Qt::CheckState::Checked + : Qt::CheckState::Unchecked); + + CheckState* tracker{}; + + // Per-game config highlight + if (setting->Switchable() && !Settings::IsConfiguringGlobal()) { + bool global_state = setting->ToStringGlobal() == "true"; + bool state = setting->ToString() == "true"; + bool global = setting->UsingGlobal(); + tracker = &trackers.emplace_front(CheckState{}); + SetColoredTristate(checkbox, global, state, global_state, *tracker); + } + + auto load_func = [checkbox, setting, tracker]() { + if (Settings::IsConfiguringGlobal()) { + setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false"); + } + + if (Settings::IsConfiguringGlobal() || !setting->Switchable()) { + return; + } + + if (*tracker != CheckState::Global) { + setting->SetGlobal(false); + setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false"); + } else { + setting->SetGlobal(true); + } + }; + + return {checkbox, load_func}; +} + +static std::pair> CreateCombobox(Settings::BasicSetting* setting, + const QString& label, + QWidget* parent) { + const auto type = setting->TypeId(); + + QWidget* group = new QWidget(parent); + group->setObjectName(QString::fromStdString(setting->GetLabel())); + QLayout* combobox_layout = new QHBoxLayout(group); + + QLabel* qt_label = new QLabel(label, parent); + QComboBox* combobox = new QComboBox(parent); + + std::forward_list combobox_enumerations = ComboboxEnumeration(type, parent); + for (const auto& item : combobox_enumerations) { + combobox->addItem(item); + } + + combobox_layout->addWidget(qt_label); + combobox_layout->addWidget(combobox); + + combobox_layout->setSpacing(6); + combobox_layout->setContentsMargins(0, 0, 0, 0); + + if (setting->Switchable() && !Settings::IsConfiguringGlobal()) { + int current = std::stoi(setting->ToString()); + int global_value = std::stoi(setting->ToStringGlobal()); + SetColoredComboBox(combobox, group, global_value); + if (setting->UsingGlobal()) { + combobox->setCurrentIndex(USE_GLOBAL_INDEX); + } else { + SetHighlight(group, true); + combobox->setCurrentIndex(current + USE_GLOBAL_OFFSET); + } + } else { + combobox->setCurrentIndex(std::stoi(setting->ToString())); + } + + const auto load_func = [combobox, setting]() { + if (Settings::IsConfiguringGlobal()) { + setting->LoadString(std::to_string(combobox->currentIndex())); + } + + if (Settings::IsConfiguringGlobal() || !setting->Switchable()) { + return; + } + + bool using_global = combobox->currentIndex() == USE_GLOBAL_INDEX; + int index = combobox->currentIndex() - USE_GLOBAL_OFFSET; + + setting->SetGlobal(using_global); + if (!using_global) { + setting->LoadString(std::to_string(index)); + } + }; + + return {group, load_func}; +} + +QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& translations, + QWidget* parent, bool runtime_lock, + std::forward_list>& apply_funcs, + std::list& trackers) { + const auto type = setting->TypeId(); + QWidget* widget{nullptr}; + + std::function load_func; + + const auto [label, tooltip] = [&]() { + const auto& setting_label = setting->GetLabel(); + if (translations.contains(setting_label)) { + return std::pair{translations.at(setting_label).first, + translations.at(setting_label).second}; + } + LOG_ERROR(Frontend, "Translation map lacks entry for \"{}\"", setting_label); + return std::pair{QString::fromStdString(setting_label), QStringLiteral("")}; + }(); + + if (type == typeid(bool)) { + auto pair = CreateCheckBox(setting, label, parent, trackers); + widget = pair.first; + load_func = pair.second; + } else if (setting->IsEnum()) { + auto pair = CreateCombobox(setting, label, parent); + widget = pair.first; + load_func = pair.second; + } + + if (widget == nullptr) { + LOG_ERROR(Frontend, "No widget was created for \"{}\"", setting->GetLabel()); + return widget; + } + + apply_funcs.push_front([load_func, setting](bool powered_on) { + if (setting->RuntimeModfiable() || !powered_on) { + load_func(); + } + }); + + bool enable = runtime_lock || setting->RuntimeModfiable(); + enable &= + setting->Switchable() && !(Settings::IsConfiguringGlobal() && !setting->UsingGlobal()); + + widget->setEnabled(enable); + widget->setVisible(Settings::IsConfiguringGlobal() || setting->Switchable()); + + widget->setToolTip(tooltip); + + return widget; +} Tab::Tab(std::shared_ptr> group_, QWidget* parent) : QWidget(parent), group{group_} { diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h index 1a3a2a985..7040673ea 100644 --- a/src/yuzu/configuration/configuration_shared.h +++ b/src/yuzu/configuration/configuration_shared.h @@ -11,6 +11,7 @@ #include #include #include "common/settings.h" +#include "yuzu/configuration/shared_translation.h" namespace ConfigurationShared { @@ -40,6 +41,11 @@ enum class CheckState { Count, // Simply the number of states, not a valid checkbox state }; +QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& translations, + QWidget* parent, bool runtime_lock, + std::forward_list>& apply_funcs, + std::list& trackers); + // Global-aware apply and set functions // ApplyPerGameSetting, given a Settings::Setting and a Qt UI element, properly applies a Setting diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 2cc9f3621..b3f4764c7 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -32,13 +32,15 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, std::vector& vk_device_records, Core::System& system_, bool enable_web_config) : QDialog(parent), ui{std::make_unique()}, - registry(registry_), system{system_}, audio_tab{std::make_unique( - system_, nullptr, this)}, + registry(registry_), system{system_}, + translations{ConfigurationShared::InitializeTranslations(this)}, + audio_tab{std::make_unique(system_, nullptr, this)}, cpu_tab{std::make_unique(system_, nullptr, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, general_tab{std::make_unique(system_, nullptr, this)}, - graphics_advanced_tab{std::make_unique(system_, nullptr, this)}, + graphics_advanced_tab{ + std::make_unique(system_, nullptr, *translations, this)}, graphics_tab{std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, nullptr, this)}, diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index 8ee89a192..0416b01d9 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h @@ -71,6 +71,7 @@ private: HotkeyRegistry& registry; Core::System& system; + std::unique_ptr translations; std::forward_list tab_group; std::unique_ptr audio_tab; diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index d332c9b7b..6d387b5c3 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include +#include #include "common/settings.h" #include "core/core.h" #include "ui_configure_graphics_advanced.h" @@ -9,94 +11,54 @@ ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced( const Core::System& system_, - std::shared_ptr> group, QWidget* parent) - : Tab(group, parent), ui{std::make_unique()}, system{system_} { + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent) + : Tab(group, parent), ui{std::make_unique()}, system{system_}, + translations{translations_} { ui->setupUi(this); - SetupPerGameUI(); - SetConfiguration(); - ui->enable_compute_pipelines_checkbox->setVisible(false); + checkbox_enable_compute_pipelines->setVisible(false); } ConfigureGraphicsAdvanced::~ConfigureGraphicsAdvanced() = default; void ConfigureGraphicsAdvanced::SetConfiguration() { const bool runtime_lock = !system.IsPoweredOn(); - ui->use_reactive_flushing->setEnabled(runtime_lock); - ui->async_present->setEnabled(runtime_lock); - ui->renderer_force_max_clock->setEnabled(runtime_lock); - ui->astc_recompression_combobox->setEnabled(runtime_lock); - ui->use_asynchronous_shaders->setEnabled(runtime_lock); - ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); - ui->enable_compute_pipelines_checkbox->setEnabled(runtime_lock); - - ui->async_present->setChecked(Settings::values.async_presentation.GetValue()); - ui->renderer_force_max_clock->setChecked(Settings::values.renderer_force_max_clock.GetValue()); - ui->use_reactive_flushing->setChecked(Settings::values.use_reactive_flushing.GetValue()); - ui->use_asynchronous_shaders->setChecked(Settings::values.use_asynchronous_shaders.GetValue()); - ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); - ui->use_vulkan_driver_pipeline_cache->setChecked( - Settings::values.use_vulkan_driver_pipeline_cache.GetValue()); - ui->enable_compute_pipelines_checkbox->setChecked( - Settings::values.enable_compute_pipelines.GetValue()); - ui->use_video_framerate_checkbox->setChecked(Settings::values.use_video_framerate.GetValue()); - ui->barrier_feedback_loops_checkbox->setChecked( - Settings::values.barrier_feedback_loops.GetValue()); - - if (Settings::IsConfiguringGlobal()) { - ui->gpu_accuracy->setCurrentIndex( - static_cast(Settings::values.gpu_accuracy.GetValue())); - ui->anisotropic_filtering_combobox->setCurrentIndex( - Settings::values.max_anisotropy.GetValue()); - ui->astc_recompression_combobox->setCurrentIndex( - static_cast(Settings::values.astc_recompression.GetValue())); - } else { - ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy); - ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox, - &Settings::values.max_anisotropy); - ConfigurationShared::SetPerGameSetting(ui->astc_recompression_combobox, - &Settings::values.astc_recompression); - ConfigurationShared::SetHighlight(ui->label_gpu_accuracy, - !Settings::values.gpu_accuracy.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->af_label, - !Settings::values.max_anisotropy.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->label_astc_recompression, - !Settings::values.astc_recompression.UsingGlobal()); + auto& layout = *ui->populate_target->layout(); + std::map hold{}; // A map will sort the data for us + + for (auto setting : + Settings::values.linkage.by_category[Settings::Category::AdvancedGraphics]) { + QWidget* widget = ConfigurationShared::CreateWidget(setting, translations, this, + runtime_lock, apply_funcs, trackers); + + if (widget == nullptr) { + continue; + } + + if (!setting->IsEnum()) { + hold.emplace(setting->GetLabel(), widget); + } else { + layout.addWidget(widget); + } + + if (setting->GetLabel() == "enable_compute_pipelines") { + checkbox_enable_compute_pipelines = widget; + } + } + for (const auto& [label, widget] : hold) { + layout.addWidget(widget); } } void ConfigureGraphicsAdvanced::ApplyConfiguration() { - ConfigurationShared::ApplyPerGameSetting(&Settings::values.gpu_accuracy, ui->gpu_accuracy); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.async_presentation, - ui->async_present, async_present); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.renderer_force_max_clock, - ui->renderer_force_max_clock, - renderer_force_max_clock); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, - ui->anisotropic_filtering_combobox); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_reactive_flushing, - ui->use_reactive_flushing, use_reactive_flushing); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.astc_recompression, - ui->astc_recompression_combobox); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, - ui->use_asynchronous_shaders, - use_asynchronous_shaders); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_fast_gpu_time, - ui->use_fast_gpu_time, use_fast_gpu_time); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vulkan_driver_pipeline_cache, - ui->use_vulkan_driver_pipeline_cache, - use_vulkan_driver_pipeline_cache); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_compute_pipelines, - ui->enable_compute_pipelines_checkbox, - enable_compute_pipelines); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_video_framerate, - ui->use_video_framerate_checkbox, use_video_framerate); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.barrier_feedback_loops, - ui->barrier_feedback_loops_checkbox, - barrier_feedback_loops); + const bool is_powered_on = system.IsPoweredOn(); + for (const auto& func : apply_funcs) { + func(is_powered_on); + } } void ConfigureGraphicsAdvanced::changeEvent(QEvent* event) { @@ -111,68 +73,6 @@ void ConfigureGraphicsAdvanced::RetranslateUI() { ui->retranslateUi(this); } -void ConfigureGraphicsAdvanced::SetupPerGameUI() { - // Disable if not global (only happens during game) - if (Settings::IsConfiguringGlobal()) { - ui->gpu_accuracy->setEnabled(Settings::values.gpu_accuracy.UsingGlobal()); - ui->async_present->setEnabled(Settings::values.async_presentation.UsingGlobal()); - ui->renderer_force_max_clock->setEnabled( - Settings::values.renderer_force_max_clock.UsingGlobal()); - ui->use_reactive_flushing->setEnabled(Settings::values.use_reactive_flushing.UsingGlobal()); - ui->astc_recompression_combobox->setEnabled( - Settings::values.astc_recompression.UsingGlobal()); - ui->use_asynchronous_shaders->setEnabled( - Settings::values.use_asynchronous_shaders.UsingGlobal()); - ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); - ui->use_vulkan_driver_pipeline_cache->setEnabled( - Settings::values.use_vulkan_driver_pipeline_cache.UsingGlobal()); - ui->anisotropic_filtering_combobox->setEnabled( - Settings::values.max_anisotropy.UsingGlobal()); - ui->enable_compute_pipelines_checkbox->setEnabled( - Settings::values.enable_compute_pipelines.UsingGlobal()); - ui->use_video_framerate_checkbox->setEnabled( - Settings::values.use_video_framerate.UsingGlobal()); - ui->barrier_feedback_loops_checkbox->setEnabled( - Settings::values.barrier_feedback_loops.UsingGlobal()); - - return; - } - - ConfigurationShared::SetColoredTristate(ui->async_present, Settings::values.async_presentation, - async_present); - ConfigurationShared::SetColoredTristate(ui->renderer_force_max_clock, - Settings::values.renderer_force_max_clock, - renderer_force_max_clock); - ConfigurationShared::SetColoredTristate( - ui->use_reactive_flushing, Settings::values.use_reactive_flushing, use_reactive_flushing); - ConfigurationShared::SetColoredTristate(ui->use_asynchronous_shaders, - Settings::values.use_asynchronous_shaders, - use_asynchronous_shaders); - ConfigurationShared::SetColoredTristate(ui->use_fast_gpu_time, - Settings::values.use_fast_gpu_time, use_fast_gpu_time); - ConfigurationShared::SetColoredTristate(ui->use_vulkan_driver_pipeline_cache, - Settings::values.use_vulkan_driver_pipeline_cache, - use_vulkan_driver_pipeline_cache); - ConfigurationShared::SetColoredTristate(ui->enable_compute_pipelines_checkbox, - Settings::values.enable_compute_pipelines, - enable_compute_pipelines); - ConfigurationShared::SetColoredTristate(ui->use_video_framerate_checkbox, - Settings::values.use_video_framerate, - use_video_framerate); - ConfigurationShared::SetColoredTristate(ui->barrier_feedback_loops_checkbox, - Settings::values.barrier_feedback_loops, - barrier_feedback_loops); - ConfigurationShared::SetColoredComboBox( - ui->gpu_accuracy, ui->label_gpu_accuracy, - static_cast(Settings::values.gpu_accuracy.GetValue(true))); - ConfigurationShared::SetColoredComboBox( - ui->anisotropic_filtering_combobox, ui->af_label, - static_cast(Settings::values.max_anisotropy.GetValue(true))); - ConfigurationShared::SetColoredComboBox( - ui->astc_recompression_combobox, ui->label_astc_recompression, - static_cast(Settings::values.astc_recompression.GetValue(true))); -} - void ConfigureGraphicsAdvanced::ExposeComputeOption() { - ui->enable_compute_pipelines_checkbox->setVisible(true); + checkbox_enable_compute_pipelines->setVisible(true); } diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index 585b9cb50..3ac6b4bce 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h @@ -20,7 +20,7 @@ public: explicit ConfigureGraphicsAdvanced( const Core::System& system_, std::shared_ptr> group, - QWidget* parent = nullptr); + const ConfigurationShared::TranslationMap& translations_, QWidget* parent = nullptr); ~ConfigureGraphicsAdvanced() override; void ApplyConfiguration() override; @@ -32,21 +32,13 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void SetupPerGameUI(); - std::unique_ptr ui; - ConfigurationShared::CheckState async_present; - ConfigurationShared::CheckState renderer_force_max_clock; - ConfigurationShared::CheckState use_vsync; - ConfigurationShared::CheckState async_astc; - ConfigurationShared::CheckState use_reactive_flushing; - ConfigurationShared::CheckState use_asynchronous_shaders; - ConfigurationShared::CheckState use_fast_gpu_time; - ConfigurationShared::CheckState use_vulkan_driver_pipeline_cache; - ConfigurationShared::CheckState enable_compute_pipelines; - ConfigurationShared::CheckState use_video_framerate; - ConfigurationShared::CheckState barrier_feedback_loops; + std::list trackers{}; const Core::System& system; + const ConfigurationShared::TranslationMap& translations; + std::forward_list> apply_funcs; + + QWidget* checkbox_enable_compute_pipelines{}; }; diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 859ab9366..113fbc010 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui @@ -26,238 +26,8 @@ - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Accuracy Level: - - - - - - - - Normal - - - - - High - - - - - Extreme(very slow) - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - ASTC recompression: - - - - - - - - Uncompressed (Best quality) - - - - - BC1 (Low quality) - - - - - BC3 (Medium quality) - - - - - - - - - - - Enable asynchronous presentation (Vulkan only) - - - - - - - Runs work in the background while waiting for graphics commands to keep the GPU from lowering its clock speed. - - - Force maximum clocks (Vulkan only) - - - - - - - Uses reactive flushing instead of predictive flushing. Allowing a more accurate syncing of memory. - - - Enable Reactive Flushing - - - - - - - Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental. - - - Use asynchronous shader building (Hack) - - - - - - - Enables Fast GPU Time. This option will force most games to run at their highest native resolution. - - - Use Fast GPU Time (Hack) - - - - - - - Enables GPU vendor-specific pipeline cache. This option can improve shader loading time significantly in cases where the Vulkan driver does not store pipeline cache files internally. - - - Use Vulkan pipeline cache - - - - - - - Enable compute pipelines, required by some games. This setting only exists for Intel proprietary drivers, and may crash if enabled. -Compute pipelines are always enabled on all other drivers. - - - Enable Compute Pipelines (Intel Vulkan only) - - - - - - - Run the game at normal speed during video playback, even when the framerate is unlocked. - - - Sync to framerate of video playback - - - - - - - Improves rendering of transparency effects in specific games. - - - Barrier feedback loops - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Anisotropic Filtering: - - - - - - - - Automatic - - - - - Default - - - - - 2x - - - - - 4x - - - - - 8x - - - - - 16x - - - - - + + diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 7ec0bf9d3..339768017 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -41,8 +41,10 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::string& file_name, std::vector& vk_device_records, Core::System& system_) - : QDialog(parent), ui(std::make_unique()), title_id{title_id_}, - system{system_}, tab_group{std::make_shared>()} { + : QDialog(parent), + ui(std::make_unique()), title_id{title_id_}, system{system_}, + translations{ConfigurationShared::InitializeTranslations(this)}, + tab_group{std::make_shared>()} { const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name)); const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()) : fmt::format("{:016X}", title_id); @@ -52,7 +54,8 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st audio_tab = std::make_unique(system_, tab_group, this); cpu_tab = std::make_unique(system_, tab_group, this); general_tab = std::make_unique(system_, tab_group, this); - graphics_advanced_tab = std::make_unique(system_, tab_group, this); + graphics_advanced_tab = + std::make_unique(system_, tab_group, *translations, this); graphics_tab = std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, tab_group, this); diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h index 9fceff414..1e222c2f9 100644 --- a/src/yuzu/configuration/configure_per_game.h +++ b/src/yuzu/configuration/configure_per_game.h @@ -75,6 +75,7 @@ private: std::unique_ptr game_config; Core::System& system; + std::unique_ptr translations; std::shared_ptr> tab_group; std::unique_ptr addons_tab; diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp new file mode 100644 index 000000000..974203f75 --- /dev/null +++ b/src/yuzu/configuration/shared_translation.cpp @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/settings.h" +#include "yuzu/configuration/shared_translation.h" + +namespace ConfigurationShared { + +std::unique_ptr InitializeTranslations(QWidget* parent) { + std::unique_ptr translations = std::make_unique(); + const auto& tr = [parent](const char* text) -> QString { return parent->tr(text); }; + +#define INSERT(LABEL, NAME, TOOLTIP) \ + translations->insert(std::pair{(LABEL), std::pair{tr((NAME)), tr((TOOLTIP))}}) + + // Audio + INSERT("output_engine", "Output Engine:", ""); + INSERT("output_device", "Output Device:", ""); + INSERT("input_device", "Input Device:", ""); + INSERT("audio_muted", "Mute audio when in background", ""); + INSERT("volume", "Volume:", ""); + + // Core + INSERT("use_multi_core", "Multicore CPU Emulation", ""); + INSERT("use_unsafe_extended_memory_layout", "Unsafe extended memory layout (8GB DRAM)", ""); + + // Cpu + INSERT("cpu_accuracy", "Accuracy:", ""); + INSERT("cpu_debug_mode", "Enable CPU Debugging", ""); + INSERT("cpuopt_page_tables", "Enable inline page tables", ""); + INSERT("cpuopt_block_linking", "Enable block linking", ""); + INSERT("cpuopt_return_stack_buffer", "Enable return stack buffer", ""); + INSERT("cpuopt_fast_dispatcher", "Enable fast dispatcher", ""); + INSERT("cpuopt_context_elimination", "Enable context elimination", ""); + INSERT("cpuopt_const_prop", "Enable constant propagation", ""); + INSERT("cpuopt_misc_ir", "Enable miscellaneous optimizations", ""); + INSERT("cpuopt_reduce_misalign_checks", "Enable misalignment check reduction", ""); + INSERT("cpuopt_fastmem", "Enable Host MMU Emulation (general memory instructions)", ""); + INSERT("cpuopt_fastmem_exclusives", "Enable Host MMU Emulation (exclusive memory instructions)", + ""); + INSERT("cpuopt_recompile_exclusives", "Enable recompilation of exlucsive memory instructions", + ""); + INSERT("cpuopt_ignore_memory_aborts", "Enable fallbacks for invalid memory accesses", ""); + + INSERT("cpuopt_unsafe_unfuse_fma", "Unfuse FMA (improve performance on CPUs without FMA)", ""); + INSERT("cpuopt_unsafe_reduce_fp_error", "Faster FRSQRTE and FRECPE", ""); + INSERT("cpuopt_unsafe_ignore_standard_fpcr", "Faster ASIMD instructions (32 bits only)", ""); + INSERT("cpuopt_unsafe_inaccurate_nan", "Inaccurate NaN handling", ""); + INSERT("cpuopt_unsafe_fastmem_check", "Disable address space checks", ""); + INSERT("cpuopt_unsafe_ignore_global_monitor", "Ignore global monitor", ""); + + // Renderer + INSERT("backend", "API:", ""); + INSERT("vulkan_device", "Device:", ""); + INSERT("shader_backend", "Shader Backend:", ""); + INSERT("resolution_setup", "Resolution:", ""); + INSERT("scaling_filter", "Window Adapting Filter:", ""); + INSERT("fsr_sharpening_slider", "AMD FidelityFX™ Super Resolution Sharpness:", ""); + INSERT("anti_aliasing", "Anti-Aliasing Method:", ""); + INSERT("fullscreen_mode", "Fullscreen Mode:", ""); + INSERT("aspect_ratio", "Aspect Ratio:", ""); + INSERT("use_disk_shader_cache", "Use disk pipeline cache", ""); + INSERT("use_asynchronous_gpu_emulation", "Use asynchronous GPU emulation", ""); + INSERT("nvdec_emulation", "NVDEC emulation:", ""); + INSERT("acclerate_astc", "ASTC Decoding Method:", ""); + INSERT( + "use_vsync", "VSync Mode:", + "FIFO (VSync) does not drop frames or exhibit tearing but is limited by the screen refresh " + "rate. FIFO Relaxed is similar to FIFO but allows tearing as it recovers from a slow down. " + "Mailbox can have lower latency than FIFO and does not tear but may drop frames. Immediate " + "(no synchronization) just presents whatever is available and can exhibit tearing."); + + // Renderer (Advanced Graphics) + INSERT("async_presentation", "Enable asynchronous presentation (Vulkan only)", ""); + INSERT("force_max_clock", "Force maximum clocks (Vulkan only)", + "Runs work in the background while waiting for graphics commands to keep the GPU from " + "lowering its clock speed."); + INSERT("max_anisotropy", "Anisotropic Filtering:", ""); + INSERT("gpu_accuracy", "Accuracy Level:", ""); + INSERT("use_asynchronous_shaders", "Use asynchronous shader building (Hack)", + "Enables asynchronous shader compilation, which may reduce shader stutter. This feature " + "is experimental."); + INSERT("use_fast_gpu_time", "Use Fast GPU Time (Hack)", + "Enables Fast GPU Time. This option will force most games to run at their highest " + "native resolution."); + INSERT("use_vulkan_driver_pipeline_cache", "Use Vulkan pipeline cache", + "Enables GPU vendor-specific pipeline cache. This option can improve shader loading " + "time significantly in cases where the Vulkan driver does not store pipeline cache " + "files internally."); + INSERT("enable_compute_pipelines", "Enable Compute Pipelines (Intel Vulkan Only)", + "Enable compute pipelines, required by some games.\nThis setting only exists for Intel " + "proprietary drivers, and may crash if enabled.\nCompute pipelines are always enabled " + "on all other drivers."); + INSERT("bg_red", "Background Color:", ""); + INSERT("bg_green", "Background Color:", ""); + INSERT("bg_blue", "Background Color:", ""); + + // Renderer (Debug) + INSERT("debug", "Enable Graphics Debugging", + "When checked, the graphics API enters a slower debugging mode"); + INSERT("shader_feedback", "Enable Shader Feedback", + "When checked, yuzu will log statistics about the compiled pipeline cache"); + INSERT("nsight_aftermath", "Enable Nsight Aftermath", + "When checked, it enables Nsight Aftermath crash dumps"); + INSERT("disable_shader_loop_safety_checks", "Disable Loop safety checks", + "When checked, it executes shaders without loop logic changes"); + + // Renderer (General) + INSERT("use_speed_limit", "Limit Speed Percent", ""); + INSERT("speed_limit", "Limit Speed Percent", ""); + + // System + INSERT("rng_seed_enabled", "RNG Seed", ""); + INSERT("rng_seed", "RNG Seed", ""); + INSERT("device_name", "Device Name", ""); + INSERT("custom_rtc_enabled", "Custom RTC", ""); + INSERT("custom_rtc", "Custom RTC", ""); + INSERT("language_index", "Language:", ""); + INSERT("region_index", "Region:", ""); + INSERT("time_zone_index", "Time Zone:", ""); + INSERT("sound_index", "Sound Output Mode:", ""); + INSERT("use_docked_mode", "Docked", ""); + +#undef INSERT + + return translations; +} + +std::forward_list ComboboxEnumeration(std::type_index type, QWidget* parent) { + const auto& tr = [&](const char* text) { return parent->tr(text); }; + + if (type == typeid(Settings::AstcDecodeMode)) { + return { + tr("CPU"), + tr("GPU"), + tr("CPU Asynchronous"), + }; + } else if (type == typeid(Settings::RendererBackend)) { + return { + tr("OpenGL"), + tr("Vulkan"), + tr("Null"), + }; + } else if (type == typeid(Settings::ShaderBackend)) { + return { + tr("GLSL"), + tr("GLASM (Assembly Shaders, NVIDIA Only)"), + tr("SPIR-V (Experimental, Mesa Only)"), + }; + } else if (type == typeid(Settings::GPUAccuracy)) { + return { + tr("Normal"), + tr("High"), + tr("Extreme"), + }; + } else if (type == typeid(Settings::AnisotropyMode)) { + return { + tr("Automatic"), tr("Default"), tr("2x"), tr("4x"), tr("8x"), tr("16x"), + }; + } + + return {}; +} + +} // namespace ConfigurationShared diff --git a/src/yuzu/configuration/shared_translation.h b/src/yuzu/configuration/shared_translation.h new file mode 100644 index 000000000..a81ae9c87 --- /dev/null +++ b/src/yuzu/configuration/shared_translation.h @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include +#include +#include + +class QWidget; + +namespace ConfigurationShared { +using TranslationMap = std::map>; + +std::unique_ptr InitializeTranslations(QWidget* parent); + +std::forward_list ComboboxEnumeration(std::type_index type, QWidget* parent); + +} // namespace ConfigurationShared -- cgit v1.2.3 From f8435d676f0073dee4d2ea87c84767a53911fbe6 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sun, 7 May 2023 12:03:40 -0400 Subject: configure_graphics: Partial runtime implementation --- src/common/settings.h | 2 +- src/yuzu/configuration/configuration_shared.cpp | 72 +- src/yuzu/configuration/configuration_shared.h | 18 +- src/yuzu/configuration/configure_dialog.cpp | 2 +- src/yuzu/configuration/configure_graphics.cpp | 785 +++++++++++---------- src/yuzu/configuration/configure_graphics.h | 16 +- src/yuzu/configuration/configure_graphics.ui | 751 +------------------- .../configuration/configure_graphics_advanced.cpp | 4 +- src/yuzu/configuration/configure_per_game.cpp | 2 +- src/yuzu/configuration/shared_translation.cpp | 9 +- 10 files changed, 513 insertions(+), 1148 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/common/settings.h b/src/common/settings.h index 70ab8d584..8f02fa9af 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -733,7 +733,7 @@ struct Values { linkage, ShaderBackend::GLSL, ShaderBackend::GLSL, ShaderBackend::SPIRV, "shader_backend", Category::Renderer}; SwitchableSetting use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders", - Category::Renderer}; + Category::RendererAdvanced}; SwitchableSetting use_fast_gpu_time{linkage, true, "use_fast_gpu_time", Category::RendererAdvanced}; SwitchableSetting use_vulkan_driver_pipeline_cache{ diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp index dc11a318a..575d239eb 100644 --- a/src/yuzu/configuration/configuration_shared.cpp +++ b/src/yuzu/configuration/configuration_shared.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -55,9 +56,8 @@ static std::pair> CreateCheckBox(Settings::Basic return {checkbox, load_func}; } -static std::pair> CreateCombobox(Settings::BasicSetting* setting, - const QString& label, - QWidget* parent) { +static std::tuple> CreateCombobox( + Settings::BasicSetting* setting, const QString& label, QWidget* parent) { const auto type = setting->TypeId(); QWidget* group = new QWidget(parent); @@ -110,15 +110,34 @@ static std::pair> CreateCombobox(Settings::Basic } }; - return {group, load_func}; + return {group, combobox, load_func}; +} + +static std::tuple> CreateLineEdit( + Settings::BasicSetting* setting, const QString& label, QWidget* parent) { + QWidget* widget = new QWidget(parent); + QHBoxLayout* layout = new QHBoxLayout(widget); + + QLabel* q_label = new QLabel(label, widget); + QLineEdit* line_edit = new QLineEdit(widget); + + layout->addWidget(q_label); + layout->addStretch(); + layout->addWidget(line_edit); + + layout->setContentsMargins(0, 0, 0, 0); + + return {widget, line_edit, []() {}}; } -QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& translations, - QWidget* parent, bool runtime_lock, - std::forward_list>& apply_funcs, - std::list& trackers) { +std::pair CreateWidget(Settings::BasicSetting* setting, + const TranslationMap& translations, QWidget* parent, + bool runtime_lock, + std::forward_list>& apply_funcs, + std::list& trackers, RequestType request) { const auto type = setting->TypeId(); QWidget* widget{nullptr}; + void* extra{nullptr}; std::function load_func; @@ -135,7 +154,7 @@ QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& tra if (label == QStringLiteral("")) { LOG_DEBUG(Frontend, "Translation table has emtpy entry for \"{}\", skipping...", setting->GetLabel()); - return widget; + return {nullptr, nullptr}; } if (type == typeid(bool)) { @@ -143,14 +162,36 @@ QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& tra widget = pair.first; load_func = pair.second; } else if (setting->IsEnum()) { - auto pair = CreateCombobox(setting, label, parent); - widget = pair.first; - load_func = pair.second; + auto tuple = CreateCombobox(setting, label, parent); + widget = std::get<0>(tuple); + extra = std::get<1>(tuple); + load_func = std::get<2>(tuple); + } else if (type == typeid(u32) || type == typeid(int)) { + switch (request) { + case RequestType::Default: { + auto tuple = CreateLineEdit(setting, label, parent); + widget = std::get<0>(tuple); + extra = std::get<1>(tuple); + load_func = std::get<2>(tuple); + break; + } + case RequestType::ComboBox: { + auto tuple = CreateCombobox(setting, label, parent); + widget = std::get<0>(tuple); + extra = std::get<1>(tuple); + load_func = std::get<2>(tuple); + break; + } + case RequestType::SpinBox: + case RequestType::Slider: + case RequestType::MaxEnum: + break; + } } if (widget == nullptr) { LOG_ERROR(Frontend, "No widget was created for \"{}\"", setting->GetLabel()); - return widget; + return {nullptr, nullptr}; } apply_funcs.push_front([load_func, setting](bool powered_on) { @@ -162,13 +203,14 @@ QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& tra bool enable = runtime_lock || setting->RuntimeModfiable(); enable &= setting->Switchable() && !(Settings::IsConfiguringGlobal() && !setting->UsingGlobal()); - + enable |= !setting->Switchable() && Settings::IsConfiguringGlobal() && runtime_lock; widget->setEnabled(enable); + widget->setVisible(Settings::IsConfiguringGlobal() || setting->Switchable()); widget->setToolTip(tooltip); - return widget; + return {widget, extra}; } Tab::Tab(std::shared_ptr> group_, QWidget* parent) diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h index 7040673ea..d0fe6ea38 100644 --- a/src/yuzu/configuration/configuration_shared.h +++ b/src/yuzu/configuration/configuration_shared.h @@ -41,10 +41,20 @@ enum class CheckState { Count, // Simply the number of states, not a valid checkbox state }; -QWidget* CreateWidget(Settings::BasicSetting* setting, const TranslationMap& translations, - QWidget* parent, bool runtime_lock, - std::forward_list>& apply_funcs, - std::list& trackers); +enum class RequestType { + Default, + ComboBox, + SpinBox, + Slider, + MaxEnum, +}; + +std::pair CreateWidget(Settings::BasicSetting* setting, + const TranslationMap& translations, QWidget* parent, + bool runtime_lock, + std::forward_list>& apply_funcs, + std::list& trackers, + RequestType request = RequestType::Default); // Global-aware apply and set functions diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index b3f4764c7..5b356a074 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -43,7 +43,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, std::make_unique(system_, nullptr, *translations, this)}, graphics_tab{std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - nullptr, this)}, + nullptr, *translations, this)}, hotkeys_tab{std::make_unique(system_.HIDCore(), this)}, input_tab{std::make_unique(system_, this)}, network_tab{std::make_unique(system_, this)}, diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index a8c5b1d9f..8128a4047 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -55,100 +55,123 @@ static constexpr VkPresentModeKHR VSyncSettingToMode(Settings::VSyncMode mode) { } } -static constexpr Settings::VSyncMode PresentModeToSetting(VkPresentModeKHR mode) { - switch (mode) { - case VK_PRESENT_MODE_IMMEDIATE_KHR: - return Settings::VSyncMode::Immediate; - case VK_PRESENT_MODE_MAILBOX_KHR: - return Settings::VSyncMode::Mailbox; - case VK_PRESENT_MODE_FIFO_KHR: - return Settings::VSyncMode::FIFO; - case VK_PRESENT_MODE_FIFO_RELAXED_KHR: - return Settings::VSyncMode::FIFORelaxed; - default: - return Settings::VSyncMode::FIFO; - } -} +// static constexpr Settings::VSyncMode PresentModeToSetting(VkPresentModeKHR mode) { +// switch (mode) { +// case VK_PRESENT_MODE_IMMEDIATE_KHR: +// return Settings::VSyncMode::Immediate; +// case VK_PRESENT_MODE_MAILBOX_KHR: +// return Settings::VSyncMode::Mailbox; +// case VK_PRESENT_MODE_FIFO_KHR: +// return Settings::VSyncMode::FIFO; +// case VK_PRESENT_MODE_FIFO_RELAXED_KHR: +// return Settings::VSyncMode::FIFORelaxed; +// default: +// return Settings::VSyncMode::FIFO; +// } +// } ConfigureGraphics::ConfigureGraphics( const Core::System& system_, std::vector& records_, const std::function& expose_compute_option_, - std::shared_ptr> group, QWidget* parent) + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent) : ConfigurationShared::Tab(group, parent), ui{std::make_unique()}, - records{records_}, expose_compute_option{expose_compute_option_}, system{system_} { + records{records_}, expose_compute_option{expose_compute_option_}, system{system_}, + translations{translations_} { vulkan_device = Settings::values.vulkan_device.GetValue(); RetrieveVulkanDevices(); ui->setupUi(this); + SetConfiguration(); + for (const auto& device : vulkan_devices) { - ui->device->addItem(device); + vulkan_device_combobox->addItem(device); } - ui->backend->addItem(QStringLiteral("GLSL")); - ui->backend->addItem(tr("GLASM (Assembly Shaders, NVIDIA Only)")); - ui->backend->addItem(tr("SPIR-V (Experimental, Mesa Only)")); + UpdateBackgroundColorButton(QColor::fromRgb(Settings::values.bg_red.GetValue(), + Settings::values.bg_green.GetValue(), + Settings::values.bg_blue.GetValue())); + UpdateAPILayout(); + PopulateVSyncModeSelection(); //< must happen after UpdateAPILayout + // SetFSRIndicatorText(ui->fsr_sharpening_slider->sliderPosition()); - SetupPerGameUI(); + // VSync setting needs to be determined after populating the VSync combobox + if (Settings::IsConfiguringGlobal()) { + const auto vsync_mode_setting = Settings::values.vsync_mode.GetValue(); + const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting); + int index{}; + for (const auto mode : vsync_mode_combobox_enum_map) { + if (mode == vsync_mode) { + break; + } + index++; + } + if (static_cast(index) < vsync_mode_combobox_enum_map.size()) { + vsync_mode_combobox->setCurrentIndex(index); + } + } - SetConfiguration(); + SetupPerGameUI(); - connect(ui->api, qOverload(&QComboBox::currentIndexChanged), this, [this] { + connect(api_combobox, qOverload(&QComboBox::currentIndexChanged), this, [this] { UpdateAPILayout(); PopulateVSyncModeSelection(); if (!Settings::IsConfiguringGlobal()) { - ConfigurationShared::SetHighlight( - ui->api_widget, ui->api->currentIndex() != ConfigurationShared::USE_GLOBAL_INDEX); + ConfigurationShared::SetHighlight(ui->api_widget, + api_combobox->currentIndex() != + ConfigurationShared::USE_GLOBAL_INDEX); } }); - connect(ui->device, qOverload(&QComboBox::activated), this, [this](int device) { - UpdateDeviceSelection(device); - PopulateVSyncModeSelection(); - }); - connect(ui->backend, qOverload(&QComboBox::activated), this, + connect(vulkan_device_combobox, qOverload(&QComboBox::activated), this, + [this](int device) { + UpdateDeviceSelection(device); + PopulateVSyncModeSelection(); + }); + connect(shader_backend_combobox, qOverload(&QComboBox::activated), this, [this](int backend) { UpdateShaderBackendSelection(backend); }); - connect(ui->bg_button, &QPushButton::clicked, this, [this] { - const QColor new_bg_color = QColorDialog::getColor(bg_color); - if (!new_bg_color.isValid()) { - return; - } - UpdateBackgroundColorButton(new_bg_color); - }); + // connect(ui->bg_button, &QPushButton::clicked, this, [this] { + // const QColor new_bg_color = QColorDialog::getColor(bg_color); + // if (!new_bg_color.isValid()) { + // return; + // } + // UpdateBackgroundColorButton(new_bg_color); + // }); - ui->api->setEnabled(!UISettings::values.has_broken_vulkan && ui->api->isEnabled()); + api_combobox->setEnabled(!UISettings::values.has_broken_vulkan && api_combobox->isEnabled()); ui->api_widget->setEnabled( (!UISettings::values.has_broken_vulkan || Settings::IsConfiguringGlobal()) && ui->api_widget->isEnabled()); - ui->bg_label->setVisible(Settings::IsConfiguringGlobal()); - ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal()); + // ui->bg_label->setVisible(Settings::IsConfiguringGlobal()); + // ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal()); - connect(ui->fsr_sharpening_slider, &QSlider::valueChanged, this, - &ConfigureGraphics::SetFSRIndicatorText); - ui->fsr_sharpening_combobox->setVisible(!Settings::IsConfiguringGlobal()); - ui->fsr_sharpening_label->setVisible(Settings::IsConfiguringGlobal()); + // connect(ui->fsr_sharpening_slider, &QSlider::valueChanged, this, + // &ConfigureGraphics::SetFSRIndicatorText); + // ui->fsr_sharpening_combobox->setVisible(!Settings::IsConfiguringGlobal()); + // ui->fsr_sharpening_label->setVisible(Settings::IsConfiguringGlobal()); } void ConfigureGraphics::PopulateVSyncModeSelection() { const Settings::RendererBackend backend{GetCurrentGraphicsBackend()}; if (backend == Settings::RendererBackend::Null) { - ui->vsync_mode_combobox->setEnabled(false); + vsync_mode_combobox->setEnabled(false); return; } - ui->vsync_mode_combobox->setEnabled(true); + vsync_mode_combobox->setEnabled(true); const int current_index = //< current selected vsync mode from combobox - ui->vsync_mode_combobox->currentIndex(); + vsync_mode_combobox->currentIndex(); const auto current_mode = //< current selected vsync mode as a VkPresentModeKHR current_index == -1 ? VSyncSettingToMode(Settings::values.vsync_mode.GetValue()) : vsync_mode_combobox_enum_map[current_index]; int index{}; - const int device{ui->device->currentIndex()}; //< current selected Vulkan device + const int device{vulkan_device_combobox->currentIndex()}; //< current selected Vulkan device const auto& present_modes = //< relevant vector of present modes for the selected device or API backend == Settings::RendererBackend::Vulkan ? device_present_modes[device] : default_present_modes; - ui->vsync_mode_combobox->clear(); + vsync_mode_combobox->clear(); vsync_mode_combobox_enum_map.clear(); vsync_mode_combobox_enum_map.reserve(present_modes.size()); for (const auto present_mode : present_modes) { @@ -157,10 +180,10 @@ void ConfigureGraphics::PopulateVSyncModeSelection() { continue; } - ui->vsync_mode_combobox->insertItem(index, mode_name); + vsync_mode_combobox->insertItem(index, mode_name); vsync_mode_combobox_enum_map.push_back(present_mode); if (present_mode == current_mode) { - ui->vsync_mode_combobox->setCurrentIndex(index); + vsync_mode_combobox->setCurrentIndex(index); } index++; } @@ -188,114 +211,137 @@ ConfigureGraphics::~ConfigureGraphics() = default; void ConfigureGraphics::SetConfiguration() { const bool runtime_lock = !system.IsPoweredOn(); + QLayout& api_layout = *ui->api_widget->layout(); + QLayout& graphics_layout = *ui->graphics_widget->layout(); - ui->api_widget->setEnabled(runtime_lock); - ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); - ui->use_disk_shader_cache->setEnabled(runtime_lock); - ui->nvdec_emulation_widget->setEnabled(runtime_lock); - ui->resolution_combobox->setEnabled(runtime_lock); - ui->astc_decode_mode_combobox->setEnabled(runtime_lock); - ui->vsync_mode_layout->setEnabled(runtime_lock || - Settings::values.renderer_backend.GetValue() == - Settings::RendererBackend::Vulkan); - ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); - ui->use_asynchronous_gpu_emulation->setChecked( - Settings::values.use_asynchronous_gpu_emulation.GetValue()); + std::map hold_graphics; - if (Settings::IsConfiguringGlobal()) { - ui->api->setCurrentIndex(static_cast(Settings::values.renderer_backend.GetValue())); - ui->fullscreen_mode_combobox->setCurrentIndex( - static_cast(Settings::values.fullscreen_mode.GetValue())); - ui->nvdec_emulation->setCurrentIndex( - static_cast(Settings::values.nvdec_emulation.GetValue())); - ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); - ui->resolution_combobox->setCurrentIndex( - static_cast(Settings::values.resolution_setup.GetValue())); - ui->scaling_filter_combobox->setCurrentIndex( - static_cast(Settings::values.scaling_filter.GetValue())); - ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue()); - ui->anti_aliasing_combobox->setCurrentIndex( - static_cast(Settings::values.anti_aliasing.GetValue())); - } else { - ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); - ConfigurationShared::SetHighlight(ui->api_widget, - !Settings::values.renderer_backend.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->astc_decode_mode_combobox, - &Settings::values.accelerate_astc); - ConfigurationShared::SetHighlight(ui->astc_decode_mode_layout, - !Settings::values.accelerate_astc.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->nvdec_emulation, - &Settings::values.nvdec_emulation); - ConfigurationShared::SetHighlight(ui->nvdec_emulation_widget, - !Settings::values.nvdec_emulation.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->fullscreen_mode_combobox, - &Settings::values.fullscreen_mode); - ConfigurationShared::SetHighlight(ui->fullscreen_mode_label, - !Settings::values.fullscreen_mode.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, - &Settings::values.aspect_ratio); - ConfigurationShared::SetHighlight(ui->ar_label, - !Settings::values.aspect_ratio.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->resolution_combobox, - &Settings::values.resolution_setup); - ConfigurationShared::SetHighlight(ui->resolution_label, - !Settings::values.resolution_setup.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->scaling_filter_combobox, - &Settings::values.scaling_filter); - ConfigurationShared::SetHighlight(ui->scaling_filter_label, - !Settings::values.scaling_filter.UsingGlobal()); - - ConfigurationShared::SetPerGameSetting(ui->anti_aliasing_combobox, - &Settings::values.anti_aliasing); - ConfigurationShared::SetHighlight(ui->anti_aliasing_label, - !Settings::values.anti_aliasing.UsingGlobal()); - - ui->fsr_sharpening_combobox->setCurrentIndex( - Settings::values.fsr_sharpening_slider.UsingGlobal() ? 0 : 1); - ui->fsr_sharpening_slider->setEnabled( - !Settings::values.fsr_sharpening_slider.UsingGlobal()); - ui->fsr_sharpening_value->setEnabled(!Settings::values.fsr_sharpening_slider.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, - !Settings::values.fsr_sharpening_slider.UsingGlobal()); - ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue()); - - ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); - ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal()); - } - UpdateBackgroundColorButton(QColor::fromRgb(Settings::values.bg_red.GetValue(), - Settings::values.bg_green.GetValue(), - Settings::values.bg_blue.GetValue())); - UpdateAPILayout(); - PopulateVSyncModeSelection(); //< must happen after UpdateAPILayout - SetFSRIndicatorText(ui->fsr_sharpening_slider->sliderPosition()); + for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) { + const auto& setting_label = setting->GetLabel(); - // VSync setting needs to be determined after populating the VSync combobox - if (Settings::IsConfiguringGlobal()) { - const auto vsync_mode_setting = Settings::values.vsync_mode.GetValue(); - const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting); - int index{}; - for (const auto mode : vsync_mode_combobox_enum_map) { - if (mode == vsync_mode) { - break; + auto [widget, extra] = [&]() { + if (setting_label == "vulkan_device") { + return ConfigurationShared::CreateWidget( + setting, translations, this, runtime_lock, apply_funcs, trackers, + ConfigurationShared::RequestType::ComboBox); } - index++; + return ConfigurationShared::CreateWidget(setting, translations, this, runtime_lock, + apply_funcs, trackers); + }(); + + if (widget == nullptr) { + continue; } - if (static_cast(index) < vsync_mode_combobox_enum_map.size()) { - ui->vsync_mode_combobox->setCurrentIndex(index); + + if (setting_label == "backend") { + api_layout.addWidget(widget); + api_combobox = reinterpret_cast(extra); + } else if (setting_label == "vulkan_device") { + api_layout.addWidget(widget); + vulkan_device_combobox = reinterpret_cast(extra); + vulkan_device_widget = widget; + } else if (setting_label == "shader_backend") { + api_layout.addWidget(widget); + shader_backend_combobox = reinterpret_cast(extra); + shader_backend_widget = widget; + } else { + hold_graphics.insert(std::pair(setting_label, widget)); } + + if (setting_label == "use_vsync") { + vsync_mode_combobox = reinterpret_cast(extra); + } + } + + for (const auto& [label, widget] : hold_graphics) { + graphics_layout.addWidget(widget); } + + // ui->api_widget->setEnabled(runtime_lock); + // ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); + // ui->use_disk_shader_cache->setEnabled(runtime_lock); + // ui->nvdec_emulation_widget->setEnabled(runtime_lock); + // ui->resolution_combobox->setEnabled(runtime_lock); + // ui->astc_decode_mode_combobox->setEnabled(runtime_lock); + // ui->vsync_mode_layout->setEnabled(runtime_lock || + // Settings::values.renderer_backend.GetValue() == + // Settings::RendererBackend::Vulkan); + // ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); + // ui->use_asynchronous_gpu_emulation->setChecked( + // Settings::values.use_asynchronous_gpu_emulation.GetValue()); + + // if (Settings::IsConfiguringGlobal()) { + // api_combobox->setCurrentIndex(static_cast(Settings::values.renderer_backend.GetValue())); + // ui->fullscreen_mode_combobox->setCurrentIndex( + // static_cast(Settings::values.fullscreen_mode.GetValue())); + // ui->nvdec_emulation->setCurrentIndex( + // static_cast(Settings::values.nvdec_emulation.GetValue())); + // ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); + // ui->resolution_combobox->setCurrentIndex( + // static_cast(Settings::values.resolution_setup.GetValue())); + // ui->scaling_filter_combobox->setCurrentIndex( + // static_cast(Settings::values.scaling_filter.GetValue())); + // ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue()); + // ui->anti_aliasing_combobox->setCurrentIndex( + // static_cast(Settings::values.anti_aliasing.GetValue())); + // } else { + // ConfigurationShared::SetPerGameSetting(api_combobox, &Settings::values.renderer_backend); + // ConfigurationShared::SetHighlight(ui->api_widget, + // !Settings::values.renderer_backend.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->astc_decode_mode_combobox, + // &Settings::values.accelerate_astc); + // ConfigurationShared::SetHighlight(ui->astc_decode_mode_layout, + // !Settings::values.accelerate_astc.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->nvdec_emulation, + // &Settings::values.nvdec_emulation); + // ConfigurationShared::SetHighlight(ui->nvdec_emulation_widget, + // !Settings::values.nvdec_emulation.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->fullscreen_mode_combobox, + // &Settings::values.fullscreen_mode); + // ConfigurationShared::SetHighlight(ui->fullscreen_mode_label, + // !Settings::values.fullscreen_mode.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, + // &Settings::values.aspect_ratio); + // ConfigurationShared::SetHighlight(ui->ar_label, + // !Settings::values.aspect_ratio.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->resolution_combobox, + // &Settings::values.resolution_setup); + // ConfigurationShared::SetHighlight(ui->resolution_label, + // !Settings::values.resolution_setup.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->scaling_filter_combobox, + // &Settings::values.scaling_filter); + // ConfigurationShared::SetHighlight(ui->scaling_filter_label, + // !Settings::values.scaling_filter.UsingGlobal()); + + // ConfigurationShared::SetPerGameSetting(ui->anti_aliasing_combobox, + // &Settings::values.anti_aliasing); + // ConfigurationShared::SetHighlight(ui->anti_aliasing_label, + // !Settings::values.anti_aliasing.UsingGlobal()); + + // ui->fsr_sharpening_combobox->setCurrentIndex( + // Settings::values.fsr_sharpening_slider.UsingGlobal() ? 0 : 1); + // ui->fsr_sharpening_slider->setEnabled( + // !Settings::values.fsr_sharpening_slider.UsingGlobal()); + // ui->fsr_sharpening_value->setEnabled(!Settings::values.fsr_sharpening_slider.UsingGlobal()); + // ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, + // !Settings::values.fsr_sharpening_slider.UsingGlobal()); + // ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue()); + + // ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); + // ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); + // ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal()); + // } } void ConfigureGraphics::SetFSRIndicatorText(int percentage) { - ui->fsr_sharpening_value->setText( - tr("%1%", "FSR sharpening percentage (e.g. 50%)").arg(100 - (percentage / 2))); + // ui->fsr_sharpening_value->setText( + // tr("%1%", "FSR sharpening percentage (e.g. 50%)").arg(100 - (percentage / 2))); } const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode, @@ -320,131 +366,134 @@ const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode, } void ConfigureGraphics::ApplyConfiguration() { - const auto resolution_setup = static_cast( - ui->resolution_combobox->currentIndex() - - ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); - - const auto scaling_filter = static_cast( - ui->scaling_filter_combobox->currentIndex() - - ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); - - const auto anti_aliasing = static_cast( - ui->anti_aliasing_combobox->currentIndex() - - ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); - - ConfigurationShared::ApplyPerGameSetting(&Settings::values.fullscreen_mode, - ui->fullscreen_mode_combobox); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio, - ui->aspect_ratio_combobox); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, - ui->use_disk_shader_cache, use_disk_shader_cache); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, - ui->use_asynchronous_gpu_emulation, - use_asynchronous_gpu_emulation); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.accelerate_astc, - ui->astc_decode_mode_combobox); - - if (Settings::IsConfiguringGlobal()) { - // Guard if during game and set to game-specific value - if (Settings::values.renderer_backend.UsingGlobal()) { - Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); - } - if (Settings::values.nvdec_emulation.UsingGlobal()) { - Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation()); - } - if (Settings::values.shader_backend.UsingGlobal()) { - Settings::values.shader_backend.SetValue(shader_backend); - } - if (Settings::values.vulkan_device.UsingGlobal()) { - Settings::values.vulkan_device.SetValue(vulkan_device); - } - if (Settings::values.bg_red.UsingGlobal()) { - Settings::values.bg_red.SetValue(static_cast(bg_color.red())); - Settings::values.bg_green.SetValue(static_cast(bg_color.green())); - Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); - } - if (Settings::values.resolution_setup.UsingGlobal()) { - Settings::values.resolution_setup.SetValue(resolution_setup); - } - if (Settings::values.scaling_filter.UsingGlobal()) { - Settings::values.scaling_filter.SetValue(scaling_filter); - } - if (Settings::values.anti_aliasing.UsingGlobal()) { - Settings::values.anti_aliasing.SetValue(anti_aliasing); - } - Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value()); - - const auto mode = vsync_mode_combobox_enum_map[ui->vsync_mode_combobox->currentIndex()]; - const auto vsync_mode = PresentModeToSetting(mode); - Settings::values.vsync_mode.SetValue(vsync_mode); - } else { - if (ui->resolution_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.resolution_setup.SetGlobal(true); - } else { - Settings::values.resolution_setup.SetGlobal(false); - Settings::values.resolution_setup.SetValue(resolution_setup); - } - if (ui->scaling_filter_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.scaling_filter.SetGlobal(true); - } else { - Settings::values.scaling_filter.SetGlobal(false); - Settings::values.scaling_filter.SetValue(scaling_filter); - } - if (ui->anti_aliasing_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.anti_aliasing.SetGlobal(true); - } else { - Settings::values.anti_aliasing.SetGlobal(false); - Settings::values.anti_aliasing.SetValue(anti_aliasing); - } - if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.renderer_backend.SetGlobal(true); - Settings::values.shader_backend.SetGlobal(true); - Settings::values.vulkan_device.SetGlobal(true); - } else { - Settings::values.renderer_backend.SetGlobal(false); - Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); - switch (GetCurrentGraphicsBackend()) { - case Settings::RendererBackend::OpenGL: - case Settings::RendererBackend::Null: - Settings::values.shader_backend.SetGlobal(false); - Settings::values.vulkan_device.SetGlobal(true); - Settings::values.shader_backend.SetValue(shader_backend); - break; - case Settings::RendererBackend::Vulkan: - Settings::values.shader_backend.SetGlobal(true); - Settings::values.vulkan_device.SetGlobal(false); - Settings::values.vulkan_device.SetValue(vulkan_device); - break; - } - } - - if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.nvdec_emulation.SetGlobal(true); - } else { - Settings::values.nvdec_emulation.SetGlobal(false); - Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation()); - } - - if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.bg_red.SetGlobal(true); - Settings::values.bg_green.SetGlobal(true); - Settings::values.bg_blue.SetGlobal(true); - } else { - Settings::values.bg_red.SetGlobal(false); - Settings::values.bg_green.SetGlobal(false); - Settings::values.bg_blue.SetGlobal(false); - Settings::values.bg_red.SetValue(static_cast(bg_color.red())); - Settings::values.bg_green.SetValue(static_cast(bg_color.green())); - Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); - } - - if (ui->fsr_sharpening_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.fsr_sharpening_slider.SetGlobal(true); - } else { - Settings::values.fsr_sharpening_slider.SetGlobal(false); - Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value()); - } - } + // const auto resolution_setup = static_cast( + // ui->resolution_combobox->currentIndex() - + // ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); + + // const auto scaling_filter = static_cast( + // ui->scaling_filter_combobox->currentIndex() - + // ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); + + // const auto anti_aliasing = static_cast( + // ui->anti_aliasing_combobox->currentIndex() - + // ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); + + // ConfigurationShared::ApplyPerGameSetting(&Settings::values.fullscreen_mode, + // ui->fullscreen_mode_combobox); + // ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio, + // ui->aspect_ratio_combobox); + // ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, + // ui->use_disk_shader_cache, use_disk_shader_cache); + // ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, + // ui->use_asynchronous_gpu_emulation, + // use_asynchronous_gpu_emulation); + // ConfigurationShared::ApplyPerGameSetting(&Settings::values.accelerate_astc, + // ui->astc_decode_mode_combobox); + + // if (Settings::IsConfiguringGlobal()) { + // // Guard if during game and set to game-specific value + // if (Settings::values.renderer_backend.UsingGlobal()) { + // Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); + // } + // if (Settings::values.nvdec_emulation.UsingGlobal()) { + // Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation()); + // } + // if (Settings::values.shader_backend.UsingGlobal()) { + // Settings::values.shader_backend.SetValue(shader_backend); + // } + // if (Settings::values.vulkan_device.UsingGlobal()) { + // Settings::values.vulkan_device.SetValue(vulkan_device); + // } + // if (Settings::values.bg_red.UsingGlobal()) { + // Settings::values.bg_red.SetValue(static_cast(bg_color.red())); + // Settings::values.bg_green.SetValue(static_cast(bg_color.green())); + // Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); + // } + // if (Settings::values.resolution_setup.UsingGlobal()) { + // Settings::values.resolution_setup.SetValue(resolution_setup); + // } + // if (Settings::values.scaling_filter.UsingGlobal()) { + // Settings::values.scaling_filter.SetValue(scaling_filter); + // } + // if (Settings::values.anti_aliasing.UsingGlobal()) { + // Settings::values.anti_aliasing.SetValue(anti_aliasing); + // } + // Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value()); + + // const auto mode = vsync_mode_combobox_enum_map[vsync_mode_combobox->currentIndex()]; + // const auto vsync_mode = PresentModeToSetting(mode); + // Settings::values.vsync_mode.SetValue(vsync_mode); + // } else { + // if (ui->resolution_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + // Settings::values.resolution_setup.SetGlobal(true); + // } else { + // Settings::values.resolution_setup.SetGlobal(false); + // Settings::values.resolution_setup.SetValue(resolution_setup); + // } + // if (ui->scaling_filter_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) + // { + // Settings::values.scaling_filter.SetGlobal(true); + // } else { + // Settings::values.scaling_filter.SetGlobal(false); + // Settings::values.scaling_filter.SetValue(scaling_filter); + // } + // if (ui->anti_aliasing_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) + // { + // Settings::values.anti_aliasing.SetGlobal(true); + // } else { + // Settings::values.anti_aliasing.SetGlobal(false); + // Settings::values.anti_aliasing.SetValue(anti_aliasing); + // } + // if (api_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + // Settings::values.renderer_backend.SetGlobal(true); + // Settings::values.shader_backend.SetGlobal(true); + // Settings::values.vulkan_device.SetGlobal(true); + // } else { + // Settings::values.renderer_backend.SetGlobal(false); + // Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); + // switch (GetCurrentGraphicsBackend()) { + // case Settings::RendererBackend::OpenGL: + // case Settings::RendererBackend::Null: + // Settings::values.shader_backend.SetGlobal(false); + // Settings::values.vulkan_device.SetGlobal(true); + // Settings::values.shader_backend.SetValue(shader_backend); + // break; + // case Settings::RendererBackend::Vulkan: + // Settings::values.shader_backend.SetGlobal(true); + // Settings::values.vulkan_device.SetGlobal(false); + // Settings::values.vulkan_device.SetValue(vulkan_device); + // break; + // } + // } + + // if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + // Settings::values.nvdec_emulation.SetGlobal(true); + // } else { + // Settings::values.nvdec_emulation.SetGlobal(false); + // Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation()); + // } + + // if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + // Settings::values.bg_red.SetGlobal(true); + // Settings::values.bg_green.SetGlobal(true); + // Settings::values.bg_blue.SetGlobal(true); + // } else { + // Settings::values.bg_red.SetGlobal(false); + // Settings::values.bg_green.SetGlobal(false); + // Settings::values.bg_blue.SetGlobal(false); + // Settings::values.bg_red.SetValue(static_cast(bg_color.red())); + // Settings::values.bg_green.SetValue(static_cast(bg_color.green())); + // Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); + // } + + // if (ui->fsr_sharpening_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) + // { + // Settings::values.fsr_sharpening_slider.SetGlobal(true); + // } else { + // Settings::values.fsr_sharpening_slider.SetGlobal(false); + // Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value()); + // } + // } } void ConfigureGraphics::changeEvent(QEvent* event) { @@ -462,43 +511,43 @@ void ConfigureGraphics::RetranslateUI() { void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) { bg_color = color; - QPixmap pixmap(ui->bg_button->size()); - pixmap.fill(bg_color); + // QPixmap pixmap(ui->bg_button->size()); + // pixmap.fill(bg_color); - const QIcon color_icon(pixmap); - ui->bg_button->setIcon(color_icon); + // const QIcon color_icon(pixmap); + // ui->bg_button->setIcon(color_icon); } void ConfigureGraphics::UpdateAPILayout() { if (!Settings::IsConfiguringGlobal() && - ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + api_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { vulkan_device = Settings::values.vulkan_device.GetValue(true); shader_backend = Settings::values.shader_backend.GetValue(true); - ui->device_widget->setEnabled(false); - ui->backend_widget->setEnabled(false); + vulkan_device_widget->setEnabled(false); + shader_backend_widget->setEnabled(false); } else { vulkan_device = Settings::values.vulkan_device.GetValue(); shader_backend = Settings::values.shader_backend.GetValue(); - ui->device_widget->setEnabled(true); - ui->backend_widget->setEnabled(true); + vulkan_device_widget->setEnabled(true); + shader_backend_widget->setEnabled(true); } switch (GetCurrentGraphicsBackend()) { case Settings::RendererBackend::OpenGL: - ui->backend->setCurrentIndex(static_cast(shader_backend)); - ui->device_widget->setVisible(false); - ui->backend_widget->setVisible(true); + shader_backend_combobox->setCurrentIndex(static_cast(shader_backend)); + vulkan_device_widget->setVisible(false); + shader_backend_widget->setVisible(true); break; case Settings::RendererBackend::Vulkan: - if (static_cast(vulkan_device) < ui->device->count()) { - ui->device->setCurrentIndex(vulkan_device); + if (static_cast(vulkan_device) < vulkan_device_combobox->count()) { + vulkan_device_combobox->setCurrentIndex(vulkan_device); } - ui->device_widget->setVisible(true); - ui->backend_widget->setVisible(false); + vulkan_device_widget->setVisible(true); + shader_backend_widget->setVisible(false); break; case Settings::RendererBackend::Null: - ui->device_widget->setVisible(false); - ui->backend_widget->setVisible(false); + vulkan_device_widget->setVisible(false); + shader_backend_widget->setVisible(false); break; } } @@ -520,92 +569,94 @@ void ConfigureGraphics::RetrieveVulkanDevices() { Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const { if (Settings::IsConfiguringGlobal()) { - return static_cast(ui->api->currentIndex()); + return static_cast(api_combobox->currentIndex()); } - if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + if (api_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { Settings::values.renderer_backend.SetGlobal(true); return Settings::values.renderer_backend.GetValue(); } Settings::values.renderer_backend.SetGlobal(false); - return static_cast(ui->api->currentIndex() - + return static_cast(api_combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET); } Settings::NvdecEmulation ConfigureGraphics::GetCurrentNvdecEmulation() const { - if (Settings::IsConfiguringGlobal()) { - return static_cast(ui->nvdec_emulation->currentIndex()); - } - - if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { - Settings::values.nvdec_emulation.SetGlobal(true); - return Settings::values.nvdec_emulation.GetValue(); - } - Settings::values.nvdec_emulation.SetGlobal(false); - return static_cast(ui->nvdec_emulation->currentIndex() - - ConfigurationShared::USE_GLOBAL_OFFSET); + return Settings::NvdecEmulation::CPU; + // if (Settings::IsConfiguringGlobal()) { + // return static_cast(ui->nvdec_emulation->currentIndex()); + // } + + // if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + // Settings::values.nvdec_emulation.SetGlobal(true); + // return Settings::values.nvdec_emulation.GetValue(); + // } + // Settings::values.nvdec_emulation.SetGlobal(false); + // return static_cast(ui->nvdec_emulation->currentIndex() - + // ConfigurationShared::USE_GLOBAL_OFFSET); } void ConfigureGraphics::SetupPerGameUI() { - if (Settings::IsConfiguringGlobal()) { - ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal()); - ui->device->setEnabled(Settings::values.renderer_backend.UsingGlobal()); - ui->fullscreen_mode_combobox->setEnabled(Settings::values.fullscreen_mode.UsingGlobal()); - ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); - ui->resolution_combobox->setEnabled(Settings::values.resolution_setup.UsingGlobal()); - ui->scaling_filter_combobox->setEnabled(Settings::values.scaling_filter.UsingGlobal()); - ui->fsr_sharpening_slider->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal()); - ui->anti_aliasing_combobox->setEnabled(Settings::values.anti_aliasing.UsingGlobal()); - ui->use_asynchronous_gpu_emulation->setEnabled( - Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); - ui->nvdec_emulation->setEnabled(Settings::values.nvdec_emulation.UsingGlobal()); - ui->astc_decode_mode_combobox->setEnabled(Settings::values.accelerate_astc.UsingGlobal()); - ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal()); - ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal()); - ui->fsr_slider_layout->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal()); - - return; - } - - connect(ui->bg_combobox, qOverload(&QComboBox::activated), this, [this](int index) { - ui->bg_button->setEnabled(index == 1); - ConfigurationShared::SetHighlight(ui->bg_layout, index == 1); - }); - - connect(ui->fsr_sharpening_combobox, qOverload(&QComboBox::activated), this, - [this](int index) { - ui->fsr_sharpening_slider->setEnabled(index == 1); - ui->fsr_sharpening_value->setEnabled(index == 1); - ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, index == 1); - }); - - ConfigurationShared::SetColoredTristate( - ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache); - ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation, - Settings::values.use_asynchronous_gpu_emulation, - use_asynchronous_gpu_emulation); - - ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label, - Settings::values.aspect_ratio.GetValue(true)); - ConfigurationShared::SetColoredComboBox( - ui->fullscreen_mode_combobox, ui->fullscreen_mode_label, - static_cast(Settings::values.fullscreen_mode.GetValue(true))); - ConfigurationShared::SetColoredComboBox( - ui->resolution_combobox, ui->resolution_label, - static_cast(Settings::values.resolution_setup.GetValue(true))); - ConfigurationShared::SetColoredComboBox( - ui->scaling_filter_combobox, ui->scaling_filter_label, - static_cast(Settings::values.scaling_filter.GetValue(true))); - ConfigurationShared::SetColoredComboBox( - ui->anti_aliasing_combobox, ui->anti_aliasing_label, - static_cast(Settings::values.anti_aliasing.GetValue(true))); - ConfigurationShared::SetColoredComboBox( - ui->astc_decode_mode_combobox, ui->astc_decode_mode_label, - static_cast(Settings::values.accelerate_astc.GetValue(true))); - ConfigurationShared::InsertGlobalItem( - ui->api, static_cast(Settings::values.renderer_backend.GetValue(true))); - ConfigurationShared::InsertGlobalItem( - ui->nvdec_emulation, static_cast(Settings::values.nvdec_emulation.GetValue(true))); - - ui->vsync_mode_layout->setVisible(false); + // if (Settings::IsConfiguringGlobal()) { + // api_combobox->setEnabled(Settings::values.renderer_backend.UsingGlobal()); + // vulkan_device_combobox->setEnabled(Settings::values.renderer_backend.UsingGlobal()); + // ui->fullscreen_mode_combobox->setEnabled(Settings::values.fullscreen_mode.UsingGlobal()); + // ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); + // ui->resolution_combobox->setEnabled(Settings::values.resolution_setup.UsingGlobal()); + // ui->scaling_filter_combobox->setEnabled(Settings::values.scaling_filter.UsingGlobal()); + // ui->fsr_sharpening_slider->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal()); + // ui->anti_aliasing_combobox->setEnabled(Settings::values.anti_aliasing.UsingGlobal()); + // ui->use_asynchronous_gpu_emulation->setEnabled( + // Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); + // ui->nvdec_emulation->setEnabled(Settings::values.nvdec_emulation.UsingGlobal()); + // ui->astc_decode_mode_combobox->setEnabled(Settings::values.accelerate_astc.UsingGlobal()); + // ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal()); + // ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal()); + // ui->fsr_slider_layout->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal()); + + // return; + // } + + // connect(ui->bg_combobox, qOverload(&QComboBox::activated), this, [this](int index) { + // ui->bg_button->setEnabled(index == 1); + // ConfigurationShared::SetHighlight(ui->bg_layout, index == 1); + // }); + + // connect(ui->fsr_sharpening_combobox, qOverload(&QComboBox::activated), this, + // [this](int index) { + // ui->fsr_sharpening_slider->setEnabled(index == 1); + // ui->fsr_sharpening_value->setEnabled(index == 1); + // ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, index == 1); + // }); + + // ConfigurationShared::SetColoredTristate( + // ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, + // use_disk_shader_cache); + // ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation, + // Settings::values.use_asynchronous_gpu_emulation, + // use_asynchronous_gpu_emulation); + + // ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label, + // Settings::values.aspect_ratio.GetValue(true)); + // ConfigurationShared::SetColoredComboBox( + // ui->fullscreen_mode_combobox, ui->fullscreen_mode_label, + // static_cast(Settings::values.fullscreen_mode.GetValue(true))); + // ConfigurationShared::SetColoredComboBox( + // ui->resolution_combobox, ui->resolution_label, + // static_cast(Settings::values.resolution_setup.GetValue(true))); + // ConfigurationShared::SetColoredComboBox( + // ui->scaling_filter_combobox, ui->scaling_filter_label, + // static_cast(Settings::values.scaling_filter.GetValue(true))); + // ConfigurationShared::SetColoredComboBox( + // ui->anti_aliasing_combobox, ui->anti_aliasing_label, + // static_cast(Settings::values.anti_aliasing.GetValue(true))); + // ConfigurationShared::SetColoredComboBox( + // ui->astc_decode_mode_combobox, ui->astc_decode_mode_label, + // static_cast(Settings::values.accelerate_astc.GetValue(true))); + // ConfigurationShared::InsertGlobalItem( + // api_combobox, static_cast(Settings::values.renderer_backend.GetValue(true))); + // ConfigurationShared::InsertGlobalItem( + // ui->nvdec_emulation, static_cast(Settings::values.nvdec_emulation.GetValue(true))); + + // ui->vsync_mode_layout->setVisible(false); } diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index adc3faffa..30dfb6163 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -17,6 +17,7 @@ class QEvent; class QObject; +class QComboBox; namespace Settings { enum class NvdecEmulation : u32; @@ -38,6 +39,7 @@ public: std::vector& records, const std::function& expose_compute_option_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent = nullptr); ~ConfigureGraphics() override; @@ -70,10 +72,8 @@ private: std::unique_ptr ui; QColor bg_color; - ConfigurationShared::CheckState use_nvdec_emulation; - ConfigurationShared::CheckState accelerate_astc; - ConfigurationShared::CheckState use_disk_shader_cache; - ConfigurationShared::CheckState use_asynchronous_gpu_emulation; + std::list trackers{}; + std::forward_list> apply_funcs{}; std::vector& records; std::vector vulkan_devices; @@ -86,4 +86,12 @@ private: const std::function& expose_compute_option; const Core::System& system; + const ConfigurationShared::TranslationMap& translations; + + QComboBox* vulkan_device_combobox; + QComboBox* api_combobox; + QComboBox* shader_backend_combobox; + QComboBox* vsync_mode_combobox; + QWidget* vulkan_device_widget; + QWidget* shader_backend_widget; }; diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 91b09625b..565429c98 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui @@ -43,112 +43,6 @@ 6 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Shader Backend: - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Device: - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - API: - - - - - - - - 0 - 0 - - - - - OpenGL - - - - - Vulkan - - - - - None - - - - - - - @@ -168,649 +62,8 @@ - - - Use disk pipeline cache - - - - - - - Use asynchronous GPU emulation - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - VSync Mode: - - - - - - - FIFO (VSync) does not drop frames or exhibit tearing but is limited by the screen refresh rate. -FIFO Relaxed is similar to FIFO but allows tearing as it recovers from a slow down. -Mailbox can have lower latency than FIFO and does not tear but may drop frames. -Immediate (no synchronization) just presents whatever is available and can exhibit tearing. - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - ASTC Texture Decoding Method: - - - - - - - - CPU - - - - - GPU Compute - - - - - CPU Asynchronous (Hack) - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - NVDEC emulation: - - - - - - - - No Video Output - - - - - CPU Video Decoding - - - - - GPU Video Decoding (Default) - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Fullscreen Mode: - - - - - - - - Borderless Windowed - - - - - Exclusive Fullscreen - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Aspect Ratio: - - - - - - - - Default (16:9) - - - - - Force 4:3 - - - - - Force 21:9 - - - - - Force 16:10 - - - - - Stretch to Window - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Resolution: - - - - - - - - 0.5X (360p/540p) [EXPERIMENTAL] - - - - - 0.75X (540p/810p) [EXPERIMENTAL] - - - - - 1X (720p/1080p) - - - - - 1.5X (1080p/1620p) [EXPERIMENTAL] - - - - - 2X (1440p/2160p) - - - - - 3X (2160p/3240p) - - - - - 4X (2880p/4320p) - - - - - 5X (3600p/5400p) - - - - - 6X (4320p/6480p) - - - - - 7X (5040p/7560p) - - - - - 8X (5760p/8640p) - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Window Adapting Filter: - - - - - - - - Nearest Neighbor - - - - - Bilinear - - - - - Bicubic - - - - - Gaussian - - - - - ScaleForce - - - - - AMD FidelityFX™️ Super Resolution - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Anti-Aliasing Method: - - - - - - - - None - - - - - FXAA - - - - - SMAA - - - - - - - - - - - true - - - - 0 - 0 - - - - - 6 - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - Use global FSR Sharpness - - - - - Set FSR Sharpness - - - - - - - - - 0 - 0 - - - - FSR Sharpness: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 6 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - 200 - - - 25 - - - Qt::Horizontal - - - true - - - - - - - - 0 - 0 - - - - - 32 - 0 - - - - 100% - - - Qt::AlignCenter - - - - - - - - - - - - - 0 - 0 - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Use global background color - - - 0 - - - 10 - - - - Use global background color - - - - - Set background color: - - - - - - - - Background Color: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 40 - 16777215 - - - - - + + diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index 7d79044d4..8a9495109 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -32,8 +32,8 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { for (auto setting : Settings::values.linkage.by_category[Settings::Category::RendererAdvanced]) { - QWidget* widget = ConfigurationShared::CreateWidget(setting, translations, this, - runtime_lock, apply_funcs, trackers); + auto [widget, extra] = ConfigurationShared::CreateWidget( + setting, translations, this, runtime_lock, apply_funcs, trackers); if (widget == nullptr) { continue; diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 339768017..9e229977d 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -58,7 +58,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st std::make_unique(system_, tab_group, *translations, this); graphics_tab = std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - tab_group, this); + tab_group, *translations, this); input_tab = std::make_unique(system_, game_config.get(), this); system_tab = std::make_unique(system_, tab_group, this); diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index ddc7569f1..73c3086ae 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -36,6 +36,7 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { // Cpu INSERT("cpu_accuracy", "Accuracy:", ""); + INSERT("cpu_accuracy_first_time", "", ""); // Cpu Debug INSERT("cpu_debug_mode", "Enable CPU Debugging", ""); @@ -75,13 +76,16 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { INSERT("use_disk_shader_cache", "Use disk pipeline cache", ""); INSERT("use_asynchronous_gpu_emulation", "Use asynchronous GPU emulation", ""); INSERT("nvdec_emulation", "NVDEC emulation:", ""); - INSERT("acclerate_astc", "ASTC Decoding Method:", ""); + INSERT("accelerate_astc", "ASTC Decoding Method:", ""); INSERT( "use_vsync", "VSync Mode:", "FIFO (VSync) does not drop frames or exhibit tearing but is limited by the screen refresh " "rate. FIFO Relaxed is similar to FIFO but allows tearing as it recovers from a slow down. " "Mailbox can have lower latency than FIFO and does not tear but may drop frames. Immediate " "(no synchronization) just presents whatever is available and can exhibit tearing."); + INSERT("bg_red", "", ""); + INSERT("bg_green", "", ""); + INSERT("bg_blue", "", ""); // Renderer (Advanced Graphics) INSERT("async_presentation", "Enable asynchronous presentation (Vulkan only)", ""); @@ -104,9 +108,6 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { "Enable compute pipelines, required by some games.\nThis setting only exists for Intel " "proprietary drivers, and may crash if enabled.\nCompute pipelines are always enabled " "on all other drivers."); - INSERT("bg_red", "Background Color:", ""); - INSERT("bg_green", "Background Color:", ""); - INSERT("bg_blue", "Background Color:", ""); // Renderer (Debug) INSERT("debug", "Enable Graphics Debugging", -- cgit v1.2.3 From 827082c5ac30ff488016d168e3ca93021eb612e4 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Tue, 9 May 2023 01:38:01 -0400 Subject: configure_general: Generate UI using containers This leaves per-game config's General tab empty? --- src/yuzu/configuration/configure_dialog.cpp | 2 +- src/yuzu/configuration/configure_general.cpp | 105 +++++--------------------- src/yuzu/configuration/configure_general.h | 8 +- src/yuzu/configuration/configure_general.ui | 87 ++++----------------- src/yuzu/configuration/configure_per_game.cpp | 2 +- 5 files changed, 41 insertions(+), 163 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 5b356a074..8baa8de1e 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -38,7 +38,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, cpu_tab{std::make_unique(system_, nullptr, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, - general_tab{std::make_unique(system_, nullptr, this)}, + general_tab{std::make_unique(system_, nullptr, *translations, this)}, graphics_advanced_tab{ std::make_unique(system_, nullptr, *translations, this)}, graphics_tab{std::make_unique( diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 764ff68b3..743ea824c 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp @@ -9,23 +9,19 @@ #include "ui_configure_general.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_general.h" +#include "yuzu/configuration/shared_widget.h" #include "yuzu/uisettings.h" ConfigureGeneral::ConfigureGeneral( const Core::System& system_, - std::shared_ptr> group, QWidget* parent) - : Tab(group, parent), ui{std::make_unique()}, system{system_} { + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent) + : Tab(group, parent), ui{std::make_unique()}, system{system_}, + translations{translations_} { ui->setupUi(this); - SetupPerGameUI(); - SetConfiguration(); - // if (Settings::IsConfiguringGlobal()) { - // connect(ui->toggle_speed_limit, &QCheckBox::clicked, ui->speed_limit, - // [this]() { ui->speed_limit->setEnabled(ui->toggle_speed_limit->isChecked()); }); - // } - connect(ui->button_reset_defaults, &QPushButton::clicked, this, &ConfigureGeneral::ResetDefaults); } @@ -34,29 +30,20 @@ ConfigureGeneral::~ConfigureGeneral() = default; void ConfigureGeneral::SetConfiguration() { const bool runtime_lock = !system.IsPoweredOn(); + QLayout& layout = *ui->general_widget->layout(); - ui->use_multi_core->setEnabled(runtime_lock); - ui->use_multi_core->setChecked(Settings::values.use_multi_core.GetValue()); - - ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing.GetValue()); - ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot.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_controller_applet_disabled->setEnabled(runtime_lock); - ui->toggle_controller_applet_disabled->setChecked( - UISettings::values.controller_applet_disabled.GetValue()); - - // ui->toggle_speed_limit->setChecked(Settings::values.use_speed_limit.GetValue()); - // ui->speed_limit->setValue(Settings::values.speed_limit.GetValue()); + for (const auto setting : + UISettings::values.linkage.by_category[Settings::Category::UiGeneral]) { + ConfigurationShared::Widget* widget = + new ConfigurationShared::Widget(setting, translations, this, runtime_lock, apply_funcs); - ui->button_reset_defaults->setEnabled(runtime_lock); + if (!widget->Valid()) { + delete widget; + continue; + } - // if (Settings::IsConfiguringGlobal()) { - // ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue()); - // } else { - // ui->speed_limit->setEnabled(Settings::values.use_speed_limit.GetValue() && - // use_speed_limit != ConfigurationShared::CheckState::Global); - // } + layout.addWidget(widget); + } } // Called to set the callback when resetting settings to defaults @@ -79,32 +66,9 @@ void ConfigureGeneral::ResetDefaults() { } void ConfigureGeneral::ApplyConfiguration() { - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core, - use_multi_core); - - if (Settings::IsConfiguringGlobal()) { - UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); - UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked(); - UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked(); - UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked(); - UISettings::values.controller_applet_disabled = - ui->toggle_controller_applet_disabled->isChecked(); - - // Guard if during game and set to game-specific value - // if (Settings::values.use_speed_limit.UsingGlobal()) { - // Settings::values.use_speed_limit.SetValue(ui->toggle_speed_limit->checkState() == - // Qt::Checked); - // Settings::values.speed_limit.SetValue(ui->speed_limit->value()); - // } - } else { - // bool global_speed_limit = use_speed_limit == ConfigurationShared::CheckState::Global; - // Settings::values.use_speed_limit.SetGlobal(global_speed_limit); - // Settings::values.speed_limit.SetGlobal(global_speed_limit); - // if (!global_speed_limit) { - // Settings::values.use_speed_limit.SetValue(ui->toggle_speed_limit->checkState() == - // Qt::Checked); - // Settings::values.speed_limit.SetValue(ui->speed_limit->value()); - // } + bool powered_on = system.IsPoweredOn(); + for (const auto& func : apply_funcs) { + func(powered_on); } } @@ -119,34 +83,3 @@ void ConfigureGeneral::changeEvent(QEvent* event) { void ConfigureGeneral::RetranslateUI() { ui->retranslateUi(this); } - -void ConfigureGeneral::SetupPerGameUI() { - if (Settings::IsConfiguringGlobal()) { - // Disables each setting if: - // - A game is running (thus settings in use), and - // - A non-global setting is applied. - // ui->toggle_speed_limit->setEnabled(Settings::values.use_speed_limit.UsingGlobal()); - // ui->speed_limit->setEnabled(Settings::values.speed_limit.UsingGlobal()); - - return; - } - - ui->toggle_check_exit->setVisible(false); - ui->toggle_user_on_boot->setVisible(false); - ui->toggle_background_pause->setVisible(false); - ui->toggle_hide_mouse->setVisible(false); - ui->toggle_controller_applet_disabled->setVisible(false); - - ui->button_reset_defaults->setVisible(false); - - // ConfigurationShared::SetColoredTristate(ui->toggle_speed_limit, - // Settings::values.use_speed_limit, use_speed_limit); - ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core, - use_multi_core); - - // connect(ui->toggle_speed_limit, &QCheckBox::clicked, ui->speed_limit, [this]() { - // ui->speed_limit->setEnabled(ui->toggle_speed_limit->isChecked() && - // (use_speed_limit != - // ConfigurationShared::CheckState::Global)); - // }); -} diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 0aad69f0a..7692c16da 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h @@ -7,6 +7,7 @@ #include #include #include "yuzu/configuration/configuration_shared.h" +#include "yuzu/configuration/shared_widget.h" namespace Core { class System; @@ -23,6 +24,7 @@ class ConfigureGeneral : public ConfigurationShared::Tab { public: explicit ConfigureGeneral(const Core::System& system_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent = nullptr); ~ConfigureGeneral() override; @@ -35,14 +37,12 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void SetupPerGameUI(); - std::function reset_callback; std::unique_ptr ui; - ConfigurationShared::CheckState use_speed_limit; - ConfigurationShared::CheckState use_multi_core; + std::forward_list> apply_funcs{}; const Core::System& system; + const ConfigurationShared::TranslationMap& translations; }; diff --git a/src/yuzu/configuration/configure_general.ui b/src/yuzu/configuration/configure_general.ui index fe757d011..a10e7d3a5 100644 --- a/src/yuzu/configuration/configure_general.ui +++ b/src/yuzu/configuration/configure_general.ui @@ -26,77 +26,22 @@ - - - - - - - Limit Speed Percent - - - - - - - % - - - 1 - - - 9999 - - - 100 - - - - - - - - - Multicore CPU Emulation - - - - - - - Confirm exit while emulation is running - - - - - - - Prompt for user on game boot - - - - - - - Pause emulation when in background - - - - - - - Hide mouse on inactivity - - - - - - - Disable controller applet - - - - + + + + 0 + + + 0 + + + 0 + + + 0 + + + diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 9e229977d..05da9bda0 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -53,7 +53,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st addons_tab = std::make_unique(system_, this); audio_tab = std::make_unique(system_, tab_group, this); cpu_tab = std::make_unique(system_, tab_group, this); - general_tab = std::make_unique(system_, tab_group, this); + general_tab = std::make_unique(system_, tab_group, *translations, this); graphics_advanced_tab = std::make_unique(system_, tab_group, *translations, this); graphics_tab = std::make_unique( -- cgit v1.2.3 From 8e151460265f04c7bf4a981b5f97f252a0444c27 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 10 May 2023 17:57:25 -0400 Subject: configure_system: Implement with for loop --- src/common/settings.cpp | 1 + src/common/settings.h | 114 +++++- src/core/core.cpp | 20 +- src/core/file_sys/control_metadata.cpp | 3 +- src/core/file_sys/patch_manager.cpp | 4 +- src/core/hle/service/ns/ns.cpp | 2 +- src/core/hle/service/set/set.cpp | 10 +- src/yuzu/configuration/config.cpp | 2 + src/yuzu/configuration/configure_dialog.cpp | 2 +- src/yuzu/configuration/configure_graphics.cpp | 2 +- src/yuzu/configuration/configure_per_game.cpp | 2 +- src/yuzu/configuration/configure_system.cpp | 232 +++++------- src/yuzu/configuration/configure_system.h | 17 +- src/yuzu/configuration/configure_system.ui | 509 +++----------------------- src/yuzu/configuration/shared_translation.cpp | 43 ++- src/yuzu/configuration/shared_widget.cpp | 179 ++++++++- src/yuzu/configuration/shared_widget.h | 13 +- src/yuzu_cmd/config.cpp | 1 + 18 files changed, 508 insertions(+), 648 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/common/settings.cpp b/src/common/settings.cpp index b7a0c063f..605fe7f86 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -162,6 +162,7 @@ const char* TranslateCategory(Category category) { case Category::RendererDebug: return "Renderer"; case Category::System: + case Category::SystemAudio: return "System"; case Category::DataStorage: return "Data Storage"; diff --git a/src/common/settings.h b/src/common/settings.h index fdadb06a1..1f95bd7d5 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -20,6 +20,86 @@ namespace Settings { +enum class Language : u32 { + Japanese, + EnglishAmerican, + French, + German, + Italian, + Spanish, + Chinese, + Korean, + Dutch, + Portuguese, + Russian, + Taiwanese, + EnglishBritish, + FrenchCanadian, + SpanishLatin, + ChineseSimplified, + ChineseTraditional, + PortugueseBrazilian, +}; + +enum class Region : u32 { + Japan, + USA, + Europe, + Australia, + China, + Korea, + Taiwan, +}; + +enum class TimeZone : u32 { + Auto, + Default, + CET, + CST6CDT, + Cuba, + EET, + Egypt, + Eire, + EST, + EST5EDT, + GB, + GBEire, + GMT, + GMTPlusZero, + GMTMinusZero, + GMTZero, + Greenwich, + Hongkong, + HST, + Iceland, + Iran, + Israel, + Jamaica, + Japan, + Kwajalein, + Libya, + MET, + MST, + MST7MDT, + Navajo, + NZ, + NZCHAT, + Poland, + Portugal, + PRC, + PST8PDT, + ROC, + ROK, + Singapore, + Turkey, + UCT, + Universal, + UTC, + W_SU, + WET, + Zulu, +}; + enum class AnisotropyMode : u32 { Automatic = 0, Default = 1, @@ -134,6 +214,7 @@ enum class Category : u32 { RendererAdvanced, RendererDebug, System, + SystemAudio, DataStorage, Debugging, DebuggingGraphics, @@ -810,22 +891,31 @@ struct Values { SwitchableSetting bg_blue{linkage, 0, "bg_blue", Category::Renderer, true, true}; // System - SwitchableSetting rng_seed_enabled{linkage, false, "rng_seed_enabled", Category::System}; - SwitchableSetting rng_seed{linkage, 0, "rng_seed", Category::System}; - Setting device_name{linkage, "Yuzu", "device_name", Category::System}; + SwitchableSetting rng_seed_enabled{linkage, false, "rng_seed_enabled", + Category::System, true, true}; + SwitchableSetting rng_seed{linkage, 0, "rng_seed", Category::System, true, true}; + Setting device_name{linkage, "Yuzu", "device_name", Category::System, true, true}; // Measured in seconds since epoch - Setting custom_rtc_enabled{linkage, false, "custom_rtc_enabled", Category::System}; - Setting custom_rtc{linkage, 0, "custom_rtc", Category::System}; + SwitchableSetting custom_rtc_enabled{linkage, false, "custom_rtc_enabled", + Category::System, true, true}; + SwitchableSetting custom_rtc{linkage, 0, "custom_rtc", Category::System, true, true}; // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` s64 custom_rtc_differential; Setting current_user{linkage, 0, "current_user", Category::System}; - SwitchableSetting language_index{linkage, 1, 0, 17, "language_index", - Category::System}; - SwitchableSetting region_index{linkage, 1, 0, 6, "region_index", Category::System}; - SwitchableSetting time_zone_index{linkage, 0, 0, 45, "time_zone_index", - Category::System}; - SwitchableSetting sound_index{linkage, 1, 0, 2, "sound_index", Category::System}; + SwitchableSetting language_index{linkage, + Language::EnglishAmerican, + Language::Japanese, + Language::PortugueseBrazilian, + "language_index", + Category::System}; + SwitchableSetting region_index{linkage, Region::USA, Region::Japan, + Region::Taiwan, "region_index", Category::System}; + SwitchableSetting time_zone_index{linkage, TimeZone::Auto, + TimeZone::Auto, TimeZone::Zulu, + "time_zone_index", Category::System}; + SwitchableSetting sound_index{ + linkage, 1, 0, 2, "sound_index", Category::SystemAudio}; SwitchableSetting use_docked_mode{linkage, true, "use_docked_mode", Category::System}; @@ -837,7 +927,7 @@ struct Values { #ifdef _WIN32 true #else - false + false #endif }; Setting controller_navigation{linkage, true, "controller_navigation", Category::Controls}; diff --git a/src/core/core.cpp b/src/core/core.cpp index da1baa892..e2902a91f 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -145,13 +145,7 @@ struct System::Impl { core_timing.SetMulticore(is_multicore); core_timing.Initialize([&system]() { system.RegisterHostThread(); }); - const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); - const auto current_time = - std::chrono::duration_cast(posix_time).count(); - Settings::values.custom_rtc_differential = - (Settings::values.custom_rtc_enabled ? Settings::values.custom_rtc.GetValue() - : current_time) - - current_time; + RefreshTime(); // Create a default fs if one doesn't already exist. if (virtual_filesystem == nullptr) { @@ -188,6 +182,16 @@ struct System::Impl { Initialize(system); } + void RefreshTime() { + const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); + const auto current_time = + std::chrono::duration_cast(posix_time).count(); + Settings::values.custom_rtc_differential = + (Settings::values.custom_rtc_enabled ? Settings::values.custom_rtc.GetValue() + : current_time) - + current_time; + } + void Run() { std::unique_lock lk(suspend_guard); @@ -1022,6 +1026,8 @@ void System::Exit() { } void System::ApplySettings() { + impl->RefreshTime(); + if (IsPoweredOn()) { Renderer().RefreshBaseSettings(); } diff --git a/src/core/file_sys/control_metadata.cpp b/src/core/file_sys/control_metadata.cpp index cd9ac2e75..0697c29ae 100644 --- a/src/core/file_sys/control_metadata.cpp +++ b/src/core/file_sys/control_metadata.cpp @@ -68,7 +68,8 @@ NACP::NACP(VirtualFile file) { NACP::~NACP() = default; const LanguageEntry& NACP::GetLanguageEntry() const { - Language language = language_to_codes[Settings::values.language_index.GetValue()]; + Language language = + language_to_codes[static_cast(Settings::values.language_index.GetValue())]; { const auto& language_entry = raw.language_entries.at(static_cast(language)); diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index d3286b352..2ba1b34a4 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -626,8 +626,8 @@ PatchManager::Metadata PatchManager::ParseControlNCA(const NCA& nca) const { auto nacp = nacp_file == nullptr ? nullptr : std::make_unique(nacp_file); // Get language code from settings - const auto language_code = - Service::Set::GetLanguageCodeFromIndex(Settings::values.language_index.GetValue()); + const auto language_code = Service::Set::GetLanguageCodeFromIndex( + static_cast(Settings::values.language_index.GetValue())); // Convert to application language and get priority list const auto application_language = diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 376067a95..91c5a2182 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -409,7 +409,7 @@ ResultVal IApplicationManagerInterface::GetApplicationDesiredLanguage( // Get language code from settings const auto language_code = - Set::GetLanguageCodeFromIndex(Settings::values.language_index.GetValue()); + Set::GetLanguageCodeFromIndex(static_cast(Settings::values.language_index.GetValue())); // Convert to application language, get priority list const auto application_language = ConvertToApplicationLanguage(language_code); diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index f5788b481..83f888c54 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -93,7 +93,8 @@ void GetAvailableLanguageCodesImpl(HLERequestContext& ctx, std::size_t max_entri } void GetKeyCodeMapImpl(HLERequestContext& ctx) { - const auto language_code = available_language_codes[Settings::values.language_index.GetValue()]; + const auto language_code = + available_language_codes[static_cast(Settings::values.language_index.GetValue())]; const auto key_code = std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), [=](const auto& element) { return element.first == language_code; }); @@ -162,7 +163,7 @@ void SET::GetQuestFlag(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push(static_cast(Settings::values.quest_flag.GetValue())); + rb.Push(static_cast(Settings::values.quest_flag.GetValue())); } void SET::GetLanguageCode(HLERequestContext& ctx) { @@ -170,7 +171,8 @@ void SET::GetLanguageCode(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); - rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]); + rb.PushEnum( + available_language_codes[static_cast(Settings::values.language_index.GetValue())]); } void SET::GetRegionCode(HLERequestContext& ctx) { @@ -178,7 +180,7 @@ void SET::GetRegionCode(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push(Settings::values.region_index.GetValue()); + rb.Push(static_cast(Settings::values.region_index.GetValue())); } void SET::GetKeyCodeMap(HLERequestContext& ctx) { diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 3181a9528..28ee5d492 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -696,6 +696,7 @@ void Config::ReadSystemValues() { qt_config->beginGroup(QStringLiteral("System")); ReadCategory(Settings::Category::System); + ReadCategory(Settings::Category::SystemAudio); qt_config->endGroup(); } @@ -1134,6 +1135,7 @@ void Config::SaveSystemValues() { qt_config->beginGroup(QStringLiteral("System")); WriteCategory(Settings::Category::System); + WriteCategory(Settings::Category::SystemAudio); qt_config->endGroup(); } diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 8baa8de1e..3a94fee9e 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -48,7 +48,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, input_tab{std::make_unique(system_, this)}, network_tab{std::make_unique(system_, this)}, profile_tab{std::make_unique(system_, this)}, - system_tab{std::make_unique(system_, nullptr, this)}, + system_tab{std::make_unique(system_, nullptr, *translations, this)}, ui_tab{std::make_unique(system_, this)}, web_tab{std::make_unique( this)} { Settings::SetConfiguringGlobal(true); diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index ae3cf269f..977aed42d 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -240,7 +240,7 @@ void ConfigureGraphics::Setup() { return new ConfigurationShared::Widget( setting, translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::SpinBox, true, 1.0f, - &Settings::values.speed_limit, QStringLiteral("%")); + &Settings::values.speed_limit, "%"); } else { return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, apply_funcs); diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 5548fc2ba..c39855334 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -58,7 +58,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, tab_group, *translations, this); input_tab = std::make_unique(system_, game_config.get(), this); - system_tab = std::make_unique(system_, tab_group, this); + system_tab = std::make_unique(system_, tab_group, *translations, this); ui->setupUi(this); diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 4872a475b..dedbad57f 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -2,17 +2,22 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include +#include #include #include +#include #include #include "common/settings.h" #include "core/core.h" #include "core/hle/service/time/time_manager.h" #include "ui_configure_system.h" +#include "yuzu/configuration/config.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_system.h" +#include "yuzu/configuration/shared_widget.h" constexpr std::array LOCALE_BLOCKLIST{ // pzzefezrpnkzeidfej @@ -39,44 +44,42 @@ static bool IsValidLocale(u32 region_index, u32 language_index) { ConfigureSystem::ConfigureSystem( Core::System& system_, std::shared_ptr> group, - QWidget* parent) - : Tab(group, parent), ui{std::make_unique()}, system{system_} { + ConfigurationShared::TranslationMap& translations_, QWidget* parent) + : Tab(group, parent), ui{std::make_unique()}, system{system_}, + translations{translations_} { ui->setupUi(this); - connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) { - ui->rng_seed_edit->setEnabled(state == Qt::Checked); + Setup(); + + connect(rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) { + rng_seed_edit->setEnabled(state == Qt::Checked); if (state != Qt::Checked) { - ui->rng_seed_edit->setText(QStringLiteral("00000000")); + rng_seed_edit->setText(QStringLiteral("00000000")); } }); - connect(ui->custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) { - ui->custom_rtc_edit->setEnabled(state == Qt::Checked); + connect(custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) { + custom_rtc_edit->setEnabled(state == Qt::Checked); if (state != Qt::Checked) { - ui->custom_rtc_edit->setDateTime(QDateTime::currentDateTime()); + custom_rtc_edit->setDateTime(QDateTime::currentDateTime()); } }); const auto locale_check = [this](int index) { - const auto region_index = ConfigurationShared::GetComboboxIndex( - Settings::values.region_index.GetValue(true), ui->combo_region); - const auto language_index = ConfigurationShared::GetComboboxIndex( - Settings::values.language_index.GetValue(true), ui->combo_language); + const auto region_index = combo_region->currentIndex(); + const auto language_index = combo_language->currentIndex(); 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\"") - .arg(ui->combo_language->currentText()) - .arg(ui->combo_region->currentText())); + .arg(combo_language->currentText()) + .arg(combo_region->currentText())); } }; - connect(ui->combo_language, qOverload(&QComboBox::currentIndexChanged), this, - locale_check); - connect(ui->combo_region, qOverload(&QComboBox::currentIndexChanged), this, locale_check); - - SetupPerGameUI(); + connect(combo_language, qOverload(&QComboBox::currentIndexChanged), this, locale_check); + connect(combo_region, qOverload(&QComboBox::currentIndexChanged), this, locale_check); SetConfiguration(); } @@ -95,137 +98,94 @@ void ConfigureSystem::RetranslateUI() { ui->retranslateUi(this); } -void ConfigureSystem::SetConfiguration() { - enabled = !system.IsPoweredOn(); - const auto rng_seed = QStringLiteral("%1") - .arg(Settings::values.rng_seed.GetValue(), 8, 16, QLatin1Char{'0'}) - .toUpper(); - const auto rtc_time = Settings::values.custom_rtc_enabled - ? Settings::values.custom_rtc.GetValue() - : QDateTime::currentSecsSinceEpoch(); - - ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed_enabled.GetValue()); - ui->rng_seed_edit->setEnabled(Settings::values.rng_seed_enabled.GetValue() && - Settings::values.rng_seed.UsingGlobal()); - ui->rng_seed_edit->setText(rng_seed); - - ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc_enabled.GetValue()); - ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc_enabled.GetValue()); - ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time)); - ui->device_name_edit->setText( - QString::fromUtf8(Settings::values.device_name.GetValue().c_str())); - ui->use_unsafe_extended_memory_layout->setEnabled(enabled); - ui->use_unsafe_extended_memory_layout->setChecked( - Settings::values.use_unsafe_extended_memory_layout.GetValue()); - - if (Settings::IsConfiguringGlobal()) { - 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()); - } 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::SetHighlight(ui->label_language, - !Settings::values.language_index.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->label_region, - !Settings::values.region_index.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->label_timezone, - !Settings::values.time_zone_index.UsingGlobal()); - } -} +void ConfigureSystem::Setup() { + const bool runtime_lock = !system.IsPoweredOn(); + auto& core_layout = *ui->core_widget->layout(); + auto& system_layout = *ui->system_widget->layout(); -void ConfigureSystem::ReadSystemSettings() {} + std::map core_hold{}; + std::map> system_hold{}; -void ConfigureSystem::ApplyConfiguration() { - // Allow setting custom RTC even if system is powered on, - // to allow in-game time to be fast forwarded - if (Settings::IsConfiguringGlobal()) { - if (ui->custom_rtc_checkbox->isChecked()) { - Settings::values.custom_rtc_enabled = true; - Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch(); - if (system.IsPoweredOn()) { - const s64 posix_time{Settings::values.custom_rtc.GetValue() + - Service::Time::TimeManager::GetExternalTimeZoneOffset()}; - system.GetTimeManager().UpdateLocalSystemClockTime(posix_time); - } - } else { - Settings::values.custom_rtc_enabled = false; + std::forward_list settings; + auto push = [&settings](std::forward_list& list) { + for (auto setting : list) { + settings.push_front(setting); } - } + }; - Settings::values.device_name = ui->device_name_edit->text().toStdString(); + push(Settings::values.linkage.by_category[Settings::Category::Core]); + push(Settings::values.linkage.by_category[Settings::Category::System]); + + for (auto setting : settings) { + ConfigurationShared::Widget* widget = [=]() { + if (setting->Id() == Settings::values.custom_rtc_enabled.Id()) { + return new ConfigurationShared::Widget( + setting, translations, this, runtime_lock, apply_funcs, + ConfigurationShared::RequestType::DateTimeEdit, true, 1.0f, + &Settings::values.custom_rtc); + } else if (setting->Id() == Settings::values.rng_seed_enabled.Id()) { + return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, + apply_funcs, + ConfigurationShared::RequestType::HexEdit, + true, 1.0f, &Settings::values.rng_seed); + } else { + return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, + + apply_funcs); + } + }(); - if (!enabled) { - return; - } + if (!widget->Valid()) { + delete widget; + continue; + } + + if (setting->Id() == Settings::values.rng_seed_enabled.Id()) { + rng_seed_checkbox = widget->checkbox; + rng_seed_edit = widget->line_edit; - ConfigurationShared::ApplyPerGameSetting(&Settings::values.language_index, ui->combo_language); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.region_index, ui->combo_region); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.time_zone_index, - ui->combo_time_zone); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_unsafe_extended_memory_layout, - ui->use_unsafe_extended_memory_layout, - use_unsafe_extended_memory_layout); - - if (Settings::IsConfiguringGlobal()) { - // Guard if during game and set to game-specific value - if (Settings::values.rng_seed.UsingGlobal()) { - Settings::values.rng_seed_enabled = ui->rng_seed_checkbox->isChecked(); - if (ui->rng_seed_checkbox->isChecked()) { - Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16)); + if (!Settings::values.rng_seed_enabled.GetValue()) { + rng_seed_edit->setEnabled(false); } + } else if (setting->Id() == Settings::values.custom_rtc_enabled.Id()) { + 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; } - } else { - switch (use_rng_seed) { - case ConfigurationShared::CheckState::On: - case ConfigurationShared::CheckState::Off: - Settings::values.rng_seed_enabled.SetGlobal(false); - Settings::values.rng_seed.SetGlobal(false); - if (ui->rng_seed_checkbox->isChecked()) { - Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16)); - } - break; - case ConfigurationShared::CheckState::Global: - Settings::values.rng_seed_enabled.SetGlobal(true); - Settings::values.rng_seed.SetGlobal(true); + + switch (setting->Category()) { + case Settings::Category::Core: + core_hold[setting->GetLabel()] = widget; break; - case ConfigurationShared::CheckState::Count: + case Settings::Category::System: + system_hold[setting->IsEnum()].insert(std::pair{setting->GetLabel(), widget}); break; + default: + delete widget; } } + 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); + } } -void ConfigureSystem::SetupPerGameUI() { - if (Settings::IsConfiguringGlobal()) { - 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->rng_seed_checkbox->setEnabled(Settings::values.rng_seed.UsingGlobal()); - ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.UsingGlobal()); +void ConfigureSystem::SetConfiguration() {} - return; +void ConfigureSystem::ApplyConfiguration() { + const bool powered_on = system.IsPoweredOn(); + for (const auto& func : apply_funcs) { + func(powered_on); } - - ConfigurationShared::SetColoredComboBox(ui->combo_language, ui->label_language, - Settings::values.language_index.GetValue(true)); - ConfigurationShared::SetColoredComboBox(ui->combo_region, ui->label_region, - Settings::values.region_index.GetValue(true)); - ConfigurationShared::SetColoredComboBox(ui->combo_time_zone, ui->label_timezone, - Settings::values.time_zone_index.GetValue(true)); - - ConfigurationShared::SetColoredTristate( - ui->rng_seed_checkbox, Settings::values.rng_seed.UsingGlobal(), - Settings::values.rng_seed_enabled.GetValue(), - Settings::values.rng_seed_enabled.GetValue(true), use_rng_seed); - - ConfigurationShared::SetColoredTristate(ui->use_unsafe_extended_memory_layout, - Settings::values.use_unsafe_extended_memory_layout, - use_unsafe_extended_memory_layout); - - ui->custom_rtc_checkbox->setVisible(false); - ui->custom_rtc_edit->setVisible(false); } diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 6064b5b40..87b575060 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -3,11 +3,15 @@ #pragma once +#include +#include #include #include #include "yuzu/configuration/configuration_shared.h" +class QDateTimeEdit; + namespace Core { class System; } @@ -20,6 +24,7 @@ class ConfigureSystem : public ConfigurationShared::Tab { public: explicit ConfigureSystem(Core::System& system_, std::shared_ptr> group, + ConfigurationShared::TranslationMap& translations, QWidget* parent = nullptr); ~ConfigureSystem() override; @@ -30,9 +35,9 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void ReadSystemSettings(); + void Setup(); - void SetupPerGameUI(); + std::forward_list> apply_funcs{}; std::unique_ptr ui; bool enabled = false; @@ -41,4 +46,12 @@ private: ConfigurationShared::CheckState use_unsafe_extended_memory_layout; Core::System& system; + ConfigurationShared::TranslationMap& translations; + + QCheckBox* rng_seed_checkbox; + QLineEdit* rng_seed_edit; + QCheckBox* custom_rtc_checkbox; + QDateTimeEdit* custom_rtc_edit; + QComboBox* combo_region; + QComboBox* combo_language; }; diff --git a/src/yuzu/configuration/configure_system.ui b/src/yuzu/configuration/configure_system.ui index e0caecd5e..a5a3e2dc3 100644 --- a/src/yuzu/configuration/configure_system.ui +++ b/src/yuzu/configuration/configure_system.ui @@ -6,7 +6,7 @@ 0 0 - 366 + 605 483 @@ -22,470 +22,53 @@ - System Settings + System - - - - - Region: - - - - - - - - Auto - - - - - Default - - - - - CET - - - - - CST6CDT - - - - - Cuba - - - - - EET - - - - - Egypt - - - - - Eire - - - - - EST - - - - - EST5EDT - - - - - GB - - - - - GB-Eire - - - - - GMT - - - - - GMT+0 - - - - - GMT-0 - - - - - GMT0 - - - - - Greenwich - - - - - Hongkong - - - - - HST - - - - - Iceland - - - - - Iran - - - - - Israel - - - - - Jamaica - - - - - Japan - - - - - Kwajalein - - - - - Libya - - - - - MET - - - - - MST - - - - - MST7MDT - - - - - Navajo - - - - - NZ - - - - - NZ-CHAT - - - - - Poland - - - - - Portugal - - - - - PRC - - - - - PST8PDT - - - - - ROC - - - - - ROK - - - - - Singapore - - - - - Turkey - - - - - UCT - - - - - Universal - - - - - UTC - - - - - W-SU - - - - - WET - - - - - Zulu - - - - - - - - - Japan - - - - - USA - - - - - Europe - - - - - Australia - - - - - China - - - - - Korea - - - - - Taiwan - - - - - - - - Time Zone: - - - - - - - Note: this can be overridden when region setting is auto-select - - - - Japanese (日本語) - - - - - American English - - - - - French (français) - - - - - German (Deutsch) - - - - - Italian (italiano) - - - - - Spanish (español) - - - - - Chinese - - - - - Korean (한국어) - - - - - Dutch (Nederlands) - - - - - Portuguese (português) - - - - - Russian (Русский) - - - - - Taiwanese - - - - - British English - - - - - Canadian French - - - - - Latin American Spanish - - - - - Simplified Chinese - - - - - Traditional Chinese (正體中文) - - - - - Brazilian Portuguese (português do Brasil) - - - - - - - - Custom RTC - - - - - - - Language - - - - - - - RNG Seed - - - - - - - Device Name - - - - - - - - 1970 - 1 - 1 - - - - - - - - 128 - - - - - - - - 0 - 0 - - - - - Lucida Console - - - - HHHHHHHH - - - 8 - - - - - - - Unsafe extended memory layout (8GB DRAM) - - - - + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + Core + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + @@ -506,7 +89,7 @@ - + true diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index d38815e77..dc9f15cdd 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -109,15 +109,16 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { // System INSERT(Settings, rng_seed_enabled, "RNG Seed", ""); - INSERT(Settings, rng_seed, "RNG Seed", ""); + INSERT(Settings, rng_seed, "", ""); INSERT(Settings, device_name, "Device Name", ""); INSERT(Settings, custom_rtc_enabled, "Custom RTC", ""); - INSERT(Settings, custom_rtc, "Custom RTC", ""); + INSERT(Settings, custom_rtc, "", ""); INSERT(Settings, language_index, "Language:", ""); INSERT(Settings, region_index, "Region:", ""); INSERT(Settings, time_zone_index, "Time Zone:", ""); INSERT(Settings, sound_index, "Sound Output Mode:", ""); INSERT(Settings, use_docked_mode, "", ""); + INSERT(Settings, current_user, "", ""); // Controls @@ -231,6 +232,44 @@ std::forward_list ComboboxEnumeration(std::type_index type, QWidget* pa return { tr("Automatic"), tr("Default"), tr("2x"), tr("4x"), tr("8x"), tr("16x"), }; + } else if (type == typeid(Settings::Language)) { + return { + tr("Japanese (日本語)"), + tr("American English"), + tr("French (français)"), + tr("German (Deutsch)"), + tr("Italian (italiano)"), + tr("Spanish (español)"), + tr("Chinese"), + tr("Korean (한국어)"), + tr("Dutch (Nederlands)"), + tr("Portuguese (português)"), + tr("Russian (Русский)"), + tr("Taiwanese"), + tr("British English"), + tr("Canadian French"), + tr("Latin American Spanish"), + tr("Simplified Chinese"), + tr("Traditional Chinese (正體中文)"), + tr("Brazilian Portuguese (português do Brasil)"), + }; + } else if (type == typeid(Settings::Region)) { + return { + tr("Japan"), tr("USA"), tr("Europe"), tr("Australia"), + tr("China"), tr("Korea"), tr("Taiwan"), + }; + } else if (type == typeid(Settings::TimeZone)) { + return { + tr("Auto"), tr("Default"), tr("CET"), tr("CST6CDT"), tr("Cuba"), + tr("EET"), tr("Egypt"), tr("Eire"), tr("EST"), tr("EST5EDT"), + tr("GB"), tr("GB-Eire"), tr("GMT"), tr("GMT+0"), tr("GMT-0"), + tr("GMT0"), tr("Greenwich"), tr("Hongkong"), tr("HST"), tr("Iceland"), + tr("Iran"), tr("Israel"), tr("Jamaica"), tr("Kwajalein"), tr("Libya"), + tr("MET"), tr("MST"), tr("MST7MDT"), tr("Navajo"), tr("NZ"), + tr("NZ-CHAT"), tr("Poland"), tr("Portugal"), tr("PRC"), tr("PST8PDT"), + tr("ROC"), tr("ROK"), tr("Singapore"), tr("Turkey"), tr("UCT"), + tr("W-SU"), tr("WET"), tr("Zulu"), + }; } return {}; diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index d1113f793..0d553c67f 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include #include @@ -9,6 +11,9 @@ #include #include #include +#include +#include +#include #include "common/common_types.h" #include "common/settings.h" #include "yuzu/configuration/configuration_shared.h" @@ -25,7 +30,7 @@ QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QStyle* style = parent->style(); QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton)); QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent); - restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); + restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); QSizePolicy sp_retain = restore_button->sizePolicy(); sp_retain.setRetainSizeWhenHidden(true); @@ -241,6 +246,67 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier, } } +void Widget::CreateCheckBoxWithHexEdit(const QString& label, Settings::BasicSetting* other_setting, + std::function& load_func) { + if (other_setting == nullptr) { + LOG_WARNING(Frontend, "Extra setting is null or not an integer"); + return; + } + created = true; + + std::function checkbox_load_func; + CreateCheckBox(label, checkbox_load_func); + + auto to_hex = [=](const std::string& input) { + return QString::fromStdString(fmt::format("{:08x}", std::stoi(input))); + }; + + QHBoxLayout* layout = reinterpret_cast(this->layout()); + const QString default_val = to_hex(other_setting->ToString()); + + line_edit = new QLineEdit(this); + line_edit->setText(default_val); + + checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + layout->insertWidget(1, line_edit); + + line_edit->setMaxLength(8); + QRegExpValidator* regex = + new QRegExpValidator{QRegExp{QStringLiteral("^[0-9a-fA-F]{0,8}$")}, line_edit}; + line_edit->setValidator(regex); + + auto hex_to_dec = [=]() -> std::string { + return std::to_string(std::stoul(line_edit->text().toStdString(), nullptr, 16)); + }; + + if (Settings::IsConfiguringGlobal()) { + load_func = [=]() { + checkbox_load_func(); + other_setting->LoadString(hex_to_dec()); + }; + } else { + QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { + line_edit->setText(to_hex(other_setting->ToStringGlobal())); + }); + + QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) { + restore_button->setEnabled(true); + restore_button->setVisible(true); + }); + + load_func = [=]() { + checkbox_load_func(); + + const bool using_global = !restore_button->isEnabled(); + other_setting->SetGlobal(using_global); + if (!using_global) { + other_setting->LoadString(hex_to_dec()); + } + }; + } +} + void Widget::CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSetting* other_setting, std::function& load_func) { if (other_setting == nullptr) { @@ -268,8 +334,9 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSet other_setting->LoadString(line_edit->text().toStdString()); }; } else { - QObject::connect(restore_button, &QAbstractButton::clicked, - [=](bool) { line_edit->setText(default_val); }); + QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { + line_edit->setText(QString::fromStdString(other_setting->ToStringGlobal())); + }); QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) { restore_button->setEnabled(true); @@ -279,7 +346,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSet load_func = [=]() { checkbox_load_func(); - const bool using_global = !restore_button->isVisible(); + const bool using_global = !restore_button->isEnabled(); other_setting->SetGlobal(using_global); if (!using_global) { other_setting->LoadString(line_edit->text().toStdString()); @@ -289,7 +356,8 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSet } void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSetting* other_setting, - std::function& load_func, const QString& suffix) { + std::function& load_func, + const std::string& suffix) { if (other_setting == nullptr && IsInt(other_setting->TypeId())) { LOG_WARNING(Frontend, "Extra setting is null or not an integer"); return; @@ -308,7 +376,7 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSett const int default_val = std::stoi(other_setting->ToString()); spinbox->setRange(min_val, max_val); spinbox->setValue(default_val); - spinbox->setSuffix(suffix); + spinbox->setSuffix(QString::fromStdString(suffix)); spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); layout->insertWidget(1, spinbox); @@ -320,7 +388,7 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSett }; } else { QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) { - spinbox->setValue(std::stoi(other_setting->ToString())); + spinbox->setValue(std::stoi(other_setting->ToStringGlobal())); }); QObject::connect(spinbox, QOverload::of(&QSpinBox::valueChanged), [this](int) { @@ -331,7 +399,7 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSett load_func = [=]() { checkbox_load_func(); - const bool using_global = !restore_button->isVisible(); + const bool using_global = !restore_button->isEnabled(); other_setting->SetGlobal(using_global); if (!using_global) { other_setting->LoadString(std::to_string(spinbox->value())); @@ -340,6 +408,81 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSett } } +// Currently tailored to custom_rtc +void Widget::CreateCheckBoxWithDateTimeEdit(const QString& label, + Settings::BasicSetting* other_setting, + std::function& load_func) { + if (other_setting == nullptr) { + LOG_WARNING(Frontend, "Extra setting is null or not an integer"); + return; + } + created = true; + + std::function checkbox_load_func; + CreateCheckBox(label, checkbox_load_func); + + QHBoxLayout* layout = reinterpret_cast(this->layout()); + const bool disabled = setting.ToString() != "true"; + const long long current_time = QDateTime::currentSecsSinceEpoch(); + const s64 the_time = disabled ? current_time : std::stoll(other_setting->ToString()); + const auto default_val = QDateTime::fromSecsSinceEpoch(the_time); + + date_time_edit = new QDateTimeEdit(this); + date_time_edit->setDateTime(default_val); + + date_time_edit->setMinimumDateTime(QDateTime::fromSecsSinceEpoch(0)); + + date_time_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + layout->insertWidget(1, date_time_edit); + + if (Settings::IsConfiguringGlobal()) { + load_func = [=]() { + checkbox_load_func(); + if (checkbox->checkState() == Qt::Unchecked) { + return; + } + + other_setting->LoadString( + std::to_string(date_time_edit->dateTime().toSecsSinceEpoch())); + }; + } else { + auto get_clear_val = [=]() { + return QDateTime::fromSecsSinceEpoch([=]() { + if (checkbox->checkState() == Qt::Checked) { + return std::stoll(other_setting->ToStringGlobal()); + } + return current_time; + }()); + }; + + QObject::connect(restore_button, &QAbstractButton::clicked, + [=](bool) { date_time_edit->setDateTime(get_clear_val()); }); + + QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished, [=]() { + if (date_time_edit->dateTime() != get_clear_val()) { + restore_button->setEnabled(true); + restore_button->setVisible(true); + } + }); + + load_func = [=]() { + checkbox_load_func(); + if (checkbox->checkState() == Qt::Unchecked) { + return; + } + + const bool using_global = !restore_button->isEnabled(); + other_setting->SetGlobal(using_global); + if (!using_global) { + other_setting->LoadString( + std::to_string(date_time_edit->dateTime().toSecsSinceEpoch())); + } + }; + } +} + bool Widget::Valid() { return created; } @@ -350,7 +493,7 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati QWidget* parent_, bool runtime_lock, std::forward_list>& apply_funcs, RequestType request, bool managed, float multiplier, Settings::BasicSetting* other_setting, - const QString& format) + const std::string& string) : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} { if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) { LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel()); @@ -379,19 +522,26 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati if (type == typeid(bool)) { switch (request) { - case RequestType::SpinBox: - CreateCheckBoxWithSpinBox(label, other_setting, load_func, format); - break; case RequestType::Default: CreateCheckBox(label, load_func); break; + case RequestType::SpinBox: + CreateCheckBoxWithSpinBox(label, other_setting, load_func, string); + break; + case RequestType::HexEdit: + CreateCheckBoxWithHexEdit(label, other_setting, load_func); + break; case RequestType::LineEdit: CreateCheckBoxWithLineEdit(label, other_setting, load_func); break; + case RequestType::DateTimeEdit: + CreateCheckBoxWithDateTimeEdit(label, other_setting, load_func); + break; case RequestType::ComboBox: case RequestType::Slider: case RequestType::ReverseSlider: case RequestType::MaxEnum: + LOG_DEBUG(Frontend, "Requested widget is unimplemented."); break; } } else if (setting.IsEnum()) { @@ -409,10 +559,15 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati case RequestType::ComboBox: CreateCombobox(label, managed, load_func); break; + case RequestType::DateTimeEdit: case RequestType::SpinBox: + case RequestType::HexEdit: case RequestType::MaxEnum: + LOG_DEBUG(Frontend, "Requested widget is unimplemented."); break; } + } else if (type == typeid(std::string)) { + CreateLineEdit(label, managed, load_func); } if (!created) { diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 88a864b42..9923aa2ea 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -9,6 +9,7 @@ class QComboBox; class QLineEdit; class QSlider; class QCheckBox; +class QDateTimeEdit; namespace Settings { class BasicSetting; @@ -23,6 +24,8 @@ enum class RequestType { Slider, ReverseSlider, LineEdit, + HexEdit, + DateTimeEdit, MaxEnum, }; @@ -33,8 +36,7 @@ public: Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent, bool runtime_lock, std::forward_list>& apply_funcs, RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f, - Settings::BasicSetting* other_setting = nullptr, - const QString& format = QStringLiteral("")); + Settings::BasicSetting* other_setting = nullptr, const std::string& format = ""); virtual ~Widget(); bool Valid(); @@ -48,13 +50,18 @@ public: QCheckBox* checkbox{}; QSlider* slider{}; QComboBox* combobox{}; + QDateTimeEdit* date_time_edit{}; private: void CreateCheckBox(const QString& label, std::function& load_func); void CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSetting* other_setting, std::function& load_func); + void CreateCheckBoxWithHexEdit(const QString& label, Settings::BasicSetting* other_setting, + std::function& load_func); void CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSetting* other_setting, - std::function& load_func, const QString& suffix); + std::function& load_func, const std::string& suffix); + void CreateCheckBoxWithDateTimeEdit(const QString& label, Settings::BasicSetting* other_setting, + std::function& load_func); void CreateCombobox(const QString& label, bool managed, std::function& load_func); void CreateLineEdit(const QString& label, bool managed, std::function& load_func); void CreateSlider(const QString& label, bool reversed, float multiplier, diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index f8cbf8034..c42d98709 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -229,6 +229,7 @@ void Config::ReadValues() { ReadCategory(Settings::Category::RendererAdvanced); ReadCategory(Settings::Category::RendererDebug); ReadCategory(Settings::Category::System); + ReadCategory(Settings::Category::SystemAudio); ReadCategory(Settings::Category::DataStorage); ReadCategory(Settings::Category::Debugging); ReadCategory(Settings::Category::DebuggingGraphics); -- cgit v1.2.3 From 432f68ad29df7a368ba375d75d667c954e9c80b9 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 May 2023 17:54:22 -0400 Subject: configure_audio: Implement ui generation Needs a considerable amount of management specific to some of the comoboboxes due to the audio engine configuration. general: Partial audio config implmentation configure_audio: Implement ui generation Needs a considerable amount of management specific to some of the comoboboxes due to the audio engine configuration. general: Partial audio config implmentation settings: Make audio settings as enums --- src/audio_core/sink/sink_details.cpp | 33 +++-- src/audio_core/sink/sink_details.h | 9 +- src/common/settings.cpp | 2 +- src/common/settings.h | 11 +- src/core/telemetry_session.cpp | 3 +- src/yuzu/configuration/configure_audio.cpp | 204 ++++++++++++-------------- src/yuzu/configuration/configure_audio.h | 16 +- src/yuzu/configuration/configure_audio.ui | 162 +------------------- src/yuzu/configuration/configure_dialog.cpp | 2 +- src/yuzu/configuration/configure_graphics.cpp | 8 +- src/yuzu/configuration/configure_per_game.cpp | 2 +- src/yuzu/configuration/shared_translation.cpp | 7 + src/yuzu/configuration/shared_widget.cpp | 78 ++++++---- src/yuzu/configuration/shared_widget.h | 11 +- 14 files changed, 219 insertions(+), 329 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/audio_core/sink/sink_details.cpp b/src/audio_core/sink/sink_details.cpp index 39ea6d91b..751e97bfc 100644 --- a/src/audio_core/sink/sink_details.cpp +++ b/src/audio_core/sink/sink_details.cpp @@ -15,6 +15,7 @@ #endif #include "audio_core/sink/null_sink.h" #include "common/logging/log.h" +#include "common/settings_enums.h" namespace AudioCore::Sink { namespace { @@ -24,7 +25,7 @@ struct SinkDetails { using LatencyFn = u32 (*)(); /// Name for this sink. - std::string_view id; + Settings::AudioEngine id; /// A method to call to construct an instance of this type of sink. FactoryFn factory; /// A method to call to list available devices. @@ -37,7 +38,7 @@ struct SinkDetails { constexpr SinkDetails sink_details[] = { #ifdef HAVE_CUBEB SinkDetails{ - "cubeb", + Settings::AudioEngine::Cubeb, [](std::string_view device_id) -> std::unique_ptr { return std::make_unique(device_id); }, @@ -47,7 +48,7 @@ constexpr SinkDetails sink_details[] = { #endif #ifdef HAVE_SDL2 SinkDetails{ - "sdl2", + Settings::AudioEngine::Sdl2, [](std::string_view device_id) -> std::unique_ptr { return std::make_unique(device_id); }, @@ -55,46 +56,46 @@ constexpr SinkDetails sink_details[] = { &GetSDLLatency, }, #endif - SinkDetails{"null", + SinkDetails{Settings::AudioEngine::Null, [](std::string_view device_id) -> std::unique_ptr { return std::make_unique(device_id); }, [](bool capture) { return std::vector{"null"}; }, []() { return 0u; }}, }; -const SinkDetails& GetOutputSinkDetails(std::string_view sink_id) { - const auto find_backend{[](std::string_view id) { +const SinkDetails& GetOutputSinkDetails(Settings::AudioEngine sink_id) { + const auto find_backend{[](Settings::AudioEngine id) { return std::find_if(std::begin(sink_details), std::end(sink_details), [&id](const auto& sink_detail) { return sink_detail.id == id; }); }}; auto iter = find_backend(sink_id); - if (sink_id == "auto") { + if (sink_id == Settings::AudioEngine::Auto) { // Auto-select a backend. Prefer CubeB, but it may report a large minimum latency which // causes audio issues, in that case go with SDL. #if defined(HAVE_CUBEB) && defined(HAVE_SDL2) - iter = find_backend("cubeb"); + iter = find_backend(Settings::AudioEngine::Cubeb); if (iter->latency() > TargetSampleCount * 3) { - iter = find_backend("sdl2"); + iter = find_backend(Settings::AudioEngine::Sdl2); } #else iter = std::begin(sink_details); #endif - LOG_INFO(Service_Audio, "Auto-selecting the {} backend", iter->id); + LOG_INFO(Service_Audio, "Auto-selecting the {} backend", Settings::TranslateEnum(iter->id)); } if (iter == std::end(sink_details)) { - LOG_ERROR(Audio, "Invalid sink_id {}", sink_id); - iter = find_backend("null"); + LOG_ERROR(Audio, "Invalid sink_id {}", Settings::TranslateEnum(sink_id)); + iter = find_backend(Settings::AudioEngine::Null); } return *iter; } } // Anonymous namespace -std::vector GetSinkIDs() { - std::vector sink_ids(std::size(sink_details)); +std::vector GetSinkIDs() { + std::vector sink_ids(std::size(sink_details)); std::transform(std::begin(sink_details), std::end(sink_details), std::begin(sink_ids), [](const auto& sink) { return sink.id; }); @@ -102,11 +103,11 @@ std::vector GetSinkIDs() { return sink_ids; } -std::vector GetDeviceListForSink(std::string_view sink_id, bool capture) { +std::vector GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture) { return GetOutputSinkDetails(sink_id).list_devices(capture); } -std::unique_ptr CreateSinkFromID(std::string_view sink_id, std::string_view device_id) { +std::unique_ptr CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id) { return GetOutputSinkDetails(sink_id).factory(device_id); } diff --git a/src/audio_core/sink/sink_details.h b/src/audio_core/sink/sink_details.h index e75932898..44403db71 100644 --- a/src/audio_core/sink/sink_details.h +++ b/src/audio_core/sink/sink_details.h @@ -7,6 +7,9 @@ #include #include +namespace Settings { +enum class AudioEngine : u32; +} namespace AudioCore { class AudioManager; @@ -19,7 +22,7 @@ class Sink; * * @return Vector of available sink names. */ -std::vector GetSinkIDs(); +std::vector GetSinkIDs(); /** * Gets the list of devices for a particular sink identified by the given ID. @@ -28,7 +31,7 @@ std::vector GetSinkIDs(); * @param capture - Get capture (input) devices, or output devices? * @return Vector of device names. */ -std::vector GetDeviceListForSink(std::string_view sink_id, bool capture); +std::vector GetDeviceListForSink(Settings::AudioEngine sink_id, bool capture); /** * Creates an audio sink identified by the given device ID. @@ -37,7 +40,7 @@ std::vector GetDeviceListForSink(std::string_view sink_id, bool cap * @param device_id - Name of the device to create. * @return Pointer to the created sink. */ -std::unique_ptr CreateSinkFromID(std::string_view sink_id, std::string_view device_id); +std::unique_ptr CreateSinkFromID(Settings::AudioEngine sink_id, std::string_view device_id); } // namespace Sink } // namespace AudioCore diff --git a/src/common/settings.cpp b/src/common/settings.cpp index c8651925e..8bfda5667 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -90,7 +90,7 @@ void LogSettings() { log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); - log_setting("Audio_OutputEngine", values.sink_id.GetValue()); + log_setting("Audio_OutputEngine", Settings::TranslateEnum(values.sink_id.GetValue())); log_setting("Audio_OutputDevice", values.audio_output_device_id.GetValue()); log_setting("Audio_InputDevice", values.audio_input_device_id.GetValue()); log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue()); diff --git a/src/common/settings.h b/src/common/settings.h index 0ac5078c6..d4b41a162 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -244,6 +244,8 @@ protected: return value_.has_value() ? std::to_string(*value_) : "none"; } else if constexpr (std::is_same()) { return value_ ? "true" : "false"; + } else if (std::is_same()) { + return TranslateEnum(value_); } else { return std::to_string(static_cast(value_)); } @@ -309,6 +311,8 @@ public: this->SetValue(static_cast(std::stoul(input))); } else if constexpr (std::is_same()) { this->SetValue(input == "true"); + } else if constexpr (std::is_same()) { + this->SetValue(ToEnum(input)); } else { this->SetValue(static_cast(std::stoll(input))); } @@ -542,7 +546,7 @@ struct Values { Linkage linkage{}; // Audio - Setting sink_id{linkage, "auto", "output_engine", Category::Audio}; + Setting sink_id{linkage, AudioEngine::Auto, "output_engine", Category::Audio}; Setting audio_output_device_id{linkage, "auto", "output_device", Category::Audio}; Setting audio_input_device_id{linkage, "auto", "input_device", Category::Audio}; Setting audio_muted{linkage, false, "audio_muted", Category::Audio, false}; @@ -731,8 +735,9 @@ struct Values { SwitchableSetting time_zone_index{linkage, TimeZone::Auto, TimeZone::Auto, TimeZone::Zulu, "time_zone_index", Category::System}; - SwitchableSetting sound_index{ - linkage, 1, 0, 2, "sound_index", Category::SystemAudio}; + SwitchableSetting sound_index{linkage, AudioMode::Stereo, + AudioMode::Mono, AudioMode::Surround, + "sound_index", Category::SystemAudio}; SwitchableSetting use_docked_mode{linkage, true, "use_docked_mode", Category::System}; diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index a3505a505..c058ac2c7 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -254,7 +254,8 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader, // Log user configuration information constexpr auto field_type = Telemetry::FieldType::UserConfig; - AddField(field_type, "Audio_SinkId", Settings::values.sink_id.GetValue()); + AddField(field_type, "Audio_SinkId", + Settings::TranslateEnum(Settings::values.sink_id.GetValue())); AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core.GetValue()); AddField(field_type, "Renderer_Backend", TranslateRenderer(Settings::values.renderer_backend.GetValue())); diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index 335662144..dd9eb4dc1 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include "audio_core/sink/sink.h" @@ -10,80 +11,105 @@ #include "ui_configure_audio.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_audio.h" +#include "yuzu/configuration/shared_translation.h" +#include "yuzu/configuration/shared_widget.h" #include "yuzu/uisettings.h" ConfigureAudio::ConfigureAudio(const Core::System& system_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent) - : Tab(group, parent), ui(std::make_unique()), system{system_} { + : Tab(group, parent), + ui(std::make_unique()), system{system_}, translations{translations_} { ui->setupUi(this); + Setup(); - InitializeAudioSinkComboBox(); + SetConfiguration(); +} - connect(ui->volume_slider, &QSlider::valueChanged, this, - &ConfigureAudio::SetVolumeIndicatorText); - connect(ui->sink_combo_box, qOverload(&QComboBox::currentIndexChanged), this, - &ConfigureAudio::UpdateAudioDevices); +ConfigureAudio::~ConfigureAudio() = default; - ui->volume_label->setVisible(Settings::IsConfiguringGlobal()); - ui->volume_combo_box->setVisible(!Settings::IsConfiguringGlobal()); +void ConfigureAudio::Setup() { + const bool runtime_lock = !system.IsPoweredOn(); + auto& layout = *ui->audio_widget->layout(); - SetupPerGameUI(); + std::forward_list settings; - SetConfiguration(); + auto push = [&](Settings::Category category) { + for (auto* setting : Settings::values.linkage.by_category[category]) { + settings.push_front(setting); + } + }; + + push(Settings::Category::Audio); + push(Settings::Category::SystemAudio); + + for (auto* setting : settings) { + auto* widget = [&]() { + if (setting->Id() == Settings::values.volume.Id()) { + return new ConfigurationShared::Widget( + setting, translations, this, runtime_lock, apply_funcs, + ConfigurationShared::RequestType::Slider, true, 1.0f, nullptr, + tr("%1%", "Volume percentage (e.g. 50%)")); + } else if (setting->Id() == Settings::values.audio_output_device_id.Id() || + setting->Id() == Settings::values.audio_input_device_id.Id() || + setting->Id() == Settings::values.sink_id.Id()) { + return new ConfigurationShared::Widget( + setting, translations, this, runtime_lock, apply_funcs, + ConfigurationShared::RequestType::ComboBox, false); + } else { + return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, + apply_funcs); + } + }(); + + if (!widget->Valid()) { + delete widget; + continue; + } - const bool is_powered_on = system_.IsPoweredOn(); - ui->sink_combo_box->setEnabled(!is_powered_on); - ui->output_combo_box->setEnabled(!is_powered_on); - ui->input_combo_box->setEnabled(!is_powered_on); -} + layout.addWidget(widget); -ConfigureAudio::~ConfigureAudio() = default; + if (setting->Id() == Settings::values.sink_id.Id()) { + sink_combo_box = widget->combobox; + InitializeAudioSinkComboBox(); + + connect(sink_combo_box, qOverload(&QComboBox::currentIndexChanged), this, + &ConfigureAudio::UpdateAudioDevices); + } else if (setting->Id() == Settings::values.audio_output_device_id.Id()) { + output_device_combo_box = widget->combobox; + } else if (setting->Id() == Settings::values.audio_input_device_id.Id()) { + input_device_combo_box = widget->combobox; + } + } +} void ConfigureAudio::SetConfiguration() { + if (!Settings::IsConfiguringGlobal()) { + return; + } + SetOutputSinkFromSinkID(); // The device list cannot be pre-populated (nor listed) until the output sink is known. - UpdateAudioDevices(ui->sink_combo_box->currentIndex()); + UpdateAudioDevices(sink_combo_box->currentIndex()); SetAudioDevicesFromDeviceID(); - - const auto volume_value = static_cast(Settings::values.volume.GetValue()); - ui->volume_slider->setValue(volume_value); - ui->toggle_background_mute->setChecked(UISettings::values.mute_when_in_background.GetValue()); - - if (!Settings::IsConfiguringGlobal()) { - if (Settings::values.volume.UsingGlobal()) { - ui->volume_combo_box->setCurrentIndex(0); - ui->volume_slider->setEnabled(false); - } else { - ui->volume_combo_box->setCurrentIndex(1); - ui->volume_slider->setEnabled(true); - } - ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index); - ConfigurationShared::SetHighlight(ui->mode_label, - !Settings::values.sound_index.UsingGlobal()); - ConfigurationShared::SetHighlight(ui->volume_layout, - !Settings::values.volume.UsingGlobal()); - } else { - ui->combo_sound->setCurrentIndex(Settings::values.sound_index.GetValue()); - } - SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); } void ConfigureAudio::SetOutputSinkFromSinkID() { - [[maybe_unused]] const QSignalBlocker blocker(ui->sink_combo_box); + [[maybe_unused]] const QSignalBlocker blocker(sink_combo_box); int new_sink_index = 0; - const QString sink_id = QString::fromStdString(Settings::values.sink_id.GetValue()); - for (int index = 0; index < ui->sink_combo_box->count(); index++) { - if (ui->sink_combo_box->itemText(index) == sink_id) { + const QString sink_id = QString::fromStdString(Settings::values.sink_id.ToString()); + for (int index = 0; index < sink_combo_box->count(); index++) { + if (sink_combo_box->itemText(index) == sink_id) { new_sink_index = index; break; } } - ui->sink_combo_box->setCurrentIndex(new_sink_index); + sink_combo_box->setCurrentIndex(new_sink_index); } void ConfigureAudio::SetAudioDevicesFromDeviceID() { @@ -91,57 +117,42 @@ void ConfigureAudio::SetAudioDevicesFromDeviceID() { const QString output_device_id = QString::fromStdString(Settings::values.audio_output_device_id.GetValue()); - for (int index = 0; index < ui->output_combo_box->count(); index++) { - if (ui->output_combo_box->itemText(index) == output_device_id) { + for (int index = 0; index < output_device_combo_box->count(); index++) { + if (output_device_combo_box->itemText(index) == output_device_id) { new_device_index = index; break; } } - ui->output_combo_box->setCurrentIndex(new_device_index); + output_device_combo_box->setCurrentIndex(new_device_index); new_device_index = -1; const QString input_device_id = QString::fromStdString(Settings::values.audio_input_device_id.GetValue()); - for (int index = 0; index < ui->input_combo_box->count(); index++) { - if (ui->input_combo_box->itemText(index) == input_device_id) { + for (int index = 0; index < input_device_combo_box->count(); index++) { + if (input_device_combo_box->itemText(index) == input_device_id) { new_device_index = index; break; } } - ui->input_combo_box->setCurrentIndex(new_device_index); -} - -void ConfigureAudio::SetVolumeIndicatorText(int percentage) { - ui->volume_indicator->setText(tr("%1%", "Volume percentage (e.g. 50%)").arg(percentage)); + input_device_combo_box->setCurrentIndex(new_device_index); } void ConfigureAudio::ApplyConfiguration() { - ConfigurationShared::ApplyPerGameSetting(&Settings::values.sound_index, ui->combo_sound); + const bool is_powered_on = system.IsPoweredOn(); + for (const auto& apply_func : apply_funcs) { + apply_func(is_powered_on); + } if (Settings::IsConfiguringGlobal()) { - Settings::values.sink_id = - ui->sink_combo_box->itemText(ui->sink_combo_box->currentIndex()).toStdString(); + Settings::values.sink_id.LoadString( + sink_combo_box->itemText(sink_combo_box->currentIndex()).toStdString()); Settings::values.audio_output_device_id.SetValue( - ui->output_combo_box->itemText(ui->output_combo_box->currentIndex()).toStdString()); + output_device_combo_box->itemText(output_device_combo_box->currentIndex()) + .toStdString()); Settings::values.audio_input_device_id.SetValue( - ui->input_combo_box->itemText(ui->input_combo_box->currentIndex()).toStdString()); - UISettings::values.mute_when_in_background = ui->toggle_background_mute->isChecked(); - - // Guard if during game and set to game-specific value - if (Settings::values.volume.UsingGlobal()) { - const auto volume = static_cast(ui->volume_slider->value()); - Settings::values.volume.SetValue(volume); - } - } else { - if (ui->volume_combo_box->currentIndex() == 0) { - Settings::values.volume.SetGlobal(true); - } else { - Settings::values.volume.SetGlobal(false); - const auto volume = static_cast(ui->volume_slider->value()); - Settings::values.volume.SetValue(volume); - } + input_device_combo_box->itemText(input_device_combo_box->currentIndex()).toStdString()); } } @@ -154,54 +165,31 @@ void ConfigureAudio::changeEvent(QEvent* event) { } void ConfigureAudio::UpdateAudioDevices(int sink_index) { - ui->output_combo_box->clear(); - ui->output_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name)); + output_device_combo_box->clear(); + output_device_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name)); - const std::string sink_id = ui->sink_combo_box->itemText(sink_index).toStdString(); + const auto sink_id = + Settings::ToEnum(sink_combo_box->itemText(sink_index).toStdString()); for (const auto& device : AudioCore::Sink::GetDeviceListForSink(sink_id, false)) { - ui->output_combo_box->addItem(QString::fromStdString(device)); + output_device_combo_box->addItem(QString::fromStdString(device)); } - ui->input_combo_box->clear(); - ui->input_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name)); + input_device_combo_box->clear(); + input_device_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name)); for (const auto& device : AudioCore::Sink::GetDeviceListForSink(sink_id, true)) { - ui->input_combo_box->addItem(QString::fromStdString(device)); + input_device_combo_box->addItem(QString::fromStdString(device)); } } void ConfigureAudio::InitializeAudioSinkComboBox() { - ui->sink_combo_box->clear(); - ui->sink_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name)); + sink_combo_box->clear(); + sink_combo_box->addItem(QString::fromUtf8(AudioCore::Sink::auto_device_name)); for (const auto& id : AudioCore::Sink::GetSinkIDs()) { - ui->sink_combo_box->addItem(QString::fromUtf8(id.data(), static_cast(id.length()))); + sink_combo_box->addItem(QString::fromStdString(Settings::TranslateEnum(id))); } } void ConfigureAudio::RetranslateUI() { ui->retranslateUi(this); - SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); -} - -void ConfigureAudio::SetupPerGameUI() { - if (Settings::IsConfiguringGlobal()) { - ui->combo_sound->setEnabled(Settings::values.sound_index.UsingGlobal()); - ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal()); - return; - } - - ConfigurationShared::SetColoredComboBox(ui->combo_sound, ui->mode_label, - Settings::values.sound_index.GetValue(true)); - - connect(ui->volume_combo_box, qOverload(&QComboBox::activated), this, [this](int index) { - ui->volume_slider->setEnabled(index == 1); - ConfigurationShared::SetHighlight(ui->volume_layout, index == 1); - }); - - ui->sink_combo_box->setVisible(false); - ui->sink_label->setVisible(false); - ui->output_combo_box->setVisible(false); - ui->output_label->setVisible(false); - ui->input_combo_box->setVisible(false); - ui->input_label->setVisible(false); } diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index d134ac957..170e0bce8 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h @@ -3,9 +3,14 @@ #pragma once +#include +#include #include #include #include "yuzu/configuration/configuration_shared.h" +#include "yuzu/configuration/shared_translation.h" + +class QPushButton; namespace Core { class System; @@ -19,6 +24,7 @@ class ConfigureAudio : public ConfigurationShared::Tab { public: explicit ConfigureAudio(const Core::System& system_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, QWidget* parent = nullptr); ~ConfigureAudio() override; @@ -36,11 +42,17 @@ private: void SetOutputSinkFromSinkID(); void SetAudioDevicesFromDeviceID(); - void SetVolumeIndicatorText(int percentage); - void SetupPerGameUI(); + void Setup(); std::unique_ptr ui; const Core::System& system; + const ConfigurationShared::TranslationMap& translations; + + std::forward_list> apply_funcs{}; + + QComboBox* sink_combo_box; + QComboBox* output_device_combo_box; + QComboBox* input_device_combo_box; }; diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui index 4128c83ad..1181aeb00 100644 --- a/src/yuzu/configuration/configure_audio.ui +++ b/src/yuzu/configuration/configure_audio.ui @@ -21,80 +21,14 @@ - - - - - Output Engine: - - - - - - - - - - - - - - Output Device: - - - - - - - - - - - - - - Input Device: - - - - - - - - - - - - - - Sound Output Mode: - - - - - - - - Mono - - - - - Stereo - - - - - Surround - - - - - - - - - + + + + 16777215 + 16777213 + + + 0 @@ -107,89 +41,9 @@ 0 - - - - - Use global volume - - - - - Set volume: - - - - - - - - Volume: - - - - - - - Qt::Horizontal - - - - 30 - 20 - - - - - - - - - 0 - 0 - - - - 200 - - - 5 - - - Qt::Horizontal - - - - - - - - 32 - 0 - - - - 0 % - - - Qt::AlignCenter - - - - - - - - - Mute audio when in background - - - - - diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 3a94fee9e..f0f00be83 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -34,7 +34,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, : QDialog(parent), ui{std::make_unique()}, registry(registry_), system{system_}, translations{ConfigurationShared::InitializeTranslations(this)}, - audio_tab{std::make_unique(system_, nullptr, this)}, + audio_tab{std::make_unique(system_, nullptr, *translations, this)}, cpu_tab{std::make_unique(system_, nullptr, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 2354323b8..45a4db430 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -240,12 +240,14 @@ void ConfigureGraphics::Setup() { } else if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) { return new ConfigurationShared::Widget( setting, translations, this, runtime_lock, apply_funcs, - ConfigurationShared::RequestType::ReverseSlider, true, 0.5f); + ConfigurationShared::RequestType::ReverseSlider, true, 0.5f, nullptr, + tr("%1%", "FSR sharpening percentage (e.g. 50%)")); } else if (setting->Id() == Settings::values.speed_limit.Id()) { return new ConfigurationShared::Widget( setting, translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::SpinBox, true, 1.0f, - &Settings::values.use_speed_limit, "%"); + &Settings::values.use_speed_limit, + tr("%", "Limit speed percentage (e.g. 50%)")); } else { return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, apply_funcs); @@ -304,7 +306,7 @@ void ConfigureGraphics::Setup() { }); } else { QPushButton* bg_restore_button = ConfigurationShared::Widget::CreateRestoreGlobalButton( - Settings::values.bg_red, ui->bg_widget); + Settings::values.bg_red.UsingGlobal(), ui->bg_widget); ui->bg_widget->layout()->addWidget(bg_restore_button); QObject::connect(bg_restore_button, &QAbstractButton::clicked, diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index c39855334..2ee0a8ffa 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -50,7 +50,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st game_config = std::make_unique(config_file_name, Config::ConfigType::PerGameConfig); addons_tab = std::make_unique(system_, this); - audio_tab = std::make_unique(system_, tab_group, this); + audio_tab = std::make_unique(system_, tab_group, *translations, this); cpu_tab = std::make_unique(system_, tab_group, this); graphics_advanced_tab = std::make_unique(system_, tab_group, *translations, this); diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 6038e8c25..c3b38f776 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -30,6 +30,7 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { INSERT(Settings, audio_input_device_id, "Input Device:", ""); INSERT(Settings, audio_muted, "Mute audio when in background", ""); INSERT(Settings, volume, "Volume:", ""); + INSERT(Settings, dump_audio_commands, "", ""); // Core INSERT(Settings, use_multi_core, "Multicore CPU Emulation", ""); @@ -270,6 +271,12 @@ std::forward_list ComboboxEnumeration(std::type_index type, QWidget* pa tr("ROC"), tr("ROK"), tr("Singapore"), tr("Turkey"), tr("UCT"), tr("W-SU"), tr("WET"), tr("Zulu"), }; + } else if (type == typeid(Settings::AudioMode)) { + return { + tr("Mono"), + tr("Stereo"), + tr("Surround"), + }; } return {}; diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index f39e3fccb..d7b7ed164 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -24,7 +24,7 @@ namespace ConfigurationShared { -QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) { +QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) { QStyle* style = parent->style(); QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_LineEditClearButton)); QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent); @@ -34,8 +34,8 @@ QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, sp_retain.setRetainSizeWhenHidden(true); restore_button->setSizePolicy(sp_retain); - restore_button->setEnabled(!setting.UsingGlobal()); - restore_button->setVisible(!setting.UsingGlobal()); + restore_button->setEnabled(!using_global); + restore_button->setVisible(!using_global); return restore_button; } @@ -57,6 +57,10 @@ QHBoxLayout* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const : Qt::CheckState::Unchecked); checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + if (!bool_setting->Save() && !Settings::IsConfiguringGlobal() && runtime_lock) { + checkbox->setEnabled(false); + } + layout->addWidget(checkbox); layout->setContentsMargins(0, 0, 0, 0); @@ -70,7 +74,8 @@ QHBoxLayout* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const bool_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false"); }; } else { - restore_button = CreateRestoreGlobalButton(*bool_setting, this); + restore_button = + CreateRestoreGlobalButton(bool_setting->UsingGlobal() && setting.UsingGlobal(), this); layout->addWidget(restore_button); QObject::connect(checkbox, &QCheckBox::stateChanged, [=](int) { @@ -128,7 +133,7 @@ void Widget::CreateCombobox(const QString& label, std::function& load_fu if (Settings::IsConfiguringGlobal()) { load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); }; } else { - restore_button = CreateRestoreGlobalButton(setting, this); + restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); layout->addWidget(restore_button); QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { @@ -194,7 +199,7 @@ void Widget::CreateLineEdit(const QString& label, std::function& load_fu }; } else { if (!has_checkbox) { - restore_button = CreateRestoreGlobalButton(setting, this); + restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); layout->addWidget(restore_button); } @@ -223,7 +228,7 @@ void Widget::CreateLineEdit(const QString& label, std::function& load_fu } void Widget::CreateSlider(const QString& label, bool reversed, float multiplier, - std::function& load_func, bool managed, + std::function& load_func, bool managed, const QString& format, Settings::BasicSetting* const other_setting) { created = true; @@ -242,15 +247,16 @@ void Widget::CreateSlider(const QString& label, bool reversed, float multiplier, int max_val = std::stoi(setting.MaxVal()); + const QString use_format = format == QStringLiteral("") ? QStringLiteral("%1") : format; + QObject::connect(slider, &QAbstractSlider::valueChanged, [=](int value) { - int present = (reversed ? max_val - value : value) * multiplier; - feedback->setText( - QStringLiteral("%1%").arg(QString::fromStdString(std::to_string(present)))); + int present = (reversed ? max_val - value : value) * multiplier + 0.5f; + feedback->setText(use_format.arg(QVariant::fromValue(present).value())); }); - slider->setValue(std::stoi(setting.ToString())); slider->setMinimum(std::stoi(setting.MinVal())); slider->setMaximum(max_val); + slider->setValue(std::stoi(setting.ToString())); slider->setInvertedAppearance(reversed); @@ -261,7 +267,7 @@ void Widget::CreateSlider(const QString& label, bool reversed, float multiplier, if (Settings::IsConfiguringGlobal()) { load_func = [=]() { setting.LoadString(std::to_string(slider->value())); }; } else { - restore_button = CreateRestoreGlobalButton(setting, this); + restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); layout->addWidget(restore_button); QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { @@ -287,7 +293,7 @@ void Widget::CreateSlider(const QString& label, bool reversed, float multiplier, } void Widget::CreateSpinBox(const QString& label, std::function& load_func, bool managed, - const std::string& suffix, Settings::BasicSetting* other_setting) { + const QString& suffix, Settings::BasicSetting* other_setting) { const bool has_checkbox = other_setting != nullptr; if (has_checkbox && other_setting->TypeId() != typeid(bool)) { LOG_WARNING(Frontend, "Extra setting requested but setting is not boolean"); @@ -315,7 +321,7 @@ void Widget::CreateSpinBox(const QString& label, std::function& load_fun spinbox = new QSpinBox(this); spinbox->setRange(min_val, max_val); spinbox->setValue(default_val); - spinbox->setSuffix(QString::fromStdString(suffix)); + spinbox->setSuffix(suffix); spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); layout->insertWidget(1, spinbox); @@ -327,7 +333,8 @@ void Widget::CreateSpinBox(const QString& label, std::function& load_fun }; } else { if (!has_checkbox) { - restore_button = CreateRestoreGlobalButton(setting, this); + restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); + layout->addWidget(restore_button); } QObject::connect(restore_button, &QAbstractButton::clicked, @@ -382,7 +389,7 @@ void Widget::CreateHexEdit(const QString& label, std::function& load_fun setting.LoadString(hex_to_dec()); }; } else { - restore_button = CreateRestoreGlobalButton(setting, this); + restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); layout->addWidget(restore_button); QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { @@ -465,7 +472,7 @@ void Widget::CreateDateTimeEdit(const QString& label, std::function& loa }; } else { if (!has_checkbox) { - restore_button = CreateRestoreGlobalButton(setting, this); + restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); layout->addWidget(restore_button); } @@ -515,12 +522,12 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati apply_funcs{apply_funcs_} {} Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, - QWidget* parent_, bool runtime_lock, + QWidget* parent_, bool runtime_lock_, std::forward_list>& apply_funcs_, RequestType request, bool managed, float multiplier, Settings::BasicSetting* other_setting, - const std::string& string) + const QString& string) : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_}, - apply_funcs{apply_funcs_} { + apply_funcs{apply_funcs_}, runtime_lock{runtime_lock_} { if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) { LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel()); return; @@ -547,23 +554,16 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati std::function load_func = []() {}; if (type == typeid(bool)) { - switch (request) { - case RequestType::Default: - CreateCheckBox(&setting, label, load_func, managed); - break; - default: - LOG_WARNING(Frontend, "Requested widget is unimplemented."); - break; - } + CreateCheckBox(&setting, label, load_func, managed); } else if (setting.IsEnum()) { CreateCombobox(label, load_func, managed); } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) || - type == typeid(s64)) { + type == typeid(s64) || type == typeid(u8)) { switch (request) { case RequestType::Slider: case RequestType::ReverseSlider: CreateSlider(label, request == RequestType::ReverseSlider, multiplier, load_func, - managed); + managed, string); break; case RequestType::LineEdit: case RequestType::Default: @@ -586,7 +586,23 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati break; } } else if (type == typeid(std::string)) { - CreateLineEdit(label, load_func, managed); + switch (request) { + case RequestType::Default: + case RequestType::LineEdit: + CreateLineEdit(label, load_func, managed); + break; + case RequestType::ComboBox: + CreateCombobox(label, load_func, false); + break; + case RequestType::SpinBox: + case RequestType::Slider: + case RequestType::ReverseSlider: + case RequestType::HexEdit: + case RequestType::DateTimeEdit: + case RequestType::MaxEnum: + LOG_WARNING(Frontend, "Requested widget is unimplemented."); + break; + } } if (!created) { diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index c4e686574..331316040 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -38,15 +38,15 @@ public: Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent, bool runtime_lock, std::forward_list>& apply_funcs_, RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f, - Settings::BasicSetting* other_setting = nullptr, const std::string& format = ""); + Settings::BasicSetting* other_setting = nullptr, + const QString& string = QStringLiteral("")); Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, QWidget* parent_, std::forward_list>& apply_funcs_); virtual ~Widget(); bool Valid(); - [[nodiscard]] static QPushButton* CreateRestoreGlobalButton(Settings::BasicSetting& setting, - QWidget* parent); + [[nodiscard]] static QPushButton* CreateRestoreGlobalButton(bool using_global, QWidget* parent); QPushButton* restore_button{}; QLineEdit* line_edit{}; @@ -68,12 +68,12 @@ private: void CreateHexEdit(const QString& label, std::function& load_func, bool managed, Settings::BasicSetting* const other_setting = nullptr); void CreateSlider(const QString& label, bool reversed, float multiplier, - std::function& load_func, bool managed, + std::function& load_func, bool managed, const QString& format, Settings::BasicSetting* const other_setting = nullptr); void CreateDateTimeEdit(const QString& label, std::function& load_func, bool managed, bool restrict, Settings::BasicSetting* const other_setting = nullptr); void CreateSpinBox(const QString& label, std::function& load_func, bool managed, - const std::string& suffix, Settings::BasicSetting* other_setting = nullptr); + const QString& suffix, Settings::BasicSetting* other_setting = nullptr); QWidget* parent; const TranslationMap& translations; @@ -81,6 +81,7 @@ private: std::forward_list>& apply_funcs; bool created{false}; + bool runtime_lock{false}; }; } // namespace ConfigurationShared -- cgit v1.2.3 From c5a3642cb62b4676d0c8b98949daec20e7c02e6b Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 May 2023 22:17:36 -0400 Subject: configuration: Use a mapping of setting value to name Makes comboboxes always correspond to the value of the setting they're modifying. --- src/yuzu/configuration/configure_audio.cpp | 21 +- src/yuzu/configuration/configure_audio.h | 11 +- src/yuzu/configuration/configure_dialog.cpp | 16 +- src/yuzu/configuration/configure_dialog.h | 1 + src/yuzu/configuration/configure_general.cpp | 9 +- src/yuzu/configuration/configure_general.h | 11 +- src/yuzu/configuration/configure_graphics.cpp | 45 ++- src/yuzu/configuration/configure_graphics.h | 17 +- .../configuration/configure_graphics_advanced.cpp | 9 +- .../configuration/configure_graphics_advanced.h | 5 +- src/yuzu/configuration/configure_per_game.cpp | 13 +- src/yuzu/configuration/configure_per_game.h | 1 + src/yuzu/configuration/configure_system.cpp | 14 +- src/yuzu/configuration/configure_system.h | 12 +- src/yuzu/configuration/shared_translation.cpp | 320 +++++++++++++-------- src/yuzu/configuration/shared_translation.h | 6 +- src/yuzu/configuration/shared_widget.cpp | 65 +++-- src/yuzu/configuration/shared_widget.h | 8 +- 18 files changed, 355 insertions(+), 229 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index dd9eb4dc1..1cafeaa31 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp @@ -15,12 +15,13 @@ #include "yuzu/configuration/shared_widget.h" #include "yuzu/uisettings.h" -ConfigureAudio::ConfigureAudio(const Core::System& system_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - QWidget* parent) - : Tab(group, parent), - ui(std::make_unique()), system{system_}, translations{translations_} { +ConfigureAudio::ConfigureAudio( + const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) + : Tab(group, parent), ui(std::make_unique()), system{system_}, + translations{translations_}, combobox_translations{combobox_translations_} { ui->setupUi(this); Setup(); @@ -48,18 +49,18 @@ void ConfigureAudio::Setup() { auto* widget = [&]() { if (setting->Id() == Settings::values.volume.Id()) { return new ConfigurationShared::Widget( - setting, translations, this, runtime_lock, apply_funcs, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::Slider, true, 1.0f, nullptr, tr("%1%", "Volume percentage (e.g. 50%)")); } else if (setting->Id() == Settings::values.audio_output_device_id.Id() || setting->Id() == Settings::values.audio_input_device_id.Id() || setting->Id() == Settings::values.sink_id.Id()) { return new ConfigurationShared::Widget( - setting, translations, this, runtime_lock, apply_funcs, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::ComboBox, false); } else { - return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, - apply_funcs); + return new ConfigurationShared::Widget(setting, translations, combobox_translations, + this, runtime_lock, apply_funcs); } }(); diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index 170e0bce8..a9b005433 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h @@ -22,10 +22,12 @@ class ConfigureAudio; class ConfigureAudio : public ConfigurationShared::Tab { public: - explicit ConfigureAudio(const Core::System& system_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - QWidget* parent = nullptr); + explicit ConfigureAudio( + const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, + QWidget* parent = nullptr); ~ConfigureAudio() override; void ApplyConfiguration() override; @@ -49,6 +51,7 @@ private: const Core::System& system; const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; std::forward_list> apply_funcs{}; diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index f0f00be83..1a339a227 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -34,21 +34,25 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, : QDialog(parent), ui{std::make_unique()}, registry(registry_), system{system_}, translations{ConfigurationShared::InitializeTranslations(this)}, - audio_tab{std::make_unique(system_, nullptr, *translations, this)}, + combobox_translations{ConfigurationShared::ComboboxEnumeration(this)}, + audio_tab{std::make_unique(system_, nullptr, *translations, + *combobox_translations, this)}, cpu_tab{std::make_unique(system_, nullptr, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, - general_tab{std::make_unique(system_, nullptr, *translations, this)}, - graphics_advanced_tab{ - std::make_unique(system_, nullptr, *translations, this)}, + general_tab{std::make_unique(system_, nullptr, *translations, + *combobox_translations, this)}, + graphics_advanced_tab{std::make_unique( + system_, nullptr, *translations, *combobox_translations, this)}, graphics_tab{std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - nullptr, *translations, this)}, + nullptr, *translations, *combobox_translations, this)}, hotkeys_tab{std::make_unique(system_.HIDCore(), this)}, input_tab{std::make_unique(system_, this)}, network_tab{std::make_unique(system_, this)}, profile_tab{std::make_unique(system_, this)}, - system_tab{std::make_unique(system_, nullptr, *translations, this)}, + system_tab{std::make_unique(system_, nullptr, *translations, + *combobox_translations, this)}, ui_tab{std::make_unique(system_, this)}, web_tab{std::make_unique( this)} { Settings::SetConfiguringGlobal(true); diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index 0416b01d9..4f8c1912f 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h @@ -72,6 +72,7 @@ private: Core::System& system; std::unique_ptr translations; + std::unique_ptr combobox_translations; std::forward_list tab_group; std::unique_ptr audio_tab; diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 7eb6cb9ec..fdae83c64 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp @@ -15,9 +15,10 @@ ConfigureGeneral::ConfigureGeneral( const Core::System& system_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, QWidget* parent) + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) : Tab(group, parent), ui{std::make_unique()}, system{system_}, - translations{translations_} { + translations{translations_}, combobox_translations{combobox_translations_} { ui->setupUi(this); SetConfiguration(); @@ -40,8 +41,8 @@ void ConfigureGeneral::SetConfiguration() { for (const auto setting : UISettings::values.linkage.by_category[Settings::Category::UiGeneral]) { - auto* widget = - new ConfigurationShared::Widget(setting, translations, this, runtime_lock, apply_funcs); + auto* widget = new ConfigurationShared::Widget(setting, translations, combobox_translations, + this, runtime_lock, apply_funcs); if (!widget->Valid()) { delete widget; diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 7692c16da..864dc3d2e 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h @@ -22,10 +22,12 @@ class ConfigureGeneral; class ConfigureGeneral : public ConfigurationShared::Tab { public: - explicit ConfigureGeneral(const Core::System& system_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - QWidget* parent = nullptr); + explicit ConfigureGeneral( + const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, + QWidget* parent = nullptr); ~ConfigureGeneral() override; void SetResetCallback(std::function callback); @@ -45,4 +47,5 @@ private: const Core::System& system; const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; }; diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 45a4db430..a4dac659f 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -79,10 +79,12 @@ ConfigureGraphics::ConfigureGraphics( const Core::System& system_, std::vector& records_, const std::function& expose_compute_option_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, QWidget* parent) + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) : ConfigurationShared::Tab(group, parent), ui{std::make_unique()}, records{records_}, expose_compute_option{expose_compute_option_}, system{system_}, - translations{translations_} { + translations{translations_}, combobox_translations{combobox_translations_}, + shader_mapping{combobox_translations.at(typeid(Settings::ShaderBackend))} { vulkan_device = Settings::values.vulkan_device.GetValue(); RetrieveVulkanDevices(); @@ -235,22 +237,22 @@ void ConfigureGraphics::Setup() { setting->Id() == Settings::values.shader_backend.Id() || setting->Id() == Settings::values.vsync_mode.Id()) { return new ConfigurationShared::Widget( - setting, translations, this, runtime_lock, apply_funcs, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::ComboBox, false); } else if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) { return new ConfigurationShared::Widget( - setting, translations, this, runtime_lock, apply_funcs, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true, 0.5f, nullptr, tr("%1%", "FSR sharpening percentage (e.g. 50%)")); } else if (setting->Id() == Settings::values.speed_limit.Id()) { return new ConfigurationShared::Widget( - setting, translations, this, runtime_lock, apply_funcs, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::SpinBox, true, 1.0f, &Settings::values.use_speed_limit, tr("%", "Limit speed percentage (e.g. 50%)")); } else { - return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, - apply_funcs); + return new ConfigurationShared::Widget(setting, translations, combobox_translations, + this, runtime_lock, apply_funcs); } }(); @@ -360,6 +362,15 @@ const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode, } } +int ConfigureGraphics::FindIndex(std::type_index enumeration, int value) const { + for (u32 i = 0; i < combobox_translations.at(enumeration).size(); i++) { + if (combobox_translations.at(enumeration)[i].first == static_cast(value)) { + return i; + } + } + return -1; +} + void ConfigureGraphics::ApplyConfiguration() { const bool powered_on = system.IsPoweredOn(); for (const auto& func : apply_funcs) { @@ -374,13 +385,17 @@ void ConfigureGraphics::ApplyConfiguration() { Settings::values.shader_backend.SetGlobal(true); Settings::values.vulkan_device.SetGlobal(true); - if (!Settings::IsConfiguringGlobal() && api_restore_global_button->isEnabled()) { - auto backend = static_cast(api_combobox->currentIndex()); + if (Settings::IsConfiguringGlobal() || + (!Settings::IsConfiguringGlobal() && api_restore_global_button->isEnabled())) { + auto backend = static_cast( + combobox_translations + .at(typeid(Settings::RendererBackend))[api_combobox->currentIndex()] + .first); switch (backend) { case Settings::RendererBackend::OpenGL: Settings::values.shader_backend.SetGlobal(false); - Settings::values.shader_backend.SetValue( - static_cast(shader_backend_combobox->currentIndex())); + Settings::values.shader_backend.SetValue(static_cast( + shader_mapping[shader_backend_combobox->currentIndex()].first)); break; case Settings::RendererBackend::Vulkan: Settings::values.vulkan_device.SetGlobal(false); @@ -430,7 +445,8 @@ void ConfigureGraphics::UpdateAPILayout() { switch (GetCurrentGraphicsBackend()) { case Settings::RendererBackend::OpenGL: - shader_backend_combobox->setCurrentIndex(static_cast(shader_backend)); + shader_backend_combobox->setCurrentIndex( + FindIndex(typeid(Settings::ShaderBackend), static_cast(shader_backend))); vulkan_device_widget->setVisible(false); shader_backend_widget->setVisible(true); break; @@ -467,5 +483,8 @@ Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const { if (!Settings::IsConfiguringGlobal() && !api_restore_global_button->isEnabled()) { return Settings::values.renderer_backend.GetValue(true); } - return static_cast(api_combobox->currentIndex()); + return static_cast( + combobox_translations.at(typeid(Settings::RendererBackend)) + .at(api_combobox->currentIndex()) + .first); } diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index f36495ed3..9e421d024 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -36,12 +36,13 @@ class ConfigureGraphics; class ConfigureGraphics : public ConfigurationShared::Tab { public: - explicit ConfigureGraphics(const Core::System& system_, - std::vector& records, - const std::function& expose_compute_option_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - QWidget* parent = nullptr); + explicit ConfigureGraphics( + const Core::System& system_, std::vector& records, + const std::function& expose_compute_option_, + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, + QWidget* parent = nullptr); ~ConfigureGraphics() override; void ApplyConfiguration() override; @@ -68,6 +69,8 @@ private: Settings::RendererBackend GetCurrentGraphicsBackend() const; + int FindIndex(std::type_index enumeration, int value) const; + std::unique_ptr ui; QColor bg_color; @@ -85,6 +88,8 @@ private: const Core::System& system; const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; + const std::vector>& shader_mapping; QPushButton* api_restore_global_button; QComboBox* vulkan_device_combobox; diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index 4f57a7ae6..61e9b3d69 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -13,9 +13,10 @@ ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced( const Core::System& system_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, QWidget* parent) + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) : Tab(group, parent), ui{std::make_unique()}, system{system_}, - translations{translations_} { + translations{translations_}, combobox_translations{combobox_translations_} { ui->setupUi(this); @@ -33,8 +34,8 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { for (auto setting : Settings::values.linkage.by_category[Settings::Category::RendererAdvanced]) { - ConfigurationShared::Widget* widget = - new ConfigurationShared::Widget(setting, translations, this, runtime_lock, apply_funcs); + ConfigurationShared::Widget* widget = new ConfigurationShared::Widget( + setting, translations, combobox_translations, this, runtime_lock, apply_funcs); if (!widget->Valid()) { delete widget; diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index 327134ee6..42634d3ff 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h @@ -20,7 +20,9 @@ public: explicit ConfigureGraphicsAdvanced( const Core::System& system_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, QWidget* parent = nullptr); + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, + QWidget* parent = nullptr); ~ConfigureGraphicsAdvanced() override; void ApplyConfiguration() override; @@ -36,6 +38,7 @@ private: const Core::System& system; const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; std::forward_list> apply_funcs; QWidget* checkbox_enable_compute_pipelines{}; diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 2ee0a8ffa..845ffeeb8 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -43,6 +43,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st : QDialog(parent), ui(std::make_unique()), title_id{title_id_}, system{system_}, translations{ConfigurationShared::InitializeTranslations(this)}, + combobox_translations{ConfigurationShared::ComboboxEnumeration(this)}, tab_group{std::make_shared>()} { const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name)); const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()) @@ -50,15 +51,17 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st game_config = std::make_unique(config_file_name, Config::ConfigType::PerGameConfig); addons_tab = std::make_unique(system_, this); - audio_tab = std::make_unique(system_, tab_group, *translations, this); + audio_tab = std::make_unique(system_, tab_group, *translations, + *combobox_translations, this); cpu_tab = std::make_unique(system_, tab_group, this); - graphics_advanced_tab = - std::make_unique(system_, tab_group, *translations, this); + graphics_advanced_tab = std::make_unique( + system_, tab_group, *translations, *combobox_translations, this); graphics_tab = std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - tab_group, *translations, this); + tab_group, *translations, *combobox_translations, this); input_tab = std::make_unique(system_, game_config.get(), this); - system_tab = std::make_unique(system_, tab_group, *translations, this); + system_tab = std::make_unique(system_, tab_group, *translations, + *combobox_translations, this); ui->setupUi(this); diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h index 32217c1f1..e43d4df94 100644 --- a/src/yuzu/configuration/configure_per_game.h +++ b/src/yuzu/configuration/configure_per_game.h @@ -75,6 +75,7 @@ private: Core::System& system; std::unique_ptr translations; + std::unique_ptr combobox_translations; std::shared_ptr> tab_group; std::unique_ptr addons_tab; diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 128860800..40d0be8ca 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -44,9 +44,10 @@ static bool IsValidLocale(u32 region_index, u32 language_index) { ConfigureSystem::ConfigureSystem( Core::System& system_, std::shared_ptr> group, - ConfigurationShared::TranslationMap& translations_, QWidget* parent) + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) : Tab(group, parent), ui{std::make_unique()}, system{system_}, - translations{translations_} { + translations{translations_}, combobox_translations{combobox_translations_} { ui->setupUi(this); Setup(); @@ -121,18 +122,17 @@ void ConfigureSystem::Setup() { ConfigurationShared::Widget* widget = [=]() { if (setting->Id() == Settings::values.custom_rtc.Id()) { return new ConfigurationShared::Widget( - setting, translations, this, runtime_lock, apply_funcs, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::DateTimeEdit, true, 1.0f, &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, + setting, translations, combobox_translations, this, runtime_lock, apply_funcs, ConfigurationShared::RequestType::HexEdit, true, 1.0f, &Settings::values.rng_seed_enabled); } else { - return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, - - apply_funcs); + return new ConfigurationShared::Widget(setting, translations, combobox_translations, + this, runtime_lock, apply_funcs); } }(); diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 87b575060..c598c07f3 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -22,10 +22,11 @@ class ConfigureSystem; class ConfigureSystem : public ConfigurationShared::Tab { public: - explicit ConfigureSystem(Core::System& system_, - std::shared_ptr> group, - ConfigurationShared::TranslationMap& translations, - QWidget* parent = nullptr); + explicit ConfigureSystem( + Core::System& system_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations, + QWidget* parent = nullptr); ~ConfigureSystem() override; void ApplyConfiguration() override; @@ -46,7 +47,8 @@ private: ConfigurationShared::CheckState use_unsafe_extended_memory_layout; Core::System& system; - ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; QCheckBox* rng_seed_checkbox; QLineEdit* rng_seed_edit; diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index c3b38f776..8fd8f3076 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -152,134 +152,204 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { return translations; } -std::forward_list ComboboxEnumeration(std::type_index type, QWidget* parent) { +std::unique_ptr ComboboxEnumeration(QWidget* parent) { + std::unique_ptr translations = + std::make_unique(); const auto& tr = [&](const char* text) { return parent->tr(text); }; // Intentionally skipping VSyncMode to let the UI fill that one out - if (type == typeid(Settings::AstcDecodeMode)) { - return { - tr("CPU"), - tr("GPU"), - tr("CPU Asynchronous"), - }; - } else if (type == typeid(Settings::RendererBackend)) { - return { - tr("OpenGL"), - tr("Vulkan"), - tr("Null"), - }; - } else if (type == typeid(Settings::ShaderBackend)) { - return { - tr("GLSL"), - tr("GLASM (Assembly Shaders, NVIDIA Only)"), - tr("SPIR-V (Experimental, Mesa Only)"), - }; - } else if (type == typeid(Settings::GPUAccuracy)) { - return { - tr("Normal"), - tr("High"), - tr("Extreme"), - }; - } else if (type == typeid(Settings::CPUAccuracy)) { - return { - tr("Auto"), - tr("Accurate"), - tr("Unsafe"), - tr("Paranoid (disables most optimizations)"), - }; - } else if (type == typeid(Settings::FullscreenMode)) { - return { - tr("Borderless Windowed"), - tr("Exclusive Fullscreen"), - }; - } else if (type == typeid(Settings::NvdecEmulation)) { - return { - tr("No Video Output"), - tr("CPU Video Decoding"), - tr("GPU Video Decoding (Default)"), - }; - } else if (type == typeid(Settings::ResolutionSetup)) { - return { - tr("0.5X (360p/540p) [EXPERIMENTAL]"), - tr("0.75X (540p/810p) [EXPERIMENTAL]"), - tr("1X (720p/1080p)"), - tr("1.5X (1080p/1620p) [EXPERIMENTAL]"), - tr("2X (1440p/2160p)"), - tr("3X (2160p/3240p)"), - tr("4X (2880p/4320p)"), - tr("5X (3600p/5400p)"), - tr("6X (4320p/6480p)"), - tr("7X (5040p/7560p)"), - tr("8X (5760p/8640p)"), - }; - } else if (type == typeid(Settings::ScalingFilter)) { - return { - tr("Nearest Neighbor"), tr("Bilinear"), tr("Bicubic"), - tr("Gaussian"), tr("ScaleForce"), tr("AMD FidelityFX™️ Super Resolution"), - }; - } else if (type == typeid(Settings::AntiAliasing)) { - return { - tr("None"), - tr("FXAA"), - tr("SMAA"), - }; - } else if (type == typeid(Settings::AspectRatio)) { - return { - tr("Default (16:9)"), tr("Force 4:3"), tr("Force 21:9"), - tr("Force 16:10"), tr("Stretch to Window"), - }; - } else if (type == typeid(Settings::AnisotropyMode)) { - return { - tr("Automatic"), tr("Default"), tr("2x"), tr("4x"), tr("8x"), tr("16x"), - }; - } else if (type == typeid(Settings::Language)) { - return { - tr("Japanese (日本語)"), - tr("American English"), - tr("French (français)"), - tr("German (Deutsch)"), - tr("Italian (italiano)"), - tr("Spanish (español)"), - tr("Chinese"), - tr("Korean (한국어)"), - tr("Dutch (Nederlands)"), - tr("Portuguese (português)"), - tr("Russian (Русский)"), - tr("Taiwanese"), - tr("British English"), - tr("Canadian French"), - tr("Latin American Spanish"), - tr("Simplified Chinese"), - tr("Traditional Chinese (正體中文)"), - tr("Brazilian Portuguese (português do Brasil)"), - }; - } else if (type == typeid(Settings::Region)) { - return { - tr("Japan"), tr("USA"), tr("Europe"), tr("Australia"), - tr("China"), tr("Korea"), tr("Taiwan"), - }; - } else if (type == typeid(Settings::TimeZone)) { - return { - tr("Auto"), tr("Default"), tr("CET"), tr("CST6CDT"), tr("Cuba"), - tr("EET"), tr("Egypt"), tr("Eire"), tr("EST"), tr("EST5EDT"), - tr("GB"), tr("GB-Eire"), tr("GMT"), tr("GMT+0"), tr("GMT-0"), - tr("GMT0"), tr("Greenwich"), tr("Hongkong"), tr("HST"), tr("Iceland"), - tr("Iran"), tr("Israel"), tr("Jamaica"), tr("Kwajalein"), tr("Libya"), - tr("MET"), tr("MST"), tr("MST7MDT"), tr("Navajo"), tr("NZ"), - tr("NZ-CHAT"), tr("Poland"), tr("Portugal"), tr("PRC"), tr("PST8PDT"), - tr("ROC"), tr("ROK"), tr("Singapore"), tr("Turkey"), tr("UCT"), - tr("W-SU"), tr("WET"), tr("Zulu"), - }; - } else if (type == typeid(Settings::AudioMode)) { - return { - tr("Mono"), - tr("Stereo"), - tr("Surround"), - }; - } - - return {}; -} + translations->insert( + {typeid(Settings::AstcDecodeMode), + { + {static_cast(Settings::AstcDecodeMode::CPU), tr("CPU")}, + {static_cast(Settings::AstcDecodeMode::GPU), tr("GPU")}, + {static_cast(Settings::AstcDecodeMode::CPUAsynchronous), tr("CPU Asynchronous")}, + }}); + translations->insert({typeid(Settings::RendererBackend), + { +#ifdef HAS_OPENGL + {static_cast(Settings::RendererBackend::OpenGL), tr("OpenGL")}, +#endif + {static_cast(Settings::RendererBackend::Vulkan), tr("Vulkan")}, + {static_cast(Settings::RendererBackend::Null), tr("Null")}, + }}); + translations->insert({typeid(Settings::ShaderBackend), + { + {static_cast(Settings::ShaderBackend::GLSL), tr("GLSL")}, + {static_cast(Settings::ShaderBackend::GLASM), + tr("GLASM (Assembly Shaders, NVIDIA Only)")}, + {static_cast(Settings::ShaderBackend::SPIRV), + tr("SPIR-V (Experimental, Mesa Only)")}, + }}); + translations->insert({typeid(Settings::GPUAccuracy), + { + {static_cast(Settings::GPUAccuracy::Normal), tr("Normal")}, + {static_cast(Settings::GPUAccuracy::High), tr("High")}, + {static_cast(Settings::GPUAccuracy::Extreme), tr("Extreme")}, + }}); + translations->insert({typeid(Settings::CPUAccuracy), + { + {static_cast(Settings::CPUAccuracy::Auto), tr("Auto")}, + {static_cast(Settings::CPUAccuracy::Accurate), tr("Accurate")}, + {static_cast(Settings::CPUAccuracy::Unsafe), tr("Unsafe")}, + {static_cast(Settings::CPUAccuracy::Paranoid), + tr("Paranoid (disables most optimizations)")}, + }}); + translations->insert( + {typeid(Settings::FullscreenMode), + { + {static_cast(Settings::FullscreenMode::Borderless), tr("Borderless Windowed")}, + {static_cast(Settings::FullscreenMode::Exclusive), tr("Exclusive Fullscreen")}, + }}); + translations->insert( + {typeid(Settings::NvdecEmulation), + { + {static_cast(Settings::NvdecEmulation::Off), tr("No Video Output")}, + {static_cast(Settings::NvdecEmulation::CPU), tr("CPU Video Decoding")}, + {static_cast(Settings::NvdecEmulation::GPU), tr("GPU Video Decoding (Default)")}, + }}); + translations->insert( + {typeid(Settings::ResolutionSetup), + { + {static_cast(Settings::ResolutionSetup::Res1_2X), + tr("0.5X (360p/540p) [EXPERIMENTAL]")}, + {static_cast(Settings::ResolutionSetup::Res3_4X), + tr("0.75X (540p/810p) [EXPERIMENTAL]")}, + {static_cast(Settings::ResolutionSetup::Res1X), tr("1X (720p/1080p)")}, + {static_cast(Settings::ResolutionSetup::Res3_2X), + tr("1.5X (1080p/1620p) [EXPERIMENTAL]")}, + {static_cast(Settings::ResolutionSetup::Res2X), tr("2X (1440p/2160p)")}, + {static_cast(Settings::ResolutionSetup::Res3X), tr("3X (2160p/3240p)")}, + {static_cast(Settings::ResolutionSetup::Res4X), tr("4X (2880p/4320p)")}, + {static_cast(Settings::ResolutionSetup::Res5X), tr("5X (3600p/5400p)")}, + {static_cast(Settings::ResolutionSetup::Res6X), tr("6X (4320p/6480p)")}, + {static_cast(Settings::ResolutionSetup::Res7X), tr("7X (5040p/7560p)")}, + {static_cast(Settings::ResolutionSetup::Res8X), tr("8X (5760p/8640p)")}, + }}); + translations->insert( + {typeid(Settings::ScalingFilter), + { + {static_cast(Settings::ScalingFilter::NearestNeighbor), tr("Nearest Neighbor")}, + {static_cast(Settings::ScalingFilter::Bilinear), tr("Bilinear")}, + {static_cast(Settings::ScalingFilter::Bicubic), tr("Bicubic")}, + {static_cast(Settings::ScalingFilter::Gaussian), tr("Gaussian")}, + {static_cast(Settings::ScalingFilter::ScaleForce), tr("ScaleForce")}, + {static_cast(Settings::ScalingFilter::Fsr), + tr("AMD FidelityFX™️ Super Resolution")}, + }}); + translations->insert({typeid(Settings::AntiAliasing), + { + {static_cast(Settings::AntiAliasing::None), tr("None")}, + {static_cast(Settings::AntiAliasing::Fxaa), tr("FXAA")}, + {static_cast(Settings::AntiAliasing::Smaa), tr("SMAA")}, + }}); + translations->insert( + {typeid(Settings::AspectRatio), + { + {static_cast(Settings::AspectRatio::R16_9), tr("Default (16:9)")}, + {static_cast(Settings::AspectRatio::R4_3), tr("Force 4:3")}, + {static_cast(Settings::AspectRatio::R21_9), tr("Force 21:9")}, + {static_cast(Settings::AspectRatio::R16_10), tr("Force 16:10")}, + {static_cast(Settings::AspectRatio::Stretch), tr("Stretch to Window")}, + }}); + translations->insert( + {typeid(Settings::AnisotropyMode), + { + {static_cast(Settings::AnisotropyMode::Automatic), tr("Automatic")}, + {static_cast(Settings::AnisotropyMode::Default), tr("Default")}, + {static_cast(Settings::AnisotropyMode::X2), tr("2x")}, + {static_cast(Settings::AnisotropyMode::X4), tr("4x")}, + {static_cast(Settings::AnisotropyMode::X8), tr("8x")}, + {static_cast(Settings::AnisotropyMode::X16), tr("16x")}, + }}); + translations->insert( + {typeid(Settings::Language), + { + {static_cast(Settings::Language::Japanese), tr("Japanese (日本語)")}, + {static_cast(Settings::Language::EnglishAmerican), tr("American English")}, + {static_cast(Settings::Language::French), tr("French (français)")}, + {static_cast(Settings::Language::German), tr("German (Deutsch)")}, + {static_cast(Settings::Language::Italian), tr("Italian (italiano)")}, + {static_cast(Settings::Language::Spanish), tr("Spanish (español)")}, + {static_cast(Settings::Language::Chinese), tr("Chinese")}, + {static_cast(Settings::Language::Korean), tr("Korean (한국어)")}, + {static_cast(Settings::Language::Dutch), tr("Dutch (Nederlands)")}, + {static_cast(Settings::Language::Portuguese), tr("Portuguese (português)")}, + {static_cast(Settings::Language::Russian), tr("Russian (Русский)")}, + {static_cast(Settings::Language::Taiwanese), tr("Taiwanese")}, + {static_cast(Settings::Language::EnglishBritish), tr("British English")}, + {static_cast(Settings::Language::FrenchCanadian), tr("Canadian French")}, + {static_cast(Settings::Language::SpanishLatin), tr("Latin American Spanish")}, + {static_cast(Settings::Language::ChineseSimplified), tr("Simplified Chinese")}, + {static_cast(Settings::Language::ChineseTraditional), + tr("Traditional Chinese (正體中文)")}, + {static_cast(Settings::Language::PortugueseBrazilian), + tr("Brazilian Portuguese (português do Brasil)")}, + }}); + translations->insert({typeid(Settings::Region), + { + {static_cast(Settings::Region::Japan), tr("Japan")}, + {static_cast(Settings::Region::USA), tr("USA")}, + {static_cast(Settings::Region::Europe), tr("Europe")}, + {static_cast(Settings::Region::Australia), tr("Australia")}, + {static_cast(Settings::Region::China), tr("China")}, + {static_cast(Settings::Region::Korea), tr("Korea")}, + {static_cast(Settings::Region::Taiwan), tr("Taiwan")}, + }}); + translations->insert({typeid(Settings::TimeZone), + { + {static_cast(Settings::TimeZone::Auto), tr("Auto")}, + {static_cast(Settings::TimeZone::Default), tr("Default")}, + {static_cast(Settings::TimeZone::CET), tr("CET")}, + {static_cast(Settings::TimeZone::CST6CDT), tr("CST6CDT")}, + {static_cast(Settings::TimeZone::Cuba), tr("Cuba")}, + {static_cast(Settings::TimeZone::EET), tr("EET")}, + {static_cast(Settings::TimeZone::Egypt), tr("Egypt")}, + {static_cast(Settings::TimeZone::Eire), tr("Eire")}, + {static_cast(Settings::TimeZone::EST), tr("EST")}, + {static_cast(Settings::TimeZone::EST5EDT), tr("EST5EDT")}, + {static_cast(Settings::TimeZone::GB), tr("GB")}, + {static_cast(Settings::TimeZone::GBEire), tr("GB-Eire")}, + {static_cast(Settings::TimeZone::GMT), tr("GMT")}, + {static_cast(Settings::TimeZone::GMTPlusZero), tr("GMT+0")}, + {static_cast(Settings::TimeZone::GMTMinusZero), tr("GMT-0")}, + {static_cast(Settings::TimeZone::GMTZero), tr("GMT0")}, + {static_cast(Settings::TimeZone::Greenwich), tr("Greenwich")}, + {static_cast(Settings::TimeZone::Hongkong), tr("Hongkong")}, + {static_cast(Settings::TimeZone::HST), tr("HST")}, + {static_cast(Settings::TimeZone::Iceland), tr("Iceland")}, + {static_cast(Settings::TimeZone::Iran), tr("Iran")}, + {static_cast(Settings::TimeZone::Israel), tr("Israel")}, + {static_cast(Settings::TimeZone::Jamaica), tr("Jamaica")}, + {static_cast(Settings::TimeZone::Kwajalein), tr("Kwajalein")}, + {static_cast(Settings::TimeZone::Libya), tr("Libya")}, + {static_cast(Settings::TimeZone::MET), tr("MET")}, + {static_cast(Settings::TimeZone::MST), tr("MST")}, + {static_cast(Settings::TimeZone::MST7MDT), tr("MST7MDT")}, + {static_cast(Settings::TimeZone::Navajo), tr("Navajo")}, + {static_cast(Settings::TimeZone::NZ), tr("NZ")}, + {static_cast(Settings::TimeZone::NZCHAT), tr("NZ-CHAT")}, + {static_cast(Settings::TimeZone::Poland), tr("Poland")}, + {static_cast(Settings::TimeZone::Portugal), tr("Portugal")}, + {static_cast(Settings::TimeZone::PRC), tr("PRC")}, + {static_cast(Settings::TimeZone::PST8PDT), tr("PST8PDT")}, + {static_cast(Settings::TimeZone::ROC), tr("ROC")}, + {static_cast(Settings::TimeZone::ROK), tr("ROK")}, + {static_cast(Settings::TimeZone::Singapore), tr("Singapore")}, + {static_cast(Settings::TimeZone::Turkey), tr("Turkey")}, + {static_cast(Settings::TimeZone::UCT), tr("UCT")}, + {static_cast(Settings::TimeZone::W_SU), tr("W-SU")}, + {static_cast(Settings::TimeZone::WET), tr("WET")}, + {static_cast(Settings::TimeZone::Zulu), tr("Zulu")}, + }}); + translations->insert({typeid(Settings::AudioMode), + { + {static_cast(Settings::AudioMode::Mono), tr("Mono")}, + {static_cast(Settings::AudioMode::Stereo), tr("Stereo")}, + {static_cast(Settings::AudioMode::Surround), tr("Surround")}, + }}); + return translations; +} } // namespace ConfigurationShared diff --git a/src/yuzu/configuration/shared_translation.h b/src/yuzu/configuration/shared_translation.h index fcf638ea5..abe9c89b1 100644 --- a/src/yuzu/configuration/shared_translation.h +++ b/src/yuzu/configuration/shared_translation.h @@ -1,21 +1,23 @@ // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include #include #include #include #include #include +#include #include class QWidget; namespace ConfigurationShared { using TranslationMap = std::map>; +using ComboboxTranslations = std::vector>; +using ComboboxTranslationMap = std::map; std::unique_ptr InitializeTranslations(QWidget* parent); -std::forward_list ComboboxEnumeration(std::type_index type, QWidget* parent); +std::unique_ptr ComboboxEnumeration(QWidget* parent); } // namespace ConfigurationShared diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index 4b21e5be8..64e1d90ad 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -113,40 +113,51 @@ void Widget::CreateCombobox(const QString& label, std::function& load_fu QLabel* qt_label = new QLabel(label, this); combobox = new QComboBox(this); - std::forward_list combobox_enumerations = ComboboxEnumeration(type, this); - for (const auto& item : combobox_enumerations) { - combobox->addItem(item); - } - layout->addWidget(qt_label); layout->addWidget(combobox); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); - if (!managed) { - return; + const ComboboxTranslations* enumeration{nullptr}; + if (combobox_enumerations.contains(type)) { + enumeration = &combobox_enumerations.at(type); + for (const auto& [id, name] : *enumeration) { + combobox->addItem(name); + } } - // TODO: Remove audio engine specialization - if (setting.TypeId() != typeid(Settings::AudioEngine)) { - combobox->setCurrentIndex(std::stoi(setting.ToString())); - } else { - combobox->setCurrentIndex( - static_cast(Settings::ToEnum(setting.ToString()))); + if (!managed || enumeration == nullptr) { + return; } + const auto find_index = [=](u32 value) -> int { + for (u32 i = 0; i < enumeration->size(); i++) { + if (enumeration->at(i).first == value) { + return i; + } + } + return -1; + }; + + const u32 setting_value = std::stoi(setting.ToString()); + combobox->setCurrentIndex(find_index(setting_value)); + if (Settings::IsConfiguringGlobal()) { - load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); }; + load_func = [=]() { + int current = combobox->currentIndex(); + setting.LoadString(std::to_string(enumeration->at(current).first)); + }; } else { restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); layout->addWidget(restore_button); - QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { + QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { restore_button->setEnabled(false); restore_button->setVisible(false); - combobox->setCurrentIndex(std::stoi(setting.ToStringGlobal())); + const u32 global_value = std::stoi(setting.ToStringGlobal()); + combobox->setCurrentIndex(find_index(global_value)); }); QObject::connect(combobox, QOverload::of(&QComboBox::activated), [=](int) { @@ -158,7 +169,8 @@ void Widget::CreateCombobox(const QString& label, std::function& load_fu bool using_global = !restore_button->isEnabled(); setting.SetGlobal(using_global); if (!using_global) { - setting.LoadString(std::to_string(combobox->currentIndex())); + int current = combobox->currentIndex(); + setting.LoadString(std::to_string(enumeration->at(current).first)); } }; } @@ -523,17 +535,13 @@ bool Widget::Valid() { Widget::~Widget() = default; Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, - QWidget* parent_, std::forward_list>& apply_funcs_) - : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_}, - apply_funcs{apply_funcs_} {} - -Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, - QWidget* parent_, bool runtime_lock_, - std::forward_list>& apply_funcs_, RequestType request, - bool managed, float multiplier, Settings::BasicSetting* other_setting, - const QString& string) - : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_}, - apply_funcs{apply_funcs_}, runtime_lock{runtime_lock_} { + const ComboboxTranslationMap& combobox_translations_, QWidget* parent_, + bool runtime_lock_, std::forward_list>& apply_funcs_, + RequestType request, bool managed, float multiplier, + Settings::BasicSetting* other_setting, const QString& string) + : QWidget(parent_), parent{parent_}, translations{translations_}, + combobox_enumerations{combobox_translations_}, setting{*setting_}, apply_funcs{apply_funcs_}, + runtime_lock{runtime_lock_} { if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) { LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel()); return; @@ -632,5 +640,4 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati this->setToolTip(tooltip); } - } // namespace ConfigurationShared diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 331316040..6077f045d 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -35,13 +35,12 @@ class Widget : public QWidget { Q_OBJECT public: - Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent, - bool runtime_lock, std::forward_list>& apply_funcs_, + Widget(Settings::BasicSetting* setting, const TranslationMap& translations, + const ComboboxTranslationMap& combobox_translations, QWidget* parent, bool runtime_lock, + std::forward_list>& apply_funcs_, RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f, Settings::BasicSetting* other_setting = nullptr, const QString& string = QStringLiteral("")); - Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, QWidget* parent_, - std::forward_list>& apply_funcs_); virtual ~Widget(); bool Valid(); @@ -77,6 +76,7 @@ private: QWidget* parent; const TranslationMap& translations; + const ComboboxTranslationMap& combobox_enumerations; Settings::BasicSetting& setting; std::forward_list>& apply_funcs; -- cgit v1.2.3 From daa31121ee75dedcb636011e02815b816a7cc446 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 May 2023 22:54:58 -0400 Subject: configure_cpu: Generate UI --- src/yuzu/configuration/configure_cpu.cpp | 138 ++++++++++---------------- src/yuzu/configuration/configure_cpu.h | 11 +- src/yuzu/configuration/configure_cpu.ui | 129 ++++++------------------ src/yuzu/configuration/configure_dialog.cpp | 3 +- src/yuzu/configuration/configure_per_game.cpp | 3 +- 5 files changed, 94 insertions(+), 190 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index ecaeb1a6b..0982e006d 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -5,88 +5,83 @@ #include #include "common/common_types.h" #include "common/settings.h" +#include "configuration/shared_widget.h" #include "core/core.h" #include "ui_configure_cpu.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_cpu.h" -ConfigureCpu::ConfigureCpu(const Core::System& system_, - std::shared_ptr> group, - QWidget* parent) - : Tab(group, parent), ui{std::make_unique()}, system{system_} { +ConfigureCpu::ConfigureCpu( + const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) + : Tab(group, parent), ui{std::make_unique()}, system{system_}, + translations{translations_}, combobox_translations{combobox_translations_} { ui->setupUi(this); - SetupPerGameUI(); + Setup(); SetConfiguration(); - connect(ui->accuracy, qOverload(&QComboBox::currentIndexChanged), this, + connect(accuracy_combobox, qOverload(&QComboBox::currentIndexChanged), this, &ConfigureCpu::UpdateGroup); } ConfigureCpu::~ConfigureCpu() = default; -void ConfigureCpu::SetConfiguration() { +void ConfigureCpu::SetConfiguration() {} +void ConfigureCpu::Setup() { const bool runtime_lock = !system.IsPoweredOn(); + auto* accuracy_layout = ui->widget_accuracy->layout(); + auto* unsafe_layout = ui->unsafe_widget->layout(); + std::map unsafe_hold{}; + + std::forward_list settings; + const auto push = [&](Settings::Category category) { + for (const auto setting : Settings::values.linkage.by_category[category]) { + settings.push_front(setting); + } + }; + + push(Settings::Category::Cpu); + push(Settings::Category::CpuUnsafe); + + for (const auto setting : settings) { + auto* widget = new ConfigurationShared::Widget(setting, translations, combobox_translations, + this, runtime_lock, apply_funcs); + + if (!widget->Valid()) { + delete widget; + continue; + } + + if (setting->Id() == Settings::values.cpu_accuracy.Id()) { + accuracy_layout->addWidget(widget); + accuracy_combobox = widget->combobox; + } else { + unsafe_hold.insert({setting->GetLabel(), widget}); + } + } - ui->accuracy->setEnabled(runtime_lock); - ui->cpuopt_unsafe_unfuse_fma->setEnabled(runtime_lock); - ui->cpuopt_unsafe_reduce_fp_error->setEnabled(runtime_lock); - ui->cpuopt_unsafe_ignore_standard_fpcr->setEnabled(runtime_lock); - ui->cpuopt_unsafe_inaccurate_nan->setEnabled(runtime_lock); - ui->cpuopt_unsafe_fastmem_check->setEnabled(runtime_lock); - ui->cpuopt_unsafe_ignore_global_monitor->setEnabled(runtime_lock); - - ui->cpuopt_unsafe_unfuse_fma->setChecked(Settings::values.cpuopt_unsafe_unfuse_fma.GetValue()); - ui->cpuopt_unsafe_reduce_fp_error->setChecked( - Settings::values.cpuopt_unsafe_reduce_fp_error.GetValue()); - ui->cpuopt_unsafe_ignore_standard_fpcr->setChecked( - Settings::values.cpuopt_unsafe_ignore_standard_fpcr.GetValue()); - ui->cpuopt_unsafe_inaccurate_nan->setChecked( - Settings::values.cpuopt_unsafe_inaccurate_nan.GetValue()); - ui->cpuopt_unsafe_fastmem_check->setChecked( - Settings::values.cpuopt_unsafe_fastmem_check.GetValue()); - ui->cpuopt_unsafe_ignore_global_monitor->setChecked( - Settings::values.cpuopt_unsafe_ignore_global_monitor.GetValue()); - - if (Settings::IsConfiguringGlobal()) { - ui->accuracy->setCurrentIndex(static_cast(Settings::values.cpu_accuracy.GetValue())); - } else { - ConfigurationShared::SetPerGameSetting(ui->accuracy, &Settings::values.cpu_accuracy); - ConfigurationShared::SetHighlight(ui->widget_accuracy, - !Settings::values.cpu_accuracy.UsingGlobal()); + for (const auto& [label, widget] : unsafe_hold) { + unsafe_layout->addWidget(widget); } - UpdateGroup(ui->accuracy->currentIndex()); + + UpdateGroup(accuracy_combobox->currentIndex()); } void ConfigureCpu::UpdateGroup(int index) { - if (!Settings::IsConfiguringGlobal()) { - index -= ConfigurationShared::USE_GLOBAL_OFFSET; - } - const auto accuracy = static_cast(index); + const auto accuracy = static_cast( + combobox_translations.at(typeid(Settings::CPUAccuracy))[index].first); ui->unsafe_group->setVisible(accuracy == Settings::CPUAccuracy::Unsafe); } void ConfigureCpu::ApplyConfiguration() { - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpu_accuracy, ui->accuracy); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_unfuse_fma, - ui->cpuopt_unsafe_unfuse_fma, - cpuopt_unsafe_unfuse_fma); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_reduce_fp_error, - ui->cpuopt_unsafe_reduce_fp_error, - cpuopt_unsafe_reduce_fp_error); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_ignore_standard_fpcr, - ui->cpuopt_unsafe_ignore_standard_fpcr, - cpuopt_unsafe_ignore_standard_fpcr); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_inaccurate_nan, - ui->cpuopt_unsafe_inaccurate_nan, - cpuopt_unsafe_inaccurate_nan); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_fastmem_check, - ui->cpuopt_unsafe_fastmem_check, - cpuopt_unsafe_fastmem_check); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_ignore_global_monitor, - ui->cpuopt_unsafe_ignore_global_monitor, - cpuopt_unsafe_ignore_global_monitor); + const bool is_powered_on = system.IsPoweredOn(); + for (const auto& apply_func : apply_funcs) { + apply_func(is_powered_on); + } } void ConfigureCpu::changeEvent(QEvent* event) { @@ -100,32 +95,3 @@ void ConfigureCpu::changeEvent(QEvent* event) { void ConfigureCpu::RetranslateUI() { ui->retranslateUi(this); } - -void ConfigureCpu::SetupPerGameUI() { - if (Settings::IsConfiguringGlobal()) { - return; - } - - ConfigurationShared::SetColoredComboBox( - ui->accuracy, ui->widget_accuracy, - static_cast(Settings::values.cpu_accuracy.GetValue(true))); - - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_unfuse_fma, - Settings::values.cpuopt_unsafe_unfuse_fma, - cpuopt_unsafe_unfuse_fma); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_reduce_fp_error, - Settings::values.cpuopt_unsafe_reduce_fp_error, - cpuopt_unsafe_reduce_fp_error); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_ignore_standard_fpcr, - Settings::values.cpuopt_unsafe_ignore_standard_fpcr, - cpuopt_unsafe_ignore_standard_fpcr); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_inaccurate_nan, - Settings::values.cpuopt_unsafe_inaccurate_nan, - cpuopt_unsafe_inaccurate_nan); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_fastmem_check, - Settings::values.cpuopt_unsafe_fastmem_check, - cpuopt_unsafe_fastmem_check); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_ignore_global_monitor, - Settings::values.cpuopt_unsafe_ignore_global_monitor, - cpuopt_unsafe_ignore_global_monitor); -} diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h index 187d080b6..fb970122d 100644 --- a/src/yuzu/configuration/configure_cpu.h +++ b/src/yuzu/configuration/configure_cpu.h @@ -19,6 +19,8 @@ class ConfigureCpu : public ConfigurationShared::Tab { public: explicit ConfigureCpu(const Core::System& system_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations, QWidget* parent = nullptr); ~ConfigureCpu() override; @@ -31,7 +33,7 @@ private: void UpdateGroup(int index); - void SetupPerGameUI(); + void Setup(); std::unique_ptr ui; @@ -43,4 +45,11 @@ private: ConfigurationShared::CheckState cpuopt_unsafe_ignore_global_monitor; const Core::System& system; + + const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; + + std::forward_list> apply_funcs{}; + + QComboBox* accuracy_combobox; }; diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui index 8ae569ee6..835788c1f 100644 --- a/src/yuzu/configuration/configure_cpu.ui +++ b/src/yuzu/configuration/configure_cpu.ui @@ -27,38 +27,19 @@ - - - - - Accuracy: - - - - - - - - Auto - - - - - Accurate - - - - - Unsafe - - - - - Paranoid (disables most optimizations) - - - - + + + 0 + + + 0 + + + 0 + + + 0 + @@ -96,75 +77,21 @@ - - - - <div>This option improves speed by reducing accuracy of fused-multiply-add instructions on CPUs without native FMA support.</div> - - - - Unfuse FMA (improve performance on CPUs without FMA) - - - - - - - - <div>This option improves the speed of some approximate floating-point functions by using less accurate native approximations.</div> - - - - Faster FRSQRTE and FRECPE - - - - - - - - <div>This option improves the speed of 32 bits ASIMD floating-point functions by running with incorrect rounding modes.</div> - - - - Faster ASIMD instructions (32 bits only) - - - - - - - - <div>This option improves speed by removing NaN checking. Please note this also reduces accuracy of certain floating-point instructions.</div> - - - - Inaccurate NaN handling - - - - - - - - <div>This option improves speed by eliminating a safety check before every memory read/write in guest. Disabling it may allow a game to read/write the emulator's memory.</div> - - - - Disable address space checks - - - - - - - - <div>This option improves speed by relying only on the semantics of cmpxchg to ensure safety of exclusive access instructions. Please note this may result in deadlocks and other race conditions.</div> - - - - Ignore global monitor - + + + + 0 + + + 0 + + + 0 + + + 0 + + diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 1a339a227..c7d132fc8 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -37,7 +37,8 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, combobox_translations{ConfigurationShared::ComboboxEnumeration(this)}, audio_tab{std::make_unique(system_, nullptr, *translations, *combobox_translations, this)}, - cpu_tab{std::make_unique(system_, nullptr, this)}, + cpu_tab{std::make_unique(system_, nullptr, *translations, + *combobox_translations, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, general_tab{std::make_unique(system_, nullptr, *translations, diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 845ffeeb8..5863beca0 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -53,7 +53,8 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st addons_tab = std::make_unique(system_, this); audio_tab = std::make_unique(system_, tab_group, *translations, *combobox_translations, this); - cpu_tab = std::make_unique(system_, tab_group, this); + cpu_tab = std::make_unique(system_, tab_group, *translations, + *combobox_translations, this); graphics_advanced_tab = std::make_unique( system_, tab_group, *translations, *combobox_translations, this); graphics_tab = std::make_unique( -- cgit v1.2.3 From ad645c29a44bd117cad90bda56e1f4d6296f2666 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 21 Jun 2023 01:42:42 -0400 Subject: configuration: Use a builder to create widgets This gets rid of some repeated code and sets us up to send more information to the new widget. --- src/yuzu/configuration/configure_audio.cpp | 38 +++++++--------- src/yuzu/configuration/configure_audio.h | 18 ++++---- src/yuzu/configuration/configure_cpu.cpp | 23 ++++------ src/yuzu/configuration/configure_cpu.h | 12 +++--- src/yuzu/configuration/configure_dialog.cpp | 23 ++++------ src/yuzu/configuration/configure_dialog.h | 4 +- src/yuzu/configuration/configure_general.cpp | 19 ++++---- src/yuzu/configuration/configure_general.h | 19 ++++---- src/yuzu/configuration/configure_graphics.cpp | 32 ++++++-------- src/yuzu/configuration/configure_graphics.h | 23 +++++----- .../configuration/configure_graphics_advanced.cpp | 21 +++++---- .../configuration/configure_graphics_advanced.h | 13 +++--- src/yuzu/configuration/configure_per_game.cpp | 19 ++++---- src/yuzu/configuration/configure_per_game.h | 4 +- src/yuzu/configuration/configure_system.cpp | 43 ++++++++----------- src/yuzu/configuration/configure_system.h | 19 ++++---- src/yuzu/configuration/shared_widget.cpp | 35 ++++++++++++--- src/yuzu/configuration/shared_widget.h | 50 ++++++++++++---------- 18 files changed, 206 insertions(+), 209 deletions(-) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index 8c5378925..6db47fd61 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp @@ -16,23 +16,19 @@ #include "yuzu/configuration/shared_widget.h" #include "yuzu/uisettings.h" -ConfigureAudio::ConfigureAudio( - const Core::System& system_, - std::shared_ptr> group_, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) - : Tab(group_, parent), ui(std::make_unique()), system{system_}, - translations{translations_}, combobox_translations{combobox_translations_} { +ConfigureAudio::ConfigureAudio(const Core::System& system_, + std::shared_ptr> group_, + const ConfigurationShared::Builder& builder, QWidget* parent) + : Tab(group_, parent), ui(std::make_unique()), system{system_} { ui->setupUi(this); - Setup(); + Setup(builder); SetConfiguration(); } ConfigureAudio::~ConfigureAudio() = default; -void ConfigureAudio::Setup() { - const bool runtime_lock = !system.IsPoweredOn(); +void ConfigureAudio::Setup(const ConfigurationShared::Builder& builder) { auto& layout = *ui->audio_widget->layout(); std::forward_list settings; @@ -47,31 +43,27 @@ void ConfigureAudio::Setup() { push(Settings::Category::SystemAudio); for (auto* setting : settings) { - if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) { - continue; - } - auto* widget = [&]() { if (setting->Id() == Settings::values.volume.Id()) { // volume needs to be a slider (default is line edit) - return new ConfigurationShared::Widget(setting, translations, combobox_translations, - this, runtime_lock, apply_funcs, nullptr, - ConfigurationShared::RequestType::Slider, - tr("%1%", "Volume percentage (e.g. 50%)")); + return builder.BuildWidget(setting, apply_funcs, nullptr, + ConfigurationShared::RequestType::Slider, + tr("%1%", "Volume percentage (e.g. 50%)")); } else if (setting->Id() == Settings::values.audio_output_device_id.Id() || setting->Id() == Settings::values.audio_input_device_id.Id() || setting->Id() == Settings::values.sink_id.Id()) { // These need to be unmanaged comboboxes, so we can populate them ourselves // TODO (lat9nq): Let it manage sink_id - return new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs, - ConfigurationShared::RequestType::ComboBox, false); + return builder.BuildWidget(setting, apply_funcs, + ConfigurationShared::RequestType::ComboBox, false); } else { - return new ConfigurationShared::Widget(setting, translations, combobox_translations, - this, runtime_lock, apply_funcs); + return builder.BuildWidget(setting, apply_funcs); } }(); + if (widget == nullptr) { + continue; + } if (!widget->Valid()) { delete widget; continue; diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index 31cf682e0..94606f210 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h @@ -8,7 +8,6 @@ #include #include #include "yuzu/configuration/configuration_shared.h" -#include "yuzu/configuration/shared_translation.h" class QComboBox; @@ -20,14 +19,15 @@ namespace Ui { class ConfigureAudio; } +namespace ConfigurationShared { +class Builder; +} + class ConfigureAudio : public ConfigurationShared::Tab { public: - explicit ConfigureAudio( - const Core::System& system_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, - QWidget* parent = nullptr); + explicit ConfigureAudio(const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::Builder& builder, QWidget* parent = nullptr); ~ConfigureAudio() override; void ApplyConfiguration() override; @@ -45,13 +45,11 @@ private: void SetOutputSinkFromSinkID(); void SetAudioDevicesFromDeviceID(); - void Setup(); + void Setup(const ConfigurationShared::Builder& builder); std::unique_ptr ui; const Core::System& system; - const ConfigurationShared::TranslationMap& translations; - const ConfigurationShared::ComboboxTranslationMap& combobox_translations; std::forward_list> apply_funcs{}; diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index 210af146d..57cdc4c63 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -13,16 +13,14 @@ #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_cpu.h" -ConfigureCpu::ConfigureCpu( - const Core::System& system_, - std::shared_ptr> group_, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) +ConfigureCpu::ConfigureCpu(const Core::System& system_, + std::shared_ptr> group_, + const ConfigurationShared::Builder& builder, QWidget* parent) : Tab(group_, parent), ui{std::make_unique()}, system{system_}, - translations{translations_}, combobox_translations{combobox_translations_} { + combobox_translations(builder.ComboboxTranslations()) { ui->setupUi(this); - Setup(); + Setup(builder); SetConfiguration(); @@ -33,8 +31,7 @@ ConfigureCpu::ConfigureCpu( ConfigureCpu::~ConfigureCpu() = default; void ConfigureCpu::SetConfiguration() {} -void ConfigureCpu::Setup() { - const bool runtime_lock = !system.IsPoweredOn(); +void ConfigureCpu::Setup(const ConfigurationShared::Builder& builder) { auto* accuracy_layout = ui->widget_accuracy->layout(); auto* unsafe_layout = ui->unsafe_widget->layout(); std::map unsafe_hold{}; @@ -50,13 +47,11 @@ void ConfigureCpu::Setup() { push(Settings::Category::CpuUnsafe); for (const auto setting : settings) { - if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) { + auto* widget = builder.BuildWidget(setting, apply_funcs); + + if (widget == nullptr) { continue; } - - auto* widget = new ConfigurationShared::Widget(setting, translations, combobox_translations, - this, runtime_lock, apply_funcs); - if (!widget->Valid()) { delete widget; continue; diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h index 57603e5c9..ab19c0ba1 100644 --- a/src/yuzu/configuration/configure_cpu.h +++ b/src/yuzu/configuration/configure_cpu.h @@ -18,13 +18,15 @@ namespace Ui { class ConfigureCpu; } +namespace ConfigurationShared { +class Builder; +} + class ConfigureCpu : public ConfigurationShared::Tab { public: explicit ConfigureCpu(const Core::System& system_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations, - QWidget* parent = nullptr); + const ConfigurationShared::Builder& builder, QWidget* parent = nullptr); ~ConfigureCpu() override; void ApplyConfiguration() override; @@ -36,15 +38,13 @@ private: void UpdateGroup(int index); - void Setup(); + void Setup(const ConfigurationShared::Builder& builder); std::unique_ptr ui; const Core::System& system; - const ConfigurationShared::TranslationMap& translations; const ConfigurationShared::ComboboxTranslationMap& combobox_translations; - std::forward_list> apply_funcs{}; QComboBox* accuracy_combobox; diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index c7d132fc8..183555acd 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -32,28 +32,23 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, std::vector& vk_device_records, Core::System& system_, bool enable_web_config) : QDialog(parent), ui{std::make_unique()}, - registry(registry_), system{system_}, - translations{ConfigurationShared::InitializeTranslations(this)}, - combobox_translations{ConfigurationShared::ComboboxEnumeration(this)}, - audio_tab{std::make_unique(system_, nullptr, *translations, - *combobox_translations, this)}, - cpu_tab{std::make_unique(system_, nullptr, *translations, - *combobox_translations, this)}, + registry(registry_), system{system_}, builder{std::make_unique( + this, !system_.IsPoweredOn())}, + audio_tab{std::make_unique(system_, nullptr, *builder, this)}, + cpu_tab{std::make_unique(system_, nullptr, *builder, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, - general_tab{std::make_unique(system_, nullptr, *translations, - *combobox_translations, this)}, - graphics_advanced_tab{std::make_unique( - system_, nullptr, *translations, *combobox_translations, this)}, + general_tab{std::make_unique(system_, nullptr, *builder, this)}, + graphics_advanced_tab{ + std::make_unique(system_, nullptr, *builder, this)}, graphics_tab{std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - nullptr, *translations, *combobox_translations, this)}, + nullptr, *builder, this)}, hotkeys_tab{std::make_unique(system_.HIDCore(), this)}, input_tab{std::make_unique(system_, this)}, network_tab{std::make_unique(system_, this)}, profile_tab{std::make_unique(system_, this)}, - system_tab{std::make_unique(system_, nullptr, *translations, - *combobox_translations, this)}, + system_tab{std::make_unique(system_, nullptr, *builder, this)}, ui_tab{std::make_unique(system_, this)}, web_tab{std::make_unique( this)} { Settings::SetConfiguringGlobal(true); diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index 931900b7d..1bfc9f9d0 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h @@ -7,6 +7,7 @@ #include #include #include +#include "configuration/shared_widget.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/shared_translation.h" #include "yuzu/vk_device_info.h" @@ -72,8 +73,7 @@ private: HotkeyRegistry& registry; Core::System& system; - std::unique_ptr translations; - std::unique_ptr combobox_translations; + std::unique_ptr builder; std::forward_list tab_group; std::unique_ptr audio_tab; diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index ca5b92bc0..54113543a 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp @@ -15,12 +15,12 @@ ConfigureGeneral::ConfigureGeneral( const Core::System& system_, std::shared_ptr> group_, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) - : Tab(group_, parent), ui{std::make_unique()}, system{system_}, - translations{translations_}, combobox_translations{combobox_translations_} { + const ConfigurationShared::Builder& builder, QWidget* parent) + : Tab(group_, parent), ui{std::make_unique()}, system{system_} { ui->setupUi(this); + Setup(builder); + SetConfiguration(); connect(ui->button_reset_defaults, &QPushButton::clicked, this, @@ -33,17 +33,20 @@ ConfigureGeneral::ConfigureGeneral( ConfigureGeneral::~ConfigureGeneral() = default; -void ConfigureGeneral::SetConfiguration() { - const bool runtime_lock = !system.IsPoweredOn(); +void ConfigureGeneral::SetConfiguration() {} + +void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) { QLayout& layout = *ui->general_widget->layout(); std::map hold{}; for (const auto setting : UISettings::values.linkage.by_category[Settings::Category::UiGeneral]) { - auto* widget = new ConfigurationShared::Widget(setting, translations, combobox_translations, - this, runtime_lock, apply_funcs); + auto* widget = builder.BuildWidget(setting, apply_funcs); + if (widget == nullptr) { + continue; + } if (!widget->Valid()) { delete widget; continue; diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 864dc3d2e..f8ed3f8ab 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h @@ -7,7 +7,6 @@ #include #include #include "yuzu/configuration/configuration_shared.h" -#include "yuzu/configuration/shared_widget.h" namespace Core { class System; @@ -20,14 +19,16 @@ namespace Ui { class ConfigureGeneral; } +namespace ConfigurationShared { +class Builder; +} + class ConfigureGeneral : public ConfigurationShared::Tab { public: - explicit ConfigureGeneral( - const Core::System& system_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, - QWidget* parent = nullptr); + explicit ConfigureGeneral(const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::Builder& builder, + QWidget* parent = nullptr); ~ConfigureGeneral() override; void SetResetCallback(std::function callback); @@ -36,6 +37,8 @@ public: void SetConfiguration() override; private: + void Setup(const ConfigurationShared::Builder& builder); + void changeEvent(QEvent* event) override; void RetranslateUI(); @@ -46,6 +49,4 @@ private: std::forward_list> apply_funcs{}; const Core::System& system; - const ConfigurationShared::TranslationMap& translations; - const ConfigurationShared::ComboboxTranslationMap& combobox_translations; }; diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 2f041cba6..18872fa69 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -81,18 +81,17 @@ ConfigureGraphics::ConfigureGraphics( const Core::System& system_, std::vector& records_, const std::function& expose_compute_option_, std::shared_ptr> group_, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) + const ConfigurationShared::Builder& builder, QWidget* parent) : ConfigurationShared::Tab(group_, parent), ui{std::make_unique()}, records{records_}, expose_compute_option{expose_compute_option_}, system{system_}, - translations{translations_}, combobox_translations{combobox_translations_}, + combobox_translations{builder.ComboboxTranslations()}, shader_mapping{combobox_translations.at(typeid(Settings::ShaderBackend))} { vulkan_device = Settings::values.vulkan_device.GetValue(); RetrieveVulkanDevices(); ui->setupUi(this); - Setup(); + Setup(builder); for (const auto& device : vulkan_devices) { vulkan_device_combobox->addItem(device); @@ -218,8 +217,7 @@ ConfigureGraphics::~ConfigureGraphics() = default; void ConfigureGraphics::SetConfiguration() {} -void ConfigureGraphics::Setup() { - const bool runtime_lock = !system.IsPoweredOn(); +void ConfigureGraphics::Setup(const ConfigurationShared::Builder& builder) { QLayout* api_layout = ui->api_widget->layout(); QWidget* api_grid_widget = new QWidget(this); QVBoxLayout* api_grid_layout = new QVBoxLayout(api_grid_widget); @@ -232,30 +230,26 @@ void ConfigureGraphics::Setup() { std::forward_list hold_api; for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) { - if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) { - continue; - } - ConfigurationShared::Widget* widget = [&]() { // Set managed to false on these and set up the comboboxes ourselves if (setting->Id() == Settings::values.vulkan_device.Id() || setting->Id() == Settings::values.shader_backend.Id() || setting->Id() == Settings::values.vsync_mode.Id()) { - return new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs, - ConfigurationShared::RequestType::ComboBox, false); + return builder.BuildWidget(setting, apply_funcs, + ConfigurationShared::RequestType::ComboBox, false); } else if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) { // FSR needs a reversed slider - return new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs, - ConfigurationShared::RequestType::ReverseSlider, true, 0.5f, nullptr, - tr("%1%", "FSR sharpening percentage (e.g. 50%)")); + return builder.BuildWidget( + setting, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true, + 0.5f, nullptr, tr("%1%", "FSR sharpening percentage (e.g. 50%)")); } else { - return new ConfigurationShared::Widget(setting, translations, combobox_translations, - this, runtime_lock, apply_funcs); + return builder.BuildWidget(setting, apply_funcs); } }(); + if (widget == nullptr) { + continue; + } if (!widget->Valid()) { delete widget; continue; diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 718ba54f5..1848b1593 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -13,9 +14,9 @@ #include #include #include "common/common_types.h" +#include "configuration/shared_translation.h" #include "vk_device_info.h" #include "yuzu/configuration/configuration_shared.h" -#include "yuzu/configuration/shared_translation.h" class QPushButton; class QEvent; @@ -36,15 +37,18 @@ namespace Ui { class ConfigureGraphics; } +namespace ConfigurationShared { +class Builder; +} + class ConfigureGraphics : public ConfigurationShared::Tab { public: - explicit ConfigureGraphics( - const Core::System& system_, std::vector& records, - const std::function& expose_compute_option_, - std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, - QWidget* parent = nullptr); + explicit ConfigureGraphics(const Core::System& system_, + std::vector& records, + const std::function& expose_compute_option_, + std::shared_ptr> group, + const ConfigurationShared::Builder& builder, + QWidget* parent = nullptr); ~ConfigureGraphics() override; void ApplyConfiguration() override; @@ -54,7 +58,7 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void Setup(); + void Setup(const ConfigurationShared::Builder& builder); void PopulateVSyncModeSelection(); void UpdateBackgroundColorButton(QColor color); @@ -89,7 +93,6 @@ private: const std::function& expose_compute_option; const Core::System& system; - const ConfigurationShared::TranslationMap& translations; const ConfigurationShared::ComboboxTranslationMap& combobox_translations; const std::vector>& shader_mapping; diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index e2f7d284d..757e4659d 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -14,13 +14,13 @@ ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced( const Core::System& system_, std::shared_ptr> group_, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) - : Tab(group_, parent), ui{std::make_unique()}, system{system_}, - translations{translations_}, combobox_translations{combobox_translations_} { + const ConfigurationShared::Builder& builder, QWidget* parent) + : Tab(group_, parent), ui{std::make_unique()}, system{system_} { ui->setupUi(this); + Setup(builder); + SetConfiguration(); checkbox_enable_compute_pipelines->setVisible(false); @@ -28,20 +28,19 @@ ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced( ConfigureGraphicsAdvanced::~ConfigureGraphicsAdvanced() = default; -void ConfigureGraphicsAdvanced::SetConfiguration() { - const bool runtime_lock = !system.IsPoweredOn(); +void ConfigureGraphicsAdvanced::SetConfiguration() {} + +void ConfigureGraphicsAdvanced::Setup(const ConfigurationShared::Builder& builder) { auto& layout = *ui->populate_target->layout(); std::map hold{}; // A map will sort the data for us for (auto setting : Settings::values.linkage.by_category[Settings::Category::RendererAdvanced]) { - if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) { + ConfigurationShared::Widget* widget = builder.BuildWidget(setting, apply_funcs); + + if (widget == nullptr) { continue; } - - ConfigurationShared::Widget* widget = new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs); - if (!widget->Valid()) { delete widget; continue; diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index 90b79f786..5530827d1 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h @@ -6,7 +6,6 @@ #include #include #include "yuzu/configuration/configuration_shared.h" -#include "yuzu/configuration/shared_translation.h" namespace Core { class System; @@ -16,14 +15,16 @@ namespace Ui { class ConfigureGraphicsAdvanced; } +namespace ConfigurationShared { +class Builder; +} + class ConfigureGraphicsAdvanced : public ConfigurationShared::Tab { public: explicit ConfigureGraphicsAdvanced( const Core::System& system_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, - QWidget* parent = nullptr); + const ConfigurationShared::Builder& builder, QWidget* parent = nullptr); ~ConfigureGraphicsAdvanced() override; void ApplyConfiguration() override; @@ -32,14 +33,14 @@ public: void ExposeComputeOption(); private: + void Setup(const ConfigurationShared::Builder& builder); void changeEvent(QEvent* event) override; void RetranslateUI(); std::unique_ptr ui; const Core::System& system; - const ConfigurationShared::TranslationMap& translations; - const ConfigurationShared::ComboboxTranslationMap& combobox_translations; + std::forward_list> apply_funcs; QWidget* checkbox_enable_compute_pipelines{}; diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 5863beca0..cee8e726d 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -17,6 +17,7 @@ #include #include "common/fs/fs_util.h" +#include "configuration/shared_widget.h" #include "core/core.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" @@ -42,8 +43,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st Core::System& system_) : QDialog(parent), ui(std::make_unique()), title_id{title_id_}, system{system_}, - translations{ConfigurationShared::InitializeTranslations(this)}, - combobox_translations{ConfigurationShared::ComboboxEnumeration(this)}, + builder{std::make_unique(this, !system_.IsPoweredOn())}, tab_group{std::make_shared>()} { const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name)); const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()) @@ -51,18 +51,15 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st game_config = std::make_unique(config_file_name, Config::ConfigType::PerGameConfig); addons_tab = std::make_unique(system_, this); - audio_tab = std::make_unique(system_, tab_group, *translations, - *combobox_translations, this); - cpu_tab = std::make_unique(system_, tab_group, *translations, - *combobox_translations, this); - graphics_advanced_tab = std::make_unique( - system_, tab_group, *translations, *combobox_translations, this); + audio_tab = std::make_unique(system_, tab_group, *builder, this); + cpu_tab = std::make_unique(system_, tab_group, *builder, this); + graphics_advanced_tab = + std::make_unique(system_, tab_group, *builder, this); graphics_tab = std::make_unique( system_, vk_device_records, [&]() { graphics_advanced_tab->ExposeComputeOption(); }, - tab_group, *translations, *combobox_translations, this); + tab_group, *builder, this); input_tab = std::make_unique(system_, game_config.get(), this); - system_tab = std::make_unique(system_, tab_group, *translations, - *combobox_translations, this); + system_tab = std::make_unique(system_, tab_group, *builder, this); ui->setupUi(this); diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h index 4849ac291..4ddd18c1f 100644 --- a/src/yuzu/configuration/configure_per_game.h +++ b/src/yuzu/configuration/configure_per_game.h @@ -11,6 +11,7 @@ #include #include +#include "configuration/shared_widget.h" #include "core/file_sys/vfs_types.h" #include "vk_device_info.h" #include "yuzu/configuration/config.h" @@ -75,8 +76,7 @@ private: std::unique_ptr game_config; Core::System& system; - std::unique_ptr translations; - std::unique_ptr combobox_translations; + std::unique_ptr builder; std::shared_ptr> tab_group; std::unique_ptr addons_tab; diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 6a985c515..9be09244a 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -46,13 +46,11 @@ static bool IsValidLocale(u32 region_index, u32 language_index) { ConfigureSystem::ConfigureSystem( Core::System& system_, std::shared_ptr> group_, - const ConfigurationShared::TranslationMap& translations_, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) - : Tab(group_, parent), ui{std::make_unique()}, system{system_}, - translations{translations_}, combobox_translations{combobox_translations_} { + const ConfigurationShared::Builder& builder, QWidget* parent) + : Tab(group_, parent), ui{std::make_unique()}, system{system_} { ui->setupUi(this); - Setup(); + Setup(builder); connect(rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) { rng_seed_edit->setEnabled(state == Qt::Checked); @@ -104,8 +102,7 @@ void ConfigureSystem::RetranslateUI() { ui->retranslateUi(this); } -void ConfigureSystem::Setup() { - const bool runtime_lock = !system.IsPoweredOn(); +void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) { auto& core_layout = *ui->core_widget->layout(); auto& system_layout = *ui->system_widget->layout(); @@ -123,37 +120,31 @@ void ConfigureSystem::Setup() { push(Settings::values.linkage.by_category[Settings::Category::System]); for (auto setting : settings) { - if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) { - continue; - } - - [[maybe_unused]] std::string label = setting->GetLabel(); - ConfigurationShared::Widget* widget = [this, setting, runtime_lock]() { + ConfigurationShared::Widget* widget = [this, setting, &builder]() { if (setting->Id() == Settings::values.custom_rtc.Id()) { // custom_rtc needs a DateTimeEdit (default is LineEdit), and a checkbox to manage // it and custom_rtc_enabled - return new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs, - &Settings::values.custom_rtc_enabled, - ConfigurationShared::RequestType::DateTimeEdit); + return builder.BuildWidget(setting, apply_funcs, + &Settings::values.custom_rtc_enabled, + ConfigurationShared::RequestType::DateTimeEdit); } else if (setting->Id() == Settings::values.rng_seed.Id()) { // rng_seed needs a HexEdit (default is LineEdit), and a checkbox to manage // it and rng_seed_enabled - return new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs, - &Settings::values.rng_seed_enabled, ConfigurationShared::RequestType::HexEdit); + return builder.BuildWidget(setting, apply_funcs, &Settings::values.rng_seed_enabled, + ConfigurationShared::RequestType::HexEdit); } else if (setting->Id() == Settings::values.speed_limit.Id()) { // speed_limit needs a checkbox to set use_speed_limit, as well as a spinbox - return new ConfigurationShared::Widget( - setting, translations, combobox_translations, this, runtime_lock, apply_funcs, - &Settings::values.use_speed_limit, ConfigurationShared::RequestType::SpinBox, - tr("%", "Limit speed percentage (e.g. 50%)")); + return builder.BuildWidget(setting, apply_funcs, &Settings::values.use_speed_limit, + ConfigurationShared::RequestType::SpinBox, + tr("%", "Limit speed percentage (e.g. 50%)")); } else { - return new ConfigurationShared::Widget(setting, translations, combobox_translations, - this, runtime_lock, apply_funcs); + return builder.BuildWidget(setting, apply_funcs); } }(); + if (widget == nullptr) { + continue; + } if (!widget->Valid()) { delete widget; continue; diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 4457ccc21..7f4259698 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -9,13 +9,11 @@ #include #include "yuzu/configuration/configuration_shared.h" -#include "yuzu/configuration/shared_translation.h" class QCheckBox; class QLineEdit; class QComboBox; class QDateTimeEdit; - namespace Core { class System; } @@ -24,13 +22,16 @@ namespace Ui { class ConfigureSystem; } +namespace ConfigurationShared { +class Builder; +} + class ConfigureSystem : public ConfigurationShared::Tab { public: - explicit ConfigureSystem( - Core::System& system_, std::shared_ptr> group, - const ConfigurationShared::TranslationMap& translations, - const ConfigurationShared::ComboboxTranslationMap& combobox_translations, - QWidget* parent = nullptr); + explicit ConfigureSystem(Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::Builder& builder, + QWidget* parent = nullptr); ~ConfigureSystem() override; void ApplyConfiguration() override; @@ -40,7 +41,7 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void Setup(); + void Setup(const ConfigurationShared::Builder& builder); std::forward_list> apply_funcs{}; @@ -48,8 +49,6 @@ private: bool enabled = false; Core::System& system; - const ConfigurationShared::TranslationMap& translations; - const ConfigurationShared::ComboboxTranslationMap& combobox_translations; QCheckBox* rng_seed_checkbox; QLineEdit* rng_seed_edit; diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index d153d8d6b..dc8b31238 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -529,11 +529,34 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati this->setToolTip(tooltip); } -Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, - const ComboboxTranslationMap& combobox_translations, QWidget* parent_, - bool runtime_lock_, std::forward_list>& apply_funcs_, - Settings::BasicSetting* other_setting, RequestType request, const QString& string) - : Widget(setting_, translations_, combobox_translations, parent_, runtime_lock_, apply_funcs_, - request, true, 1.0f, other_setting, string) {} +Builder::Builder(QWidget* parent_, bool runtime_lock_) + : translations{InitializeTranslations(parent_)}, + combobox_translations{ComboboxEnumeration(parent_)}, parent{parent_}, runtime_lock{ + runtime_lock_} {} + +Builder::~Builder() = default; + +Widget* Builder::BuildWidget(Settings::BasicSetting* setting, + std::forward_list>& apply_funcs, + RequestType request, bool managed, float multiplier, + Settings::BasicSetting* other_setting, const QString& string) const { + if (!Settings::IsConfiguringGlobal() && !setting->Switchable()) { + return nullptr; + } + + return new Widget(setting, *translations, *combobox_translations, parent, runtime_lock, + apply_funcs, request, managed, multiplier, other_setting, string); +} + +Widget* Builder::BuildWidget(Settings::BasicSetting* setting, + std::forward_list>& apply_funcs, + Settings::BasicSetting* other_setting, RequestType request, + const QString& string) const { + return BuildWidget(setting, apply_funcs, request, true, 1.0f, other_setting, string); +} + +const ComboboxTranslationMap& Builder::ComboboxTranslations() const { + return *combobox_translations; +} } // namespace ConfigurationShared diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 10d2d353e..e8c281b81 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -44,28 +45,6 @@ class Widget : public QWidget { Q_OBJECT public: - /** - * Shorter-hand version of the constructor - * - * @param setting The primary Setting to create the Widget for - * @param translations Map of translations to display on the left side label/checkbox - * @param combobox_translations Map of translations for enumerating combo boxes - * @param parent Qt parent - * @param runtime_lock Emulated guest powered on state, for use on settings that should be - * configured during guest execution - * @param apply_funcs_ List to append, functions to run to apply the widget state to the setting - * @param other_setting Second setting to modify, to replace the label with a checkbox - * @param request What type of data representation component to create -- not always respected - * for the Setting data type - * @param string Set to specify formats for Slider feedback labels or SpinBox - */ - explicit Widget(Settings::BasicSetting* setting, const TranslationMap& translations, - const ComboboxTranslationMap& combobox_translations, QWidget* parent, - bool runtime_lock, std::forward_list>& apply_funcs_, - Settings::BasicSetting* other_setting, - RequestType request = RequestType::Default, - const QString& string = QStringLiteral("")); - /** * @param setting The primary Setting to create the Widget for * @param translations Map of translations to display on the left side label/checkbox @@ -152,4 +131,31 @@ private: bool runtime_lock{false}; }; +class Builder { +public: + explicit Builder(QWidget* parent, bool runtime_lock); + ~Builder(); + + Widget* BuildWidget(Settings::BasicSetting* setting, + std::forward_list>& apply_funcs, + RequestType request = RequestType::Default, bool managed = true, + float multiplier = 1.0f, Settings::BasicSetting* other_setting = nullptr, + const QString& string = QStringLiteral("")) const; + + Widget* BuildWidget(Settings::BasicSetting* setting, + std::forward_list>& apply_funcs, + Settings::BasicSetting* other_setting, + RequestType request = RequestType::Default, + const QString& string = QStringLiteral("")) const; + + const ComboboxTranslationMap& ComboboxTranslations() const; + +private: + std::unique_ptr translations; + std::unique_ptr combobox_translations; + + QWidget* parent; + const bool runtime_lock; +}; + } // namespace ConfigurationShared -- cgit v1.2.3 From 33d118509ad201cecf60519e41437740705148ea Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Fri, 21 Jul 2023 23:56:01 -0400 Subject: configure_dialog: Focus the button box on start Without this, the Reset All Settings button would be selected by default --- src/yuzu/configuration/configure_dialog.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/yuzu/configuration/configure_dialog.cpp') diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 183555acd..3c6bb3eb1 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -97,6 +97,9 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, adjustSize(); ui->selectorList->setCurrentRow(0); + + // Selects the leftmost button on the bottom bar (Cancel as of writing) + ui->buttonBox->setFocus(); } ConfigureDialog::~ConfigureDialog() = default; -- cgit v1.2.3