scenelayer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * scenelayer.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../lib/int3.h"
  12. class MapSceneBase;
  13. class MapScene;
  14. class MapController;
  15. class MapHandler;
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class CMap;
  18. class CGObjectInstance;
  19. VCMI_LIB_NAMESPACE_END
  20. class AbstractLayer : public QObject
  21. {
  22. Q_OBJECT
  23. public:
  24. AbstractLayer(MapSceneBase * s);
  25. virtual void update() = 0;
  26. void show(bool show);
  27. void redraw();
  28. void initialize(MapController & controller);
  29. protected:
  30. MapSceneBase * scene;
  31. CMap * map = nullptr;
  32. MapHandler * handler = nullptr;
  33. bool isShown = false;
  34. std::unique_ptr<QPixmap> pixmap;
  35. QPixmap emptyPixmap;
  36. private:
  37. std::unique_ptr<QGraphicsPixmapItem> item;
  38. };
  39. class GridLayer: public AbstractLayer
  40. {
  41. Q_OBJECT
  42. public:
  43. GridLayer(MapSceneBase * s);
  44. void update() override;
  45. };
  46. class PassabilityLayer: public AbstractLayer
  47. {
  48. Q_OBJECT
  49. public:
  50. PassabilityLayer(MapSceneBase * s);
  51. void update() override;
  52. };
  53. class SelectionTerrainLayer: public AbstractLayer
  54. {
  55. Q_OBJECT
  56. public:
  57. SelectionTerrainLayer(MapSceneBase* s);
  58. void update() override;
  59. void draw();
  60. void select(const int3 & tile);
  61. void erase(const int3 & tile);
  62. void clear();
  63. const std::set<int3> & selection() const;
  64. signals:
  65. void selectionMade(bool anythingSlected);
  66. private:
  67. std::set<int3> area, areaAdd, areaErase;
  68. void onSelection();
  69. };
  70. class TerrainLayer: public AbstractLayer
  71. {
  72. Q_OBJECT
  73. public:
  74. TerrainLayer(MapSceneBase * s);
  75. void update() override;
  76. void draw(bool onlyDirty = true);
  77. void setDirty(const int3 & tile);
  78. private:
  79. std::set<int3> dirty;
  80. };
  81. class ObjectsLayer: public AbstractLayer
  82. {
  83. Q_OBJECT
  84. public:
  85. ObjectsLayer(MapSceneBase * s);
  86. void update() override;
  87. void draw(bool onlyDirty = true); //TODO: implement dirty
  88. void setDirty(int x, int y);
  89. void setDirty(const CGObjectInstance * object);
  90. private:
  91. std::set<const CGObjectInstance *> objDirty;
  92. std::set<int3> dirty;
  93. };
  94. class SelectionObjectsLayer: public AbstractLayer
  95. {
  96. Q_OBJECT
  97. public:
  98. enum SelectionMode
  99. {
  100. NOTHING, SELECTION, MOVEMENT
  101. };
  102. SelectionObjectsLayer(MapSceneBase* s);
  103. void update() override;
  104. void draw();
  105. CGObjectInstance * selectObjectAt(int x, int y, const CGObjectInstance * ignore = nullptr) const;
  106. void selectObjects(int x1, int y1, int x2, int y2);
  107. void selectObject(CGObjectInstance *, bool inform = true);
  108. void deselectObject(CGObjectInstance *);
  109. bool isSelected(const CGObjectInstance *) const;
  110. std::set<CGObjectInstance*> getSelection() const;
  111. void clear();
  112. QPoint shift;
  113. CGObjectInstance * newObject;
  114. //FIXME: magic number
  115. SelectionMode selectionMode = SelectionMode::NOTHING;
  116. signals:
  117. void selectionMade(bool anythingSlected);
  118. private:
  119. std::set<CGObjectInstance *> selectedObjects;
  120. void onSelection();
  121. };
  122. class MinimapLayer: public AbstractLayer
  123. {
  124. public:
  125. MinimapLayer(MapSceneBase * s);
  126. void update() override;
  127. };
  128. class MinimapViewLayer: public AbstractLayer
  129. {
  130. public:
  131. MinimapViewLayer(MapSceneBase * s);
  132. void setViewport(int x, int y, int w, int h);
  133. void draw();
  134. void update() override;
  135. int viewportX() const {return x;}
  136. int viewportY() const {return y;}
  137. int viewportWidth() const {return w;}
  138. int viewportHeight() const {return h;}
  139. private:
  140. int x = 0, y = 0, w = 1, h = 1;
  141. };