selection_system.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "../core/entity.h"
  3. #include "../core/system.h"
  4. #include <QObject>
  5. #include <functional>
  6. #include <vector>
  7. namespace Engine::Core {
  8. class Entity;
  9. class World;
  10. } // namespace Engine::Core
  11. namespace Game::Systems {
  12. class PickingService;
  13. class SelectionSystem : public Engine::Core::System {
  14. public:
  15. void update(Engine::Core::World *world, float delta_time) override;
  16. void select_unit(Engine::Core::EntityID unit_id);
  17. void deselect_unit(Engine::Core::EntityID unit_id);
  18. void clear_selection();
  19. void select_units_in_area(float x1, float y1, float x2, float y2);
  20. [[nodiscard]] auto
  21. get_selected_units() const -> const std::vector<Engine::Core::EntityID> & {
  22. return m_selected_units;
  23. }
  24. private:
  25. std::vector<Engine::Core::EntityID> m_selected_units;
  26. static auto is_unit_in_area(Engine::Core::Entity *entity, float x1, float y1,
  27. float x2, float y2) -> bool;
  28. };
  29. class SelectionController : public QObject {
  30. Q_OBJECT
  31. public:
  32. SelectionController(Engine::Core::World *world,
  33. SelectionSystem *selection_system,
  34. PickingService *picking_service,
  35. QObject *parent = nullptr);
  36. void on_click_select(qreal sx, qreal sy, bool additive, int viewport_width,
  37. int viewport_height, void *camera, int local_owner_id);
  38. void on_area_selected(qreal x1, qreal y1, qreal x2, qreal y2, bool additive,
  39. int viewport_width, int viewport_height, void *camera,
  40. int local_owner_id);
  41. void on_right_click_clear_selection();
  42. void select_all_player_troops(int local_owner_id);
  43. void select_single_unit(Engine::Core::EntityID id, int local_owner_id);
  44. [[nodiscard]] auto has_units_selected() const -> bool;
  45. void get_selected_unit_ids(std::vector<Engine::Core::EntityID> &out) const;
  46. [[nodiscard]] auto has_selected_type(const QString &type) const -> bool;
  47. signals:
  48. void selection_changed();
  49. void selection_model_refresh_requested();
  50. private:
  51. Engine::Core::World *m_world;
  52. SelectionSystem *m_selection_system;
  53. PickingService *m_picking_service;
  54. void sync_selection_flags();
  55. };
  56. } // namespace Game::Systems