MapViewController.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class Point;
  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. bool isEventVisible(const CGObjectInstance * obj);
  47. bool isEventVisible(const CGHeroInstance * obj, const int3 & from, const int3 & dest);
  48. void fadeOutObject(const CGObjectInstance * obj);
  49. void fadeInObject(const CGObjectInstance * obj);
  50. void removeObject(const CGObjectInstance * obj);
  51. void addObject(const CGObjectInstance * obj);
  52. // IMapObjectObserver impl
  53. bool hasOngoingAnimations() override;
  54. void onObjectFadeIn(const CGObjectInstance * obj) override;
  55. void onObjectFadeOut(const CGObjectInstance * obj) override;
  56. void onObjectInstantAdd(const CGObjectInstance * obj) override;
  57. void onObjectInstantRemove(const CGObjectInstance * obj) override;
  58. void onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  59. void onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  60. void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  61. void onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  62. void onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  63. void onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  64. void onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
  65. void resetContext();
  66. public:
  67. MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view);
  68. std::shared_ptr<IMapRendererContext> getContext() const;
  69. void setViewCenter(const int3 & position);
  70. void setViewCenter(const Point & position, int level);
  71. void setTileSize(const Point & tileSize);
  72. void updateBefore(uint32_t timeDelta);
  73. void updateAfter(uint32_t timeDelta);
  74. void activateAdventureContext(uint32_t animationTime);
  75. void activateAdventureContext();
  76. void activateWorldViewContext();
  77. void activateSpellViewContext();
  78. void activatePuzzleMapContext(const int3 & grailPosition);
  79. void setTerrainVisibility(bool showAllTerrain);
  80. void setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions);
  81. };