InfoWindows.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * InfoWindows.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 "InfoWindows.h"
  12. #include "../CPlayerInterface.h"
  13. #include "../PlayerLocalState.h"
  14. #include "../adventureMap/AdventureMapInterface.h"
  15. #include "../adventureMap/CMinimap.h"
  16. #include "../GameEngine.h"
  17. #include "../GameInstance.h"
  18. #include "../gui/CursorHandler.h"
  19. #include "../gui/Shortcut.h"
  20. #include "../gui/WindowHandler.h"
  21. #include "../widgets/Buttons.h"
  22. #include "../widgets/CComponent.h"
  23. #include "../widgets/GraphicalPrimitiveCanvas.h"
  24. #include "../widgets/Images.h"
  25. #include "../widgets/MiscWidgets.h"
  26. #include "../widgets/TextControls.h"
  27. #include "../widgets/Slider.h"
  28. #include "../windows/CMessage.h"
  29. #include "../../lib/CConfigHandler.h"
  30. #include "../../lib/callback/CCallback.h"
  31. #include "../../lib/gameState/InfoAboutArmy.h"
  32. #include "../../lib/mapObjects/CGCreature.h"
  33. #include "../../lib/mapObjects/CGHeroInstance.h"
  34. #include "../../lib/mapObjects/CGTownInstance.h"
  35. #include "../../lib/mapObjects/CQuest.h"
  36. #include "../../lib/mapObjects/MiscObjects.h"
  37. #include "../../lib/ConditionalWait.h"
  38. CSelWindow::CSelWindow( const std::string & Text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath, CFunctionList<void()>>> & Buttons, QueryID askID)
  39. {
  40. OBJECT_CONSTRUCTION;
  41. backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
  42. ID = askID;
  43. for(int i = 0; i < Buttons.size(); i++)
  44. {
  45. buttons.push_back(std::make_shared<CButton>(Point(0, 0), Buttons[i].first, CButton::tooltip(), Buttons[i].second));
  46. if(!i && askID.getNum() >= 0)
  47. buttons.back()->addCallback(std::bind(&CSelWindow::madeChoice, this));
  48. buttons[i]->addCallback(std::bind(&CInfoWindow::close, this)); //each button will close the window apart from call-defined actions
  49. }
  50. text = std::make_shared<CTextBox>(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
  51. if(buttons.size() > 1 && askID.getNum() >= 0) //cancel button functionality
  52. buttons.back()->addCallback([askID](){GAME->interface()->cb->selectionMade(0, askID);});
  53. if(buttons.size() == 1)
  54. buttons.front()->assignedKey = EShortcut::GLOBAL_RETURN;
  55. if(buttons.size() == 2)
  56. {
  57. buttons.front()->assignedKey = EShortcut::GLOBAL_ACCEPT;
  58. buttons.back()->assignedKey = EShortcut::GLOBAL_CANCEL;
  59. }
  60. if(!comps.empty())
  61. {
  62. components = std::make_shared<CComponentBox>(comps, Rect(0,0,0,0));
  63. for (auto & comp : comps)
  64. comp->onChoose = [this](){ madeChoiceAndClose(); };
  65. }
  66. CMessage::drawIWindow(this, Text, player);
  67. }
  68. void CSelWindow::madeChoice()
  69. {
  70. if(ID.getNum() < 0)
  71. return;
  72. int ret = -1;
  73. if(components)
  74. ret = components->selectedIndex();
  75. GAME->interface()->cb->selectionMade(ret + 1, ID);
  76. }
  77. void CSelWindow::madeChoiceAndClose()
  78. {
  79. madeChoice();
  80. close();
  81. }
  82. CInfoWindow::CInfoWindow(const std::string & Text, PlayerColor player, const TCompsInfo & comps, const TButtonsInfo & Buttons)
  83. {
  84. OBJECT_CONSTRUCTION;
  85. backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
  86. ID = QueryID(-1);
  87. for(const auto & Button : Buttons)
  88. {
  89. auto button = std::make_shared<CButton>(Point(0, 0), Button.first, CButton::tooltip(), std::bind(&CInfoWindow::close, this));
  90. button->setBorderColor(Colors::METALLIC_GOLD);
  91. button->addCallback(Button.second); //each button will close the window apart from call-defined actions
  92. buttons.push_back(button);
  93. }
  94. text = std::make_shared<CTextBox>(Text, Rect(0, 0, 250, 100), 0, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
  95. if(!text->slider)
  96. {
  97. int finalWidth = std::min(250, text->label->textSize.x + 32);
  98. int finalHeight = text->label->textSize.y;
  99. text->resize(Point(finalWidth, finalHeight));
  100. }
  101. if(buttons.size() == 1)
  102. buttons.front()->assignedKey = EShortcut::GLOBAL_RETURN;
  103. if(buttons.size() == 2)
  104. {
  105. buttons.front()->assignedKey = EShortcut::GLOBAL_ACCEPT;
  106. buttons.back()->assignedKey = EShortcut::GLOBAL_CANCEL;
  107. }
  108. if(!comps.empty())
  109. components = std::make_shared<CComponentBox>(comps, Rect(0,0,0,0));
  110. CMessage::drawIWindow(this, Text, player);
  111. }
  112. CInfoWindow::CInfoWindow()
  113. {
  114. ID = QueryID(-1);
  115. }
  116. void CInfoWindow::close()
  117. {
  118. WindowBase::close();
  119. if(GAME->interface())
  120. GAME->interface()->showingDialog->setFree();
  121. }
  122. void CInfoWindow::showAll(Canvas & to)
  123. {
  124. CIntObject::showAll(to);
  125. CMessage::drawBorder(GAME->interface() ? GAME->interface()->playerID : PlayerColor(1), to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
  126. }
  127. CInfoWindow::~CInfoWindow() = default;
  128. void CInfoWindow::showInfoDialog(const std::string & text, const TCompsInfo & components, PlayerColor player)
  129. {
  130. ENGINE->windows().pushWindow(CInfoWindow::create(text, player, components));
  131. }
  132. void CInfoWindow::showYesNoDialog(const std::string & text, const TCompsInfo & components, const CFunctionList<void()> & onYes, const CFunctionList<void()> & onNo, PlayerColor player)
  133. {
  134. assert(!GAME->interface() || GAME->interface()->showingDialog->isBusy());
  135. std::vector<std::pair<AnimationPath, CFunctionList<void()>>> pom;
  136. pom.emplace_back(AnimationPath::builtin("IOKAY.DEF"), nullptr);
  137. pom.emplace_back(AnimationPath::builtin("ICANCEL.DEF"), nullptr);
  138. auto temp = std::make_shared<CInfoWindow>(text, player, components, pom);
  139. temp->buttons[0]->addCallback(onYes);
  140. temp->buttons[1]->addCallback(onNo);
  141. ENGINE->windows().pushWindow(temp);
  142. }
  143. std::shared_ptr<CInfoWindow> CInfoWindow::create(const std::string & text, PlayerColor playerID, const TCompsInfo & components)
  144. {
  145. std::vector<std::pair<AnimationPath, CFunctionList<void()>>> pom;
  146. pom.emplace_back(AnimationPath::builtin("IOKAY.DEF"), nullptr);
  147. return std::make_shared<CInfoWindow>(text, playerID, components, pom);
  148. }
  149. std::string CInfoWindow::genText(const std::string & title, const std::string & description)
  150. {
  151. return std::string("{") + title + "}" + "\n\n" + description;
  152. }
  153. bool CRClickPopup::isPopupWindow() const
  154. {
  155. return true;
  156. }
  157. void CRClickPopup::createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo & comps)
  158. {
  159. PlayerColor player = GAME->interface() ? GAME->interface()->playerID : PlayerColor(1); //if no player, then use blue
  160. if(settings["session"]["spectate"].Bool()) //TODO: there must be better way to implement this
  161. player = PlayerColor(1);
  162. auto temp = std::make_shared<CInfoWindow>(txt, player, comps);
  163. temp->center(ENGINE->getCursorPosition()); //center on mouse
  164. #ifdef VCMI_MOBILE
  165. temp->moveBy({0, -temp->pos.h / 2});
  166. #endif
  167. temp->fitToScreen(10);
  168. ENGINE->windows().createAndPushWindow<CRClickPopupInt>(temp);
  169. }
  170. void CRClickPopup::createAndPush(const std::string & txt, const std::shared_ptr<CComponent> & component)
  171. {
  172. CInfoWindow::TCompsInfo intComps;
  173. intComps.push_back(component);
  174. createAndPush(txt, intComps);
  175. }
  176. void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p, ETextAlignment alignment)
  177. {
  178. auto iWin = createCustomInfoWindow(p, obj); //try get custom infowindow for this obj
  179. if(iWin)
  180. {
  181. ENGINE->windows().pushWindow(iWin);
  182. }
  183. else
  184. {
  185. std::vector<Component> components;
  186. if(settings["general"]["enableUiEnhancements"].Bool())
  187. {
  188. if(GAME->interface()->localState->getCurrentHero())
  189. components = obj->getPopupComponents(GAME->interface()->localState->getCurrentHero());
  190. else
  191. components = obj->getPopupComponents(GAME->interface()->playerID);
  192. }
  193. std::vector<std::shared_ptr<CComponent>> guiComponents;
  194. for(auto & component : components)
  195. guiComponents.push_back(std::make_shared<CComponent>(component, CComponent::medium));
  196. if(GAME->interface()->localState->getCurrentHero())
  197. CRClickPopup::createAndPush(obj->getPopupText(GAME->interface()->localState->getCurrentHero()), guiComponents);
  198. else
  199. CRClickPopup::createAndPush(obj->getPopupText(GAME->interface()->playerID), guiComponents);
  200. }
  201. }
  202. CRClickPopupInt::CRClickPopupInt(const std::shared_ptr<CIntObject> & our) :
  203. dragDistance(Point(0, 0))
  204. {
  205. addUsedEvents(DRAG_POPUP);
  206. ENGINE->cursor().hide();
  207. inner = our;
  208. addChild(our.get(), false);
  209. }
  210. CRClickPopupInt::~CRClickPopupInt()
  211. {
  212. ENGINE->cursor().show();
  213. }
  214. void CRClickPopupInt::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
  215. {
  216. if(!settings["adventure"]["rightButtonDrag"].Bool())
  217. return;
  218. dragDistance += lastUpdateDistance;
  219. if(dragDistance.length() > 16)
  220. close();
  221. }
  222. template<typename... Args>
  223. AdventureMapPopup::AdventureMapPopup(Args&&... args) :
  224. CWindowObject(std::forward<Args>(args)...), dragDistance(Point(0, 0))
  225. {
  226. addUsedEvents(DRAG_POPUP);
  227. }
  228. void AdventureMapPopup::mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance)
  229. {
  230. if(!settings["adventure"]["rightButtonDrag"].Bool())
  231. return;
  232. dragDistance += lastUpdateDistance;
  233. if(dragDistance.length() > 16)
  234. close();
  235. }
  236. CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town)
  237. : AdventureMapPopup(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("TOWNQVBK"), position)
  238. {
  239. InfoAboutTown iah;
  240. GAME->interface()->cb->getTownInfo(town, iah, GAME->interface()->localState->getCurrentArmy()); //todo: should this be nearest hero?
  241. OBJECT_CONSTRUCTION;
  242. tooltip = std::make_shared<CTownTooltip>(Point(9, 10), iah);
  243. if(settings["general"]["enableUiEnhancements"].Bool())
  244. background->setPlayerColor(town->getOwner());
  245. addUsedEvents(DRAG_POPUP);
  246. fitToScreen(10);
  247. }
  248. CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero)
  249. : AdventureMapPopup(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin("HEROQVBK"), position)
  250. {
  251. InfoAboutHero iah;
  252. GAME->interface()->cb->getHeroInfo(hero, iah, GAME->interface()->localState->getCurrentArmy()); //todo: should this be nearest hero?
  253. OBJECT_CONSTRUCTION;
  254. tooltip = std::make_shared<CHeroTooltip>(Point(9, 10), iah);
  255. if(settings["general"]["enableUiEnhancements"].Bool())
  256. background->setPlayerColor(hero->getOwner());
  257. addUsedEvents(DRAG_POPUP);
  258. fitToScreen(10);
  259. }
  260. CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
  261. : AdventureMapPopup(RCLICK_POPUP | PLAYER_COLORED, ImagePath::builtin(settings["general"]["enableUiEnhancements"].Bool() ? "GARRIPOP" : "TOWNQVBK"), position)
  262. {
  263. InfoAboutTown iah;
  264. GAME->interface()->cb->getTownInfo(garr, iah);
  265. OBJECT_CONSTRUCTION;
  266. if(settings["general"]["enableUiEnhancements"].Bool())
  267. {
  268. tooltip = std::make_shared<CGarrisonTooltip>(Point(9, 10), iah);
  269. }
  270. else
  271. {
  272. tooltip = std::make_shared<CArmyTooltip>(Point(9, 10), iah);
  273. }
  274. if(settings["general"]["enableUiEnhancements"].Bool())
  275. background->setPlayerColor(garr->getOwner());
  276. addUsedEvents(DRAG_POPUP);
  277. fitToScreen(10);
  278. }
  279. CInfoBoxPopup::CInfoBoxPopup(Point position, const CGCreature * creature)
  280. : AdventureMapPopup(RCLICK_POPUP | BORDERED, ImagePath::builtin("DIBOXBCK"), position)
  281. {
  282. OBJECT_CONSTRUCTION;
  283. tooltip = std::make_shared<CreatureTooltip>(Point(9, 10), creature);
  284. addUsedEvents(DRAG_POPUP);
  285. fitToScreen(10);
  286. }
  287. MinimapWithIcons::MinimapWithIcons(const Point & position)
  288. {
  289. OBJECT_CONSTRUCTION;
  290. pos += position;
  291. recreate();
  292. }
  293. void MinimapWithIcons::recreate()
  294. {
  295. OBJECT_CONSTRUCTION;
  296. Rect area1(11, 41, 144, 144);
  297. Rect area2(167, 41, 144, 144);
  298. Rect border1(10, 40, 147, 147);
  299. Rect border2(166, 40, 147, 147);
  300. int levels = GAME->interface()->cb->getMapSize().z;
  301. int currentLevel = slider ? slider->getValue() : 0;
  302. bool singleLevelMap = levels == 1;
  303. if(levels > 2)
  304. {
  305. slider = std::make_shared<CSlider>(Point(10, 192), 303, [this](int value){ recreate(); setRedrawParent(true); redraw(); }, 2, levels, currentLevel, Orientation::HORIZONTAL);
  306. slider->setPanningStep(147);
  307. }
  308. if (singleLevelMap)
  309. {
  310. area1.x += 78;
  311. border1.x += 78;
  312. }
  313. background1 = std::make_shared<TransparentFilledRectangle>(border1, Colors::TRANSPARENCY, Colors::YELLOW);
  314. map1 = std::make_shared<CMinimapInstance>(area1.topLeft(), area1.dimensions(), currentLevel);
  315. if (!singleLevelMap)
  316. {
  317. background2 = std::make_shared<TransparentFilledRectangle>(border2, Colors::TRANSPARENCY, Colors::YELLOW);
  318. map2 = std::make_shared<CMinimapInstance>(area2.topLeft(), area2.dimensions(), currentLevel + 1);
  319. }
  320. iconsOverlay.clear();
  321. for(auto & icon : icons)
  322. {
  323. int positionX = 144 * icon.first.x / GAME->interface()->cb->getMapSize().x;
  324. int positionY = 144 * icon.first.y / GAME->interface()->cb->getMapSize().y;
  325. Point iconPosition(positionX, positionY);
  326. iconPosition -= Point(8,8); // compensate for 16x16 icon half-size
  327. if (icon.first.z == currentLevel)
  328. iconPosition += area1.topLeft();
  329. else if (icon.first.z == currentLevel + 1)
  330. iconPosition += area2.topLeft();
  331. else
  332. continue;
  333. iconsOverlay.push_back(std::make_shared<CPicture>(icon.second, iconPosition));
  334. }
  335. }
  336. void MinimapWithIcons::addIcon(const int3 & coordinates, const ImagePath & image )
  337. {
  338. icons.push_back({coordinates, image});
  339. }
  340. TeleporterPopup::TeleporterPopup(const Point & position, const CGTeleport * teleporter)
  341. : AdventureMapPopup(BORDERED | RCLICK_POPUP)
  342. {
  343. OBJECT_CONSTRUCTION;
  344. pos.w = 322;
  345. pos.h = 200 + (GAME->interface()->cb->getMapSize().z > 2 ? 21 : 0);
  346. filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
  347. labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, teleporter->getPopupText(GAME->interface()->playerID));
  348. minimap = std::make_shared<MinimapWithIcons>(Point(0,0));
  349. const auto & entrances = teleporter->getAllEntrances();
  350. const auto & exits = teleporter->getAllExits();
  351. std::set<ObjectInstanceID> allTeleporters;
  352. allTeleporters.insert(entrances.begin(), entrances.end());
  353. allTeleporters.insert(exits.begin(), exits.end());
  354. for (const auto exit : allTeleporters)
  355. {
  356. const auto * exitObject = GAME->interface()->cb->getObj(exit, false);
  357. if (!exitObject)
  358. continue;
  359. int3 position = exitObject->visitablePos();
  360. ImagePath image;
  361. if (!vstd::contains(entrances, exit))
  362. image = ImagePath::builtin("minimapIcons/portalExit");
  363. else if (!vstd::contains(exits, exit))
  364. image = ImagePath::builtin("minimapIcons/portalEntrance");
  365. else
  366. image = ImagePath::builtin("minimapIcons/portalBidirectional");
  367. minimap->addIcon(position, image);
  368. }
  369. minimap->recreate();
  370. center(position);
  371. fitToScreen(10);
  372. }
  373. KeymasterPopup::KeymasterPopup(const Point & position, const CGKeys * keymasterOrGuard)
  374. : AdventureMapPopup(BORDERED | RCLICK_POPUP)
  375. {
  376. OBJECT_CONSTRUCTION;
  377. pos.w = 322;
  378. pos.h = 220 + (GAME->interface()->cb->getMapSize().z > 2 ? 21 : 0);
  379. filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
  380. labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, keymasterOrGuard->getObjectName());
  381. labelDescription = std::make_shared<CLabel>(pos.w / 2, 40, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, keymasterOrGuard->getObjectDescription(GAME->interface()->playerID));
  382. minimap = std::make_shared<MinimapWithIcons>(Point(0,20));
  383. const auto allObjects = GAME->interface()->cb->getAllVisitableObjs();
  384. for (const auto mapObject : allObjects)
  385. {
  386. if (!mapObject)
  387. continue;
  388. switch (mapObject->ID)
  389. {
  390. case Obj::KEYMASTER:
  391. if (mapObject->subID == keymasterOrGuard->subID)
  392. minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/keymaster"));
  393. break;
  394. case Obj::BORDERGUARD:
  395. if (mapObject->subID == keymasterOrGuard->subID)
  396. minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/borderguard"));
  397. break;
  398. case Obj::BORDER_GATE:
  399. if (mapObject->subID == keymasterOrGuard->subID)
  400. minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/bordergate"));
  401. break;
  402. }
  403. }
  404. minimap->recreate();
  405. center(position);
  406. fitToScreen(10);
  407. }
  408. ObeliskPopup::ObeliskPopup(const Point & position, const CGObelisk * obelisk)
  409. : AdventureMapPopup(BORDERED | RCLICK_POPUP)
  410. {
  411. OBJECT_CONSTRUCTION;
  412. pos.w = 322;
  413. pos.h = 220 + (GAME->interface()->cb->getMapSize().z > 2 ? 21 : 0);
  414. filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
  415. labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, obelisk->getObjectName());
  416. labelDescription = std::make_shared<CLabel>(pos.w / 2, 40, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, obelisk->getObjectDescription(GAME->interface()->playerID));
  417. minimap = std::make_shared<MinimapWithIcons>(Point(0,20));
  418. const auto allObjects = GAME->interface()->cb->getAllVisitableObjs();
  419. for (const auto mapObject : allObjects)
  420. {
  421. if (!mapObject)
  422. continue;
  423. if (mapObject->ID != Obj::OBELISK)
  424. continue;
  425. if (mapObject->wasVisited(GAME->interface()->playerID))
  426. minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/obeliskVisited"));
  427. else
  428. minimap->addIcon(mapObject->visitablePos(), ImagePath::builtin("minimapIcons/obelisk"));
  429. }
  430. minimap->recreate();
  431. center(position);
  432. fitToScreen(10);
  433. }
  434. SearchPopup::SearchPopup(std::vector<const CGObjectInstance *> objs)
  435. : AdventureMapPopup(BORDERED | RCLICK_POPUP)
  436. {
  437. OBJECT_CONSTRUCTION;
  438. pos.w = 322;
  439. pos.h = 220 + (GAME->interface()->cb->getMapSize().z > 2 ? 21 : 0);
  440. if(!objs.size())
  441. return;
  442. auto name = GAME->interface()->cb->getObjInstance(objs.at(0)->id)->getObjectName();
  443. filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
  444. labelTitle = std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, name);
  445. minimap = std::make_shared<MinimapWithIcons>(Point(0,20));
  446. for (const auto obj : objs)
  447. minimap->addIcon(obj->visitablePos(), ImagePath::builtin("minimapIcons/generic"));
  448. minimap->recreate();
  449. center();
  450. fitToScreen(10);
  451. }
  452. std::shared_ptr<WindowBase>
  453. CRClickPopup::createCustomInfoWindow(Point position, const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  454. {
  455. if(nullptr == specific)
  456. specific = GAME->interface()->localState->getCurrentArmy();
  457. if(nullptr == specific)
  458. {
  459. logGlobal->error("createCustomInfoWindow: no object to describe");
  460. return nullptr;
  461. }
  462. switch(specific->ID)
  463. {
  464. case Obj::HERO:
  465. return std::make_shared<CInfoBoxPopup>(position, dynamic_cast<const CGHeroInstance *>(specific));
  466. case Obj::TOWN:
  467. return std::make_shared<CInfoBoxPopup>(position, dynamic_cast<const CGTownInstance *>(specific));
  468. case Obj::MONSTER:
  469. return std::make_shared<CInfoBoxPopup>(position, dynamic_cast<const CGCreature *>(specific));
  470. case Obj::GARRISON:
  471. case Obj::GARRISON2:
  472. return std::make_shared<CInfoBoxPopup>(position, dynamic_cast<const CGGarrison *>(specific));
  473. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  474. case Obj::MONOLITH_ONE_WAY_EXIT:
  475. case Obj::MONOLITH_TWO_WAY:
  476. case Obj::SUBTERRANEAN_GATE:
  477. case Obj::WHIRLPOOL:
  478. return std::make_shared<TeleporterPopup>(position, dynamic_cast<const CGTeleport *>(specific));
  479. case Obj::KEYMASTER:
  480. case Obj::BORDERGUARD:
  481. case Obj::BORDER_GATE:
  482. return std::make_shared<KeymasterPopup>(position, dynamic_cast<const CGKeys *>(specific));
  483. case Obj::OBELISK:
  484. return std::make_shared<ObeliskPopup>(position, dynamic_cast<const CGObelisk *>(specific));
  485. default:
  486. return std::shared_ptr<WindowBase>();
  487. }
  488. }