MapViewController.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * MapViewController.cpp, 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. #include "StdInc.h"
  11. #include "MapViewController.h"
  12. #include "MapRendererContext.h"
  13. #include "MapRendererContextState.h"
  14. #include "MapViewCache.h"
  15. #include "MapViewModel.h"
  16. #include "../CPlayerInterface.h"
  17. #include "../adventureMap/AdventureMapInterface.h"
  18. #include "../GameEngine.h"
  19. #include "../GameInstance.h"
  20. #include "../gui/WindowHandler.h"
  21. #include "../eventsSDL/InputHandler.h"
  22. #include "../../lib/CConfigHandler.h"
  23. #include "../../lib/StartInfo.h"
  24. #include "../../lib/UnlockGuard.h"
  25. #include "../../lib/callback/CCallback.h"
  26. #include "../../lib/mapObjects/CGHeroInstance.h"
  27. #include "../../lib/mapObjects/MiscObjects.h"
  28. #include "../../lib/pathfinder/CGPathNode.h"
  29. #include "../../lib/spells/ViewSpellInt.h"
  30. void MapViewController::setViewCenter(const int3 & position)
  31. {
  32. setViewCenter(Point(position) * model->getSingleTileSize() + model->getSingleTileSize() / 2, position.z);
  33. }
  34. void MapViewController::setViewCenter(const Point & position, int level)
  35. {
  36. Point upperLimit = Point(context->getMapSize()) * model->getSingleTileSize();
  37. Point lowerLimit = Point(0, 0);
  38. if(worldViewContext)
  39. {
  40. Point area = model->getPixelsVisibleDimensions();
  41. Point mapCenter = upperLimit / 2;
  42. Point desiredLowerLimit = lowerLimit + area / 2;
  43. Point desiredUpperLimit = upperLimit - area / 2;
  44. Point actualLowerLimit{
  45. std::min(desiredLowerLimit.x, mapCenter.x),
  46. std::min(desiredLowerLimit.y, mapCenter.y)
  47. };
  48. Point actualUpperLimit{
  49. std::max(desiredUpperLimit.x, mapCenter.x),
  50. std::max(desiredUpperLimit.y, mapCenter.y)
  51. };
  52. upperLimit = actualUpperLimit;
  53. lowerLimit = actualLowerLimit;
  54. }
  55. Point betterPosition = {std::clamp(position.x, lowerLimit.x, upperLimit.x), std::clamp(position.y, lowerLimit.y, upperLimit.y)};
  56. model->setViewCenter(betterPosition);
  57. model->setLevel(std::clamp(level, 0, context->getMapSize().z));
  58. if(adventureInt && !puzzleMapContext) // may be called before adventureInt is initialized
  59. adventureInt->onMapViewMoved(model->getTilesTotalRect(), model->getLevel());
  60. }
  61. void MapViewController::setTileSize(const Point & tileSize, bool setTarget)
  62. {
  63. Point oldSize = model->getSingleTileSize();
  64. model->setTileSize(tileSize);
  65. double scaleChangeX = 1.0 * tileSize.x / oldSize.x;
  66. double scaleChangeY = 1.0 * tileSize.y / oldSize.y;
  67. Point newViewCenter {
  68. static_cast<int>(std::round(model->getMapViewCenter().x * scaleChangeX)),
  69. static_cast<int>(std::round(model->getMapViewCenter().y * scaleChangeY))
  70. };
  71. // force update of view center since changing tile size may invalidated it
  72. setViewCenter(newViewCenter, model->getLevel());
  73. if(setTarget)
  74. targetTileSize = tileSize;
  75. }
  76. void MapViewController::modifyTileSize(int stepsChange, bool useDeadZone)
  77. {
  78. // we want to zoom in/out in fixed 10% steps, to allow player to return back to exactly 100% zoom just by scrolling
  79. // so, zooming in for 5 steps will put game at 1.1^5 = 1.61 scale
  80. // try to determine current zooming level and change it by requested number of steps
  81. double currentZoomFactor = targetTileSize.x / static_cast<double>(defaultTileSize);
  82. double currentZoomSteps = std::round(std::log(currentZoomFactor) / std::log(1.01));
  83. double newZoomSteps = stepsChange != 0 ? currentZoomSteps + stepsChange : stepsChange;
  84. double newZoomFactor = std::pow(1.01, newZoomSteps);
  85. Point currentZoom = targetTileSize;
  86. Point desiredZoom = Point(defaultTileSize,defaultTileSize) * newZoomFactor;
  87. if (desiredZoom == currentZoom && stepsChange < 0)
  88. desiredZoom -= Point(1,1);
  89. if (desiredZoom == currentZoom && stepsChange > 0)
  90. desiredZoom += Point(1,1);
  91. Point minimal = model->getSingleTileSizeLowerLimit();
  92. Point maximal = model->getSingleTileSizeUpperLimit();
  93. Point actualZoom = {
  94. std::clamp(desiredZoom.x, minimal.x, maximal.x),
  95. std::clamp(desiredZoom.y, minimal.y, maximal.y)
  96. };
  97. if (actualZoom != currentZoom)
  98. {
  99. targetTileSize = actualZoom;
  100. if (useDeadZone)
  101. {
  102. if(actualZoom.x >= defaultTileSize - zoomTileDeadArea && actualZoom.x <= defaultTileSize + zoomTileDeadArea)
  103. actualZoom.x = defaultTileSize;
  104. if(actualZoom.y >= defaultTileSize - zoomTileDeadArea && actualZoom.y <= defaultTileSize + zoomTileDeadArea)
  105. actualZoom.y = defaultTileSize;
  106. }
  107. bool isInDeadZone = targetTileSize != actualZoom || actualZoom == Point(defaultTileSize, defaultTileSize);
  108. if(!wasInDeadZone && isInDeadZone)
  109. ENGINE->input().hapticFeedback();
  110. wasInDeadZone = isInDeadZone;
  111. setTileSize(actualZoom, false);
  112. if (adventureContext)
  113. {
  114. Settings tileZoom = settings.write["adventure"]["tileZoom"];
  115. tileZoom->Integer() = actualZoom.x;
  116. }
  117. }
  118. }
  119. MapViewController::MapViewController(std::shared_ptr<MapViewModel> model, std::shared_ptr<MapViewCache> view)
  120. : state(new MapRendererContextState())
  121. , model(std::move(model))
  122. , view(view)
  123. {
  124. adventureContext = std::make_shared<MapRendererAdventureContext>(*state);
  125. context = adventureContext;
  126. }
  127. std::shared_ptr<IMapRendererContext> MapViewController::getContext() const
  128. {
  129. return context;
  130. }
  131. void MapViewController::tick(uint32_t timeDelta)
  132. {
  133. // confirmed to match H3 for
  134. // - hero embarking on boat (500 ms)
  135. // - hero disembarking from boat (500 ms)
  136. // - TODO: picking up resources
  137. // - TODO: killing mosters
  138. // - teleporting ( 250 ms)
  139. static const double fadeOutDuration = 500;
  140. static const double fadeInDuration = 500;
  141. static const double heroTeleportDuration = 250;
  142. if(movementContext)
  143. {
  144. const auto * object = context->getObject(movementContext->target);
  145. const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
  146. const auto * boat = dynamic_cast<const CGBoat *>(object);
  147. assert(boat || hero);
  148. if(!hero)
  149. hero = boat->getBoardedHero();
  150. double heroMoveTime = GAME->interface()->playerID == hero->getOwner() ?
  151. settings["adventure"]["heroMoveTime"].Float() :
  152. settings["adventure"]["enemyMoveTime"].Float();
  153. movementContext->progress += timeDelta / heroMoveTime;
  154. movementContext->progress = std::min( 1.0, movementContext->progress);
  155. Point positionFrom = Point(hero->convertToVisitablePos(movementContext->tileFrom)) * model->getSingleTileSize() + model->getSingleTileSize() / 2;
  156. Point positionDest = Point(hero->convertToVisitablePos(movementContext->tileDest)) * model->getSingleTileSize() + model->getSingleTileSize() / 2;
  157. Point positionCurr = vstd::lerp(positionFrom, positionDest, movementContext->progress);
  158. setViewCenter(positionCurr, movementContext->tileDest.z);
  159. }
  160. if(teleportContext)
  161. {
  162. teleportContext->progress += timeDelta / heroTeleportDuration;
  163. teleportContext->progress = std::min( 1.0, teleportContext->progress);
  164. }
  165. if(fadingOutContext)
  166. {
  167. fadingOutContext->progress -= timeDelta / fadeOutDuration;
  168. fadingOutContext->progress = std::max( 0.0, fadingOutContext->progress);
  169. }
  170. if(fadingInContext)
  171. {
  172. fadingInContext->progress += timeDelta / fadeInDuration;
  173. fadingInContext->progress = std::min( 1.0, fadingInContext->progress);
  174. }
  175. if (adventureContext)
  176. adventureContext->animationTime += timeDelta;
  177. updateState();
  178. }
  179. void MapViewController::updateState()
  180. {
  181. if(adventureContext)
  182. {
  183. adventureContext->settingsSessionSpectate = settings["session"]["spectate"].Bool();
  184. adventureContext->settingsAdventureObjectAnimation = settings["adventure"]["objectAnimation"].Bool();
  185. adventureContext->settingsAdventureTerrainAnimation = settings["adventure"]["terrainAnimation"].Bool();
  186. adventureContext->settingShowGrid = settings["gameTweaks"]["showGrid"].Bool();
  187. adventureContext->settingShowVisitable = settings["session"]["showVisitable"].Bool();
  188. adventureContext->settingShowBlocked = settings["session"]["showBlocked"].Bool();
  189. adventureContext->settingTextOverlay = (ENGINE->isKeyboardAltDown() || ENGINE->input().getNumTouchFingers() == 2) && settings["general"]["enableOverlay"].Bool();
  190. }
  191. }
  192. void MapViewController::afterRender()
  193. {
  194. if(movementContext)
  195. {
  196. const auto * object = context->getObject(movementContext->target);
  197. const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
  198. const auto * boat = dynamic_cast<const CGBoat *>(object);
  199. assert(boat || hero);
  200. if(!hero)
  201. hero = boat->getBoardedHero();
  202. if(movementContext->progress >= 0.999)
  203. {
  204. logGlobal->debug("Ending movement animation");
  205. setViewCenter(hero->getSightCenter());
  206. removeObject(context->getObject(movementContext->target));
  207. addObject(context->getObject(movementContext->target));
  208. activateAdventureContext(movementContext->animationTime);
  209. }
  210. }
  211. if(teleportContext && teleportContext->progress >= 0.999)
  212. {
  213. logGlobal->debug("Ending teleport animation");
  214. activateAdventureContext(teleportContext->animationTime);
  215. }
  216. if(fadingOutContext && fadingOutContext->progress <= 0.001)
  217. {
  218. logGlobal->debug("Ending fade out animation");
  219. removeObject(context->getObject(fadingOutContext->target));
  220. activateAdventureContext(fadingOutContext->animationTime);
  221. }
  222. if(fadingInContext && fadingInContext->progress >= 0.999)
  223. {
  224. logGlobal->debug("Ending fade in animation");
  225. activateAdventureContext(fadingInContext->animationTime);
  226. }
  227. }
  228. bool MapViewController::isEventInstant(const CGObjectInstance * obj, const PlayerColor & initiator)
  229. {
  230. if(settings["gameTweaks"]["skipAdventureMapAnimations"].Bool())
  231. return true;
  232. if (!isEventVisible(obj, initiator))
  233. return true;
  234. if (!initiator.isValidPlayer())
  235. return true; // skip effects such as new monsters on new month
  236. if(initiator != GAME->interface()->playerID && settings["adventure"]["enemyMoveTime"].Float() <= 0)
  237. return true; // instant movement speed
  238. if(initiator == GAME->interface()->playerID && settings["adventure"]["heroMoveTime"].Float() <= 0)
  239. return true; // instant movement speed
  240. return false;
  241. }
  242. bool MapViewController::isEventVisible(const CGObjectInstance * obj, const PlayerColor & initiator)
  243. {
  244. if(adventureContext == nullptr)
  245. return false;
  246. if(initiator != GAME->interface()->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
  247. return false; // enemy move speed set to "hidden/none"
  248. if(!ENGINE->windows().isTopWindow(adventureInt))
  249. return false;
  250. // do not focus on actions of other players except for AI with simturns off
  251. if (initiator != GAME->interface()->playerID && initiator.isValidPlayer())
  252. {
  253. if (GAME->interface()->makingTurn)
  254. return false;
  255. if (GAME->interface()->cb->getStartInfo()->playerInfos.at(initiator).isControlledByHuman() && !settings["session"]["adventureTrackHero"].Bool())
  256. return false;
  257. }
  258. if(obj->isVisitable())
  259. return context->isVisible(obj->visitablePos());
  260. else
  261. return context->isVisible(obj->anchorPos());
  262. }
  263. bool MapViewController::isEventVisible(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  264. {
  265. if(adventureContext == nullptr)
  266. return false;
  267. if(obj->getOwner() != GAME->interface()->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
  268. return false; // enemy move speed set to "hidden/none"
  269. if(!ENGINE->windows().isTopWindow(adventureInt))
  270. return false;
  271. // do not focus on actions of other players except for AI with simturns off
  272. if (obj->getOwner() != GAME->interface()->playerID)
  273. {
  274. if (GAME->interface()->makingTurn)
  275. return false;
  276. if (GAME->interface()->cb->getStartInfo()->playerInfos.at(obj->getOwner()).isControlledByHuman() && !settings["session"]["adventureTrackHero"].Bool())
  277. return false;
  278. }
  279. if(context->isVisible(obj->convertToVisitablePos(from)))
  280. return true;
  281. if(context->isVisible(obj->convertToVisitablePos(dest)))
  282. return true;
  283. return false;
  284. }
  285. void MapViewController::fadeOutObject(const CGObjectInstance * obj)
  286. {
  287. animationWait.setBusy();
  288. logGlobal->debug("Starting fade out animation");
  289. fadingOutContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
  290. fadingOutContext->animationTime = adventureContext->animationTime;
  291. adventureContext = fadingOutContext;
  292. context = fadingOutContext;
  293. const CGObjectInstance * movingObject = obj;
  294. if (obj->ID == Obj::HERO)
  295. {
  296. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  297. if (hero->inBoat())
  298. movingObject = hero->getBoat();
  299. }
  300. fadingOutContext->target = movingObject->id;
  301. fadingOutContext->progress = 1.0;
  302. }
  303. void MapViewController::fadeInObject(const CGObjectInstance * obj)
  304. {
  305. animationWait.setBusy();
  306. logGlobal->debug("Starting fade in animation");
  307. fadingInContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
  308. fadingInContext->animationTime = adventureContext->animationTime;
  309. adventureContext = fadingInContext;
  310. context = fadingInContext;
  311. const CGObjectInstance * movingObject = obj;
  312. if (obj->ID == Obj::HERO)
  313. {
  314. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  315. if (hero->inBoat())
  316. movingObject = hero->getBoat();
  317. }
  318. fadingInContext->target = movingObject->id;
  319. fadingInContext->progress = 0.0;
  320. }
  321. void MapViewController::removeObject(const CGObjectInstance * obj)
  322. {
  323. if (obj->ID == Obj::BOAT)
  324. {
  325. auto * boat = dynamic_cast<const CGBoat*>(obj);
  326. if (boat->getBoardedHero())
  327. {
  328. view->invalidate(context, boat->getBoardedHero()->id);
  329. state->removeObject(boat->getBoardedHero());
  330. }
  331. }
  332. if (obj->ID == Obj::HERO)
  333. {
  334. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  335. if (hero->inBoat())
  336. {
  337. view->invalidate(context, hero->getBoat()->id);
  338. state->removeObject(hero->getBoat());
  339. }
  340. }
  341. view->invalidate(context, obj->id);
  342. state->removeObject(obj);
  343. }
  344. void MapViewController::addObject(const CGObjectInstance * obj)
  345. {
  346. state->addObject(obj);
  347. view->invalidate(context, obj->id);
  348. }
  349. void MapViewController::onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  350. {
  351. if(isEventVisible(obj, from, dest))
  352. {
  353. if (!isEventInstant(obj, obj->getOwner()))
  354. fadeOutObject(obj);
  355. setViewCenter(obj->getSightCenter());
  356. }
  357. else
  358. removeObject(obj);
  359. }
  360. void MapViewController::onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  361. {
  362. if(isEventVisible(obj, from, dest))
  363. setViewCenter(obj->getSightCenter());
  364. }
  365. void MapViewController::onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  366. {
  367. if(isEventVisible(obj, from, dest))
  368. setViewCenter(obj->getSightCenter());
  369. }
  370. void MapViewController::onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  371. {
  372. if(isEventVisible(obj, from, dest))
  373. {
  374. if (!isEventInstant(obj, obj->getOwner()))
  375. fadeInObject(obj);
  376. setViewCenter(obj->getSightCenter());
  377. }
  378. addObject(obj);
  379. }
  380. void MapViewController::onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator)
  381. {
  382. assert(!hasOngoingAnimations());
  383. if(isEventVisible(obj, initiator) && !isEventInstant(obj, initiator) )
  384. fadeInObject(obj);
  385. addObject(obj);
  386. }
  387. void MapViewController::onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator)
  388. {
  389. assert(!hasOngoingAnimations());
  390. if(isEventVisible(obj, initiator) && !isEventInstant(obj, initiator) )
  391. fadeOutObject(obj);
  392. else
  393. removeObject(obj);
  394. }
  395. void MapViewController::onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator)
  396. {
  397. addObject(obj);
  398. };
  399. void MapViewController::onObjectInstantRemove(const CGObjectInstance * obj, const PlayerColor & initiator)
  400. {
  401. removeObject(obj);
  402. };
  403. void MapViewController::onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  404. {
  405. assert(!hasOngoingAnimations());
  406. if(isEventVisible(obj, from, dest))
  407. {
  408. setViewCenter(obj->getSightCenter());
  409. view->createTransitionSnapshot(context);
  410. }
  411. }
  412. void MapViewController::onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  413. {
  414. assert(!hasOngoingAnimations());
  415. const CGObjectInstance * movingObject = obj;
  416. if(obj->inBoat())
  417. movingObject = obj->getBoat();
  418. removeObject(movingObject);
  419. addObject(movingObject);
  420. if(isEventVisible(obj, from, dest))
  421. {
  422. animationWait.setBusy();
  423. logGlobal->debug("Starting teleport animation");
  424. teleportContext = std::make_shared<MapRendererAdventureTransitionContext>(*state);
  425. teleportContext->animationTime = adventureContext->animationTime;
  426. adventureContext = teleportContext;
  427. context = teleportContext;
  428. setViewCenter(movingObject->getSightCenter());
  429. }
  430. }
  431. void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  432. {
  433. assert(!hasOngoingAnimations());
  434. // revisiting via spacebar, no need to animate
  435. if(from == dest)
  436. return;
  437. const CGObjectInstance * movingObject = obj;
  438. if(obj->inBoat())
  439. movingObject = obj->getBoat();
  440. removeObject(movingObject);
  441. if(!isEventVisible(obj, from, dest))
  442. {
  443. addObject(movingObject);
  444. return;
  445. }
  446. double movementTime = GAME->interface()->playerID == obj->tempOwner ?
  447. settings["adventure"]["heroMoveTime"].Float() :
  448. settings["adventure"]["enemyMoveTime"].Float();
  449. if(movementTime > 1)
  450. {
  451. animationWait.setBusy();
  452. logGlobal->debug("Starting movement animation");
  453. movementContext = std::make_shared<MapRendererAdventureMovingContext>(*state);
  454. movementContext->animationTime = adventureContext->animationTime;
  455. adventureContext = movementContext;
  456. context = movementContext;
  457. state->addMovingObject(movingObject, from, dest);
  458. movementContext->target = movingObject->id;
  459. movementContext->tileFrom = from;
  460. movementContext->tileDest = dest;
  461. movementContext->progress = 0.0;
  462. }
  463. else // instant movement
  464. {
  465. addObject(movingObject);
  466. setViewCenter(movingObject->visitablePos());
  467. }
  468. }
  469. bool MapViewController::hasOngoingAnimations()
  470. {
  471. if(movementContext)
  472. return true;
  473. if(fadingOutContext)
  474. return true;
  475. if(fadingInContext)
  476. return true;
  477. if(teleportContext)
  478. return true;
  479. return false;
  480. }
  481. void MapViewController::waitForOngoingAnimations()
  482. {
  483. auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
  484. animationWait.waitWhileBusy();
  485. }
  486. void MapViewController::endNetwork()
  487. {
  488. animationWait.requestTermination();
  489. }
  490. void MapViewController::activateAdventureContext(uint32_t animationTime)
  491. {
  492. resetContext();
  493. adventureContext = std::make_shared<MapRendererAdventureContext>(*state);
  494. adventureContext->animationTime = animationTime;
  495. context = adventureContext;
  496. updateState();
  497. }
  498. void MapViewController::activateAdventureContext()
  499. {
  500. activateAdventureContext(0);
  501. }
  502. void MapViewController::activateWorldViewContext()
  503. {
  504. if(worldViewContext)
  505. return;
  506. resetContext();
  507. worldViewContext = std::make_shared<MapRendererWorldViewContext>(*state);
  508. context = worldViewContext;
  509. }
  510. void MapViewController::activateSpellViewContext()
  511. {
  512. if(spellViewContext)
  513. return;
  514. resetContext();
  515. spellViewContext = std::make_shared<MapRendererSpellViewContext>(*state);
  516. worldViewContext = spellViewContext;
  517. context = spellViewContext;
  518. }
  519. void MapViewController::activatePuzzleMapContext(const int3 & grailPosition)
  520. {
  521. resetContext();
  522. puzzleMapContext = std::make_shared<MapRendererPuzzleMapContext>(*state);
  523. context = puzzleMapContext;
  524. CGPathNode fakeNode;
  525. fakeNode.coord = grailPosition;
  526. puzzleMapContext->grailPos = std::make_unique<CGPath>();
  527. // create two nodes since 1st one is normally not visible
  528. puzzleMapContext->grailPos->nodes.push_back(fakeNode);
  529. puzzleMapContext->grailPos->nodes.push_back(fakeNode);
  530. }
  531. void MapViewController::resetContext()
  532. {
  533. adventureContext.reset();
  534. movementContext.reset();
  535. fadingOutContext.reset();
  536. fadingInContext.reset();
  537. teleportContext.reset();
  538. worldViewContext.reset();
  539. spellViewContext.reset();
  540. puzzleMapContext.reset();
  541. animationWait.setFree();
  542. }
  543. void MapViewController::setTerrainVisibility(bool showAllTerrain)
  544. {
  545. assert(spellViewContext);
  546. spellViewContext->showAllTerrain = showAllTerrain;
  547. }
  548. void MapViewController::setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions)
  549. {
  550. assert(spellViewContext);
  551. spellViewContext->additionalOverlayIcons = objectPositions;
  552. }