MapViewController.h 3.7 KB

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