diff options
| author | 2020-11-25 11:20:46 -0800 | |
|---|---|---|
| committer | 2020-11-25 11:20:46 -0800 | |
| commit | dcfa1992ea5fa450b64a75503ba487fba401e757 (patch) | |
| tree | 68adf47f034e256d19985aed5e578fb0b91d27d9 /src | |
| parent | Merge pull request #4932 from ogniK5377/misc-audio (diff) | |
| parent | applets/controller: Use a pair of emulated controller index to controller type (diff) | |
| download | yuzu-dcfa1992ea5fa450b64a75503ba487fba401e757.tar.gz yuzu-dcfa1992ea5fa450b64a75503ba487fba401e757.tar.xz yuzu-dcfa1992ea5fa450b64a75503ba487fba401e757.zip | |
Merge pull request #4959 from Morph1984/emulated-controller-styleset
configure_input_player: Use the NpadStyleSet to limit the available controllers shown
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/applets/controller.cpp | 123 | ||||
| -rw-r--r-- | src/yuzu/applets/controller.h | 17 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 138 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.h | 13 |
4 files changed, 192 insertions, 99 deletions
diff --git a/src/yuzu/applets/controller.cpp b/src/yuzu/applets/controller.cpp index 8ecfec770..6944478f3 100644 --- a/src/yuzu/applets/controller.cpp +++ b/src/yuzu/applets/controller.cpp | |||
| @@ -72,40 +72,6 @@ bool IsControllerCompatible(Settings::ControllerType controller_type, | |||
| 72 | } | 72 | } |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | /// Maps the controller type combobox index to Controller Type enum | ||
| 76 | constexpr Settings::ControllerType GetControllerTypeFromIndex(int index) { | ||
| 77 | switch (index) { | ||
| 78 | case 0: | ||
| 79 | default: | ||
| 80 | return Settings::ControllerType::ProController; | ||
| 81 | case 1: | ||
| 82 | return Settings::ControllerType::DualJoyconDetached; | ||
| 83 | case 2: | ||
| 84 | return Settings::ControllerType::LeftJoycon; | ||
| 85 | case 3: | ||
| 86 | return Settings::ControllerType::RightJoycon; | ||
| 87 | case 4: | ||
| 88 | return Settings::ControllerType::Handheld; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | /// Maps the Controller Type enum to controller type combobox index | ||
| 93 | constexpr int GetIndexFromControllerType(Settings::ControllerType type) { | ||
| 94 | switch (type) { | ||
| 95 | case Settings::ControllerType::ProController: | ||
| 96 | default: | ||
| 97 | return 0; | ||
| 98 | case Settings::ControllerType::DualJoyconDetached: | ||
| 99 | return 1; | ||
| 100 | case Settings::ControllerType::LeftJoycon: | ||
| 101 | return 2; | ||
| 102 | case Settings::ControllerType::RightJoycon: | ||
| 103 | return 3; | ||
| 104 | case Settings::ControllerType::Handheld: | ||
| 105 | return 4; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | } // namespace | 75 | } // namespace |
| 110 | 76 | ||
| 111 | QtControllerSelectorDialog::QtControllerSelectorDialog( | 77 | QtControllerSelectorDialog::QtControllerSelectorDialog( |
| @@ -184,6 +150,11 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 184 | // This avoids unintentionally changing the states of elements while loading them in. | 150 | // This avoids unintentionally changing the states of elements while loading them in. |
| 185 | SetSupportedControllers(); | 151 | SetSupportedControllers(); |
| 186 | DisableUnsupportedPlayers(); | 152 | DisableUnsupportedPlayers(); |
| 153 | |||
| 154 | for (std::size_t player_index = 0; player_index < NUM_PLAYERS; ++player_index) { | ||
| 155 | SetEmulatedControllers(player_index); | ||
| 156 | } | ||
| 157 | |||
| 187 | LoadConfiguration(); | 158 | LoadConfiguration(); |
| 188 | 159 | ||
| 189 | for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { | 160 | for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { |
| @@ -223,8 +194,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 223 | 194 | ||
| 224 | if (i == 0) { | 195 | if (i == 0) { |
| 225 | connect(emulated_controllers[i], qOverload<int>(&QComboBox::currentIndexChanged), | 196 | connect(emulated_controllers[i], qOverload<int>(&QComboBox::currentIndexChanged), |
| 226 | [this](int index) { | 197 | [this, i](int index) { |
| 227 | UpdateDockedState(GetControllerTypeFromIndex(index) == | 198 | UpdateDockedState(GetControllerTypeFromIndex(index, i) == |
| 228 | Settings::ControllerType::Handheld); | 199 | Settings::ControllerType::Handheld); |
| 229 | }); | 200 | }); |
| 230 | } | 201 | } |
| @@ -281,8 +252,8 @@ void QtControllerSelectorDialog::LoadConfiguration() { | |||
| 281 | (index == 0 && Settings::values.players.GetValue()[HANDHELD_INDEX].connected); | 252 | (index == 0 && Settings::values.players.GetValue()[HANDHELD_INDEX].connected); |
| 282 | player_groupboxes[index]->setChecked(connected); | 253 | player_groupboxes[index]->setChecked(connected); |
| 283 | connected_controller_checkboxes[index]->setChecked(connected); | 254 | connected_controller_checkboxes[index]->setChecked(connected); |
| 284 | emulated_controllers[index]->setCurrentIndex( | 255 | emulated_controllers[index]->setCurrentIndex(GetIndexFromControllerType( |
| 285 | GetIndexFromControllerType(Settings::values.players.GetValue()[index].controller_type)); | 256 | Settings::values.players.GetValue()[index].controller_type, index)); |
| 286 | } | 257 | } |
| 287 | 258 | ||
| 288 | UpdateDockedState(Settings::values.players.GetValue()[HANDHELD_INDEX].connected); | 259 | UpdateDockedState(Settings::values.players.GetValue()[HANDHELD_INDEX].connected); |
| @@ -338,7 +309,7 @@ bool QtControllerSelectorDialog::CheckIfParametersMet() { | |||
| 338 | } | 309 | } |
| 339 | 310 | ||
| 340 | const auto compatible = IsControllerCompatible( | 311 | const auto compatible = IsControllerCompatible( |
| 341 | GetControllerTypeFromIndex(emulated_controllers[index]->currentIndex()), | 312 | GetControllerTypeFromIndex(emulated_controllers[index]->currentIndex(), index), |
| 342 | parameters); | 313 | parameters); |
| 343 | 314 | ||
| 344 | // If any controller is found to be incompatible, return false early. | 315 | // If any controller is found to be incompatible, return false early. |
| @@ -422,6 +393,63 @@ void QtControllerSelectorDialog::SetSupportedControllers() { | |||
| 422 | } | 393 | } |
| 423 | } | 394 | } |
| 424 | 395 | ||
| 396 | void QtControllerSelectorDialog::SetEmulatedControllers(std::size_t player_index) { | ||
| 397 | auto& pairs = index_controller_type_pairs[player_index]; | ||
| 398 | |||
| 399 | pairs.clear(); | ||
| 400 | emulated_controllers[player_index]->clear(); | ||
| 401 | |||
| 402 | pairs.emplace_back(emulated_controllers[player_index]->count(), | ||
| 403 | Settings::ControllerType::ProController); | ||
| 404 | emulated_controllers[player_index]->addItem(tr("Pro Controller")); | ||
| 405 | |||
| 406 | pairs.emplace_back(emulated_controllers[player_index]->count(), | ||
| 407 | Settings::ControllerType::DualJoyconDetached); | ||
| 408 | emulated_controllers[player_index]->addItem(tr("Dual Joycons")); | ||
| 409 | |||
| 410 | pairs.emplace_back(emulated_controllers[player_index]->count(), | ||
| 411 | Settings::ControllerType::LeftJoycon); | ||
| 412 | emulated_controllers[player_index]->addItem(tr("Left Joycon")); | ||
| 413 | |||
| 414 | pairs.emplace_back(emulated_controllers[player_index]->count(), | ||
| 415 | Settings::ControllerType::RightJoycon); | ||
| 416 | emulated_controllers[player_index]->addItem(tr("Right Joycon")); | ||
| 417 | |||
| 418 | if (player_index == 0) { | ||
| 419 | pairs.emplace_back(emulated_controllers[player_index]->count(), | ||
| 420 | Settings::ControllerType::Handheld); | ||
| 421 | emulated_controllers[player_index]->addItem(tr("Handheld")); | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | Settings::ControllerType QtControllerSelectorDialog::GetControllerTypeFromIndex( | ||
| 426 | int index, std::size_t player_index) const { | ||
| 427 | const auto& pairs = index_controller_type_pairs[player_index]; | ||
| 428 | |||
| 429 | const auto it = std::find_if(pairs.begin(), pairs.end(), | ||
| 430 | [index](const auto& pair) { return pair.first == index; }); | ||
| 431 | |||
| 432 | if (it == pairs.end()) { | ||
| 433 | return Settings::ControllerType::ProController; | ||
| 434 | } | ||
| 435 | |||
| 436 | return it->second; | ||
| 437 | } | ||
| 438 | |||
| 439 | int QtControllerSelectorDialog::GetIndexFromControllerType(Settings::ControllerType type, | ||
| 440 | std::size_t player_index) const { | ||
| 441 | const auto& pairs = index_controller_type_pairs[player_index]; | ||
| 442 | |||
| 443 | const auto it = std::find_if(pairs.begin(), pairs.end(), | ||
| 444 | [type](const auto& pair) { return pair.second == type; }); | ||
| 445 | |||
| 446 | if (it == pairs.end()) { | ||
| 447 | return 0; | ||
| 448 | } | ||
| 449 | |||
| 450 | return it->first; | ||
| 451 | } | ||
| 452 | |||
| 425 | void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) { | 453 | void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) { |
| 426 | if (!player_groupboxes[player_index]->isChecked()) { | 454 | if (!player_groupboxes[player_index]->isChecked()) { |
| 427 | connected_controller_icons[player_index]->setStyleSheet(QString{}); | 455 | connected_controller_icons[player_index]->setStyleSheet(QString{}); |
| @@ -430,7 +458,8 @@ void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) | |||
| 430 | } | 458 | } |
| 431 | 459 | ||
| 432 | const QString stylesheet = [this, player_index] { | 460 | const QString stylesheet = [this, player_index] { |
| 433 | switch (GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex())) { | 461 | switch (GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(), |
| 462 | player_index)) { | ||
| 434 | case Settings::ControllerType::ProController: | 463 | case Settings::ControllerType::ProController: |
| 435 | return QStringLiteral("image: url(:/controller/applet_pro_controller%0); "); | 464 | return QStringLiteral("image: url(:/controller/applet_pro_controller%0); "); |
| 436 | case Settings::ControllerType::DualJoyconDetached: | 465 | case Settings::ControllerType::DualJoyconDetached: |
| @@ -446,6 +475,12 @@ void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) | |||
| 446 | } | 475 | } |
| 447 | }(); | 476 | }(); |
| 448 | 477 | ||
| 478 | if (stylesheet.isEmpty()) { | ||
| 479 | connected_controller_icons[player_index]->setStyleSheet(QString{}); | ||
| 480 | player_labels[player_index]->show(); | ||
| 481 | return; | ||
| 482 | } | ||
| 483 | |||
| 449 | const QString theme = [] { | 484 | const QString theme = [] { |
| 450 | if (QIcon::themeName().contains(QStringLiteral("dark"))) { | 485 | if (QIcon::themeName().contains(QStringLiteral("dark"))) { |
| 451 | return QStringLiteral("_dark"); | 486 | return QStringLiteral("_dark"); |
| @@ -463,8 +498,8 @@ void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) | |||
| 463 | void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index) { | 498 | void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index) { |
| 464 | auto& player = Settings::values.players.GetValue()[player_index]; | 499 | auto& player = Settings::values.players.GetValue()[player_index]; |
| 465 | 500 | ||
| 466 | const auto controller_type = | 501 | const auto controller_type = GetControllerTypeFromIndex( |
| 467 | GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex()); | 502 | emulated_controllers[player_index]->currentIndex(), player_index); |
| 468 | const auto player_connected = player_groupboxes[player_index]->isChecked() && | 503 | const auto player_connected = player_groupboxes[player_index]->isChecked() && |
| 469 | controller_type != Settings::ControllerType::Handheld; | 504 | controller_type != Settings::ControllerType::Handheld; |
| 470 | 505 | ||
| @@ -507,8 +542,8 @@ void QtControllerSelectorDialog::UpdateControllerState(std::size_t player_index) | |||
| 507 | 542 | ||
| 508 | void QtControllerSelectorDialog::UpdateLEDPattern(std::size_t player_index) { | 543 | void QtControllerSelectorDialog::UpdateLEDPattern(std::size_t player_index) { |
| 509 | if (!player_groupboxes[player_index]->isChecked() || | 544 | if (!player_groupboxes[player_index]->isChecked() || |
| 510 | GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex()) == | 545 | GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(), |
| 511 | Settings::ControllerType::Handheld) { | 546 | player_index) == Settings::ControllerType::Handheld) { |
| 512 | led_patterns_boxes[player_index][0]->setChecked(false); | 547 | led_patterns_boxes[player_index][0]->setChecked(false); |
| 513 | led_patterns_boxes[player_index][1]->setChecked(false); | 548 | led_patterns_boxes[player_index][1]->setChecked(false); |
| 514 | led_patterns_boxes[player_index][2]->setChecked(false); | 549 | led_patterns_boxes[player_index][2]->setChecked(false); |
diff --git a/src/yuzu/applets/controller.h b/src/yuzu/applets/controller.h index 4344e1dd0..7a421d856 100644 --- a/src/yuzu/applets/controller.h +++ b/src/yuzu/applets/controller.h | |||
| @@ -22,6 +22,10 @@ namespace InputCommon { | |||
| 22 | class InputSubsystem; | 22 | class InputSubsystem; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | namespace Settings { | ||
| 26 | enum class ControllerType; | ||
| 27 | } | ||
| 28 | |||
| 25 | namespace Ui { | 29 | namespace Ui { |
| 26 | class QtControllerSelectorDialog; | 30 | class QtControllerSelectorDialog; |
| 27 | } | 31 | } |
| @@ -57,6 +61,15 @@ private: | |||
| 57 | // Sets the controller icons for "Supported Controller Types". | 61 | // Sets the controller icons for "Supported Controller Types". |
| 58 | void SetSupportedControllers(); | 62 | void SetSupportedControllers(); |
| 59 | 63 | ||
| 64 | // Sets the emulated controllers per player. | ||
| 65 | void SetEmulatedControllers(std::size_t player_index); | ||
| 66 | |||
| 67 | // Gets the Controller Type for a given controller combobox index per player. | ||
| 68 | Settings::ControllerType GetControllerTypeFromIndex(int index, std::size_t player_index) const; | ||
| 69 | |||
| 70 | // Gets the controller combobox index for a given Controller Type per player. | ||
| 71 | int GetIndexFromControllerType(Settings::ControllerType type, std::size_t player_index) const; | ||
| 72 | |||
| 60 | // Updates the controller icons per player. | 73 | // Updates the controller icons per player. |
| 61 | void UpdateControllerIcon(std::size_t player_index); | 74 | void UpdateControllerIcon(std::size_t player_index); |
| 62 | 75 | ||
| @@ -114,6 +127,10 @@ private: | |||
| 114 | // Comboboxes with a list of emulated controllers per player. | 127 | // Comboboxes with a list of emulated controllers per player. |
| 115 | std::array<QComboBox*, NUM_PLAYERS> emulated_controllers; | 128 | std::array<QComboBox*, NUM_PLAYERS> emulated_controllers; |
| 116 | 129 | ||
| 130 | /// Pairs of emulated controller index and Controller Type enum per player. | ||
| 131 | std::array<std::vector<std::pair<int, Settings::ControllerType>>, NUM_PLAYERS> | ||
| 132 | index_controller_type_pairs; | ||
| 133 | |||
| 117 | // Labels representing the number of connected controllers | 134 | // Labels representing the number of connected controllers |
| 118 | // above the "Connected Controllers" checkboxes. | 135 | // above the "Connected Controllers" checkboxes. |
| 119 | std::array<QLabel*, NUM_PLAYERS> connected_controller_labels; | 136 | std::array<QLabel*, NUM_PLAYERS> connected_controller_labels; |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 56ab32a35..918bfb56b 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -27,6 +27,8 @@ | |||
| 27 | #include "yuzu/configuration/input_profiles.h" | 27 | #include "yuzu/configuration/input_profiles.h" |
| 28 | #include "yuzu/util/limitable_input_dialog.h" | 28 | #include "yuzu/util/limitable_input_dialog.h" |
| 29 | 29 | ||
| 30 | using namespace Service::HID; | ||
| 31 | |||
| 30 | const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM> | 32 | const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM> |
| 31 | ConfigureInputPlayer::analog_sub_buttons{{ | 33 | ConfigureInputPlayer::analog_sub_buttons{{ |
| 32 | "up", | 34 | "up", |
| @@ -47,48 +49,12 @@ void UpdateController(Settings::ControllerType controller_type, std::size_t npad | |||
| 47 | } | 49 | } |
| 48 | Service::SM::ServiceManager& sm = system.ServiceManager(); | 50 | Service::SM::ServiceManager& sm = system.ServiceManager(); |
| 49 | 51 | ||
| 50 | auto& npad = | 52 | auto& npad = sm.GetService<Hid>("hid")->GetAppletResource()->GetController<Controller_NPad>( |
| 51 | sm.GetService<Service::HID::Hid>("hid") | 53 | HidController::NPad); |
| 52 | ->GetAppletResource() | ||
| 53 | ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad); | ||
| 54 | 54 | ||
| 55 | npad.UpdateControllerAt(npad.MapSettingsTypeToNPad(controller_type), npad_index, connected); | 55 | npad.UpdateControllerAt(npad.MapSettingsTypeToNPad(controller_type), npad_index, connected); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /// Maps the controller type combobox index to Controller Type enum | ||
| 59 | constexpr Settings::ControllerType GetControllerTypeFromIndex(int index) { | ||
| 60 | switch (index) { | ||
| 61 | case 0: | ||
| 62 | default: | ||
| 63 | return Settings::ControllerType::ProController; | ||
| 64 | case 1: | ||
| 65 | return Settings::ControllerType::DualJoyconDetached; | ||
| 66 | case 2: | ||
| 67 | return Settings::ControllerType::LeftJoycon; | ||
| 68 | case 3: | ||
| 69 | return Settings::ControllerType::RightJoycon; | ||
| 70 | case 4: | ||
| 71 | return Settings::ControllerType::Handheld; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | /// Maps the Controller Type enum to controller type combobox index | ||
| 76 | constexpr int GetIndexFromControllerType(Settings::ControllerType type) { | ||
| 77 | switch (type) { | ||
| 78 | case Settings::ControllerType::ProController: | ||
| 79 | default: | ||
| 80 | return 0; | ||
| 81 | case Settings::ControllerType::DualJoyconDetached: | ||
| 82 | return 1; | ||
| 83 | case Settings::ControllerType::LeftJoycon: | ||
| 84 | return 2; | ||
| 85 | case Settings::ControllerType::RightJoycon: | ||
| 86 | return 3; | ||
| 87 | case Settings::ControllerType::Handheld: | ||
| 88 | return 4; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | QString GetKeyName(int key_code) { | 58 | QString GetKeyName(int key_code) { |
| 93 | switch (key_code) { | 59 | switch (key_code) { |
| 94 | case Qt::LeftButton: | 60 | case Qt::LeftButton: |
| @@ -453,18 +419,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 453 | connect(ui->groupConnectedController, &QGroupBox::toggled, | 419 | connect(ui->groupConnectedController, &QGroupBox::toggled, |
| 454 | [this](bool checked) { emit Connected(checked); }); | 420 | [this](bool checked) { emit Connected(checked); }); |
| 455 | 421 | ||
| 456 | // Set up controller type. Only Player 1 can choose Handheld. | ||
| 457 | ui->comboControllerType->clear(); | ||
| 458 | |||
| 459 | QStringList controller_types = { | ||
| 460 | tr("Pro Controller"), | ||
| 461 | tr("Dual Joycons"), | ||
| 462 | tr("Left Joycon"), | ||
| 463 | tr("Right Joycon"), | ||
| 464 | }; | ||
| 465 | |||
| 466 | if (player_index == 0) { | 422 | if (player_index == 0) { |
| 467 | controller_types.append(tr("Handheld")); | ||
| 468 | connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), | 423 | connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), |
| 469 | [this](int index) { | 424 | [this](int index) { |
| 470 | emit HandheldStateChanged(GetControllerTypeFromIndex(index) == | 425 | emit HandheldStateChanged(GetControllerTypeFromIndex(index) == |
| @@ -480,12 +435,9 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 480 | if (debug) { | 435 | if (debug) { |
| 481 | ui->buttonScreenshot->setEnabled(false); | 436 | ui->buttonScreenshot->setEnabled(false); |
| 482 | ui->buttonHome->setEnabled(false); | 437 | ui->buttonHome->setEnabled(false); |
| 483 | QStringList debug_controller_types = { | 438 | ui->comboControllerType->addItem(tr("Pro Controller")); |
| 484 | tr("Pro Controller"), | ||
| 485 | }; | ||
| 486 | ui->comboControllerType->addItems(debug_controller_types); | ||
| 487 | } else { | 439 | } else { |
| 488 | ui->comboControllerType->addItems(controller_types); | 440 | SetConnectableControllers(); |
| 489 | } | 441 | } |
| 490 | 442 | ||
| 491 | UpdateControllerIcon(); | 443 | UpdateControllerIcon(); |
| @@ -667,7 +619,7 @@ void ConfigureInputPlayer::LoadConfiguration() { | |||
| 667 | return; | 619 | return; |
| 668 | } | 620 | } |
| 669 | 621 | ||
| 670 | ui->comboControllerType->setCurrentIndex(static_cast<int>(player.controller_type)); | 622 | ui->comboControllerType->setCurrentIndex(GetIndexFromControllerType(player.controller_type)); |
| 671 | ui->groupConnectedController->setChecked( | 623 | ui->groupConnectedController->setChecked( |
| 672 | player.connected || | 624 | player.connected || |
| 673 | (player_index == 0 && Settings::values.players.GetValue()[HANDHELD_INDEX].connected)); | 625 | (player_index == 0 && Settings::values.players.GetValue()[HANDHELD_INDEX].connected)); |
| @@ -841,6 +793,82 @@ void ConfigureInputPlayer::UpdateUI() { | |||
| 841 | } | 793 | } |
| 842 | } | 794 | } |
| 843 | 795 | ||
| 796 | void ConfigureInputPlayer::SetConnectableControllers() { | ||
| 797 | const auto add_controllers = [this](bool enable_all, | ||
| 798 | Controller_NPad::NpadStyleSet npad_style_set = {}) { | ||
| 799 | index_controller_type_pairs.clear(); | ||
| 800 | ui->comboControllerType->clear(); | ||
| 801 | |||
| 802 | if (enable_all || npad_style_set.pro_controller == 1) { | ||
| 803 | index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), | ||
| 804 | Settings::ControllerType::ProController); | ||
| 805 | ui->comboControllerType->addItem(tr("Pro Controller")); | ||
| 806 | } | ||
| 807 | |||
| 808 | if (enable_all || npad_style_set.joycon_dual == 1) { | ||
| 809 | index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), | ||
| 810 | Settings::ControllerType::DualJoyconDetached); | ||
| 811 | ui->comboControllerType->addItem(tr("Dual Joycons")); | ||
| 812 | } | ||
| 813 | |||
| 814 | if (enable_all || npad_style_set.joycon_left == 1) { | ||
| 815 | index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), | ||
| 816 | Settings::ControllerType::LeftJoycon); | ||
| 817 | ui->comboControllerType->addItem(tr("Left Joycon")); | ||
| 818 | } | ||
| 819 | |||
| 820 | if (enable_all || npad_style_set.joycon_right == 1) { | ||
| 821 | index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), | ||
| 822 | Settings::ControllerType::RightJoycon); | ||
| 823 | ui->comboControllerType->addItem(tr("Right Joycon")); | ||
| 824 | } | ||
| 825 | |||
| 826 | if (player_index == 0 && (enable_all || npad_style_set.handheld == 1)) { | ||
| 827 | index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), | ||
| 828 | Settings::ControllerType::Handheld); | ||
| 829 | ui->comboControllerType->addItem(tr("Handheld")); | ||
| 830 | } | ||
| 831 | }; | ||
| 832 | |||
| 833 | Core::System& system{Core::System::GetInstance()}; | ||
| 834 | |||
| 835 | if (!system.IsPoweredOn()) { | ||
| 836 | add_controllers(true); | ||
| 837 | return; | ||
| 838 | } | ||
| 839 | |||
| 840 | Service::SM::ServiceManager& sm = system.ServiceManager(); | ||
| 841 | |||
| 842 | auto& npad = sm.GetService<Hid>("hid")->GetAppletResource()->GetController<Controller_NPad>( | ||
| 843 | HidController::NPad); | ||
| 844 | |||
| 845 | add_controllers(false, npad.GetSupportedStyleSet()); | ||
| 846 | } | ||
| 847 | |||
| 848 | Settings::ControllerType ConfigureInputPlayer::GetControllerTypeFromIndex(int index) const { | ||
| 849 | const auto it = | ||
| 850 | std::find_if(index_controller_type_pairs.begin(), index_controller_type_pairs.end(), | ||
| 851 | [index](const auto& pair) { return pair.first == index; }); | ||
| 852 | |||
| 853 | if (it == index_controller_type_pairs.end()) { | ||
| 854 | return Settings::ControllerType::ProController; | ||
| 855 | } | ||
| 856 | |||
| 857 | return it->second; | ||
| 858 | } | ||
| 859 | |||
| 860 | int ConfigureInputPlayer::GetIndexFromControllerType(Settings::ControllerType type) const { | ||
| 861 | const auto it = | ||
| 862 | std::find_if(index_controller_type_pairs.begin(), index_controller_type_pairs.end(), | ||
| 863 | [type](const auto& pair) { return pair.second == type; }); | ||
| 864 | |||
| 865 | if (it == index_controller_type_pairs.end()) { | ||
| 866 | return -1; | ||
| 867 | } | ||
| 868 | |||
| 869 | return it->first; | ||
| 870 | } | ||
| 871 | |||
| 844 | void ConfigureInputPlayer::UpdateInputDevices() { | 872 | void ConfigureInputPlayer::UpdateInputDevices() { |
| 845 | input_devices = input_subsystem->GetInputDevices(); | 873 | input_devices = input_subsystem->GetInputDevices(); |
| 846 | ui->comboDevices->clear(); | 874 | ui->comboDevices->clear(); |
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index 23cf6f958..9c30879a2 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <memory> | 9 | #include <memory> |
| 10 | #include <optional> | 10 | #include <optional> |
| 11 | #include <string> | 11 | #include <string> |
| 12 | #include <vector> | ||
| 12 | 13 | ||
| 13 | #include <QWidget> | 14 | #include <QWidget> |
| 14 | 15 | ||
| @@ -112,6 +113,15 @@ private: | |||
| 112 | /// Update UI to reflect current configuration. | 113 | /// Update UI to reflect current configuration. |
| 113 | void UpdateUI(); | 114 | void UpdateUI(); |
| 114 | 115 | ||
| 116 | /// Sets the available controllers. | ||
| 117 | void SetConnectableControllers(); | ||
| 118 | |||
| 119 | /// Gets the Controller Type for a given controller combobox index. | ||
| 120 | Settings::ControllerType GetControllerTypeFromIndex(int index) const; | ||
| 121 | |||
| 122 | /// Gets the controller combobox index for a given Controller Type. | ||
| 123 | int GetIndexFromControllerType(Settings::ControllerType type) const; | ||
| 124 | |||
| 115 | /// Update the available input devices. | 125 | /// Update the available input devices. |
| 116 | void UpdateInputDevices(); | 126 | void UpdateInputDevices(); |
| 117 | 127 | ||
| @@ -151,6 +161,9 @@ private: | |||
| 151 | std::unique_ptr<QTimer> timeout_timer; | 161 | std::unique_ptr<QTimer> timeout_timer; |
| 152 | std::unique_ptr<QTimer> poll_timer; | 162 | std::unique_ptr<QTimer> poll_timer; |
| 153 | 163 | ||
| 164 | /// Stores a pair of "Connected Controllers" combobox index and Controller Type enum. | ||
| 165 | std::vector<std::pair<int, Settings::ControllerType>> index_controller_type_pairs; | ||
| 166 | |||
| 154 | static constexpr int PLAYER_COUNT = 8; | 167 | static constexpr int PLAYER_COUNT = 8; |
| 155 | std::array<QCheckBox*, PLAYER_COUNT> player_connected_checkbox; | 168 | std::array<QCheckBox*, PLAYER_COUNT> player_connected_checkbox; |
| 156 | 169 | ||