controller.h 4.3 KB

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