diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_input_per_game.cpp | 104 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_per_game.h | 14 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_per_game.ui | 49 |
3 files changed, 113 insertions, 54 deletions
diff --git a/src/yuzu/configuration/configure_input_per_game.cpp b/src/yuzu/configuration/configure_input_per_game.cpp index 5773c268d..af5cee542 100644 --- a/src/yuzu/configuration/configure_input_per_game.cpp +++ b/src/yuzu/configuration/configure_input_per_game.cpp | |||
| @@ -13,64 +13,90 @@ ConfigureInputPerGame::ConfigureInputPerGame(Core::System& system_, QWidget* par | |||
| 13 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPerGame>()), | 13 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPerGame>()), |
| 14 | profiles(std::make_unique<InputProfiles>()), system{system_} { | 14 | profiles(std::make_unique<InputProfiles>()), system{system_} { |
| 15 | ui->setupUi(this); | 15 | ui->setupUi(this); |
| 16 | 16 | const std::array labels = { | |
| 17 | Settings::values.players.SetGlobal(false); | 17 | ui->label_player_1, ui->label_player_2, ui->label_player_3, ui->label_player_4, |
| 18 | const auto previous_profile = Settings::values.players.GetValue()[0].profile_name; | 18 | ui->label_player_5, ui->label_player_6, ui->label_player_7, ui->label_player_8, |
| 19 | }; | ||
| 20 | profile_comboboxes = { | ||
| 21 | ui->profile_player_1, ui->profile_player_2, ui->profile_player_3, ui->profile_player_4, | ||
| 22 | ui->profile_player_5, ui->profile_player_6, ui->profile_player_7, ui->profile_player_8, | ||
| 23 | }; | ||
| 19 | 24 | ||
| 20 | const auto& profile_names = profiles->GetInputProfileNames(); | 25 | const auto& profile_names = profiles->GetInputProfileNames(); |
| 26 | const auto populate_profiles = [this, &profile_names](size_t player_index) { | ||
| 27 | const auto previous_profile = | ||
| 28 | Settings::values.players.GetValue()[player_index].profile_name; | ||
| 21 | 29 | ||
| 22 | ui->profile_player_1->addItem(QString::fromStdString("Use global configuration")); | 30 | auto* const player_combobox = profile_comboboxes[player_index]; |
| 23 | for (size_t index = 0; index < profile_names.size(); ++index) { | 31 | player_combobox->addItem(tr("Use global input configuration")); |
| 24 | const auto& profile_name = profile_names[index]; | 32 | for (size_t index = 0; index < profile_names.size(); ++index) { |
| 25 | ui->profile_player_1->addItem(QString::fromStdString(profile_name)); | 33 | const auto& profile_name = profile_names[index]; |
| 26 | if (profile_name == previous_profile) { | 34 | player_combobox->addItem(QString::fromStdString(profile_name)); |
| 27 | // offset by 1 since the first element is the global config | 35 | if (profile_name == previous_profile) { |
| 28 | ui->profile_player_1->setCurrentIndex(static_cast<int>(index + 1)); | 36 | // offset by 1 since the first element is the global config |
| 37 | player_combobox->setCurrentIndex(static_cast<int>(index + 1)); | ||
| 38 | } | ||
| 29 | } | 39 | } |
| 40 | }; | ||
| 41 | |||
| 42 | for (size_t index = 0; index < profile_comboboxes.size(); ++index) { | ||
| 43 | labels[index]->setText(tr("Player %1 profile").arg(index + 1)); | ||
| 44 | populate_profiles(index); | ||
| 30 | } | 45 | } |
| 46 | |||
| 31 | LoadConfiguration(); | 47 | LoadConfiguration(); |
| 32 | } | 48 | } |
| 33 | 49 | ||
| 34 | void ConfigureInputPerGame::ApplyConfiguration() { | 50 | void ConfigureInputPerGame::ApplyConfiguration() { |
| 35 | LoadConfiguration(); | 51 | LoadConfiguration(); |
| 52 | SaveConfiguration(); | ||
| 53 | } | ||
| 36 | 54 | ||
| 55 | void ConfigureInputPerGame::LoadConfiguration() { | ||
| 37 | auto& hid_core = system.HIDCore(); | 56 | auto& hid_core = system.HIDCore(); |
| 38 | auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(0); | 57 | const auto load_player_profile = [this, &hid_core](size_t player_index) { |
| 58 | Settings::values.players.SetGlobal(false); | ||
| 59 | |||
| 60 | auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); | ||
| 61 | auto* const player_combobox = profile_comboboxes[player_index]; | ||
| 39 | 62 | ||
| 40 | const auto selection_index = ui->profile_player_1->currentIndex(); | 63 | const auto selection_index = player_combobox->currentIndex(); |
| 41 | if (selection_index == 0) { | 64 | if (selection_index == 0) { |
| 42 | Settings::values.players.SetGlobal(true); | 65 | Settings::values.players.GetValue()[player_index].profile_name = ""; |
| 66 | Settings::values.players.SetGlobal(true); | ||
| 67 | emulated_controller->ReloadFromSettings(); | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | const auto profile_name = player_combobox->itemText(selection_index).toStdString(); | ||
| 71 | if (profile_name.empty()) { | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | profiles->LoadProfile(profile_name, player_index); | ||
| 75 | Settings::values.players.GetValue()[player_index].profile_name = profile_name; | ||
| 43 | emulated_controller->ReloadFromSettings(); | 76 | emulated_controller->ReloadFromSettings(); |
| 44 | return; | 77 | }; |
| 45 | } else { | 78 | |
| 46 | Settings::values.players.SetGlobal(false); | 79 | for (size_t index = 0; index < profile_comboboxes.size(); ++index) { |
| 47 | } | 80 | load_player_profile(index); |
| 48 | const QString profile_name = ui->profile_player_1->itemText(selection_index); | ||
| 49 | if (profile_name.isEmpty()) { | ||
| 50 | return; | ||
| 51 | } | 81 | } |
| 52 | profiles->SaveProfile(Settings::values.players.GetValue()[0].profile_name, 0); | ||
| 53 | emulated_controller->ReloadFromSettings(); | ||
| 54 | } | 82 | } |
| 55 | 83 | ||
| 56 | void ConfigureInputPerGame::LoadConfiguration() { | 84 | void ConfigureInputPerGame::SaveConfiguration() { |
| 57 | auto& hid_core = system.HIDCore(); | ||
| 58 | auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(0); | ||
| 59 | |||
| 60 | Settings::values.players.SetGlobal(false); | 85 | Settings::values.players.SetGlobal(false); |
| 61 | 86 | ||
| 62 | const auto selection_index = ui->profile_player_1->currentIndex(); | 87 | auto& hid_core = system.HIDCore(); |
| 63 | if (selection_index == 0) { | 88 | const auto save_player_profile = [this, &hid_core](size_t player_index) { |
| 64 | Settings::values.players.GetValue()[0].profile_name = ""; | 89 | const auto selection_index = profile_comboboxes[player_index]->currentIndex(); |
| 65 | Settings::values.players.SetGlobal(true); | 90 | if (selection_index == 0) { |
| 91 | return; | ||
| 92 | } | ||
| 93 | auto* emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); | ||
| 94 | profiles->SaveProfile(Settings::values.players.GetValue()[player_index].profile_name, | ||
| 95 | player_index); | ||
| 66 | emulated_controller->ReloadFromSettings(); | 96 | emulated_controller->ReloadFromSettings(); |
| 67 | return; | 97 | }; |
| 68 | } | 98 | |
| 69 | const QString profile_name = ui->profile_player_1->itemText(selection_index); | 99 | for (size_t index = 0; index < profile_comboboxes.size(); ++index) { |
| 70 | if (profile_name.isEmpty()) { | 100 | save_player_profile(index); |
| 71 | return; | ||
| 72 | } | 101 | } |
| 73 | profiles->LoadProfile(profile_name.toStdString(), 0); | ||
| 74 | Settings::values.players.GetValue()[0].profile_name = profile_name.toStdString(); | ||
| 75 | emulated_controller->ReloadFromSettings(); | ||
| 76 | } | 102 | } |
diff --git a/src/yuzu/configuration/configure_input_per_game.h b/src/yuzu/configuration/configure_input_per_game.h index 6feb608b7..a586ec07c 100644 --- a/src/yuzu/configuration/configure_input_per_game.h +++ b/src/yuzu/configuration/configure_input_per_game.h | |||
| @@ -11,10 +11,6 @@ namespace Core { | |||
| 11 | class System; | 11 | class System; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | namespace InputCommon { | ||
| 15 | class InputSubsystem; | ||
| 16 | } | ||
| 17 | |||
| 18 | namespace Ui { | 14 | namespace Ui { |
| 19 | class ConfigureInputPerGame; | 15 | class ConfigureInputPerGame; |
| 20 | } | 16 | } |
| @@ -27,18 +23,20 @@ class ConfigureInputPerGame : public QWidget { | |||
| 27 | public: | 23 | public: |
| 28 | explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr); | 24 | explicit ConfigureInputPerGame(Core::System& system_, QWidget* parent = nullptr); |
| 29 | 25 | ||
| 30 | /// Initializes the input dialog with the given input subsystem. | 26 | /// Load and Save configurations to settings file. |
| 31 | // void Initialize(InputCommon::InputSubsystem* input_subsystem_, std::size_t max_players = 8); | ||
| 32 | |||
| 33 | /// Save configurations to settings file. | ||
| 34 | void ApplyConfiguration(); | 27 | void ApplyConfiguration(); |
| 35 | 28 | ||
| 36 | private: | 29 | private: |
| 37 | /// Load configuration from settings file. | 30 | /// Load configuration from settings file. |
| 38 | void LoadConfiguration(); | 31 | void LoadConfiguration(); |
| 39 | 32 | ||
| 33 | /// Save configuration to settings file. | ||
| 34 | void SaveConfiguration(); | ||
| 35 | |||
| 40 | std::unique_ptr<Ui::ConfigureInputPerGame> ui; | 36 | std::unique_ptr<Ui::ConfigureInputPerGame> ui; |
| 41 | std::unique_ptr<InputProfiles> profiles; | 37 | std::unique_ptr<InputProfiles> profiles; |
| 42 | 38 | ||
| 39 | std::array<QComboBox*, 8> profile_comboboxes; | ||
| 40 | |||
| 43 | Core::System& system; | 41 | Core::System& system; |
| 44 | }; | 42 | }; |
diff --git a/src/yuzu/configuration/configure_input_per_game.ui b/src/yuzu/configuration/configure_input_per_game.ui index 8a384c0df..fbd8eab1c 100644 --- a/src/yuzu/configuration/configure_input_per_game.ui +++ b/src/yuzu/configuration/configure_input_per_game.ui | |||
| @@ -30,7 +30,7 @@ | |||
| 30 | <layout class="QVBoxLayout" name="verticalLayout_4"> | 30 | <layout class="QVBoxLayout" name="verticalLayout_4"> |
| 31 | <item> | 31 | <item> |
| 32 | <widget class="QWidget" name="player_1" native="true"> | 32 | <widget class="QWidget" name="player_1" native="true"> |
| 33 | <layout class="QHBoxLayout" name="input_profile_layout"> | 33 | <layout class="QHBoxLayout" name="input_profile_layout_1"> |
| 34 | <property name="leftMargin"> | 34 | <property name="leftMargin"> |
| 35 | <number>0</number> | 35 | <number>0</number> |
| 36 | </property> | 36 | </property> |
| @@ -64,8 +64,43 @@ | |||
| 64 | </widget> | 64 | </widget> |
| 65 | </item> | 65 | </item> |
| 66 | <item> | 66 | <item> |
| 67 | <widget class="QWidget" name="player_2" native="true"> | ||
| 68 | <layout class="QHBoxLayout" name="input_profile_layout_2"> | ||
| 69 | <property name="leftMargin"> | ||
| 70 | <number>0</number> | ||
| 71 | </property> | ||
| 72 | <property name="topMargin"> | ||
| 73 | <number>0</number> | ||
| 74 | </property> | ||
| 75 | <property name="rightMargin"> | ||
| 76 | <number>0</number> | ||
| 77 | </property> | ||
| 78 | <property name="bottomMargin"> | ||
| 79 | <number>0</number> | ||
| 80 | </property> | ||
| 81 | <item> | ||
| 82 | <widget class="QLabel" name="label_player_2"> | ||
| 83 | <property name="text"> | ||
| 84 | <string>Player 2 Profile</string> | ||
| 85 | </property> | ||
| 86 | </widget> | ||
| 87 | </item> | ||
| 88 | <item> | ||
| 89 | <widget class="QComboBox" name="profile_player_2"> | ||
| 90 | <property name="sizePolicy"> | ||
| 91 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | ||
| 92 | <horstretch>0</horstretch> | ||
| 93 | <verstretch>0</verstretch> | ||
| 94 | </sizepolicy> | ||
| 95 | </property> | ||
| 96 | </widget> | ||
| 97 | </item> | ||
| 98 | </layout> | ||
| 99 | </widget> | ||
| 100 | </item> | ||
| 101 | <item> | ||
| 67 | <widget class="QWidget" name="player_3" native="true"> | 102 | <widget class="QWidget" name="player_3" native="true"> |
| 68 | <layout class="QHBoxLayout" name="input_profile_layout"> | 103 | <layout class="QHBoxLayout" name="input_profile_layout_3"> |
| 69 | <property name="leftMargin"> | 104 | <property name="leftMargin"> |
| 70 | <number>0</number> | 105 | <number>0</number> |
| 71 | </property> | 106 | </property> |
| @@ -100,7 +135,7 @@ | |||
| 100 | </item> | 135 | </item> |
| 101 | <item> | 136 | <item> |
| 102 | <widget class="QWidget" name="player_4" native="true"> | 137 | <widget class="QWidget" name="player_4" native="true"> |
| 103 | <layout class="QHBoxLayout" name="input_profile_layout"> | 138 | <layout class="QHBoxLayout" name="input_profile_layout_4"> |
| 104 | <property name="leftMargin"> | 139 | <property name="leftMargin"> |
| 105 | <number>0</number> | 140 | <number>0</number> |
| 106 | </property> | 141 | </property> |
| @@ -135,7 +170,7 @@ | |||
| 135 | </item> | 170 | </item> |
| 136 | <item> | 171 | <item> |
| 137 | <widget class="QWidget" name="player_5" native="true"> | 172 | <widget class="QWidget" name="player_5" native="true"> |
| 138 | <layout class="QHBoxLayout" name="input_profile_layout"> | 173 | <layout class="QHBoxLayout" name="input_profile_layout_5"> |
| 139 | <property name="leftMargin"> | 174 | <property name="leftMargin"> |
| 140 | <number>0</number> | 175 | <number>0</number> |
| 141 | </property> | 176 | </property> |
| @@ -170,7 +205,7 @@ | |||
| 170 | </item> | 205 | </item> |
| 171 | <item> | 206 | <item> |
| 172 | <widget class="QWidget" name="player_6" native="true"> | 207 | <widget class="QWidget" name="player_6" native="true"> |
| 173 | <layout class="QHBoxLayout" name="input_profile_layout"> | 208 | <layout class="QHBoxLayout" name="input_profile_layout_6"> |
| 174 | <property name="leftMargin"> | 209 | <property name="leftMargin"> |
| 175 | <number>0</number> | 210 | <number>0</number> |
| 176 | </property> | 211 | </property> |
| @@ -205,7 +240,7 @@ | |||
| 205 | </item> | 240 | </item> |
| 206 | <item> | 241 | <item> |
| 207 | <widget class="QWidget" name="player_7" native="true"> | 242 | <widget class="QWidget" name="player_7" native="true"> |
| 208 | <layout class="QHBoxLayout" name="input_profile_layout"> | 243 | <layout class="QHBoxLayout" name="input_profile_layout_7"> |
| 209 | <property name="leftMargin"> | 244 | <property name="leftMargin"> |
| 210 | <number>0</number> | 245 | <number>0</number> |
| 211 | </property> | 246 | </property> |
| @@ -240,7 +275,7 @@ | |||
| 240 | </item> | 275 | </item> |
| 241 | <item> | 276 | <item> |
| 242 | <widget class="QWidget" name="player_8" native="true"> | 277 | <widget class="QWidget" name="player_8" native="true"> |
| 243 | <layout class="QHBoxLayout" name="input_profile_layout"> | 278 | <layout class="QHBoxLayout" name="input_profile_layout_8"> |
| 244 | <property name="leftMargin"> | 279 | <property name="leftMargin"> |
| 245 | <number>0</number> | 280 | <number>0</number> |
| 246 | </property> | 281 | </property> |