summaryrefslogtreecommitdiffstats
path: root/src/yuzu/configuration/configure_input_per_game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu/configuration/configure_input_per_game.cpp')
-rw-r--r--src/yuzu/configuration/configure_input_per_game.cpp61
1 files changed, 37 insertions, 24 deletions
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<Ui::ConfigureInputPerGame>()),
- profiles(std::make_unique<InputProfiles>()), system{system_} {
+ profiles(std::make_unique<InputProfiles>()), 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);
}
}