CKingdomInterface.cpp 33 KB

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