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: [PATCH] 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 +- .../configure_graphics_advanced.cpp | 9 +- .../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 | 318 +++++++++++------- src/yuzu/configuration/shared_translation.h | 6 +- src/yuzu/configuration/shared_widget.cpp | 65 ++-- src/yuzu/configuration/shared_widget.h | 8 +- 18 files changed, 354 insertions(+), 228 deletions(-) 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"), - }; - } + 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 {}; + 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) { + const ComboboxTranslations* enumeration{nullptr}; + if (combobox_enumerations.contains(type)) { + enumeration = &combobox_enumerations.at(type); + for (const auto& [id, name] : *enumeration) { + combobox->addItem(name); + } + } + + if (!managed || enumeration == nullptr) { return; } - // 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()))); - } + 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;