diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/applets/controller.cpp | 123 | ||||
| -rw-r--r-- | src/yuzu/applets/controller.h | 17 |
2 files changed, 96 insertions, 44 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; |