MapRendererContext.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * MapRendererContext.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 "IMapRendererContext.h"
  12. #include "../lib/int3.h"
  13. #include "../lib/GameConstants.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct ObjectPosInfo;
  16. VCMI_LIB_NAMESPACE_END
  17. class MapObjectsSorter
  18. {
  19. IMapRendererContext & context;
  20. public:
  21. explicit MapObjectsSorter(IMapRendererContext & context);
  22. bool operator()(const ObjectInstanceID & left, const ObjectInstanceID & right) const;
  23. bool operator()(const CGObjectInstance * left, const CGObjectInstance * right) const;
  24. };
  25. struct HeroAnimationState
  26. {
  27. ObjectInstanceID target;
  28. int3 tileFrom;
  29. int3 tileDest;
  30. double progress;
  31. };
  32. struct FadingAnimationState
  33. {
  34. ObjectInstanceID target;
  35. double progress;
  36. };
  37. // from VwSymbol.def
  38. enum class EWorldViewIcon
  39. {
  40. TOWN = 0,
  41. HERO = 1,
  42. ARTIFACT = 2,
  43. TELEPORT = 3,
  44. GATE = 4,
  45. MINE_WOOD = 5,
  46. MINE_MERCURY = 6,
  47. MINE_STONE = 7,
  48. MINE_SULFUR = 8,
  49. MINE_CRYSTAL = 9,
  50. MINE_GEM = 10,
  51. MINE_GOLD = 11,
  52. RES_WOOD = 12,
  53. RES_MERCURY = 13,
  54. RES_STONE = 14,
  55. RES_SULFUR = 15,
  56. RES_CRYSTAL = 16,
  57. RES_GEM = 17,
  58. RES_GOLD = 18,
  59. ICONS_PER_PLAYER = 19,
  60. ICONS_TOTAL = 19 * 9 // 8 players + neutral set at the end
  61. };
  62. class MapRendererContext : public IMapRendererContext
  63. {
  64. friend class MapViewController;
  65. boost::multi_array<MapObjectsList, 3> objects;
  66. uint32_t animationTime = 0;
  67. boost::optional<HeroAnimationState> movementAnimation;
  68. boost::optional<HeroAnimationState> teleportAnimation;
  69. boost::optional<FadingAnimationState> fadeOutAnimation;
  70. boost::optional<FadingAnimationState> fadeInAnimation;
  71. std::vector<ObjectPosInfo> additionalOverlayIcons;
  72. bool worldViewModeActive = false;
  73. bool showAllTerrain = false;
  74. bool settingsSessionSpectate = false;
  75. bool settingsAdventureObjectAnimation = true;
  76. bool settingsAdventureTerrainAnimation = true;
  77. bool settingsSessionShowGrid = false;
  78. bool settingsSessionShowVisitable = false;
  79. bool settingsSessionShowBlockable = false;
  80. size_t selectOverlayImageForObject(const ObjectPosInfo & objectID) const;
  81. public:
  82. MapRendererContext();
  83. void addObject(const CGObjectInstance * object);
  84. void addMovingObject(const CGObjectInstance * object, const int3 & tileFrom, const int3 & tileDest);
  85. void removeObject(const CGObjectInstance * object);
  86. int3 getMapSize() const final;
  87. bool isInMap(const int3 & coordinates) const final;
  88. bool isVisible(const int3 & coordinates) const override;
  89. bool tileAnimated(const int3 & coordinates) const override;
  90. const TerrainTile & getMapTile(const int3 & coordinates) const override;
  91. const MapObjectsList & getObjects(const int3 & coordinates) const override;
  92. const CGObjectInstance * getObject(ObjectInstanceID objectID) const override;
  93. const CGPath * currentPath() const override;
  94. size_t objectGroupIndex(ObjectInstanceID objectID) const override;
  95. Point objectImageOffset(ObjectInstanceID objectID, const int3 & coordinates) const override;
  96. double objectTransparency(ObjectInstanceID objectID, const int3 &coordinates) const override;
  97. size_t objectImageIndex(ObjectInstanceID objectID, size_t groupSize) const override;
  98. size_t terrainImageIndex(size_t groupSize) const override;
  99. size_t overlayImageIndex(const int3 & coordinates) const override;
  100. bool filterGrayscale() const override;
  101. bool showRoads() const override;
  102. bool showRivers() const override;
  103. bool showBorder() const override;
  104. bool showOverlay() const override;
  105. bool showGrid() const override;
  106. bool showVisitable() const override;
  107. bool showBlockable() const override;
  108. };