From 9efdad6a2733e701b24e9edcbad1851692ca8863 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Thu, 17 Nov 2022 19:23:48 -0500 Subject: [PATCH 1/4] Configuration: Add per-game input profiles --- src/common/settings_input.h | 1 + src/core/hid/emulated_controller.cpp | 3 +- src/yuzu/CMakeLists.txt | 3 + src/yuzu/configuration/config.cpp | 24 +- .../configure_input_per_game.cpp | 76 +++++ .../configuration/configure_input_per_game.h | 44 +++ .../configuration/configure_input_per_game.ui | 298 ++++++++++++++++++ .../configuration/configure_input_player.h | 2 +- src/yuzu/configuration/configure_per_game.cpp | 5 +- src/yuzu/configuration/configure_per_game.h | 6 + src/yuzu/main.cpp | 17 +- 11 files changed, 465 insertions(+), 14 deletions(-) create mode 100644 src/yuzu/configuration/configure_input_per_game.cpp create mode 100644 src/yuzu/configuration/configure_input_per_game.h create mode 100644 src/yuzu/configuration/configure_input_per_game.ui diff --git a/src/common/settings_input.h b/src/common/settings_input.h index 485e4ad223..46f38c7030 100644 --- a/src/common/settings_input.h +++ b/src/common/settings_input.h @@ -391,6 +391,7 @@ struct PlayerInput { u32 body_color_right; u32 button_color_left; u32 button_color_right; + std::string profile_name; }; struct TouchscreenInput { diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index ec13644528..a2d1062458 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -107,10 +107,9 @@ void EmulatedController::ReloadFromSettings() { original_npad_type = npad_type; } + Disconnect(); if (player.connected) { Connect(); - } else { - Disconnect(); } ReloadInput(); diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 5cc1fbf326..8a252bd5d5 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -85,6 +85,9 @@ add_executable(yuzu configuration/configure_input_advanced.cpp configuration/configure_input_advanced.h configuration/configure_input_advanced.ui + configuration/configure_input_per_game.cpp + configuration/configure_input_per_game.h + configuration/configure_input_per_game.ui configuration/configure_input_player.cpp configuration/configure_input_player.h configuration/configure_input_player.ui diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 343f3b8e50..4067ea6075 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -186,7 +186,7 @@ void Config::WriteGlobalSetting(const Settings::SwitchableSetting& void Config::ReadPlayerValue(std::size_t player_index) { const QString player_prefix = [this, player_index] { - if (type == ConfigType::InputProfile) { + if (type == ConfigType::InputProfile && global) { return QString{}; } else { return QStringLiteral("player_%1_").arg(player_index); @@ -244,6 +244,14 @@ void Config::ReadPlayerValue(std::size_t player_index) { ->value(QStringLiteral("%1button_color_right").arg(player_prefix), Settings::JOYCON_BUTTONS_NEON_RED) .toUInt(); + + // This only applies to per-game configs + if (!global) { + player.profile_name = + qt_config->value(QStringLiteral("%1profile_name").arg(player_prefix), QString{}) + .toString() + .toStdString(); + } } for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { @@ -386,6 +394,7 @@ void Config::ReadAudioValues() { } void Config::ReadControlValues() { + Settings::values.players.SetGlobal(global); qt_config->beginGroup(QStringLiteral("Controls")); for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) { @@ -904,7 +913,6 @@ void Config::ReadMultiplayerValues() { void Config::ReadValues() { if (global) { - ReadControlValues(); ReadDataStorageValues(); ReadDebuggingValues(); ReadDisabledAddOnValues(); @@ -913,6 +921,7 @@ void Config::ReadValues() { ReadWebServiceValues(); ReadMiscellaneousValues(); } + ReadControlValues(); ReadCoreValues(); ReadCpuValues(); ReadRendererValues(); @@ -923,7 +932,7 @@ void Config::ReadValues() { void Config::SavePlayerValue(std::size_t player_index) { const QString player_prefix = [this, player_index] { - if (type == ConfigType::InputProfile) { + if (type == ConfigType::InputProfile && global) { return QString{}; } else { return QStringLiteral("player_%1_").arg(player_index); @@ -951,6 +960,12 @@ void Config::SavePlayerValue(std::size_t player_index) { player.button_color_left, Settings::JOYCON_BUTTONS_NEON_BLUE); WriteSetting(QStringLiteral("%1button_color_right").arg(player_prefix), player.button_color_right, Settings::JOYCON_BUTTONS_NEON_RED); + + // This only applies to per-game configs + if (!global) { + WriteSetting(QStringLiteral("%1profile_name").arg(player_prefix), + QString::fromStdString(player.profile_name), QString{}); + } } for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { @@ -1054,7 +1069,6 @@ void Config::SaveIrCameraValues() { void Config::SaveValues() { if (global) { - SaveControlValues(); SaveDataStorageValues(); SaveDebuggingValues(); SaveDisabledAddOnValues(); @@ -1063,6 +1077,7 @@ void Config::SaveValues() { SaveWebServiceValues(); SaveMiscellaneousValues(); } + SaveControlValues(); SaveCoreValues(); SaveCpuValues(); SaveRendererValues(); @@ -1085,6 +1100,7 @@ void Config::SaveAudioValues() { } void Config::SaveControlValues() { + Settings::values.players.SetGlobal(global); qt_config->beginGroup(QStringLiteral("Controls")); for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) { diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp new file mode 100644 index 0000000000..5773c268de --- /dev/null +++ b/src/yuzu/configuration/configure_input_per_game.cpp @@ -0,0 +1,76 @@ +// SPDX-FileCopyrightText: 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/settings.h" +#include "core/core.h" +#include "core/hid/emulated_controller.h" +#include "core/hid/hid_core.h" +#include "ui_configure_input_per_game.h" +#include "yuzu/configuration/configure_input_per_game.h" +#include "yuzu/configuration/input_profiles.h" + +ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* parent) + : QWidget(parent), ui(std::make_unique()), + profiles(std::make_unique()), system{system_} { + ui->setupUi(this); + + Settings::values.players.SetGlobal(false); + const auto previous_profile = Settings::values.players.GetValue()[0].profile_name; + + const auto& profile_names = profiles->GetInputProfileNames(); + + ui->profile_player_1->addItem(QString::fromStdString("Use global configuration")); + for (size_t index = 0; index < profile_names.size(); ++index) { + const auto& profile_name = profile_names[index]; + ui->profile_player_1->addItem(QString::fromStdString(profile_name)); + if (profile_name == previous_profile) { + // offset by 1 since the first element is the global config + ui->profile_player_1->setCurrentIndex(static_cast(index + 1)); + } + } + LoadConfiguration(); +} + +void ConfigureInputPerGame::ApplyConfiguration() { + LoadConfiguration(); + + auto& hid_core = system.HIDCore(); + auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(0); + + const auto selection_index = ui->profile_player_1->currentIndex(); + if (selection_index == 0) { + Settings::values.players.SetGlobal(true); + emulated_controller->ReloadFromSettings(); + return; + } else { + Settings::values.players.SetGlobal(false); + } + const QString profile_name = ui->profile_player_1->itemText(selection_index); + if (profile_name.isEmpty()) { + return; + } + profiles->SaveProfile(Settings::values.players.GetValue()[0].profile_name, 0); + emulated_controller->ReloadFromSettings(); +} + +void ConfigureInputPerGame::LoadConfiguration() { + auto& hid_core = system.HIDCore(); + auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(0); + + Settings::values.players.SetGlobal(false); + + const auto selection_index = ui->profile_player_1->currentIndex(); + if (selection_index == 0) { + Settings::values.players.GetValue()[0].profile_name = ""; + Settings::values.players.SetGlobal(true); + emulated_controller->ReloadFromSettings(); + return; + } + const QString profile_name = ui->profile_player_1->itemText(selection_index); + if (profile_name.isEmpty()) { + return; + } + profiles->LoadProfile(profile_name.toStdString(), 0); + Settings::values.players.GetValue()[0].profile_name = profile_name.toStdString(); + emulated_controller->ReloadFromSettings(); +} diff --git a/src/yuzu/configuration/configure_input_per_game.h b/src/yuzu/configuration/configure_input_per_game.h new file mode 100644 index 0000000000..6feb608b7a --- /dev/null +++ b/src/yuzu/configuration/configure_input_per_game.h @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include + +namespace Core { +class System; +} + +namespace InputCommon { +class InputSubsystem; +} + +namespace Ui { +class ConfigureInputPerGame; +} + +class InputProfiles; + +class ConfigureInputPerGame : public QWidget { + Q_OBJECT + +public: + explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr); + + /// Initializes the input dialog with the given input subsystem. + // void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8); + + /// Save configurations to settings file. + void ApplyConfiguration(); + +private: + /// Load configuration from settings file. + void LoadConfiguration(); + + std::unique_ptr ui; + std::unique_ptr profiles; + + Core::System& system; +}; diff --git a/src/yuzu/configuration/configure_input_per_game.ui b/src/yuzu/configuration/configure_input_per_game.ui new file mode 100644 index 0000000000..8a384c0df7 --- /dev/null +++ b/src/yuzu/configuration/configure_input_per_game.ui @@ -0,0 +1,298 @@ + + + ConfigureInputPerGame + + + + 0 + 0 + 541 + 759 + + + + Form + + + Graphics + + + + + + 0 + + + + + Input Profiles + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 1 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 3 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 4 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 5 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 6 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 7 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 8 Profile + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index 79434fdd8d..26f60d121c 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h @@ -38,7 +38,7 @@ enum class InputType; namespace Ui { class ConfigureInputPlayer; -} +} // namespace Ui namespace Core::HID { class HIDCore; diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index c3cb8f61d1..cf0a6dc0e9 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -28,7 +28,7 @@ #include "yuzu/configuration/configure_general.h" #include "yuzu/configuration/configure_graphics.h" #include "yuzu/configuration/configure_graphics_advanced.h" -#include "yuzu/configuration/configure_input.h" +#include "yuzu/configuration/configure_input_per_game.h" #include "yuzu/configuration/configure_per_game.h" #include "yuzu/configuration/configure_per_game_addons.h" #include "yuzu/configuration/configure_system.h" @@ -50,6 +50,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st general_tab = std::make_unique(system_, this); graphics_tab = std::make_unique(system_, this); graphics_advanced_tab = std::make_unique(system_, this); + input_tab = std::make_unique(system_, this); system_tab = std::make_unique(system_, this); ui->setupUi(this); @@ -61,6 +62,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics")); ui->tabWidget->addTab(graphics_advanced_tab.get(), tr("Adv. Graphics")); ui->tabWidget->addTab(audio_tab.get(), tr("Audio")); + ui->tabWidget->addTab(input_tab.get(), tr("Input Profiles")); setFocusPolicy(Qt::ClickFocus); setWindowTitle(tr("Properties")); @@ -91,6 +93,7 @@ void ConfigurePerGame::ApplyConfiguration() { graphics_tab->ApplyConfiguration(); graphics_advanced_tab->ApplyConfiguration(); audio_tab->ApplyConfiguration(); + input_tab->ApplyConfiguration(); system.ApplySettings(); Settings::LogSettings(); diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h index 17a98a0f3d..4ecc435417 100644 --- a/src/yuzu/configuration/configure_per_game.h +++ b/src/yuzu/configuration/configure_per_game.h @@ -16,12 +16,17 @@ namespace Core { class System; } +namespace InputCommon { +class InputSubsystem; +} + class ConfigurePerGameAddons; class ConfigureAudio; class ConfigureCpu; class ConfigureGeneral; class ConfigureGraphics; class ConfigureGraphicsAdvanced; +class ConfigureInputPerGame; class ConfigureSystem; class QGraphicsScene; @@ -72,5 +77,6 @@ private: std::unique_ptr general_tab; std::unique_ptr graphics_tab; std::unique_ptr graphics_advanced_tab; + std::unique_ptr input_tab; std::unique_ptr system_tab; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 72498f52a7..e0c3537887 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -124,6 +124,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual #include "yuzu/compatibility_list.h" #include "yuzu/configuration/config.h" #include "yuzu/configuration/configure_dialog.h" +#include "yuzu/configuration/configure_input_per_game.h" #include "yuzu/debugger/console.h" #include "yuzu/debugger/controller.h" #include "yuzu/debugger/profiler.h" @@ -1647,6 +1648,11 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t LOG_INFO(Frontend, "yuzu starting..."); StoreRecentFile(filename); // Put the filename on top of the list + // Save configurations + UpdateUISettings(); + game_list->SaveInterfaceLayout(); + config->Save(); + u64 title_id{0}; last_filename_booted = filename; @@ -1666,11 +1672,6 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t system->ApplySettings(); } - // Save configurations - UpdateUISettings(); - game_list->SaveInterfaceLayout(); - config->Save(); - Settings::LogSettings(); if (UISettings::values.select_user_on_boot) { @@ -2790,6 +2791,7 @@ void GMainWindow::OnStopGame() { ShutdownGame(); Settings::RestoreGlobalState(system->IsPoweredOn()); + system->HIDCore().ReloadInputDevices(); UpdateStatusButtons(); } @@ -3250,6 +3252,7 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file // Do not cause the global config to write local settings into the config file const bool is_powered_on = system->IsPoweredOn(); Settings::RestoreGlobalState(is_powered_on); + system->HIDCore().ReloadInputDevices(); UISettings::values.configuration_applied = false; @@ -3709,6 +3712,7 @@ void GMainWindow::OnCoreError(Core::SystemResultStatus result, std::string detai ShutdownGame(); Settings::RestoreGlobalState(system->IsPoweredOn()); + system->HIDCore().ReloadInputDevices(); UpdateStatusButtons(); } } else { @@ -3860,18 +3864,19 @@ void GMainWindow::closeEvent(QCloseEvent* event) { // Unload controllers early controller_dialog->UnloadController(); game_list->UnloadController(); - system->HIDCore().UnloadInputDevices(); // Shutdown session if the emu thread is active... if (emu_thread != nullptr) { ShutdownGame(); Settings::RestoreGlobalState(system->IsPoweredOn()); + system->HIDCore().ReloadInputDevices(); UpdateStatusButtons(); } render_window->close(); multiplayer_state->Close(); + system->HIDCore().UnloadInputDevices(); system->GetRoomNetwork().Shutdown(); QWidget::closeEvent(event); From b1b20ad84a5e966bb13f01de037bbfe88ac985cc Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Thu, 17 Nov 2022 20:11:47 -0500 Subject: [PATCH 2/4] configure_input_per_game: Allow configuring all 8 players --- .../configure_input_per_game.cpp | 108 +++++++++++------- .../configuration/configure_input_per_game.h | 14 +-- .../configuration/configure_input_per_game.ui | 49 ++++++-- 3 files changed, 115 insertions(+), 56 deletions(-) diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp index 5773c268de..af5cee542d 100644 --- a/src/yuzu/configuration/configure_input_per_game.cpp +++ b/src/yuzu/configuration/configure_input_per_game.cpp @@ -13,64 +13,90 @@ ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* par : QWidget(parent), ui(std::make_unique()), profiles(std::make_unique()), system{system_} { ui->setupUi(this); - - Settings::values.players.SetGlobal(false); - const auto previous_profile = Settings::values.players.GetValue()[0].profile_name; + const std::array labels = { + ui->label_player_1, ui->label_player_2, ui->label_player_3, ui->label_player_4, + ui->label_player_5, ui->label_player_6, ui->label_player_7, ui->label_player_8, + }; + profile_comboboxes = { + ui->profile_player_1, ui->profile_player_2, ui->profile_player_3, ui->profile_player_4, + ui->profile_player_5, ui->profile_player_6, ui->profile_player_7, ui->profile_player_8, + }; const auto& profile_names = profiles->GetInputProfileNames(); + const auto populate_profiles = [this, &profile_names](size_t player_index) { + const auto previous_profile = + Settings::values.players.GetValue()[player_index].profile_name; - ui->profile_player_1->addItem(QString::fromStdString("Use global configuration")); - for (size_t index = 0; index < profile_names.size(); ++index) { - const auto& profile_name = profile_names[index]; - ui->profile_player_1->addItem(QString::fromStdString(profile_name)); - if (profile_name == previous_profile) { - // offset by 1 since the first element is the global config - ui->profile_player_1->setCurrentIndex(static_cast(index + 1)); + auto* const player_combobox = profile_comboboxes[player_index]; + player_combobox->addItem(tr("Use global input configuration")); + for (size_t index = 0; index < profile_names.size(); ++index) { + const auto& profile_name = profile_names[index]; + player_combobox->addItem(QString::fromStdString(profile_name)); + if (profile_name == previous_profile) { + // offset by 1 since the first element is the global config + player_combobox->setCurrentIndex(static_cast(index + 1)); + } } + }; + + for (size_t index = 0; index < profile_comboboxes.size(); ++index) { + labels[index]->setText(tr("Player %1 profile").arg(index + 1)); + populate_profiles(index); } + LoadConfiguration(); } void ConfigureInputPerGame::ApplyConfiguration() { LoadConfiguration(); - - auto& hid_core = system.HIDCore(); - auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(0); - - const auto selection_index = ui->profile_player_1->currentIndex(); - if (selection_index == 0) { - Settings::values.players.SetGlobal(true); - emulated_controller->ReloadFromSettings(); - return; - } else { - Settings::values.players.SetGlobal(false); - } - const QString profile_name = ui->profile_player_1->itemText(selection_index); - if (profile_name.isEmpty()) { - return; - } - profiles->SaveProfile(Settings::values.players.GetValue()[0].profile_name, 0); - emulated_controller->ReloadFromSettings(); + SaveConfiguration(); } void ConfigureInputPerGame::LoadConfiguration() { auto& hid_core = system.HIDCore(); - auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(0); + const auto load_player_profile = [this, &hid_core](size_t player_index) { + Settings::values.players.SetGlobal(false); + auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); + auto* const player_combobox = profile_comboboxes[player_index]; + + const auto selection_index = player_combobox->currentIndex(); + if (selection_index == 0) { + Settings::values.players.GetValue()[player_index].profile_name = ""; + Settings::values.players.SetGlobal(true); + emulated_controller->ReloadFromSettings(); + return; + } + const auto profile_name = player_combobox->itemText(selection_index).toStdString(); + if (profile_name.empty()) { + return; + } + profiles->LoadProfile(profile_name, player_index); + Settings::values.players.GetValue()[player_index].profile_name = profile_name; + emulated_controller->ReloadFromSettings(); + }; + + for (size_t index = 0; index < profile_comboboxes.size(); ++index) { + load_player_profile(index); + } +} + +void ConfigureInputPerGame::SaveConfiguration() { Settings::values.players.SetGlobal(false); - const auto selection_index = ui->profile_player_1->currentIndex(); - if (selection_index == 0) { - Settings::values.players.GetValue()[0].profile_name = ""; - Settings::values.players.SetGlobal(true); + auto& hid_core = system.HIDCore(); + const auto save_player_profile = [this, &hid_core](size_t player_index) { + const auto selection_index = profile_comboboxes[player_index]->currentIndex(); + if (selection_index == 0) { + return; + } + auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); + profiles->SaveProfile(Settings::values.players.GetValue()[player_index].profile_name, + player_index); emulated_controller->ReloadFromSettings(); - return; + }; + + for (size_t index = 0; index < profile_comboboxes.size(); ++index) { + save_player_profile(index); } - const QString profile_name = ui->profile_player_1->itemText(selection_index); - if (profile_name.isEmpty()) { - return; - } - profiles->LoadProfile(profile_name.toStdString(), 0); - Settings::values.players.GetValue()[0].profile_name = profile_name.toStdString(); - emulated_controller->ReloadFromSettings(); } diff --git a/src/yuzu/configuration/configure_input_per_game.h b/src/yuzu/configuration/configure_input_per_game.h index 6feb608b7a..a586ec07c8 100644 --- a/src/yuzu/configuration/configure_input_per_game.h +++ b/src/yuzu/configuration/configure_input_per_game.h @@ -11,10 +11,6 @@ namespace Core { class System; } -namespace InputCommon { -class InputSubsystem; -} - namespace Ui { class ConfigureInputPerGame; } @@ -27,18 +23,20 @@ class ConfigureInputPerGame : public QWidget { public: explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr); - /// Initializes the input dialog with the given input subsystem. - // void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8); - - /// Save configurations to settings file. + /// Load and Save configurations to settings file. void ApplyConfiguration(); private: /// Load configuration from settings file. void LoadConfiguration(); + /// Save configuration to settings file. + void SaveConfiguration(); + std::unique_ptr ui; std::unique_ptr profiles; + std::array profile_comboboxes; + Core::System& system; }; diff --git a/src/yuzu/configuration/configure_input_per_game.ui b/src/yuzu/configuration/configure_input_per_game.ui index 8a384c0df7..fbd8eab1ca 100644 --- a/src/yuzu/configuration/configure_input_per_game.ui +++ b/src/yuzu/configuration/configure_input_per_game.ui @@ -30,7 +30,7 @@ - + 0 @@ -63,9 +63,44 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Player 2 Profile + + + + + + + + 0 + 0 + + + + + + + - + 0 @@ -100,7 +135,7 @@ - + 0 @@ -135,7 +170,7 @@ - + 0 @@ -170,7 +205,7 @@ - + 0 @@ -205,7 +240,7 @@ - + 0 @@ -240,7 +275,7 @@ - + 0 From 3de05726eb9d6bd8637134eb37ce8072c4289cd6 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:39:09 -0500 Subject: [PATCH 3/4] config: Custom profile detection fixes Also only reads/writes applicable configs for the custom profiles. --- src/yuzu/configuration/config.cpp | 89 ++++++++++++------- src/yuzu/configuration/config.h | 2 + .../configure_input_per_game.cpp | 63 +++++++------ .../configuration/configure_input_per_game.h | 17 ++-- src/yuzu/configuration/configure_per_game.cpp | 2 +- src/yuzu/main.cpp | 1 + 6 files changed, 109 insertions(+), 65 deletions(-) diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 4067ea6075..cc1ba9f701 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -124,6 +124,10 @@ void Config::Initialize(const std::string& config_name) { } } +bool Config::IsCustomConfig() { + return type == ConfigType::PerGameConfig; +} + /* {Read,Write}BasicSetting and WriteGlobalSetting templates must be defined here before their * usages later in this file. This allows explicit definition of some types that don't work * nicely with the general version. @@ -186,7 +190,7 @@ void Config::WriteGlobalSetting(const Settings::SwitchableSetting& void Config::ReadPlayerValue(std::size_t player_index) { const QString player_prefix = [this, player_index] { - if (type == ConfigType::InputProfile && global) { + if (type == ConfigType::InputProfile) { return QString{}; } else { return QStringLiteral("player_%1_").arg(player_index); @@ -194,8 +198,20 @@ void Config::ReadPlayerValue(std::size_t player_index) { }(); auto& player = Settings::values.players.GetValue()[player_index]; + if (IsCustomConfig()) { + const auto profile_name = + qt_config->value(QStringLiteral("%1profile_name").arg(player_prefix), QString{}) + .toString() + .toStdString(); + if (profile_name.empty()) { + // Use the global input config + player = Settings::values.players.GetValue(true)[player_index]; + return; + } + player.profile_name = profile_name; + } - if (player_prefix.isEmpty()) { + if (player_prefix.isEmpty() && Settings::IsConfiguringGlobal()) { const auto controller = static_cast( qt_config ->value(QStringLiteral("%1type").arg(player_prefix), @@ -244,14 +260,6 @@ void Config::ReadPlayerValue(std::size_t player_index) { ->value(QStringLiteral("%1button_color_right").arg(player_prefix), Settings::JOYCON_BUTTONS_NEON_RED) .toUInt(); - - // This only applies to per-game configs - if (!global) { - player.profile_name = - qt_config->value(QStringLiteral("%1profile_name").arg(player_prefix), QString{}) - .toString() - .toStdString(); - } } for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { @@ -394,12 +402,28 @@ void Config::ReadAudioValues() { } void Config::ReadControlValues() { - Settings::values.players.SetGlobal(global); qt_config->beginGroup(QStringLiteral("Controls")); + Settings::values.players.SetGlobal(!IsCustomConfig()); for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) { ReadPlayerValue(p); } + ReadGlobalSetting(Settings::values.use_docked_mode); + + // Disable docked mode if handheld is selected + const auto controller_type = Settings::values.players.GetValue()[0].controller_type; + if (controller_type == Settings::ControllerType::Handheld) { + Settings::values.use_docked_mode.SetGlobal(!IsCustomConfig()); + Settings::values.use_docked_mode.SetValue(false); + } + + ReadGlobalSetting(Settings::values.vibration_enabled); + ReadGlobalSetting(Settings::values.enable_accurate_vibrations); + ReadGlobalSetting(Settings::values.motion_enabled); + if (IsCustomConfig()) { + qt_config->endGroup(); + return; + } ReadDebugValues(); ReadKeyboardValues(); ReadMouseValues(); @@ -421,18 +445,6 @@ void Config::ReadControlValues() { ReadBasicSetting(Settings::values.tas_loop); ReadBasicSetting(Settings::values.pause_tas_on_load); - ReadGlobalSetting(Settings::values.use_docked_mode); - - // Disable docked mode if handheld is selected - const auto controller_type = Settings::values.players.GetValue()[0].controller_type; - if (controller_type == Settings::ControllerType::Handheld) { - Settings::values.use_docked_mode.SetValue(false); - } - - ReadGlobalSetting(Settings::values.vibration_enabled); - ReadGlobalSetting(Settings::values.enable_accurate_vibrations); - ReadGlobalSetting(Settings::values.motion_enabled); - ReadBasicSetting(Settings::values.controller_navigation); qt_config->endGroup(); @@ -932,7 +944,7 @@ void Config::ReadValues() { void Config::SavePlayerValue(std::size_t player_index) { const QString player_prefix = [this, player_index] { - if (type == ConfigType::InputProfile && global) { + if (type == ConfigType::InputProfile) { return QString{}; } else { return QStringLiteral("player_%1_").arg(player_index); @@ -940,12 +952,20 @@ void Config::SavePlayerValue(std::size_t player_index) { }(); const auto& player = Settings::values.players.GetValue()[player_index]; + if (IsCustomConfig()) { + if (player.profile_name.empty()) { + // No custom profile selected + return; + } + WriteSetting(QStringLiteral("%1profile_name").arg(player_prefix), + QString::fromStdString(player.profile_name), QString{}); + } WriteSetting(QStringLiteral("%1type").arg(player_prefix), static_cast(player.controller_type), static_cast(Settings::ControllerType::ProController)); - if (!player_prefix.isEmpty()) { + if (!player_prefix.isEmpty() || !Settings::IsConfiguringGlobal()) { WriteSetting(QStringLiteral("%1connected").arg(player_prefix), player.connected, player_index == 0); WriteSetting(QStringLiteral("%1vibration_enabled").arg(player_prefix), @@ -960,12 +980,6 @@ void Config::SavePlayerValue(std::size_t player_index) { player.button_color_left, Settings::JOYCON_BUTTONS_NEON_BLUE); WriteSetting(QStringLiteral("%1button_color_right").arg(player_prefix), player.button_color_right, Settings::JOYCON_BUTTONS_NEON_RED); - - // This only applies to per-game configs - if (!global) { - WriteSetting(QStringLiteral("%1profile_name").arg(player_prefix), - QString::fromStdString(player.profile_name), QString{}); - } } for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { @@ -1100,12 +1114,16 @@ void Config::SaveAudioValues() { } void Config::SaveControlValues() { - Settings::values.players.SetGlobal(global); qt_config->beginGroup(QStringLiteral("Controls")); + Settings::values.players.SetGlobal(!IsCustomConfig()); for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) { SavePlayerValue(p); } + if (IsCustomConfig()) { + qt_config->endGroup(); + return; + } SaveDebugValues(); SaveMouseValues(); SaveTouchscreenValues(); @@ -1590,6 +1608,13 @@ void Config::SaveControlPlayerValue(std::size_t player_index) { qt_config->endGroup(); } +void Config::ClearControlPlayerValues() { + qt_config->beginGroup(QStringLiteral("Controls")); + // If key is an empty string, all keys in the current group() are removed. + qt_config->remove(QString{}); + qt_config->endGroup(); +} + const std::string& Config::GetConfigFilePath() const { return qt_config_loc; } diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 06fa7d2d07..7d26e9ab62 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -34,6 +34,7 @@ public: void ReadControlPlayerValue(std::size_t player_index); void SaveControlPlayerValue(std::size_t player_index); + void ClearControlPlayerValues(); const std::string& GetConfigFilePath() const; @@ -58,6 +59,7 @@ public: private: void Initialize(const std::string& config_name); + bool IsCustomConfig(); void ReadValues(); void ReadPlayerValue(std::size_t player_index); diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp index af5cee542d..78e65d4689 100644 --- a/src/yuzu/configuration/configure_input_per_game.cpp +++ b/src/yuzu/configuration/configure_input_per_game.cpp @@ -6,12 +6,14 @@ #include "core/hid/emulated_controller.h" #include "core/hid/hid_core.h" #include "ui_configure_input_per_game.h" +#include "yuzu/configuration/config.h" #include "yuzu/configuration/configure_input_per_game.h" #include "yuzu/configuration/input_profiles.h" -ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* parent) +ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, Config* config_, + QWidget* parent) : QWidget(parent), ui(std::make_unique()), - profiles(std::make_unique()), system{system_} { + profiles(std::make_unique()), system{system_}, config{config_} { ui->setupUi(this); const std::array labels = { ui->label_player_1, ui->label_player_2, ui->label_player_3, ui->label_player_4, @@ -22,6 +24,8 @@ ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* par ui->profile_player_5, ui->profile_player_6, ui->profile_player_7, ui->profile_player_8, }; + Settings::values.players.SetGlobal(false); + const auto& profile_names = profiles->GetInputProfileNames(); const auto populate_profiles = [this, &profile_names](size_t player_index) { const auto previous_profile = @@ -29,6 +33,7 @@ ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* par auto* const player_combobox = profile_comboboxes[player_index]; player_combobox->addItem(tr("Use global input configuration")); + for (size_t index = 0; index < profile_names.size(); ++index) { const auto& profile_name = profile_names[index]; player_combobox->addItem(QString::fromStdString(profile_name)); @@ -38,7 +43,6 @@ ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* par } } }; - for (size_t index = 0; index < profile_comboboxes.size(); ++index) { labels[index]->setText(tr("Player %1 profile").arg(index + 1)); populate_profiles(index); @@ -53,8 +57,10 @@ void ConfigureInputPerGame::ApplyConfiguration() { } void ConfigureInputPerGame::LoadConfiguration() { + static constexpr size_t HANDHELD_INDEX = 8; + auto& hid_core = system.HIDCore(); - const auto load_player_profile = [this, &hid_core](size_t player_index) { + for (size_t player_index = 0; player_index < profile_comboboxes.size(); ++player_index) { Settings::values.players.SetGlobal(false); auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); @@ -63,40 +69,47 @@ void ConfigureInputPerGame::LoadConfiguration() { const auto selection_index = player_combobox->currentIndex(); if (selection_index == 0) { Settings::values.players.GetValue()[player_index].profile_name = ""; + if (player_index == 0) { + Settings::values.players.GetValue()[HANDHELD_INDEX] = {}; + } Settings::values.players.SetGlobal(true); emulated_controller->ReloadFromSettings(); - return; + continue; } const auto profile_name = player_combobox->itemText(selection_index).toStdString(); if (profile_name.empty()) { - return; + continue; } + auto& player = Settings::values.players.GetValue()[player_index]; + player.profile_name = profile_name; + // Read from the profile into the custom player settings profiles->LoadProfile(profile_name, player_index); - Settings::values.players.GetValue()[player_index].profile_name = profile_name; - emulated_controller->ReloadFromSettings(); - }; + // Make sure the controller is connected + player.connected = true; - for (size_t index = 0; index < profile_comboboxes.size(); ++index) { - load_player_profile(index); + emulated_controller->ReloadFromSettings(); + + if (player_index > 0) { + continue; + } + // Handle Handheld cases + auto& handheld_player = Settings::values.players.GetValue()[HANDHELD_INDEX]; + auto* handheld_controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); + if (player.controller_type == Settings::ControllerType::Handheld) { + handheld_player = player; + } else { + handheld_player = {}; + } + handheld_controller->ReloadFromSettings(); } } void ConfigureInputPerGame::SaveConfiguration() { Settings::values.players.SetGlobal(false); - auto& hid_core = system.HIDCore(); - const auto save_player_profile = [this, &hid_core](size_t player_index) { - const auto selection_index = profile_comboboxes[player_index]->currentIndex(); - if (selection_index == 0) { - return; - } - auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); - profiles->SaveProfile(Settings::values.players.GetValue()[player_index].profile_name, - player_index); - emulated_controller->ReloadFromSettings(); - }; - - for (size_t index = 0; index < profile_comboboxes.size(); ++index) { - save_player_profile(index); + // Clear all controls from the config in case the user reverted back to globals + config->ClearControlPlayerValues(); + for (size_t index = 0; index < Settings::values.players.GetValue().size(); ++index) { + config->SaveControlPlayerValue(index); } } diff --git a/src/yuzu/configuration/configure_input_per_game.h b/src/yuzu/configuration/configure_input_per_game.h index a586ec07c8..660faf5743 100644 --- a/src/yuzu/configuration/configure_input_per_game.h +++ b/src/yuzu/configuration/configure_input_per_game.h @@ -7,21 +7,23 @@ #include +#include "ui_configure_input_per_game.h" +#include "yuzu/configuration/input_profiles.h" + +class QComboBox; + namespace Core { class System; -} +} // namespace Core -namespace Ui { -class ConfigureInputPerGame; -} - -class InputProfiles; +class Config; class ConfigureInputPerGame : public QWidget { Q_OBJECT public: - explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr); + explicit ConfigureInputPerGame(Core::System& system_, Config* config_, + QWidget* parent = nullptr); /// Load and Save configurations to settings file. void ApplyConfiguration(); @@ -39,4 +41,5 @@ private: std::array profile_comboboxes; Core::System& system; + Config* config; }; diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index cf0a6dc0e9..93db47cfd0 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 general_tab = std::make_unique(system_, this); graphics_tab = std::make_unique(system_, this); graphics_advanced_tab = std::make_unique(system_, this); - input_tab = std::make_unique(system_, this); + input_tab = std::make_unique(system_, game_config.get(), this); system_tab = std::make_unique(system_, this); ui->setupUi(this); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e0c3537887..21983a7998 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1669,6 +1669,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t ? Common::FS::PathToUTF8String(file_path.filename()) : fmt::format("{:016X}", title_id); Config per_game_config(config_file_name, Config::ConfigType::PerGameConfig); + system->HIDCore().ReloadInputDevices(); system->ApplySettings(); } From 4cbbf590e3e811fac4b2605e148cd1b7f1ae2eb5 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 20 Nov 2022 17:10:25 -0500 Subject: [PATCH 4/4] configure_input_player: Fix profile saving when using handheld controller type --- src/yuzu/configuration/configure_input_player.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 9e5a40fe74..ed21f4b92f 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -1553,6 +1553,7 @@ void ConfigureInputPlayer::LoadProfile() { } void ConfigureInputPlayer::SaveProfile() { + static constexpr size_t HANDHELD_INDEX = 8; const QString profile_name = ui->comboProfiles->itemText(ui->comboProfiles->currentIndex()); if (profile_name.isEmpty()) { @@ -1561,7 +1562,12 @@ void ConfigureInputPlayer::SaveProfile() { ApplyConfiguration(); - if (!profiles->SaveProfile(profile_name.toStdString(), player_index)) { + // When we're in handheld mode, only the handheld emulated controller bindings are updated + const bool is_handheld = player_index == 0 && emulated_controller->GetNpadIdType() == + Core::HID::NpadIdType::Handheld; + const auto profile_player_index = is_handheld ? HANDHELD_INDEX : player_index; + + if (!profiles->SaveProfile(profile_name.toStdString(), profile_player_index)) { QMessageBox::critical(this, tr("Save Input Profile"), tr("Failed to save the input profile \"%1\"").arg(profile_name)); UpdateInputProfiles();