diff options
author | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-11-17 19:23:48 -0500 |
---|---|---|
committer | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-11-20 14:06:31 -0500 |
commit | 9efdad6a2733e701b24e9edcbad1851692ca8863 (patch) | |
tree | a0ba33591b59e59bcea565e3d5ec5b8b1846a687 /src/yuzu/configuration/configure_input_per_game.cpp | |
parent | f426fd95fe9e31beb7ea926cc7677a027a431da5 (diff) |
Configuration: Add per-game input profiles
Diffstat (limited to 'src/yuzu/configuration/configure_input_per_game.cpp')
-rw-r--r-- | src/yuzu/configuration/configure_input_per_game.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
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<Ui::ConfigureInputPerGame>()), + profiles(std::make_unique<InputProfiles>()), 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<int>(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(); +} |