CKingdomInterface.cpp 34 KB

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