CKingdomInterface.cpp 33 KB

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