TASInputWindow.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2018 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <map>
  5. #include <optional>
  6. #include <string_view>
  7. #include <utility>
  8. #include <QDialog>
  9. #include "Common/CommonTypes.h"
  10. #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
  11. #include "InputCommon/ControllerInterface/CoreDevice.h"
  12. class QBoxLayout;
  13. class QCheckBox;
  14. class QDialog;
  15. class QEvent;
  16. class QGroupBox;
  17. class QSpinBox;
  18. class QString;
  19. class TASCheckBox;
  20. class TASSpinBox;
  21. class InputOverrider final
  22. {
  23. public:
  24. using OverrideFunction = std::function<std::optional<ControlState>(ControlState)>;
  25. void AddFunction(std::string_view group_name, std::string_view control_name,
  26. OverrideFunction function);
  27. ControllerEmu::InputOverrideFunction GetInputOverrideFunction() const;
  28. private:
  29. std::map<std::pair<std::string_view, std::string_view>, OverrideFunction> m_functions;
  30. };
  31. class TASInputWindow : public QDialog
  32. {
  33. Q_OBJECT
  34. public:
  35. explicit TASInputWindow(QWidget* parent);
  36. int GetTurboPressFrames() const;
  37. int GetTurboReleaseFrames() const;
  38. protected:
  39. TASCheckBox* CreateButton(const QString& text, std::string_view group_name,
  40. std::string_view control_name, InputOverrider* overrider);
  41. QGroupBox* CreateStickInputs(const QString& text, std::string_view group_name,
  42. InputOverrider* overrider, int min_x, int min_y, int max_x,
  43. int max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key);
  44. QBoxLayout* CreateSliderValuePairLayout(const QString& text, std::string_view group_name,
  45. std::string_view control_name, InputOverrider* overrider,
  46. int zero, int default_, int min, int max,
  47. Qt::Key shortcut_key, QWidget* shortcut_widget,
  48. std::optional<ControlState> scale = {});
  49. TASSpinBox* CreateSliderValuePair(std::string_view group_name, std::string_view control_name,
  50. InputOverrider* overrider, QBoxLayout* layout, int zero,
  51. int default_, int min, int max,
  52. QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
  53. QWidget* shortcut_widget,
  54. std::optional<ControlState> scale = {});
  55. TASSpinBox* CreateSliderValuePair(QBoxLayout* layout, int default_, int max,
  56. QKeySequence shortcut_key_sequence, Qt::Orientation orientation,
  57. QWidget* shortcut_widget);
  58. void changeEvent(QEvent* event) override;
  59. QGroupBox* m_settings_box;
  60. QCheckBox* m_use_controller;
  61. QSpinBox* m_turbo_press_frames;
  62. QSpinBox* m_turbo_release_frames;
  63. private:
  64. std::optional<ControlState> GetButton(TASCheckBox* checkbox, ControlState controller_state);
  65. std::optional<ControlState> GetSpinBox(TASSpinBox* spin, int zero, int min, int max,
  66. ControlState controller_state);
  67. std::optional<ControlState> GetSpinBox(TASSpinBox* spin, int zero, ControlState controller_state,
  68. ControlState scale);
  69. };