MapViewController.h 4.1 KB

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