qt_controller.h 5.3 KB

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