controller.h 4.3 KB

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