qt_controller.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <memory>
  7. #include <QDialog>
  8. #include "core/frontend/applets/controller.h"
  9. class GMainWindow;
  10. class QCheckBox;
  11. class QComboBox;
  12. class QDialogButtonBox;
  13. class QGroupBox;
  14. class QLabel;
  15. class InputProfiles;
  16. namespace InputCommon {
  17. class InputSubsystem;
  18. }
  19. namespace Ui {
  20. class QtControllerSelectorDialog;
  21. }
  22. namespace Core {
  23. class System;
  24. }
  25. namespace Core::HID {
  26. class HIDCore;
  27. enum class NpadStyleIndex : u8;
  28. } // namespace Core::HID
  29. class QtControllerSelectorDialog final : public QDialog {
  30. Q_OBJECT
  31. public:
  32. explicit QtControllerSelectorDialog(QWidget* parent,
  33. Core::Frontend::ControllerParameters parameters_,
  34. InputCommon::InputSubsystem* input_subsystem_,
  35. Core::System& system_);
  36. ~QtControllerSelectorDialog() override;
  37. int exec() override;
  38. private:
  39. // Applies the current configuration.
  40. void ApplyConfiguration();
  41. // Loads the current input configuration into the frontend applet.
  42. void LoadConfiguration();
  43. // Initializes the "Configure Vibration" Dialog.
  44. void CallConfigureVibrationDialog();
  45. // Initializes the "Configure Motion / Touch" Dialog.
  46. void CallConfigureMotionTouchDialog();
  47. // Initializes the "Create Input Profile" Dialog.
  48. void CallConfigureInputProfileDialog();
  49. // Checks the current configuration against the given parameters.
  50. // This sets and returns the value of parameters_met.
  51. bool CheckIfParametersMet();
  52. // Sets the controller icons for "Supported Controller Types".
  53. void SetSupportedControllers();
  54. // Sets the emulated controllers per player.
  55. void SetEmulatedControllers(std::size_t player_index);
  56. // Gets the Controller Type for a given controller combobox index per player.
  57. Core::HID::NpadStyleIndex GetControllerTypeFromIndex(int index, std::size_t player_index) const;
  58. // Gets the controller combobox index for a given Controller Type per player.
  59. int GetIndexFromControllerType(Core::HID::NpadStyleIndex type, std::size_t player_index) const;
  60. // Updates the controller icons per player.
  61. void UpdateControllerIcon(std::size_t player_index);
  62. // Updates the controller state (type and connection status) per player.
  63. void UpdateControllerState(std::size_t player_index);
  64. // Updates the LED pattern per player.
  65. void UpdateLEDPattern(std::size_t player_index);
  66. // Updates the border color per player.
  67. void UpdateBorderColor(std::size_t player_index);
  68. // Sets the "Explain Text" per player.
  69. void SetExplainText(std::size_t player_index);
  70. // Updates the console mode.
  71. void UpdateDockedState(bool is_handheld);
  72. // Disables and disconnects unsupported players based on the given parameters.
  73. void DisableUnsupportedPlayers();
  74. std::unique_ptr<Ui::QtControllerSelectorDialog> ui;
  75. // Parameters sent in from the backend HLE applet.
  76. Core::Frontend::ControllerParameters parameters;
  77. InputCommon::InputSubsystem* input_subsystem;
  78. std::unique_ptr<InputProfiles> input_profiles;
  79. Core::System& system;
  80. // This is true if and only if all parameters are met. Otherwise, this is false.
  81. // This determines whether the "OK" button can be clicked to exit the applet.
  82. bool parameters_met{false};
  83. static constexpr std::size_t NUM_PLAYERS = 8;
  84. // Widgets encapsulating the groupboxes and comboboxes per player.
  85. std::array<QWidget*, NUM_PLAYERS> player_widgets;
  86. // Groupboxes encapsulating the controller icons and LED patterns per player.
  87. std::array<QGroupBox*, NUM_PLAYERS> player_groupboxes;
  88. // Icons for currently connected controllers/players.
  89. std::array<QWidget*, NUM_PLAYERS> connected_controller_icons;
  90. // Labels that represent the player numbers in place of the controller icons.
  91. std::array<QLabel*, NUM_PLAYERS> player_labels;
  92. // LED patterns for currently connected controllers/players.
  93. std::array<std::array<QCheckBox*, 4>, NUM_PLAYERS> led_patterns_boxes;
  94. // Labels representing additional information known as "Explain Text" per player.
  95. std::array<QLabel*, NUM_PLAYERS> explain_text_labels;
  96. // Comboboxes with a list of emulated controllers per player.
  97. std::array<QComboBox*, NUM_PLAYERS> emulated_controllers;
  98. /// Pairs of emulated controller index and Controller Type enum per player.
  99. std::array<std::vector<std::pair<int, Core::HID::NpadStyleIndex>>, NUM_PLAYERS>
  100. index_controller_type_pairs;
  101. // Labels representing the number of connected controllers
  102. // above the "Connected Controllers" checkboxes.
  103. std::array<QLabel*, NUM_PLAYERS> connected_controller_labels;
  104. // Checkboxes representing the "Connected Controllers".
  105. std::array<QCheckBox*, NUM_PLAYERS> connected_controller_checkboxes;
  106. };
  107. class QtControllerSelector final : public QObject, public Core::Frontend::ControllerApplet {
  108. Q_OBJECT
  109. public:
  110. explicit QtControllerSelector(GMainWindow& parent);
  111. ~QtControllerSelector() override;
  112. void ReconfigureControllers(
  113. std::function<void()> callback_,
  114. const Core::Frontend::ControllerParameters& parameters) const override;
  115. signals:
  116. void MainWindowReconfigureControllers(
  117. const Core::Frontend::ControllerParameters& parameters) const;
  118. private:
  119. void MainWindowReconfigureFinished();
  120. mutable std::function<void()> callback;
  121. };