MapViewController.h 4.3 KB

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