Merge pull request #9273 from ameerj/per-game-profile
Configuration: Add per-game input profilesmaster
commit
522e7c5663
@ -0,0 +1,115 @@
|
||||
// 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/config.h"
|
||||
#include "yuzu/configuration/configure_input_per_game.h"
|
||||
#include "yuzu/configuration/input_profiles.h"
|
||||
|
||||
ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, Config* config_,
|
||||
QWidget* parent)
|
||||
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPerGame>()),
|
||||
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,
|
||||
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,
|
||||
};
|
||||
|
||||
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 =
|
||||
Settings::values.players.GetValue()[player_index].profile_name;
|
||||
|
||||
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<int>(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() {
|
||||
static constexpr size_t HANDHELD_INDEX = 8;
|
||||
|
||||
auto& hid_core = system.HIDCore();
|
||||
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);
|
||||
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 = "";
|
||||
if (player_index == 0) {
|
||||
Settings::values.players.GetValue()[HANDHELD_INDEX] = {};
|
||||
}
|
||||
Settings::values.players.SetGlobal(true);
|
||||
emulated_controller->ReloadFromSettings();
|
||||
continue;
|
||||
}
|
||||
const auto profile_name = player_combobox->itemText(selection_index).toStdString();
|
||||
if (profile_name.empty()) {
|
||||
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);
|
||||
// Make sure the controller is connected
|
||||
player.connected = true;
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui_configure_input_per_game.h"
|
||||
#include "yuzu/configuration/input_profiles.h"
|
||||
|
||||
class QComboBox;
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
} // namespace Core
|
||||
|
||||
class Config;
|
||||
|
||||
class ConfigureInputPerGame : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigureInputPerGame(Core::System& system_, Config* config_,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
/// 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::ConfigureInputPerGame> ui;
|
||||
std::unique_ptr<InputProfiles> profiles;
|
||||
|
||||
std::array<QComboBox*, 8> profile_comboboxes;
|
||||
|
||||
Core::System& system;
|
||||
Config* config;
|
||||
};
|
@ -0,0 +1,333 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ConfigureInputPerGame</class>
|
||||
<widget class="QWidget" name="PerGameInput">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>541</width>
|
||||
<height>759</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string>Graphics</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_1">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Input Profiles</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QWidget" name="player_1" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_1">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_1">
|
||||
<property name="text">
|
||||
<string>Player 1 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_2" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_2">
|
||||
<property name="text">
|
||||
<string>Player 2 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_3" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_3">
|
||||
<property name="text">
|
||||
<string>Player 3 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_4" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_4">
|
||||
<property name="text">
|
||||
<string>Player 4 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_5" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_5">
|
||||
<property name="text">
|
||||
<string>Player 5 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_5">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_6" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_6">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_6">
|
||||
<property name="text">
|
||||
<string>Player 6 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_6">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_7" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_7">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_7">
|
||||
<property name="text">
|
||||
<string>Player 7 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_7">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="player_8" native="true">
|
||||
<layout class="QHBoxLayout" name="input_profile_layout_8">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_player_8">
|
||||
<property name="text">
|
||||
<string>Player 8 Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profile_player_8">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue