MapViewController.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * MapViewController.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 "IMapRendererObserver.h"
  12. #include "../ConditionalWait.h"
  13. #include "../../lib/Point.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct ObjectPosInfo;
  16. class PlayerColor;
  17. VCMI_LIB_NAMESPACE_END
  18. struct MapRendererContextState;
  19. class MapViewCache;
  20. class MapViewModel;
  21. class IMapRendererContext;
  22. class MapRendererAdventureContext;
  23. class MapRendererAdventureFadingContext;
  24. class MapRendererAdventureMovingContext;
  25. class MapRendererAdventureTransitionContext;
  26. class MapRendererWorldViewContext;
  27. class MapRendererSpellViewContext;
  28. class MapRendererPuzzleMapContext;
  29. /// Class responsible for updating view state,
  30. /// such as its position and any animations
  31. class MapViewController : public IMapObjectObserver
  32. {
  33. ConditionalWait animationWait;
  34. std::shared_ptr<IMapRendererContext> context;
  35. std::shared_ptr<MapRendererContextState> state;
  36. std::shared_ptr<MapViewModel> model;
  37. std::shared_ptr<MapViewCache> view;
  38. // all potential contexts for view
  39. // only some are present at any given moment, rest are nullptr's
  40. std::shared_ptr<MapRendererAdventureContext> adventureContext;
  41. std::shared_ptr<MapRendererAdventureMovingContext> movementContext;
  42. std::shared_ptr<MapRendererAdventureTransitionContext> teleportContext;
  43. std::shared_ptr<MapRendererAdventureFadingContext> fadingOutContext;
  44. std::shared_ptr<MapRendererAdventureFadingContext> fadingInContext;
  45. std::shared_ptr<MapRendererWorldViewContext> worldViewContext;
  46. std::shared_ptr<MapRendererSpellViewContext> spellViewContext;
  47. std::shared_ptr<MapRendererPuzzleMapContext> puzzleMapContext;
  48. private:
  49. const int defaultTileSize = 32;
  50. const int zoomTileDeadArea = 4;
  51. Point targetTileSize = Point(32, 32);
  52. bool wasInDeadZone = true;
  53. bool isEventInstant(const CGObjectInstance * obj, const PlayerColor & initiator);
  54. bool isEventVisible(const CGObjectInstance * obj, const PlayerColor & initiator);
  55. bool isEventVisible(const CGHeroInstance * obj, const int3 & from, const int3 & dest);
  56. void fadeOutObject(const CGObjectInstance * obj);
  57. void fadeInObject(const CGObjectInstance * obj);
  58. void removeObject(const CGObjectInstance * obj);
  59. void addObject(const CGObjectInstance * obj);
  60. // IMapObjectObserver impl
  61. bool hasOngoingAnimations() override;
  62. void waitForOngoingAnimations() override;
  63. void endNetwork() override;
  64. void onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator) override;
  65. void onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator) override;
  66. void onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator) override;
  67. void onObjectInstantRemove(const CGObjectInstance * obj, const PlayerColor & initiator) override;
  68. void onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  69. void onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  70. void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  71. void onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  72. void onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  73. void onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  74. void onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  75. void resetContext();
  76. void updateState();
  77. public:
  78. MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view);
  79. std::shared_ptr<IMapRendererContext> getContext() const;
  80. void setViewCenter(const int3 & position);
  81. void setViewCenter(const Point & position, int level);
  82. void setTileSize(const Point & tileSize, bool setTarget = true);
  83. void modifyTileSize(int stepsChange, bool useDeadZone);
  84. void tick(uint32_t timePassed);
  85. void afterRender();
  86. void activateAdventureContext(uint32_t animationTime);
  87. void activateAdventureContext();
  88. void activateWorldViewContext();
  89. void activateSpellViewContext();
  90. void activatePuzzleMapContext(const int3 & grailPosition);
  91. void setTerrainVisibility(bool showAllTerrain);
  92. void setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions);
  93. };