diff options
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 138 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.h | 13 |
2 files changed, 96 insertions, 55 deletions
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 | ||