command_controller.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include <QObject>
  3. #include <QString>
  4. #include <QVector3D>
  5. #include <vector>
  6. namespace Engine::Core {
  7. class World;
  8. class Entity;
  9. using EntityID = unsigned int;
  10. } // namespace Engine::Core
  11. namespace Game::Systems {
  12. class SelectionSystem;
  13. class PickingService;
  14. } // namespace Game::Systems
  15. namespace App::Controllers {
  16. struct CommandResult {
  17. bool input_consumed = false;
  18. bool reset_cursor_to_normal = false;
  19. };
  20. class CommandController : public QObject {
  21. Q_OBJECT
  22. public:
  23. CommandController(Engine::Core::World *world,
  24. Game::Systems::SelectionSystem *selection_system,
  25. Game::Systems::PickingService *picking_service,
  26. QObject *parent = nullptr);
  27. auto on_attack_click(qreal sx, qreal sy, int viewport_width,
  28. int viewport_height, void *camera) -> CommandResult;
  29. auto on_stop_command() -> CommandResult;
  30. auto on_hold_command() -> CommandResult;
  31. auto on_guard_command() -> CommandResult;
  32. auto on_formation_command() -> CommandResult;
  33. auto on_run_command() -> CommandResult;
  34. void enable_run_mode_for_selected();
  35. void disable_run_mode_for_selected();
  36. auto on_guard_click(qreal sx, qreal sy, int viewport_width,
  37. int viewport_height, void *camera) -> CommandResult;
  38. auto on_patrol_click(qreal sx, qreal sy, int viewport_width,
  39. int viewport_height, void *camera) -> CommandResult;
  40. auto set_rally_at_screen(qreal sx, qreal sy, int viewport_width,
  41. int viewport_height, void *camera,
  42. int local_owner_id) -> CommandResult;
  43. void recruit_near_selected(const QString &unit_type, int local_owner_id);
  44. [[nodiscard]] bool has_patrol_first_waypoint() const {
  45. return m_has_patrol_first_waypoint;
  46. }
  47. [[nodiscard]] QVector3D get_patrol_first_waypoint() const {
  48. return m_patrol_first_waypoint;
  49. }
  50. void clear_patrol_first_waypoint() { m_has_patrol_first_waypoint = false; }
  51. void reset_transient_state();
  52. [[nodiscard]] bool is_placing_formation() const {
  53. return m_is_placing_formation;
  54. }
  55. void update_formation_placement(const QVector3D &position);
  56. void update_formation_rotation(float angle_degrees);
  57. void confirm_formation_placement();
  58. void cancel_formation_placement();
  59. [[nodiscard]] QVector3D get_formation_placement_position() const {
  60. return m_formation_placement_position;
  61. }
  62. [[nodiscard]] float get_formation_placement_angle() const {
  63. return m_formation_placement_angle;
  64. }
  65. Q_INVOKABLE [[nodiscard]] bool any_selected_in_hold_mode() const;
  66. Q_INVOKABLE [[nodiscard]] bool any_selected_in_guard_mode() const;
  67. Q_INVOKABLE [[nodiscard]] bool any_selected_in_formation_mode() const;
  68. Q_INVOKABLE [[nodiscard]] bool any_selected_in_run_mode() const;
  69. signals:
  70. void attack_target_selected();
  71. void troop_limit_reached();
  72. void hold_mode_changed(bool active);
  73. void guard_mode_changed(bool active);
  74. void formation_mode_changed(bool active);
  75. void run_mode_changed(bool active);
  76. void formation_placement_started();
  77. void formation_placement_updated(QVector3D position, float angle);
  78. void formation_placement_ended();
  79. private:
  80. Engine::Core::World *m_world;
  81. Game::Systems::SelectionSystem *m_selection_system;
  82. Game::Systems::PickingService *m_picking_service;
  83. bool m_has_patrol_first_waypoint = false;
  84. QVector3D m_patrol_first_waypoint;
  85. bool m_is_placing_formation = false;
  86. QVector3D m_formation_placement_position;
  87. float m_formation_placement_angle = 0.0F;
  88. std::vector<Engine::Core::EntityID> m_formation_units;
  89. static void reset_movement(Engine::Core::Entity *entity);
  90. };
  91. } // namespace App::Controllers