From 6f5b9428971904ad8815a56d50c9aab4805a1c56 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 29 Oct 2020 12:15:35 -0400 Subject: [PATCH] configure_input: Update the input profiles for other player tabs --- src/yuzu/configuration/configure_input.cpp | 16 +++++++++++++-- src/yuzu/configuration/configure_input.h | 1 + .../configuration/configure_input_player.cpp | 20 +++++++++++++------ .../configuration/configure_input_player.h | 12 ++++++++--- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index 600cc03aef..d9009091b8 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp @@ -124,8 +124,10 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem, } } }); - connect(player_controllers[i], &ConfigureInputPlayer::RefreshInputDevices, - [this] { UpdateAllInputDevices(); }); + connect(player_controllers[i], &ConfigureInputPlayer::RefreshInputDevices, this, + &ConfigureInput::UpdateAllInputDevices); + connect(player_controllers[i], &ConfigureInputPlayer::RefreshInputProfiles, this, + &ConfigureInput::UpdateAllInputProfiles, Qt::QueuedConnection); connect(player_connected[i], &QCheckBox::stateChanged, [this, i](int state) { player_controllers[i]->ConnectPlayer(state == Qt::Checked); }); @@ -259,3 +261,13 @@ void ConfigureInput::UpdateAllInputDevices() { player->UpdateInputDeviceCombobox(); } } + +void ConfigureInput::UpdateAllInputProfiles(std::size_t player_index) { + for (std::size_t i = 0; i < player_controllers.size(); ++i) { + if (i == player_index) { + continue; + } + + player_controllers[i]->UpdateInputProfiles(); + } +} diff --git a/src/yuzu/configuration/configure_input.h b/src/yuzu/configuration/configure_input.h index 9eba9b5230..f4eb0d78b7 100644 --- a/src/yuzu/configuration/configure_input.h +++ b/src/yuzu/configuration/configure_input.h @@ -52,6 +52,7 @@ private: void UpdateDockedState(bool is_handheld); void UpdateAllInputDevices(); + void UpdateAllInputProfiles(std::size_t player_index); /// Load configuration settings. void LoadConfiguration(); diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 0d10c1360d..f65a7fe736 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -541,7 +541,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i } }); - RefreshInputProfiles(); + UpdateInputProfiles(); connect(ui->buttonProfilesNew, &QPushButton::clicked, this, &ConfigureInputPlayer::CreateProfile); @@ -1132,10 +1132,13 @@ void ConfigureInputPlayer::CreateProfile() { if (!profiles->CreateProfile(profile_name.toStdString(), player_index)) { QMessageBox::critical(this, tr("Create Input Profile"), tr("Failed to create the input profile \"%1\"").arg(profile_name)); - RefreshInputProfiles(); + UpdateInputProfiles(); + emit RefreshInputProfiles(player_index); return; } + emit RefreshInputProfiles(player_index); + ui->comboProfiles->addItem(profile_name); ui->comboProfiles->setCurrentIndex(ui->comboProfiles->count() - 1); } @@ -1150,10 +1153,13 @@ void ConfigureInputPlayer::DeleteProfile() { if (!profiles->DeleteProfile(profile_name.toStdString())) { QMessageBox::critical(this, tr("Delete Input Profile"), tr("Failed to delete the input profile \"%1\"").arg(profile_name)); - RefreshInputProfiles(); + UpdateInputProfiles(); + emit RefreshInputProfiles(player_index); return; } + emit RefreshInputProfiles(player_index); + ui->comboProfiles->removeItem(ui->comboProfiles->currentIndex()); ui->comboProfiles->setCurrentIndex(-1); } @@ -1170,7 +1176,8 @@ void ConfigureInputPlayer::LoadProfile() { if (!profiles->LoadProfile(profile_name.toStdString(), player_index)) { QMessageBox::critical(this, tr("Load Input Profile"), tr("Failed to load the input profile \"%1\"").arg(profile_name)); - RefreshInputProfiles(); + UpdateInputProfiles(); + emit RefreshInputProfiles(player_index); return; } @@ -1189,12 +1196,13 @@ void ConfigureInputPlayer::SaveProfile() { if (!profiles->SaveProfile(profile_name.toStdString(), player_index)) { QMessageBox::critical(this, tr("Save Input Profile"), tr("Failed to save the input profile \"%1\"").arg(profile_name)); - RefreshInputProfiles(); + UpdateInputProfiles(); + emit RefreshInputProfiles(player_index); return; } } -void ConfigureInputPlayer::RefreshInputProfiles() { +void ConfigureInputPlayer::UpdateInputProfiles() { ui->comboProfiles->clear(); for (const auto& profile_name : profiles->GetInputProfileNames()) { diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index 4895e8850e..23cf6f9589 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h @@ -59,6 +59,9 @@ public: /// Update the input devices combobox. void UpdateInputDeviceCombobox(); + /// Updates the list of controller profiles. + void UpdateInputProfiles(); + /// Restore all buttons to their default values. void RestoreDefaults(); @@ -72,6 +75,12 @@ signals: void HandheldStateChanged(bool is_handheld); /// Emitted when the input devices combobox is being refreshed. void RefreshInputDevices(); + /** + * Emitted when the input profiles combobox is being refreshed. + * The player_index represents the current player's index, and the profile combobox + * will not be updated for this index as they are already updated by other mechanisms. + */ + void RefreshInputProfiles(std::size_t player_index); protected: void showEvent(QShowEvent* event) override; @@ -130,9 +139,6 @@ private: /// Saves the current controller configuration into a selected controller profile. void SaveProfile(); - /// Refreshes the list of controller profiles. - void RefreshInputProfiles(); - std::unique_ptr ui; std::size_t player_index;