scenelayer.h 3.3 KB

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