qt_controller.h 5.5 KB

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