CKingdomInterface.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. /*
  2. * CKingdomInterface.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 "CKingdomInterface.h"
  12. #include "CCastleInterface.h"
  13. #include "CPlayerState.h"
  14. #include "InfoWindows.h"
  15. #include "../CPlayerInterface.h"
  16. #include "../PlayerLocalState.h"
  17. #include "../adventureMap/CResDataBar.h"
  18. #include "../GameEngine.h"
  19. #include "../GameInstance.h"
  20. #include "../gui/Shortcut.h"
  21. #include "../gui/WindowHandler.h"
  22. #include "../widgets/CComponent.h"
  23. #include "../widgets/CGarrisonInt.h"
  24. #include "../widgets/TextControls.h"
  25. #include "../widgets/MiscWidgets.h"
  26. #include "../widgets/Buttons.h"
  27. #include "../widgets/ObjectLists.h"
  28. #include "../windows/CHeroWindow.h"
  29. #include "../windows/CMarketWindow.h"
  30. #include "../../lib/CConfigHandler.h"
  31. #include "../../lib/CCreatureHandler.h"
  32. #include "../../lib/CSkillHandler.h"
  33. #include "../../lib/GameLibrary.h"
  34. #include "../../lib/IGameSettings.h"
  35. #include "../../lib/StartInfo.h"
  36. #include "../../lib/callback/CCallback.h"
  37. #include "../../lib/entities/hero/CHeroHandler.h"
  38. #include "../../lib/texts/TextOperations.h"
  39. #include "../../lib/mapObjects/CGHeroInstance.h"
  40. #include "../../lib/mapObjects/CGTownInstance.h"
  41. #include "../../lib/mapObjects/MiscObjects.h"
  42. #include "texts/CGeneralTextHandler.h"
  43. #include "../../lib/GameSettings.h"
  44. static const std::string OVERVIEW_BACKGROUND = "OvCast.pcx";
  45. static const size_t OVERVIEW_SIZE = 4;
  46. InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, std::shared_ptr<IInfoBoxData> Data):
  47. size(Size),
  48. infoPos(Pos),
  49. data(Data),
  50. value(nullptr),
  51. name(nullptr)
  52. {
  53. assert(data);
  54. addUsedEvents(LCLICK | SHOW_POPUP);
  55. EFonts font = (size < SIZE_MEDIUM)? FONT_SMALL: FONT_MEDIUM;
  56. OBJECT_CONSTRUCTION;
  57. pos+=position;
  58. image = std::make_shared<CAnimImage>(data->getImageName(size), data->getImageIndex());
  59. pos = image->pos;
  60. switch(infoPos)
  61. {
  62. case POS_CORNER:
  63. value = std::make_shared<CLabel>(pos.w, pos.h, font, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, data->getValueText());
  64. break;
  65. case POS_INSIDE:
  66. value = std::make_shared<CLabel>(pos.w/2, pos.h-6, font, ETextAlignment::CENTER, Colors::WHITE, data->getValueText());
  67. break;
  68. case POS_UP_DOWN:
  69. name = std::make_shared<CLabel>(pos.w/2, -12, font, ETextAlignment::CENTER, Colors::WHITE, data->getNameText());
  70. [[fallthrough]];
  71. case POS_DOWN:
  72. value = std::make_shared<CLabel>(pos.w/2, pos.h+8, font, ETextAlignment::CENTER, Colors::WHITE, data->getValueText());
  73. break;
  74. case POS_RIGHT:
  75. name = std::make_shared<CLabel>(pos.w+6, 6, font, ETextAlignment::TOPLEFT, Colors::WHITE, data->getNameText());
  76. value = std::make_shared<CLabel>(pos.w+6, pos.h-16, font, ETextAlignment::TOPLEFT, Colors::WHITE, data->getValueText());
  77. break;
  78. }
  79. if(name)
  80. pos = pos.include(name->pos);
  81. if(value)
  82. pos = pos.include(value->pos);
  83. hover = std::make_shared<CHoverableArea>();
  84. hover->hoverText = data->getHoverText();
  85. hover->pos = pos;
  86. }
  87. InfoBox::~InfoBox() = default;
  88. void InfoBox::showPopupWindow(const Point & cursorPosition)
  89. {
  90. std::shared_ptr<CComponent> comp;
  91. std::string text;
  92. data->prepareMessage(text, comp);
  93. if (comp)
  94. CRClickPopup::createAndPush(text, CInfoWindow::TCompsInfo(1, comp));
  95. else if (!text.empty())
  96. CRClickPopup::createAndPush(text);
  97. }
  98. void InfoBox::clickPressed(const Point & cursorPosition)
  99. {
  100. std::shared_ptr<CComponent> comp;
  101. std::string text;
  102. data->prepareMessage(text, comp);
  103. if(comp)
  104. GAME->interface()->showInfoDialog(text, CInfoWindow::TCompsInfo(1, comp));
  105. else if (!text.empty())
  106. GAME->interface()->showInfoDialog(text);
  107. }
  108. IInfoBoxData::IInfoBoxData(InfoType Type)
  109. : type(Type)
  110. {
  111. }
  112. InfoBoxAbstractHeroData::InfoBoxAbstractHeroData(InfoType Type)
  113. : IInfoBoxData(Type)
  114. {
  115. }
  116. std::string InfoBoxAbstractHeroData::getValueText()
  117. {
  118. switch (type)
  119. {
  120. case HERO_MANA:
  121. case HERO_PRIMARY_SKILL:
  122. return std::to_string(getValue());
  123. case HERO_EXPERIENCE:
  124. return TextOperations::formatMetric(getValue(), 6);
  125. case HERO_SPECIAL:
  126. return LIBRARY->generaltexth->jktexts[5];
  127. case HERO_SECONDARY_SKILL:
  128. {
  129. si64 value = getValue();
  130. if (value)
  131. return LIBRARY->generaltexth->levels[value];
  132. else
  133. return "";
  134. }
  135. default:
  136. logGlobal->error("Invalid InfoBox info type");
  137. }
  138. return "";
  139. }
  140. std::string InfoBoxAbstractHeroData::getNameText()
  141. {
  142. switch (type)
  143. {
  144. case HERO_PRIMARY_SKILL:
  145. return LIBRARY->generaltexth->primarySkillNames[getSubID()];
  146. case HERO_MANA:
  147. return LIBRARY->generaltexth->allTexts[387];
  148. case HERO_EXPERIENCE:
  149. return LIBRARY->generaltexth->jktexts[6];
  150. case HERO_SPECIAL:
  151. return LIBRARY->heroh->objects[getSubID()]->getSpecialtyNameTranslated();
  152. case HERO_SECONDARY_SKILL:
  153. if (getValue())
  154. return LIBRARY->skillh->getByIndex(getSubID())->getNameTranslated();
  155. else
  156. return "";
  157. default:
  158. logGlobal->error("Invalid InfoBox info type");
  159. }
  160. return "";
  161. }
  162. AnimationPath InfoBoxAbstractHeroData::getImageName(InfoBox::InfoSize size)
  163. {
  164. //TODO: sizes
  165. switch(size)
  166. {
  167. case InfoBox::SIZE_SMALL:
  168. {
  169. switch(type)
  170. {
  171. case HERO_PRIMARY_SKILL:
  172. case HERO_MANA:
  173. case HERO_EXPERIENCE:
  174. return AnimationPath::builtin("PSKIL32");
  175. case HERO_SPECIAL:
  176. return AnimationPath::builtin("UN32");
  177. case HERO_SECONDARY_SKILL:
  178. return AnimationPath::builtin("SECSK32");
  179. default:
  180. assert(0);
  181. }
  182. }
  183. case InfoBox::SIZE_BIG:
  184. {
  185. switch(type)
  186. {
  187. case HERO_PRIMARY_SKILL:
  188. case HERO_MANA:
  189. case HERO_EXPERIENCE:
  190. return AnimationPath::builtin("PSKIL42");
  191. case HERO_SPECIAL:
  192. return AnimationPath::builtin("UN44");
  193. case HERO_SECONDARY_SKILL:
  194. return AnimationPath::builtin("SECSKILL");
  195. default:
  196. assert(0);
  197. }
  198. }
  199. default:
  200. assert(0);
  201. }
  202. return {};
  203. }
  204. std::string InfoBoxAbstractHeroData::getHoverText()
  205. {
  206. //TODO: any texts here?
  207. return "";
  208. }
  209. size_t InfoBoxAbstractHeroData::getImageIndex()
  210. {
  211. switch (type)
  212. {
  213. case HERO_SPECIAL:
  214. return LIBRARY->heroh->objects[getSubID()]->imageIndex;
  215. case HERO_PRIMARY_SKILL:
  216. return getSubID();
  217. case HERO_MANA:
  218. return 5;
  219. case HERO_EXPERIENCE:
  220. return 4;
  221. case HERO_SECONDARY_SKILL:
  222. {
  223. si64 value = getValue();
  224. if (value)
  225. return getSubID()*3 + value + 2;
  226. else
  227. return 0;//FIXME: Should be transparent instead of empty
  228. }
  229. default:
  230. assert(0);
  231. return 0;
  232. }
  233. }
  234. void InfoBoxAbstractHeroData::prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)
  235. {
  236. comp.reset();
  237. switch (type)
  238. {
  239. case HERO_SPECIAL:
  240. text = LIBRARY->heroh->objects[getSubID()]->getSpecialtyDescriptionTranslated();
  241. break;
  242. case HERO_PRIMARY_SKILL:
  243. text = LIBRARY->generaltexth->arraytxt[2+getSubID()];
  244. comp = std::make_shared<CComponent>(ComponentType::PRIM_SKILL, PrimarySkill(getSubID()), getValue());
  245. break;
  246. case HERO_MANA:
  247. text = LIBRARY->generaltexth->allTexts[149];
  248. break;
  249. case HERO_EXPERIENCE:
  250. text = LIBRARY->generaltexth->allTexts[241];
  251. break;
  252. case HERO_SECONDARY_SKILL:
  253. {
  254. si64 value = getValue();
  255. int subID = getSubID();
  256. if(value)
  257. {
  258. text = LIBRARY->skillh->getByIndex(subID)->getDescriptionTranslated((int)value);
  259. comp = std::make_shared<CComponent>(ComponentType::SEC_SKILL, SecondarySkill(subID), (int)value);
  260. }
  261. break;
  262. }
  263. default:
  264. break;
  265. }
  266. }
  267. InfoBoxHeroData::InfoBoxHeroData(InfoType Type, const CGHeroInstance * Hero, int Index):
  268. InfoBoxAbstractHeroData(Type),
  269. hero(Hero),
  270. index(Index)
  271. {
  272. }
  273. int InfoBoxHeroData::getSubID()
  274. {
  275. switch(type)
  276. {
  277. case HERO_PRIMARY_SKILL:
  278. return index;
  279. case HERO_SECONDARY_SKILL:
  280. if(hero->secSkills.size() > index)
  281. return hero->secSkills[index].first.getNum();
  282. else
  283. return 0;
  284. case HERO_SPECIAL:
  285. return hero->getHeroTypeID().getNum();
  286. case HERO_MANA:
  287. case HERO_EXPERIENCE:
  288. return 0;
  289. default:
  290. assert(0);
  291. return 0;
  292. }
  293. }
  294. si64 InfoBoxHeroData::getValue()
  295. {
  296. if(!hero)
  297. return 0;
  298. switch(type)
  299. {
  300. case HERO_PRIMARY_SKILL:
  301. return hero->getPrimSkillLevel(static_cast<PrimarySkill>(index));
  302. case HERO_MANA:
  303. return hero->mana;
  304. case HERO_EXPERIENCE:
  305. return hero->exp;
  306. case HERO_SECONDARY_SKILL:
  307. if(hero->secSkills.size() > index)
  308. return hero->secSkills[index].second;
  309. else
  310. return 0;
  311. case HERO_SPECIAL:
  312. return 0;
  313. default:
  314. assert(0);
  315. return 0;
  316. }
  317. }
  318. std::string InfoBoxHeroData::getHoverText()
  319. {
  320. switch (type)
  321. {
  322. case HERO_PRIMARY_SKILL:
  323. return boost::str(boost::format(LIBRARY->generaltexth->heroscrn[1]) % LIBRARY->generaltexth->primarySkillNames[index]);
  324. case HERO_MANA:
  325. return LIBRARY->generaltexth->heroscrn[22];
  326. case HERO_EXPERIENCE:
  327. return LIBRARY->generaltexth->heroscrn[9];
  328. case HERO_SPECIAL:
  329. return LIBRARY->generaltexth->heroscrn[27];
  330. case HERO_SECONDARY_SKILL:
  331. if (hero->secSkills.size() > index)
  332. {
  333. std::string level = LIBRARY->generaltexth->levels[hero->secSkills[index].second-1];
  334. std::string skill = hero->secSkills[index].first.toEntity(LIBRARY)->getNameTranslated();
  335. return boost::str(boost::format(LIBRARY->generaltexth->heroscrn[21]) % level % skill);
  336. }
  337. else
  338. {
  339. return "";
  340. }
  341. default:
  342. return InfoBoxAbstractHeroData::getHoverText();
  343. }
  344. }
  345. std::string InfoBoxHeroData::getValueText()
  346. {
  347. if (hero)
  348. {
  349. switch (type)
  350. {
  351. case HERO_MANA:
  352. return std::to_string(hero->mana) + '/' +
  353. std::to_string(hero->manaLimit());
  354. case HERO_EXPERIENCE:
  355. return TextOperations::formatMetric(hero->exp, 6);
  356. }
  357. }
  358. return InfoBoxAbstractHeroData::getValueText();
  359. }
  360. void InfoBoxHeroData::prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)
  361. {
  362. comp.reset();
  363. switch(type)
  364. {
  365. case HERO_MANA:
  366. text = LIBRARY->generaltexth->allTexts[205];
  367. boost::replace_first(text, "%s", hero->getNameTranslated());
  368. boost::replace_first(text, "%d", std::to_string(hero->mana));
  369. boost::replace_first(text, "%d", std::to_string(hero->manaLimit()));
  370. break;
  371. case HERO_EXPERIENCE:
  372. text = LIBRARY->generaltexth->allTexts[2];
  373. boost::replace_first(text, "%d", std::to_string(hero->level));
  374. boost::replace_first(text, "%d", std::to_string(LIBRARY->heroh->reqExp(hero->level+1)));
  375. boost::replace_first(text, "%d", std::to_string(hero->exp));
  376. break;
  377. default:
  378. InfoBoxAbstractHeroData::prepareMessage(text, comp);
  379. break;
  380. }
  381. }
  382. InfoBoxCustomHeroData::InfoBoxCustomHeroData(InfoType Type, int SubID, si64 Value):
  383. InfoBoxAbstractHeroData(Type),
  384. subID(SubID),
  385. value(Value)
  386. {
  387. }
  388. int InfoBoxCustomHeroData::getSubID()
  389. {
  390. return subID;
  391. }
  392. si64 InfoBoxCustomHeroData::getValue()
  393. {
  394. return value;
  395. }
  396. InfoBoxCustom::InfoBoxCustom(std::string ValueText, std::string NameText, const AnimationPath & ImageName, size_t ImageIndex, std::string HoverText):
  397. IInfoBoxData(CUSTOM),
  398. valueText(ValueText),
  399. nameText(NameText),
  400. imageName(ImageName),
  401. hoverText(HoverText),
  402. imageIndex(ImageIndex)
  403. {
  404. }
  405. std::string InfoBoxCustom::getHoverText()
  406. {
  407. return hoverText;
  408. }
  409. size_t InfoBoxCustom::getImageIndex()
  410. {
  411. return imageIndex;
  412. }
  413. AnimationPath InfoBoxCustom::getImageName(InfoBox::InfoSize size)
  414. {
  415. return imageName;
  416. }
  417. std::string InfoBoxCustom::getNameText()
  418. {
  419. return nameText;
  420. }
  421. std::string InfoBoxCustom::getValueText()
  422. {
  423. return valueText;
  424. }
  425. void InfoBoxCustom::prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)
  426. {
  427. }
  428. CKingdomInterface::CKingdomInterface()
  429. : CWindowObject(PLAYER_COLORED | BORDERED, ImagePath::builtin(OVERVIEW_BACKGROUND))
  430. {
  431. OBJECT_CONSTRUCTION;
  432. ui32 footerPos = OVERVIEW_SIZE * 116;
  433. tabArea = std::make_shared<CTabbedInt>(std::bind(&CKingdomInterface::createMainTab, this, _1), Point(4,4));
  434. std::vector<const CGObjectInstance * > ownedObjects = GAME->interface()->cb->getMyObjects();
  435. generateObjectsList(ownedObjects);
  436. generateMinesList(ownedObjects);
  437. generateButtons();
  438. statusbar = CGStatusBar::create(std::make_shared<CPicture>(ImagePath::builtin("KSTATBAR"), 10,pos.h - 45));
  439. resdatabar = std::make_shared<CResDataBar>(ImagePath::builtin("KRESBAR"), 7, 111+footerPos, 29, 3, 76, 81);
  440. activateTab(settings["general"]["lastKindomInterface"].Integer());
  441. }
  442. void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects)
  443. {
  444. ui32 footerPos = OVERVIEW_SIZE * 116;
  445. size_t dwellSize = (footerPos - 64)/57;
  446. //Map used to determine image number for several objects
  447. std::map<std::pair<int,int>,int> idToImage;
  448. idToImage[std::make_pair( 20, 1)] = 81;//Golem factory
  449. idToImage[std::make_pair( 42, 0)] = 82;//Lighthouse
  450. idToImage[std::make_pair( 33, 0)] = 83;//Garrison
  451. idToImage[std::make_pair(219, 0)] = 83;//Garrison
  452. idToImage[std::make_pair( 33, 1)] = 84;//Anti-magic Garrison
  453. idToImage[std::make_pair(219, 1)] = 84;//Anti-magic Garrison
  454. idToImage[std::make_pair( 53, 7)] = 85;//Abandoned mine
  455. idToImage[std::make_pair( 20, 0)] = 86;//Conflux
  456. idToImage[std::make_pair( 87, 0)] = 87;//Harbor
  457. std::map<int, OwnedObjectInfo> visibleObjects;
  458. for(const CGObjectInstance * object : ownedObjects)
  459. {
  460. //Dwellings
  461. if(object->ID == Obj::CREATURE_GENERATOR1)
  462. {
  463. OwnedObjectInfo & info = visibleObjects[object->subID];
  464. if(info.count++ == 0)
  465. {
  466. info.hoverText = object->getObjectName();
  467. info.imageID = object->subID;
  468. }
  469. }
  470. //Special objects from idToImage map that should be displayed in objects list
  471. auto iter = idToImage.find(std::make_pair(object->ID, object->subID));
  472. if(iter != idToImage.end())
  473. {
  474. OwnedObjectInfo & info = visibleObjects[iter->second];
  475. if(info.count++ == 0)
  476. {
  477. info.hoverText = object->getObjectName();
  478. info.imageID = iter->second;
  479. }
  480. }
  481. }
  482. objects.reserve(visibleObjects.size());
  483. for(auto & element : visibleObjects)
  484. {
  485. objects.push_back(element.second);
  486. }
  487. dwellingsList = std::make_shared<CListBox>(std::bind(&CKingdomInterface::createOwnedObject, this, _1),
  488. Point(740,44), Point(0,57), dwellSize, visibleObjects.size());
  489. }
  490. std::shared_ptr<CIntObject> CKingdomInterface::createOwnedObject(size_t index)
  491. {
  492. if(index < objects.size())
  493. {
  494. OwnedObjectInfo & obj = objects[index];
  495. std::string value = std::to_string(obj.count);
  496. auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("FLAGPORT"), obj.imageID, obj.hoverText);
  497. return std::make_shared<InfoBox>(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, data);
  498. }
  499. return std::shared_ptr<CIntObject>();
  500. }
  501. std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index)
  502. {
  503. size_t size = OVERVIEW_SIZE;
  504. switch(index)
  505. {
  506. case 0:
  507. return std::make_shared<CKingdHeroList>(size, [this](const CWindowWithArtifacts::CArtifactsOfHeroPtr & newHeroSet)
  508. {
  509. newHeroSet->clickPressedCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
  510. {
  511. clickPressedOnArtPlace(newHeroSet->getHero(), artPlace.slot, false, false, false, cursorPosition);
  512. };
  513. newHeroSet->showPopupCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
  514. {
  515. showArtifactAssembling(*newHeroSet, artPlace, cursorPosition);
  516. };
  517. newHeroSet->gestureCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
  518. {
  519. showQuickBackpackWindow(newHeroSet->getHero(), artPlace.slot, cursorPosition);
  520. };
  521. addSet(newHeroSet);
  522. });
  523. case 1:
  524. return std::make_shared<CKingdTownList>(size);
  525. default:
  526. return std::shared_ptr<CIntObject>();
  527. }
  528. }
  529. void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstance *> & ownedObjects)
  530. {
  531. ui32 footerPos = OVERVIEW_SIZE * 116;
  532. ResourceSet minesCount = ResourceSet();
  533. int totalIncome=0;
  534. for(const CGObjectInstance * object : ownedObjects)
  535. {
  536. //Mines
  537. if(object->ID == Obj::MINE || object->ID == Obj::ABANDONED_MINE)
  538. {
  539. const CGMine * mine = dynamic_cast<const CGMine *>(object);
  540. minesCount[mine->producedResource]++;
  541. }
  542. }
  543. for(auto & mapObject : ownedObjects)
  544. totalIncome += mapObject->asOwnable()->dailyIncome()[EGameResID::GOLD];
  545. //if player has some modded boosts we want to show that as well
  546. const auto * playerSettings = GAME->interface()->cb->getPlayerSettings(GAME->interface()->playerID);
  547. const auto & towns = GAME->interface()->cb->getTownsInfo(true);
  548. totalIncome += GAME->interface()->cb->getPlayerState(GAME->interface()->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * playerSettings->handicap.percentIncome / 100;
  549. totalIncome += GAME->interface()->cb->getPlayerState(GAME->interface()->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size() * playerSettings->handicap.percentIncome / 100;
  550. for(int i=0; i<7; i++)
  551. {
  552. std::string value = std::to_string(minesCount[i]);
  553. auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("OVMINES"), i, LIBRARY->generaltexth->translate("core.minename", i));
  554. minesBox[i] = std::make_shared<InfoBox>(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data);
  555. minesBox[i]->removeUsedEvents(LCLICK|SHOW_POPUP); //fixes #890 - mines boxes ignore clicks
  556. }
  557. incomeArea = std::make_shared<CHoverableArea>();
  558. incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68);
  559. incomeArea->hoverText = LIBRARY->generaltexth->allTexts[255];
  560. incomeAmount = std::make_shared<CLabel>(628, footerPos + 70, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, std::to_string(totalIncome));
  561. }
  562. void CKingdomInterface::generateButtons()
  563. {
  564. ui32 footerPos = OVERVIEW_SIZE * 116;
  565. //Main control buttons
  566. btnHeroes = std::make_shared<CButton>(Point(748, 28+footerPos), AnimationPath::builtin("OVBUTN1.DEF"), CButton::tooltip(LIBRARY->generaltexth->overview[11], LIBRARY->generaltexth->overview[6]),
  567. std::bind(&CKingdomInterface::activateTab, this, 0), EShortcut::KINGDOM_HEROES_TAB);
  568. btnHeroes->block(true);
  569. btnTowns = std::make_shared<CButton>(Point(748, 64+footerPos), AnimationPath::builtin("OVBUTN6.DEF"), CButton::tooltip(LIBRARY->generaltexth->overview[12], LIBRARY->generaltexth->overview[7]),
  570. std::bind(&CKingdomInterface::activateTab, this, 1), EShortcut::KINGDOM_TOWNS_TAB);
  571. btnExit = std::make_shared<CButton>(Point(748,99+footerPos), AnimationPath::builtin("OVBUTN1.DEF"), CButton::tooltip(LIBRARY->generaltexth->allTexts[600]),
  572. std::bind(&CKingdomInterface::close, this), EShortcut::GLOBAL_RETURN);
  573. btnExit->setImageOrder(3, 4, 5, 6);
  574. //Object list control buttons
  575. dwellTop = std::make_shared<CButton>(Point(733, 4), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPos(0);});
  576. dwellBottom = std::make_shared<CButton>(Point(733, footerPos+2), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPos(-1); });
  577. dwellBottom->setImageOrder(2, 3, 4, 5);
  578. dwellUp = std::make_shared<CButton>(Point(733, 24), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPrev(); });
  579. dwellUp->setImageOrder(4, 5, 6, 7);
  580. dwellDown = std::make_shared<CButton>(Point(733, footerPos-18), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToNext(); });
  581. dwellDown->setImageOrder(6, 7, 8, 9);
  582. }
  583. void CKingdomInterface::activateTab(size_t which)
  584. {
  585. Settings s = settings.write["general"]["lastKindomInterface"];
  586. s->Integer() = which;
  587. btnHeroes->block(which == 0);
  588. btnTowns->block(which == 1);
  589. tabArea->setActive(which);
  590. }
  591. void CKingdomInterface::buildChanged()
  592. {
  593. tabArea->reset();
  594. }
  595. void CKingdomInterface::townChanged(const CGTownInstance *town)
  596. {
  597. if(auto townList = std::dynamic_pointer_cast<CKingdTownList>(tabArea->getItem()))
  598. townList->townChanged(town);
  599. }
  600. void CKingdomInterface::heroRemoved()
  601. {
  602. tabArea->reset();
  603. }
  604. void CKingdomInterface::updateGarrisons()
  605. {
  606. if(auto garrison = std::dynamic_pointer_cast<IGarrisonHolder>(tabArea->getItem()))
  607. garrison->updateGarrisons();
  608. }
  609. bool CKingdomInterface::holdsGarrison(const CArmedInstance * army)
  610. {
  611. return army->getOwner() == GAME->interface()->playerID;
  612. }
  613. CKingdHeroList::CKingdHeroList(size_t maxSize, const CreateHeroItemFunctor & onCreateHeroItemCallback)
  614. {
  615. OBJECT_CONSTRUCTION;
  616. title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"),16,0);
  617. title->setPlayerColor(GAME->interface()->playerID);
  618. heroLabel = std::make_shared<CLabel>(150, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->overview[0]);
  619. skillsLabel = std::make_shared<CLabel>(500, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->overview[1]);
  620. ui32 townCount = GAME->interface()->cb->howManyHeroes(false);
  621. ui32 size = OVERVIEW_SIZE*116 + 19;
  622. heroes = std::make_shared<CListBox>([onCreateHeroItemCallback](size_t idx) -> std::shared_ptr<CIntObject>
  623. {
  624. auto heroesList = GAME->interface()->localState->getWanderingHeroes();
  625. if(idx < heroesList.size())
  626. {
  627. auto hero = std::make_shared<CHeroItem>(heroesList[idx]);
  628. onCreateHeroItemCallback(hero->heroArts);
  629. return hero;
  630. }
  631. else
  632. {
  633. return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (idx - 2) % GameConstants::KINGDOM_WINDOW_HEROES_SLOTS);
  634. }
  635. }, Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size));
  636. }
  637. void CKingdHeroList::updateGarrisons()
  638. {
  639. for(std::shared_ptr<CIntObject> object : heroes->getItems())
  640. {
  641. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  642. garrison->updateGarrisons();
  643. }
  644. }
  645. bool CKingdHeroList::holdsGarrison(const CArmedInstance * army)
  646. {
  647. for(std::shared_ptr<CIntObject> object : heroes->getItems())
  648. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  649. if (garrison->holdsGarrison(army))
  650. return true;
  651. return false;
  652. }
  653. CKingdTownList::CKingdTownList(size_t maxSize)
  654. {
  655. OBJECT_CONSTRUCTION;
  656. title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"), 16, 0);
  657. title->setPlayerColor(GAME->interface()->playerID);
  658. townLabel = std::make_shared<CLabel>(146, 10,FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->overview[3]);
  659. garrHeroLabel = std::make_shared<CLabel>(375, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->overview[4]);
  660. visitHeroLabel = std::make_shared<CLabel>(608, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->overview[5]);
  661. ui32 townCount = GAME->interface()->cb->howManyTowns();
  662. ui32 size = OVERVIEW_SIZE*116 + 19;
  663. towns = std::make_shared<CListBox>(std::bind(&CKingdTownList::createTownItem, this, _1),
  664. Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size));
  665. }
  666. void CKingdTownList::townChanged(const CGTownInstance * town)
  667. {
  668. for(std::shared_ptr<CIntObject> object : towns->getItems())
  669. {
  670. CTownItem * townItem = dynamic_cast<CTownItem *>(object.get());
  671. if(townItem && townItem->town == town)
  672. townItem->update();
  673. }
  674. }
  675. void CKingdTownList::updateGarrisons()
  676. {
  677. for(std::shared_ptr<CIntObject> object : towns->getItems())
  678. {
  679. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  680. garrison->updateGarrisons();
  681. }
  682. }
  683. bool CKingdTownList::holdsGarrison(const CArmedInstance * army)
  684. {
  685. for(std::shared_ptr<CIntObject> object : towns->getItems())
  686. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  687. if (garrison->holdsGarrison(army))
  688. return true;
  689. return false;
  690. }
  691. std::shared_ptr<CIntObject> CKingdTownList::createTownItem(size_t index)
  692. {
  693. ui32 picCount = 4; // OVSLOT contains 4 images
  694. auto townsList = GAME->interface()->localState->getOwnedTowns();
  695. if(index < townsList.size())
  696. return std::make_shared<CTownItem>(townsList[index]);
  697. else
  698. return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (index-2) % picCount );
  699. }
  700. CTownItem::CTownItem(const CGTownInstance * Town)
  701. : town(Town)
  702. {
  703. OBJECT_CONSTRUCTION;
  704. background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 6);
  705. name = std::make_shared<CLabel>(74, 8, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, town->getNameTranslated());
  706. income = std::make_shared<CLabel>( 190, 60, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string(town->dailyIncome()[EGameResID::GOLD]));
  707. hall = std::make_shared<CTownInfo>( 69, 31, town, true);
  708. fort = std::make_shared<CTownInfo>(111, 31, town, false);
  709. garr = std::make_shared<CGarrisonInt>(Point(313, 3), 4, Point(232,0), town->getUpperArmy(), town->getVisitingHero(), true, true, CGarrisonInt::ESlotsLayout::TWO_ROWS);
  710. heroes = std::make_shared<HeroSlots>(town, Point(244,6), Point(475,6), garr, false);
  711. size_t iconIndex = town->getTown()->clientInfo.icons[town->hasFort()][town->built >= GAME->interface()->cb->getSettings().getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
  712. picture = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPT"), iconIndex, 0, 5, 6);
  713. openTown = std::make_shared<LRClickableAreaOpenTown>(Rect(5, 6, 58, 64), town);
  714. for(size_t i=0; i<town->creatures.size() && i<GameConstants::CREATURES_PER_TOWN; i++)
  715. {
  716. growth.push_back(std::make_shared<CCreaInfo>(Point(401+37*(int)i, 78), town, (int)i, true, true));
  717. available.push_back(std::make_shared<CCreaInfo>(Point(48+37*(int)i, 78), town, (int)i, true, false));
  718. }
  719. fastTownHall = std::make_shared<CButton>(Point(69, 31), AnimationPath::builtin("castleInterfaceQuickAccess"), CButton::tooltip(), [this]() { std::make_shared<CCastleBuildings>(town)->enterTownHall(); });
  720. fastTownHall->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("ITMTL"), town->hallLevel()));
  721. int imageIndex = town->fortLevel() == CGTownInstance::EFortLevel::NONE ? 3 : town->fortLevel() - 1;
  722. fastArmyPurchase = std::make_shared<CButton>(Point(111, 31), AnimationPath::builtin("castleInterfaceQuickAccess"), CButton::tooltip(), [this]() { std::make_shared<CCastleBuildings>(town)->enterToTheQuickRecruitmentWindow(); });
  723. fastArmyPurchase->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("itmcl"), imageIndex));
  724. fastTavern = std::make_shared<LRClickableArea>(Rect(5, 6, 58, 64), [&]()
  725. {
  726. if(town->hasBuilt(BuildingID::TAVERN))
  727. GAME->interface()->showTavernWindow(town, nullptr, QueryID::NONE);
  728. }, [&]{
  729. if(!town->getTown()->faction->getDescriptionTranslated().empty())
  730. CRClickPopup::createAndPush(town->getFaction()->getDescriptionTranslated());
  731. });
  732. fastMarket = std::make_shared<LRClickableArea>(Rect(153, 6, 65, 64), []()
  733. {
  734. std::vector<const CGTownInstance*> towns = GAME->interface()->cb->getTownsInfo(true);
  735. for(auto & town : towns)
  736. {
  737. if(town->hasBuilt(BuildingID::MARKETPLACE))
  738. {
  739. ENGINE->windows().createAndPushWindow<CMarketWindow>(town, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
  740. return;
  741. }
  742. }
  743. GAME->interface()->showInfoDialog(LIBRARY->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
  744. });
  745. fastTown = std::make_shared<LRClickableArea>(Rect(67, 6, 165, 20), [&]()
  746. {
  747. ENGINE->windows().createAndPushWindow<CCastleInterface>(town);
  748. });
  749. labelCreatureGrowth = std::make_shared<CMultiLineLabel>(Rect(4, 76, 50, 35), EFonts::FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, LIBRARY->generaltexth->translate("core.genrltxt.265"));
  750. labelCreatureAvailable = std::make_shared<CMultiLineLabel>(Rect(349, 76, 57, 35), EFonts::FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, LIBRARY->generaltexth->translate("core.genrltxt.266"));
  751. }
  752. void CTownItem::updateGarrisons()
  753. {
  754. garr->selectSlot(nullptr);
  755. garr->setArmy(town->getUpperArmy(), EGarrisonType::UPPER);
  756. garr->setArmy(town->getVisitingHero(), EGarrisonType::LOWER);
  757. garr->recreateSlots();
  758. }
  759. bool CTownItem::holdsGarrison(const CArmedInstance * army)
  760. {
  761. return army == town || army == town->getUpperArmy() || army == town->getVisitingHero();
  762. }
  763. void CTownItem::update()
  764. {
  765. std::string incomeVal = std::to_string(town->dailyIncome()[EGameResID::GOLD]);
  766. if (incomeVal != income->getText())
  767. income->setText(incomeVal);
  768. heroes->update();
  769. for (size_t i=0; i<std::min(static_cast<int>(town->creatures.size()), GameConstants::CREATURES_PER_TOWN); i++)
  770. {
  771. growth[i]->update();
  772. available[i]->update();
  773. }
  774. }
  775. class ArtSlotsTab : public CIntObject
  776. {
  777. public:
  778. std::shared_ptr<CAnimImage> background;
  779. std::vector<std::shared_ptr<CArtPlace>> arts;
  780. ArtSlotsTab(CIntObject * parent)
  781. {
  782. OBJECT_CONSTRUCTION_TARGETED(parent);
  783. background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 4);
  784. pos = background->pos;
  785. for(int i=0; i<9; i++)
  786. arts.push_back(std::make_shared<CArtPlace>(Point(269+i*48, 66)));
  787. }
  788. };
  789. class BackpackTab : public CIntObject
  790. {
  791. public:
  792. std::shared_ptr<CAnimImage> background;
  793. std::vector<std::shared_ptr<CArtPlace>> arts;
  794. std::shared_ptr<CButton> btnLeft;
  795. std::shared_ptr<CButton> btnRight;
  796. BackpackTab(CIntObject * parent)
  797. {
  798. OBJECT_CONSTRUCTION_TARGETED(parent);
  799. background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 5);
  800. pos = background->pos;
  801. btnLeft = std::make_shared<CButton>(Point(269, 66), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), 0);
  802. btnRight = std::make_shared<CButton>(Point(675, 66), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), 0);
  803. for(int i=0; i<8; i++)
  804. arts.push_back(std::make_shared<CArtPlace>(Point(294+i*48, 66)));
  805. }
  806. };
  807. CHeroItem::CHeroItem(const CGHeroInstance * Hero)
  808. : hero(Hero)
  809. {
  810. OBJECT_CONSTRUCTION;
  811. artTabs.resize(3);
  812. auto arts1 = std::make_shared<ArtSlotsTab>(this);
  813. auto arts2 = std::make_shared<ArtSlotsTab>(this);
  814. auto backpack = std::make_shared<BackpackTab>(this);
  815. artTabs[0] = arts1;
  816. artTabs[1] = arts2;
  817. artTabs[2] = backpack;
  818. arts1->recActions = SHARE_POS;
  819. arts2->recActions = SHARE_POS;
  820. backpack->recActions = SHARE_POS;
  821. name = std::make_shared<CLabel>(75, 7, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero->getNameTranslated());
  822. //layout is not trivial: MACH4 - catapult - excluded, MISC[x] rearranged
  823. assert(arts1->arts.size() == 9);
  824. assert(arts2->arts.size() == 9);
  825. CArtifactsOfHeroMain::ArtPlaceMap arts =
  826. {
  827. {ArtifactPosition::HEAD, arts1->arts[0]},
  828. {ArtifactPosition::SHOULDERS,arts1->arts[1]},
  829. {ArtifactPosition::NECK,arts1->arts[2]},
  830. {ArtifactPosition::RIGHT_HAND,arts1->arts[3]},
  831. {ArtifactPosition::LEFT_HAND,arts1->arts[4]},
  832. {ArtifactPosition::TORSO, arts1->arts[5]},
  833. {ArtifactPosition::RIGHT_RING,arts1->arts[6]},
  834. {ArtifactPosition::LEFT_RING, arts1->arts[7]},
  835. {ArtifactPosition::FEET, arts1->arts[8]},
  836. {ArtifactPosition::MISC1, arts2->arts[0]},
  837. {ArtifactPosition::MISC2, arts2->arts[1]},
  838. {ArtifactPosition::MISC3, arts2->arts[2]},
  839. {ArtifactPosition::MISC4, arts2->arts[3]},
  840. {ArtifactPosition::MISC5, arts2->arts[4]},
  841. {ArtifactPosition::MACH1, arts2->arts[5]},
  842. {ArtifactPosition::MACH2, arts2->arts[6]},
  843. {ArtifactPosition::MACH3, arts2->arts[7]},
  844. {ArtifactPosition::SPELLBOOK, arts2->arts[8]}
  845. };
  846. heroArts = std::make_shared<CArtifactsOfHeroKingdom>(arts, backpack->arts, backpack->btnLeft, backpack->btnRight);
  847. heroArts->setHero(hero);
  848. artsTabs = std::make_shared<CTabbedInt>(std::bind(&CHeroItem::onTabSelected, this, _1));
  849. artButtons = std::make_shared<CToggleGroup>(0);
  850. for(size_t it = 0; it<3; it++)
  851. {
  852. int stringID[3] = {259, 261, 262};
  853. std::string hover = LIBRARY->generaltexth->overview[13+it];
  854. std::string overlay = LIBRARY->generaltexth->overview[8+it];
  855. auto button = std::make_shared<CToggleButton>(Point(364+(int)it*112, 46), AnimationPath::builtin("OVBUTN3"), CButton::tooltip(hover, overlay), 0);
  856. button->setTextOverlay(LIBRARY->generaltexth->allTexts[stringID[it]], FONT_SMALL, Colors::YELLOW);
  857. artButtons->addToggle((int)it, button);
  858. }
  859. artButtons->addCallback(std::bind(&CTabbedInt::setActive, artsTabs, _1));
  860. artButtons->addCallback(std::bind(&CHeroItem::onArtChange, this, _1));
  861. artButtons->setSelected(0);
  862. garr = std::make_shared<CGarrisonInt>(Point(6, 78), 4, Point(), hero, nullptr, true, true);
  863. portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero->getIconIndex(), 0, 5, 6);
  864. heroArea = std::make_shared<CHeroArea>(5, 6, hero);
  865. heroArea->addRClickCallback([this](){ ENGINE->windows().createAndPushWindow<CRClickPopupInt>(std::make_shared<CHeroWindow>(hero)); });
  866. name = std::make_shared<CLabel>(73, 7, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero->getNameTranslated());
  867. artsText = std::make_shared<CLabel>(320, 55, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->overview[2]);
  868. for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
  869. {
  870. auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_PRIMARY_SKILL, hero, (int)i);
  871. heroInfo.push_back(std::make_shared<InfoBox>(Point(78+(int)i*36, 26), InfoBox::POS_DOWN, InfoBox::SIZE_SMALL, data));
  872. }
  873. int slots = 8;
  874. bool isMoreSkillsThanSlots = hero->secSkills.size() > slots;
  875. for(size_t i=0; i<slots; i++)
  876. {
  877. if(isMoreSkillsThanSlots && i == slots - 1)
  878. {
  879. Rect r(Point(410+(int)i*36, 5), Point(34, 28));
  880. heroInfoFull = std::make_shared<CMultiLineLabel>(r, EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "...");
  881. heroInfoFullArea = std::make_shared<LRClickableAreaWText>(r, LIBRARY->generaltexth->translate("vcmi.kingdomOverview.secSkillOverflow.hover"), LIBRARY->generaltexth->translate("vcmi.kingdomOverview.secSkillOverflow.help"));
  882. continue;
  883. }
  884. auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_SECONDARY_SKILL, hero, (int)i);
  885. heroInfo.push_back(std::make_shared<InfoBox>(Point(410+(int)i*36, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL, data));
  886. }
  887. {
  888. auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_SPECIAL, hero);
  889. heroInfo.push_back(std::make_shared<InfoBox>(Point(375, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL, data));
  890. data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_EXPERIENCE, hero);
  891. heroInfo.push_back(std::make_shared<InfoBox>(Point(330, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data));
  892. data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_MANA, hero);
  893. heroInfo.push_back(std::make_shared<InfoBox>(Point(280, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data));
  894. }
  895. morale = std::make_shared<MoraleLuckBox>(true, Rect(225, 53, 30, 22), true);
  896. luck = std::make_shared<MoraleLuckBox>(false, Rect(225, 28, 30, 22), true);
  897. morale->set(hero);
  898. luck->set(hero);
  899. }
  900. void CHeroItem::updateGarrisons()
  901. {
  902. garr->recreateSlots();
  903. }
  904. bool CHeroItem::holdsGarrison(const CArmedInstance * army)
  905. {
  906. return hero == army;
  907. }
  908. std::shared_ptr<CIntObject> CHeroItem::onTabSelected(size_t index)
  909. {
  910. return artTabs.at(index);
  911. }
  912. void CHeroItem::onArtChange(int tabIndex)
  913. {
  914. //redraw item after background change
  915. if(isActive())
  916. redraw();
  917. }