configure_input_player.h 3.3 KB

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