MapViewController.h 3.9 KB

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