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: Configuration: Add per-game input profiles --- .../configuration/configure_input_per_game.cpp | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/yuzu/configuration/configure_input_per_game.cpp (limited to 'src/yuzu/configuration/configure_input_per_game.cpp') 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 000000000..5773c268d --- /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(); +} -- cgit v1.2.3 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: configure_input_per_game: Allow configuring all 8 players --- .../configuration/configure_input_per_game.cpp | 104 +++++++++++++-------- 1 file changed, 65 insertions(+), 39 deletions(-) (limited to 'src/yuzu/configuration/configure_input_per_game.cpp') diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp index 5773c268d..af5cee542 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(); + 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 = ui->profile_player_1->currentIndex(); - if (selection_index == 0) { - Settings::values.players.SetGlobal(true); + 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(); - return; - } else { - Settings::values.players.SetGlobal(false); - } - const QString profile_name = ui->profile_player_1->itemText(selection_index); - if (profile_name.isEmpty()) { - return; + }; + + for (size_t index = 0; index < profile_comboboxes.size(); ++index) { + load_player_profile(index); } - 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); - +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; - } - const QString profile_name = ui->profile_player_1->itemText(selection_index); - if (profile_name.isEmpty()) { - return; + }; + + for (size_t index = 0; index < profile_comboboxes.size(); ++index) { + save_player_profile(index); } - profiles->LoadProfile(profile_name.toStdString(), 0); - Settings::values.players.GetValue()[0].profile_name = profile_name.toStdString(); - emulated_controller->ReloadFromSettings(); } -- cgit v1.2.3 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: config: Custom profile detection fixes Also only reads/writes applicable configs for the custom profiles. --- .../configuration/configure_input_per_game.cpp | 61 +++++++++++++--------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'src/yuzu/configuration/configure_input_per_game.cpp') diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp index af5cee542..78e65d468 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; + // Make sure the controller is connected + player.connected = true; + emulated_controller->ReloadFromSettings(); - }; - for (size_t index = 0; index < profile_comboboxes.size(); ++index) { - load_player_profile(index); + 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); } } -- cgit v1.2.3