controller.h 3.9 KB

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