Configuration: Add per-game input profiles

This commit is contained in:
ameerj 2022-11-17 19:23:48 -05:00
parent f426fd95fe
commit 9efdad6a27
11 changed files with 465 additions and 14 deletions

View file

@ -391,6 +391,7 @@ struct PlayerInput {
u32 body_color_right;
u32 button_color_left;
u32 button_color_right;
std::string profile_name;
};
struct TouchscreenInput {

View file

@ -107,10 +107,9 @@ void EmulatedController::ReloadFromSettings() {
original_npad_type = npad_type;
}
Disconnect();
if (player.connected) {
Connect();
} else {
Disconnect();
}
ReloadInput();

View file

@ -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

View file

@ -186,7 +186,7 @@ void Config::WriteGlobalSetting(const Settings::SwitchableSetting<Type, ranged>&
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) {

View file

@ -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();
}

View file

@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <QWidget>
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::ConfigureInputPerGame> ui;
std::unique_ptr<InputProfiles> profiles;
Core::System& system;
};

View file

@ -0,0 +1,298 @@
<?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">
<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_3" native="true">
<layout class="QHBoxLayout" name="input_profile_layout">
<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">
<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">
<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">
<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">
<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">
<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>

View file

@ -38,7 +38,7 @@ enum class InputType;
namespace Ui {
class ConfigureInputPlayer;
}
} // namespace Ui
namespace Core::HID {
class HIDCore;

View file

@ -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<ConfigureGeneral>(system_, this);
graphics_tab = std::make_unique<ConfigureGraphics>(system_, this);
graphics_advanced_tab = std::make_unique<ConfigureGraphicsAdvanced>(system_, this);
input_tab = std::make_unique<ConfigureInputPerGame>(system_, this);
system_tab = std::make_unique<ConfigureSystem>(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();

View file

@ -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<ConfigureGeneral> general_tab;
std::unique_ptr<ConfigureGraphics> graphics_tab;
std::unique_ptr<ConfigureGraphicsAdvanced> graphics_advanced_tab;
std::unique_ptr<ConfigureInputPerGame> input_tab;
std::unique_ptr<ConfigureSystem> system_tab;
};

View file

@ -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);