configure_input_per_game: Allow configuring all 8 players

This commit is contained in:
ameerj 2022-11-17 20:11:47 -05:00
parent 9efdad6a27
commit b1b20ad84a
3 changed files with 115 additions and 56 deletions

View file

@ -13,64 +13,90 @@ ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* par
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPerGame>()), : QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPerGame>()),
profiles(std::make_unique<InputProfiles>()), system{system_} { profiles(std::make_unique<InputProfiles>()), system{system_} {
ui->setupUi(this); ui->setupUi(this);
const std::array labels = {
Settings::values.players.SetGlobal(false); ui->label_player_1, ui->label_player_2, ui->label_player_3, ui->label_player_4,
const auto previous_profile = Settings::values.players.GetValue()[0].profile_name; 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& 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")); auto* const player_combobox = profile_comboboxes[player_index];
for (size_t index = 0; index < profile_names.size(); ++index) { player_combobox->addItem(tr("Use global input configuration"));
const auto& profile_name = profile_names[index]; for (size_t index = 0; index < profile_names.size(); ++index) {
ui->profile_player_1->addItem(QString::fromStdString(profile_name)); const auto& profile_name = profile_names[index];
if (profile_name == previous_profile) { player_combobox->addItem(QString::fromStdString(profile_name));
// offset by 1 since the first element is the global config if (profile_name == previous_profile) {
ui->profile_player_1->setCurrentIndex(static_cast<int>(index + 1)); // 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(); LoadConfiguration();
} }
void ConfigureInputPerGame::ApplyConfiguration() { void ConfigureInputPerGame::ApplyConfiguration() {
LoadConfiguration(); LoadConfiguration();
SaveConfiguration();
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() { void ConfigureInputPerGame::LoadConfiguration() {
auto& hid_core = system.HIDCore(); 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 = 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();
};
for (size_t index = 0; index < profile_comboboxes.size(); ++index) {
load_player_profile(index);
}
}
void ConfigureInputPerGame::SaveConfiguration() {
Settings::values.players.SetGlobal(false); Settings::values.players.SetGlobal(false);
const auto selection_index = ui->profile_player_1->currentIndex(); auto& hid_core = system.HIDCore();
if (selection_index == 0) { const auto save_player_profile = [this, &hid_core](size_t player_index) {
Settings::values.players.GetValue()[0].profile_name = ""; const auto selection_index = profile_comboboxes[player_index]->currentIndex();
Settings::values.players.SetGlobal(true); 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(); emulated_controller->ReloadFromSettings();
return; };
for (size_t index = 0; index < profile_comboboxes.size(); ++index) {
save_player_profile(index);
} }
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

@ -11,10 +11,6 @@ namespace Core {
class System; class System;
} }
namespace InputCommon {
class InputSubsystem;
}
namespace Ui { namespace Ui {
class ConfigureInputPerGame; class ConfigureInputPerGame;
} }
@ -27,18 +23,20 @@ class ConfigureInputPerGame : public QWidget {
public: public:
explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr); explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr);
/// Initializes the input dialog with the given input subsystem. /// Load and Save configurations to settings file.
// void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8);
/// Save configurations to settings file.
void ApplyConfiguration(); void ApplyConfiguration();
private: private:
/// Load configuration from settings file. /// Load configuration from settings file.
void LoadConfiguration(); void LoadConfiguration();
/// Save configuration to settings file.
void SaveConfiguration();
std::unique_ptr<Ui::ConfigureInputPerGame> ui; std::unique_ptr<Ui::ConfigureInputPerGame> ui;
std::unique_ptr<InputProfiles> profiles; std::unique_ptr<InputProfiles> profiles;
std::array<QComboBox*, 8> profile_comboboxes;
Core::System& system; Core::System& system;
}; };

View file

@ -30,7 +30,7 @@
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QWidget" name="player_1" native="true"> <widget class="QWidget" name="player_1" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_1">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -63,9 +63,44 @@
</layout> </layout>
</widget> </widget>
</item> </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> <item>
<widget class="QWidget" name="player_3" native="true"> <widget class="QWidget" name="player_3" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_3">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -100,7 +135,7 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="player_4" native="true"> <widget class="QWidget" name="player_4" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_4">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -135,7 +170,7 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="player_5" native="true"> <widget class="QWidget" name="player_5" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_5">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -170,7 +205,7 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="player_6" native="true"> <widget class="QWidget" name="player_6" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_6">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -205,7 +240,7 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="player_7" native="true"> <widget class="QWidget" name="player_7" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_7">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -240,7 +275,7 @@
</item> </item>
<item> <item>
<widget class="QWidget" name="player_8" native="true"> <widget class="QWidget" name="player_8" native="true">
<layout class="QHBoxLayout" name="input_profile_layout"> <layout class="QHBoxLayout" name="input_profile_layout_8">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>