MapViewController.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. void updateState();
  67. public:
  68. MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view);
  69. std::shared_ptr<IMapRendererContext> getContext() const;
  70. void setViewCenter(const int3 & position);
  71. void setViewCenter(const Point & position, int level);
  72. void setTileSize(const Point & tileSize);
  73. void modifyTileSize(int stepsChange);
  74. void tick(uint32_t timePassed);
  75. void afterRender();
  76. void activateAdventureContext(uint32_t animationTime);
  77. void activateAdventureContext();
  78. void activateWorldViewContext();
  79. void activateSpellViewContext();
  80. void activatePuzzleMapContext(const int3 & grailPosition);
  81. void setTerrainVisibility(bool showAllTerrain);
  82. void setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions);
  83. };