MapViewController.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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->settingSpellRange = settings["session"]["showSpellRange"].Bool();
  190. adventureContext->settingTextOverlay = (ENGINE->isKeyboardAltDown() || ENGINE->input().getNumTouchFingers() == 2) && settings["general"]["enableOverlay"].Bool();
  191. }
  192. }
  193. void MapViewController::afterRender()
  194. {
  195. if(movementContext)
  196. {
  197. const auto * object = context->getObject(movementContext->target);
  198. const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
  199. const auto * boat = dynamic_cast<const CGBoat *>(object);
  200. assert(boat || hero);
  201. if(!hero)
  202. hero = boat->getBoardedHero();
  203. if(movementContext->progress >= 0.999)
  204. {
  205. logGlobal->debug("Ending movement animation");
  206. setViewCenter(hero->getSightCenter());
  207. removeObject(context->getObject(movementContext->target));
  208. addObject(context->getObject(movementContext->target));
  209. activateAdventureContext(movementContext->animationTime);
  210. }
  211. }
  212. if(teleportContext && teleportContext->progress >= 0.999)
  213. {
  214. logGlobal->debug("Ending teleport animation");
  215. activateAdventureContext(teleportContext->animationTime);
  216. }
  217. if(fadingOutContext && fadingOutContext->progress <= 0.001)
  218. {
  219. logGlobal->debug("Ending fade out animation");
  220. removeObject(context->getObject(fadingOutContext->target));
  221. activateAdventureContext(fadingOutContext->animationTime);
  222. }
  223. if(fadingInContext && fadingInContext->progress >= 0.999)
  224. {
  225. logGlobal->debug("Ending fade in animation");
  226. activateAdventureContext(fadingInContext->animationTime);
  227. }
  228. }
  229. bool MapViewController::isEventInstant(const CGObjectInstance * obj, const PlayerColor & initiator)
  230. {
  231. if(settings["gameTweaks"]["skipAdventureMapAnimations"].Bool())
  232. return true;
  233. if (!isEventVisible(obj, initiator))
  234. return true;
  235. if (!initiator.isValidPlayer())
  236. return true; // skip effects such as new monsters on new month
  237. if(initiator != GAME->interface()->playerID && settings["adventure"]["enemyMoveTime"].Float() <= 0)
  238. return true; // instant movement speed
  239. if(initiator == GAME->interface()->playerID && settings["adventure"]["heroMoveTime"].Float() <= 0)
  240. return true; // instant movement speed
  241. return false;
  242. }
  243. bool MapViewController::isEventVisible(const CGObjectInstance * obj, const PlayerColor & initiator)
  244. {
  245. if(adventureContext == nullptr)
  246. return false;
  247. if(initiator != GAME->interface()->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
  248. return false; // enemy move speed set to "hidden/none"
  249. if(!ENGINE->windows().isTopWindow(adventureInt))
  250. return false;
  251. // do not focus on actions of other players except for AI with simturns off
  252. if (initiator != GAME->interface()->playerID && initiator.isValidPlayer())
  253. {
  254. if (GAME->interface()->makingTurn)
  255. return false;
  256. if (GAME->interface()->cb->getStartInfo()->playerInfos.at(initiator).isControlledByHuman() && !settings["session"]["adventureTrackHero"].Bool())
  257. return false;
  258. }
  259. if(obj->isVisitable())
  260. return context->isVisible(obj->visitablePos());
  261. else
  262. return context->isVisible(obj->anchorPos());
  263. }
  264. bool MapViewController::isEventVisible(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  265. {
  266. if(adventureContext == nullptr)
  267. return false;
  268. if(obj->getOwner() != GAME->interface()->playerID && settings["adventure"]["enemyMoveTime"].Float() < 0)
  269. return false; // enemy move speed set to "hidden/none"
  270. if(!ENGINE->windows().isTopWindow(adventureInt))
  271. return false;
  272. // do not focus on actions of other players except for AI with simturns off
  273. if (obj->getOwner() != GAME->interface()->playerID)
  274. {
  275. if (GAME->interface()->makingTurn)
  276. return false;
  277. if (GAME->interface()->cb->getStartInfo()->playerInfos.at(obj->getOwner()).isControlledByHuman() && !settings["session"]["adventureTrackHero"].Bool())
  278. return false;
  279. }
  280. if(context->isVisible(obj->convertToVisitablePos(from)))
  281. return true;
  282. if(context->isVisible(obj->convertToVisitablePos(dest)))
  283. return true;
  284. return false;
  285. }
  286. void MapViewController::fadeOutObject(const CGObjectInstance * obj)
  287. {
  288. animationWait.setBusy();
  289. logGlobal->debug("Starting fade out animation");
  290. fadingOutContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
  291. fadingOutContext->animationTime = adventureContext->animationTime;
  292. adventureContext = fadingOutContext;
  293. context = fadingOutContext;
  294. const CGObjectInstance * movingObject = obj;
  295. if (obj->ID == Obj::HERO)
  296. {
  297. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  298. if (hero->inBoat())
  299. movingObject = hero->getBoat();
  300. }
  301. fadingOutContext->target = movingObject->id;
  302. fadingOutContext->progress = 1.0;
  303. }
  304. void MapViewController::fadeInObject(const CGObjectInstance * obj)
  305. {
  306. animationWait.setBusy();
  307. logGlobal->debug("Starting fade in animation");
  308. fadingInContext = std::make_shared<MapRendererAdventureFadingContext>(*state);
  309. fadingInContext->animationTime = adventureContext->animationTime;
  310. adventureContext = fadingInContext;
  311. context = fadingInContext;
  312. const CGObjectInstance * movingObject = obj;
  313. if (obj->ID == Obj::HERO)
  314. {
  315. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  316. if (hero->inBoat())
  317. movingObject = hero->getBoat();
  318. }
  319. fadingInContext->target = movingObject->id;
  320. fadingInContext->progress = 0.0;
  321. }
  322. void MapViewController::removeObject(const CGObjectInstance * obj)
  323. {
  324. if (obj->ID == Obj::BOAT)
  325. {
  326. auto * boat = dynamic_cast<const CGBoat*>(obj);
  327. if (boat->getBoardedHero())
  328. {
  329. view->invalidate(context, boat->getBoardedHero()->id);
  330. state->removeObject(boat->getBoardedHero());
  331. }
  332. }
  333. if (obj->ID == Obj::HERO)
  334. {
  335. auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
  336. if (hero->inBoat())
  337. {
  338. view->invalidate(context, hero->getBoat()->id);
  339. state->removeObject(hero->getBoat());
  340. }
  341. }
  342. view->invalidate(context, obj->id);
  343. state->removeObject(obj);
  344. }
  345. void MapViewController::addObject(const CGObjectInstance * obj)
  346. {
  347. state->addObject(obj);
  348. view->invalidate(context, obj->id);
  349. }
  350. void MapViewController::onBeforeHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  351. {
  352. if(isEventVisible(obj, from, dest))
  353. {
  354. if (!isEventInstant(obj, obj->getOwner()))
  355. fadeOutObject(obj);
  356. setViewCenter(obj->getSightCenter());
  357. }
  358. else
  359. removeObject(obj);
  360. }
  361. void MapViewController::onAfterHeroEmbark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  362. {
  363. if(isEventVisible(obj, from, dest))
  364. setViewCenter(obj->getSightCenter());
  365. }
  366. void MapViewController::onBeforeHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  367. {
  368. if(isEventVisible(obj, from, dest))
  369. setViewCenter(obj->getSightCenter());
  370. }
  371. void MapViewController::onAfterHeroDisembark(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  372. {
  373. if(isEventVisible(obj, from, dest))
  374. {
  375. if (!isEventInstant(obj, obj->getOwner()))
  376. fadeInObject(obj);
  377. setViewCenter(obj->getSightCenter());
  378. }
  379. addObject(obj);
  380. }
  381. void MapViewController::onObjectFadeIn(const CGObjectInstance * obj, const PlayerColor & initiator)
  382. {
  383. assert(!hasOngoingAnimations());
  384. if(isEventVisible(obj, initiator) && !isEventInstant(obj, initiator) )
  385. fadeInObject(obj);
  386. addObject(obj);
  387. }
  388. void MapViewController::onObjectFadeOut(const CGObjectInstance * obj, const PlayerColor & initiator)
  389. {
  390. assert(!hasOngoingAnimations());
  391. if(isEventVisible(obj, initiator) && !isEventInstant(obj, initiator) )
  392. fadeOutObject(obj);
  393. else
  394. removeObject(obj);
  395. }
  396. void MapViewController::onObjectInstantAdd(const CGObjectInstance * obj, const PlayerColor & initiator)
  397. {
  398. addObject(obj);
  399. };
  400. void MapViewController::onObjectInstantRemove(const CGObjectInstance * obj, const PlayerColor & initiator)
  401. {
  402. removeObject(obj);
  403. };
  404. void MapViewController::onBeforeHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  405. {
  406. assert(!hasOngoingAnimations());
  407. if(isEventVisible(obj, from, dest))
  408. {
  409. setViewCenter(obj->getSightCenter());
  410. view->createTransitionSnapshot(context);
  411. }
  412. }
  413. void MapViewController::onAfterHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  414. {
  415. assert(!hasOngoingAnimations());
  416. const CGObjectInstance * movingObject = obj;
  417. if(obj->inBoat())
  418. movingObject = obj->getBoat();
  419. removeObject(movingObject);
  420. addObject(movingObject);
  421. if(isEventVisible(obj, from, dest))
  422. {
  423. animationWait.setBusy();
  424. logGlobal->debug("Starting teleport animation");
  425. teleportContext = std::make_shared<MapRendererAdventureTransitionContext>(*state);
  426. teleportContext->animationTime = adventureContext->animationTime;
  427. adventureContext = teleportContext;
  428. context = teleportContext;
  429. setViewCenter(movingObject->getSightCenter());
  430. }
  431. }
  432. void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
  433. {
  434. assert(!hasOngoingAnimations());
  435. // revisiting via spacebar, no need to animate
  436. if(from == dest)
  437. return;
  438. const CGObjectInstance * movingObject = obj;
  439. if(obj->inBoat())
  440. movingObject = obj->getBoat();
  441. removeObject(movingObject);
  442. if(!isEventVisible(obj, from, dest))
  443. {
  444. addObject(movingObject);
  445. return;
  446. }
  447. double movementTime = GAME->interface()->playerID == obj->tempOwner ?
  448. settings["adventure"]["heroMoveTime"].Float() :
  449. settings["adventure"]["enemyMoveTime"].Float();
  450. if(movementTime > 1)
  451. {
  452. animationWait.setBusy();
  453. logGlobal->debug("Starting movement animation");
  454. movementContext = std::make_shared<MapRendererAdventureMovingContext>(*state);
  455. movementContext->animationTime = adventureContext->animationTime;
  456. adventureContext = movementContext;
  457. context = movementContext;
  458. state->addMovingObject(movingObject, from, dest);
  459. movementContext->target = movingObject->id;
  460. movementContext->tileFrom = from;
  461. movementContext->tileDest = dest;
  462. movementContext->progress = 0.0;
  463. }
  464. else // instant movement
  465. {
  466. addObject(movingObject);
  467. setViewCenter(movingObject->visitablePos());
  468. }
  469. }
  470. bool MapViewController::hasOngoingAnimations()
  471. {
  472. if(movementContext)
  473. return true;
  474. if(fadingOutContext)
  475. return true;
  476. if(fadingInContext)
  477. return true;
  478. if(teleportContext)
  479. return true;
  480. return false;
  481. }
  482. void MapViewController::waitForOngoingAnimations()
  483. {
  484. auto unlockInterface = vstd::makeUnlockGuard(ENGINE->interfaceMutex);
  485. animationWait.waitWhileBusy();
  486. }
  487. void MapViewController::endNetwork()
  488. {
  489. animationWait.requestTermination();
  490. }
  491. void MapViewController::activateAdventureContext(uint32_t animationTime)
  492. {
  493. resetContext();
  494. adventureContext = std::make_shared<MapRendererAdventureContext>(*state);
  495. adventureContext->animationTime = animationTime;
  496. context = adventureContext;
  497. updateState();
  498. }
  499. void MapViewController::activateAdventureContext()
  500. {
  501. activateAdventureContext(0);
  502. }
  503. void MapViewController::activateWorldViewContext()
  504. {
  505. if(worldViewContext)
  506. return;
  507. resetContext();
  508. worldViewContext = std::make_shared<MapRendererWorldViewContext>(*state);
  509. context = worldViewContext;
  510. }
  511. void MapViewController::activateSpellViewContext()
  512. {
  513. if(spellViewContext)
  514. return;
  515. resetContext();
  516. spellViewContext = std::make_shared<MapRendererSpellViewContext>(*state);
  517. worldViewContext = spellViewContext;
  518. context = spellViewContext;
  519. }
  520. void MapViewController::activatePuzzleMapContext(const int3 & grailPosition)
  521. {
  522. resetContext();
  523. puzzleMapContext = std::make_shared<MapRendererPuzzleMapContext>(*state);
  524. context = puzzleMapContext;
  525. CGPathNode fakeNode;
  526. fakeNode.coord = grailPosition;
  527. puzzleMapContext->grailPos = std::make_unique<CGPath>();
  528. // create two nodes since 1st one is normally not visible
  529. puzzleMapContext->grailPos->nodes.push_back(fakeNode);
  530. puzzleMapContext->grailPos->nodes.push_back(fakeNode);
  531. }
  532. void MapViewController::resetContext()
  533. {
  534. adventureContext.reset();
  535. movementContext.reset();
  536. fadingOutContext.reset();
  537. fadingInContext.reset();
  538. teleportContext.reset();
  539. worldViewContext.reset();
  540. spellViewContext.reset();
  541. puzzleMapContext.reset();
  542. animationWait.setFree();
  543. }
  544. void MapViewController::setTerrainVisibility(bool showAllTerrain)
  545. {
  546. assert(spellViewContext);
  547. spellViewContext->showAllTerrain = showAllTerrain;
  548. }
  549. void MapViewController::setOverlayVisibility(const std::vector<ObjectPosInfo> & objectPositions)
  550. {
  551. assert(spellViewContext);
  552. spellViewContext->additionalOverlayIcons = objectPositions;
  553. }