configure_input_player.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2016 Citra 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 <functional>
  7. #include <memory>
  8. #include <optional>
  9. #include <string>
  10. #include <QDialog>
  11. #include "common/param_package.h"
  12. #include "core/settings.h"
  13. #include "ui_configure_input.h"
  14. class QKeyEvent;
  15. class QPushButton;
  16. class QString;
  17. class QTimer;
  18. namespace InputCommon::Polling {
  19. class DevicePoller;
  20. enum class DeviceType;
  21. } // namespace InputCommon::Polling
  22. namespace Ui {
  23. class ConfigureInputPlayer;
  24. }
  25. class ConfigureInputPlayer : public QDialog {
  26. Q_OBJECT
  27. public:
  28. explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false);
  29. ~ConfigureInputPlayer() override;
  30. /// Save all button configurations to settings file
  31. void applyConfiguration();
  32. private:
  33. void OnControllerButtonClick(int i);
  34. /// Load configuration settings.
  35. void loadConfiguration();
  36. /// Restore all buttons to their default values.
  37. void restoreDefaults();
  38. /// Clear all input configuration
  39. void ClearAll();
  40. /// Update UI to reflect current configuration.
  41. void updateButtonLabels();
  42. /// Called when the button was pressed.
  43. void handleClick(QPushButton* button,
  44. std::function<void(const Common::ParamPackage&)> new_input_setter,
  45. InputCommon::Polling::DeviceType type);
  46. /// Finish polling and configure input using the input_setter
  47. void setPollingResult(const Common::ParamPackage& params, bool abort);
  48. /// Handle key press events.
  49. void keyPressEvent(QKeyEvent* event) override;
  50. std::unique_ptr<Ui::ConfigureInputPlayer> ui;
  51. std::size_t player_index;
  52. bool debug;
  53. std::unique_ptr<QTimer> timeout_timer;
  54. std::unique_ptr<QTimer> poll_timer;
  55. /// This will be the the setting function when an input is awaiting configuration.
  56. std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
  57. std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
  58. std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
  59. static constexpr int ANALOG_SUB_BUTTONS_NUM = 5;
  60. /// Each button input is represented by a QPushButton.
  61. std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
  62. std::vector<QWidget*> debug_hidden;
  63. std::vector<QWidget*> layout_hidden;
  64. /// A group of five QPushButtons represent one analog input. The buttons each represent up,
  65. /// down, left, right, and modifier, respectively.
  66. std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
  67. analog_map_buttons;
  68. /// Analog inputs are also represented each with a single button, used to configure with an
  69. /// actual analog stick
  70. std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> analog_map_stick;
  71. static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
  72. std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
  73. /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
  74. /// keyboard events are ignored.
  75. bool want_keyboard_keys = false;
  76. std::array<QPushButton*, 4> controller_color_buttons;
  77. std::array<QColor, 4> controller_colors;
  78. };