command_controller.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <QObject>
  3. #include <QString>
  4. #include <QVector3D>
  5. #include <vector>
  6. namespace Engine {
  7. namespace Core {
  8. class World;
  9. class Entity;
  10. using EntityID = unsigned int;
  11. } // namespace Core
  12. } // namespace Engine
  13. namespace Game::Systems {
  14. class SelectionSystem;
  15. class PickingService;
  16. } // namespace Game::Systems
  17. namespace App::Controllers {
  18. struct CommandResult {
  19. bool inputConsumed = false;
  20. bool resetCursorToNormal = false;
  21. };
  22. class CommandController : public QObject {
  23. Q_OBJECT
  24. public:
  25. CommandController(Engine::Core::World *world,
  26. Game::Systems::SelectionSystem *selectionSystem,
  27. Game::Systems::PickingService *pickingService,
  28. QObject *parent = nullptr);
  29. CommandResult onAttackClick(qreal sx, qreal sy, int viewportWidth,
  30. int viewportHeight, void *camera);
  31. CommandResult onStopCommand();
  32. CommandResult onHoldCommand();
  33. CommandResult onPatrolClick(qreal sx, qreal sy, int viewportWidth,
  34. int viewportHeight, void *camera);
  35. CommandResult setRallyAtScreen(qreal sx, qreal sy, int viewportWidth,
  36. int viewportHeight, void *camera,
  37. int localOwnerId);
  38. void recruitNearSelected(const QString &unitType, int localOwnerId);
  39. bool hasPatrolFirstWaypoint() const { return m_hasPatrolFirstWaypoint; }
  40. QVector3D getPatrolFirstWaypoint() const { return m_patrolFirstWaypoint; }
  41. void clearPatrolFirstWaypoint() { m_hasPatrolFirstWaypoint = false; }
  42. Q_INVOKABLE bool anySelectedInHoldMode() const;
  43. signals:
  44. void attackTargetSelected();
  45. void troopLimitReached();
  46. void holdModeChanged(bool active);
  47. private:
  48. Engine::Core::World *m_world;
  49. Game::Systems::SelectionSystem *m_selectionSystem;
  50. Game::Systems::PickingService *m_pickingService;
  51. bool m_hasPatrolFirstWaypoint = false;
  52. QVector3D m_patrolFirstWaypoint;
  53. void resetMovement(Engine::Core::Entity *entity);
  54. };
  55. } // namespace App::Controllers