CKingdomInterface.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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 "../CGameInfo.h"
  16. #include "../CPlayerInterface.h"
  17. #include "../PlayerLocalState.h"
  18. #include "../adventureMap/CResDataBar.h"
  19. #include "../gui/CGuiHandler.h"
  20. #include "../gui/CursorHandler.h"
  21. #include "../gui/Shortcut.h"
  22. #include "../gui/WindowHandler.h"
  23. #include "../widgets/CComponent.h"
  24. #include "../widgets/CGarrisonInt.h"
  25. #include "../widgets/TextControls.h"
  26. #include "../widgets/MiscWidgets.h"
  27. #include "../widgets/Buttons.h"
  28. #include "../widgets/ObjectLists.h"
  29. #include "../windows/CMarketWindow.h"
  30. #include "../../CCallback.h"
  31. #include "../../lib/CConfigHandler.h"
  32. #include "../../lib/CCreatureHandler.h"
  33. #include "../../lib/CGeneralTextHandler.h"
  34. #include "../../lib/CHeroHandler.h"
  35. #include "../../lib/GameSettings.h"
  36. #include "../../lib/CSkillHandler.h"
  37. #include "../../lib/CTownHandler.h"
  38. #include "../../lib/mapObjects/CGHeroInstance.h"
  39. #include "../../lib/mapObjects/CGTownInstance.h"
  40. #include "../../lib/mapObjects/MiscObjects.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_CAPTURING(255-DISPOSE);
  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. LOCPLINT->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 CGI->generaltexth->jktexts[5];
  121. case HERO_SECONDARY_SKILL:
  122. {
  123. si64 value = getValue();
  124. if (value)
  125. return CGI->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 CGI->generaltexth->primarySkillNames[getSubID()];
  140. case HERO_MANA:
  141. return CGI->generaltexth->allTexts[387];
  142. case HERO_EXPERIENCE:
  143. return CGI->generaltexth->jktexts[6];
  144. case HERO_SPECIAL:
  145. return CGI->heroh->objects[getSubID()]->getSpecialtyNameTranslated();
  146. case HERO_SECONDARY_SKILL:
  147. if (getValue())
  148. return CGI->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 CGI->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 = CGI->heroh->objects[getSubID()]->getSpecialtyDescriptionTranslated();
  235. break;
  236. case HERO_PRIMARY_SKILL:
  237. text = CGI->generaltexth->arraytxt[2+getSubID()];
  238. comp = std::make_shared<CComponent>(ComponentType::PRIM_SKILL, PrimarySkill(getSubID()), getValue());
  239. break;
  240. case HERO_MANA:
  241. text = CGI->generaltexth->allTexts[149];
  242. break;
  243. case HERO_EXPERIENCE:
  244. text = CGI->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 = CGI->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;
  276. else
  277. return 0;
  278. case HERO_SPECIAL:
  279. return hero->type->getIndex();
  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(CGI->generaltexth->heroscrn[1]) % CGI->generaltexth->primarySkillNames[index]);
  318. case HERO_MANA:
  319. return CGI->generaltexth->heroscrn[22];
  320. case HERO_EXPERIENCE:
  321. return CGI->generaltexth->heroscrn[9];
  322. case HERO_SPECIAL:
  323. return CGI->generaltexth->heroscrn[27];
  324. case HERO_SECONDARY_SKILL:
  325. if (hero->secSkills.size() > index)
  326. {
  327. std::string level = CGI->generaltexth->levels[hero->secSkills[index].second-1];
  328. std::string skill = CGI->skillh->getByIndex(hero->secSkills[index].first)->getNameTranslated();
  329. return boost::str(boost::format(CGI->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 = CGI->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 = CGI->generaltexth->allTexts[2];
  367. boost::replace_first(text, "%d", std::to_string(hero->level));
  368. boost::replace_first(text, "%d", std::to_string(CGI->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_CAPTURING(255-DISPOSE);
  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 = LOCPLINT->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, 5, 76, 81);
  434. activateTab(persistentStorage["gui"]["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);
  502. case 1:
  503. return std::make_shared<CKingdTownList>(size);
  504. default:
  505. return std::shared_ptr<CIntObject>();
  506. }
  507. }
  508. void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstance *> & ownedObjects)
  509. {
  510. ui32 footerPos = OVERVIEW_SIZE * 116;
  511. ResourceSet minesCount = ResourceSet();
  512. int totalIncome=0;
  513. for(const CGObjectInstance * object : ownedObjects)
  514. {
  515. //Mines
  516. if(object->ID == Obj::MINE || object->ID == Obj::ABANDONED_MINE)
  517. {
  518. const CGMine * mine = dynamic_cast<const CGMine *>(object);
  519. assert(mine);
  520. minesCount[mine->producedResource]++;
  521. if (mine->producedResource == EGameResID::GOLD)
  522. totalIncome += mine->producedQuantity;
  523. }
  524. }
  525. //Heroes can produce gold as well - skill, specialty or arts
  526. std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
  527. for(auto & hero : heroes)
  528. {
  529. totalIncome += hero->valOfBonuses(Selector::typeSubtype(BonusType::GENERATE_RESOURCE, BonusSubtypeID(GameResID(EGameResID::GOLD))));
  530. }
  531. //Add town income of all towns
  532. std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
  533. for(auto & town : towns)
  534. {
  535. totalIncome += town->dailyIncome()[EGameResID::GOLD];
  536. }
  537. //if player has some modded boosts we want to show that as well
  538. totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD)));
  539. totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size();
  540. for(int i=0; i<7; i++)
  541. {
  542. std::string value = std::to_string(minesCount[i]);
  543. auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("OVMINES"), i, CGI->generaltexth->translate("core.minename", i));
  544. minesBox[i] = std::make_shared<InfoBox>(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data);
  545. minesBox[i]->removeUsedEvents(LCLICK|SHOW_POPUP); //fixes #890 - mines boxes ignore clicks
  546. }
  547. incomeArea = std::make_shared<CHoverableArea>();
  548. incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68);
  549. incomeArea->hoverText = CGI->generaltexth->allTexts[255];
  550. incomeAmount = std::make_shared<CLabel>(628, footerPos + 70, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, std::to_string(totalIncome));
  551. }
  552. void CKingdomInterface::generateButtons()
  553. {
  554. ui32 footerPos = OVERVIEW_SIZE * 116;
  555. //Main control buttons
  556. btnHeroes = std::make_shared<CButton>(Point(748, 28+footerPos), AnimationPath::builtin("OVBUTN1.DEF"), CButton::tooltip(CGI->generaltexth->overview[11], CGI->generaltexth->overview[6]),
  557. std::bind(&CKingdomInterface::activateTab, this, 0), EShortcut::KINGDOM_HEROES_TAB);
  558. btnHeroes->block(true);
  559. btnTowns = std::make_shared<CButton>(Point(748, 64+footerPos), AnimationPath::builtin("OVBUTN6.DEF"), CButton::tooltip(CGI->generaltexth->overview[12], CGI->generaltexth->overview[7]),
  560. std::bind(&CKingdomInterface::activateTab, this, 1), EShortcut::KINGDOM_TOWNS_TAB);
  561. btnExit = std::make_shared<CButton>(Point(748,99+footerPos), AnimationPath::builtin("OVBUTN1.DEF"), CButton::tooltip(CGI->generaltexth->allTexts[600]),
  562. std::bind(&CKingdomInterface::close, this), EShortcut::GLOBAL_RETURN);
  563. btnExit->setImageOrder(3, 4, 5, 6);
  564. //Object list control buttons
  565. dwellTop = std::make_shared<CButton>(Point(733, 4), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPos(0);});
  566. dwellBottom = std::make_shared<CButton>(Point(733, footerPos+2), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPos(-1); });
  567. dwellBottom->setImageOrder(2, 3, 4, 5);
  568. dwellUp = std::make_shared<CButton>(Point(733, 24), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPrev(); });
  569. dwellUp->setImageOrder(4, 5, 6, 7);
  570. dwellDown = std::make_shared<CButton>(Point(733, footerPos-18), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToNext(); });
  571. dwellDown->setImageOrder(6, 7, 8, 9);
  572. }
  573. void CKingdomInterface::activateTab(size_t which)
  574. {
  575. Settings s = persistentStorage.write["gui"]["lastKindomInterface"];
  576. s->Integer() = which;
  577. btnHeroes->block(which == 0);
  578. btnTowns->block(which == 1);
  579. tabArea->setActive(which);
  580. }
  581. void CKingdomInterface::buildChanged()
  582. {
  583. tabArea->reset();
  584. }
  585. void CKingdomInterface::townChanged(const CGTownInstance *town)
  586. {
  587. if(auto townList = std::dynamic_pointer_cast<CKingdTownList>(tabArea->getItem()))
  588. townList->townChanged(town);
  589. }
  590. void CKingdomInterface::heroRemoved()
  591. {
  592. tabArea->reset();
  593. }
  594. void CKingdomInterface::updateGarrisons()
  595. {
  596. if(auto garrison = std::dynamic_pointer_cast<IGarrisonHolder>(tabArea->getItem()))
  597. garrison->updateGarrisons();
  598. }
  599. bool CKingdomInterface::holdsGarrison(const CArmedInstance * army)
  600. {
  601. return army->getOwner() == LOCPLINT->playerID;
  602. }
  603. void CKingdomInterface::artifactAssembled(const ArtifactLocation& artLoc)
  604. {
  605. if(auto arts = std::dynamic_pointer_cast<CArtifactHolder>(tabArea->getItem()))
  606. arts->artifactAssembled(artLoc);
  607. }
  608. void CKingdomInterface::artifactDisassembled(const ArtifactLocation& artLoc)
  609. {
  610. if(auto arts = std::dynamic_pointer_cast<CArtifactHolder>(tabArea->getItem()))
  611. arts->artifactDisassembled(artLoc);
  612. }
  613. void CKingdomInterface::artifactMoved(const ArtifactLocation& artLoc, const ArtifactLocation& destLoc, bool withRedraw)
  614. {
  615. if(auto arts = std::dynamic_pointer_cast<CArtifactHolder>(tabArea->getItem()))
  616. arts->artifactMoved(artLoc, destLoc, withRedraw);
  617. }
  618. void CKingdomInterface::artifactRemoved(const ArtifactLocation& artLoc)
  619. {
  620. if(auto arts = std::dynamic_pointer_cast<CArtifactHolder>(tabArea->getItem()))
  621. arts->artifactRemoved(artLoc);
  622. }
  623. CKingdHeroList::CKingdHeroList(size_t maxSize)
  624. {
  625. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  626. title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"),16,0);
  627. title->colorize(LOCPLINT->playerID);
  628. heroLabel = std::make_shared<CLabel>(150, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[0]);
  629. skillsLabel = std::make_shared<CLabel>(500, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[1]);
  630. ui32 townCount = LOCPLINT->cb->howManyHeroes(false);
  631. ui32 size = OVERVIEW_SIZE*116 + 19;
  632. heroes = std::make_shared<CListBox>(std::bind(&CKingdHeroList::createHeroItem, this, _1),
  633. Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size));
  634. }
  635. void CKingdHeroList::updateGarrisons()
  636. {
  637. for(std::shared_ptr<CIntObject> object : heroes->getItems())
  638. {
  639. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  640. garrison->updateGarrisons();
  641. }
  642. }
  643. bool CKingdHeroList::holdsGarrison(const CArmedInstance * army)
  644. {
  645. for(std::shared_ptr<CIntObject> object : heroes->getItems())
  646. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  647. if (garrison->holdsGarrison(army))
  648. return true;
  649. return false;
  650. }
  651. void CKingdHeroList::deactivate()
  652. {
  653. CCS->curh->dragAndDropCursor(nullptr);
  654. CIntObject::deactivate();
  655. }
  656. std::shared_ptr<CIntObject> CKingdHeroList::createHeroItem(size_t index)
  657. {
  658. ui32 picCount = 4; // OVSLOT contains 4 images
  659. auto heroesList = LOCPLINT->localState->getWanderingHeroes();
  660. if(index < heroesList.size())
  661. {
  662. auto hero = std::make_shared<CHeroItem>(heroesList[index]);
  663. addSetAndCallbacks(hero->heroArts);
  664. return hero;
  665. }
  666. else
  667. {
  668. return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (index-2) % picCount );
  669. }
  670. }
  671. CKingdTownList::CKingdTownList(size_t maxSize)
  672. {
  673. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  674. title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"), 16, 0);
  675. title->colorize(LOCPLINT->playerID);
  676. townLabel = std::make_shared<CLabel>(146, 10,FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[3]);
  677. garrHeroLabel = std::make_shared<CLabel>(375, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[4]);
  678. visitHeroLabel = std::make_shared<CLabel>(608, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[5]);
  679. ui32 townCount = LOCPLINT->cb->howManyTowns();
  680. ui32 size = OVERVIEW_SIZE*116 + 19;
  681. towns = std::make_shared<CListBox>(std::bind(&CKingdTownList::createTownItem, this, _1),
  682. Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size));
  683. }
  684. void CKingdTownList::townChanged(const CGTownInstance * town)
  685. {
  686. for(std::shared_ptr<CIntObject> object : towns->getItems())
  687. {
  688. CTownItem * townItem = dynamic_cast<CTownItem *>(object.get());
  689. if(townItem && townItem->town == town)
  690. townItem->update();
  691. }
  692. }
  693. void CKingdTownList::updateGarrisons()
  694. {
  695. for(std::shared_ptr<CIntObject> object : towns->getItems())
  696. {
  697. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  698. garrison->updateGarrisons();
  699. }
  700. }
  701. bool CKingdTownList::holdsGarrison(const CArmedInstance * army)
  702. {
  703. for(std::shared_ptr<CIntObject> object : towns->getItems())
  704. if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
  705. if (garrison->holdsGarrison(army))
  706. return true;
  707. return false;
  708. }
  709. std::shared_ptr<CIntObject> CKingdTownList::createTownItem(size_t index)
  710. {
  711. ui32 picCount = 4; // OVSLOT contains 4 images
  712. auto townsList = LOCPLINT->localState->getOwnedTowns();
  713. if(index < townsList.size())
  714. return std::make_shared<CTownItem>(townsList[index]);
  715. else
  716. return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (index-2) % picCount );
  717. }
  718. CTownItem::CTownItem(const CGTownInstance * Town)
  719. : town(Town)
  720. {
  721. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  722. background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 6);
  723. name = std::make_shared<CLabel>(74, 8, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, town->getNameTranslated());
  724. income = std::make_shared<CLabel>( 190, 60, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string(town->dailyIncome()[EGameResID::GOLD]));
  725. hall = std::make_shared<CTownInfo>( 69, 31, town, true);
  726. fort = std::make_shared<CTownInfo>(111, 31, town, false);
  727. garr = std::make_shared<CGarrisonInt>(Point(313, 3), 4, Point(232,0), town->getUpperArmy(), town->visitingHero, true, true, CGarrisonInt::ESlotsLayout::TWO_ROWS);
  728. heroes = std::make_shared<HeroSlots>(town, Point(244,6), Point(475,6), garr, false);
  729. size_t iconIndex = town->town->clientInfo.icons[town->hasFort()][town->builded >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
  730. picture = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPT"), iconIndex, 0, 5, 6);
  731. openTown = std::make_shared<LRClickableAreaOpenTown>(Rect(5, 6, 58, 64), town);
  732. for(size_t i=0; i<town->creatures.size(); i++)
  733. {
  734. growth.push_back(std::make_shared<CCreaInfo>(Point(401+37*(int)i, 78), town, (int)i, true, true));
  735. available.push_back(std::make_shared<CCreaInfo>(Point(48+37*(int)i, 78), town, (int)i, true, false));
  736. }
  737. fastTownHall = std::make_shared<CButton>(Point(69, 31), AnimationPath::builtin("castleInterfaceQuickAccess"), CButton::tooltip(), [this]() { std::make_shared<CCastleBuildings>(town)->enterTownHall(); });
  738. fastTownHall->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("ITMTL"), town->hallLevel()));
  739. int imageIndex = town->fortLevel() == CGTownInstance::EFortLevel::NONE ? 3 : town->fortLevel() - 1;
  740. fastArmyPurchase = std::make_shared<CButton>(Point(111, 31), AnimationPath::builtin("castleInterfaceQuickAccess"), CButton::tooltip(), [this]() { std::make_shared<CCastleBuildings>(town)->enterToTheQuickRecruitmentWindow(); });
  741. fastArmyPurchase->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("itmcl"), imageIndex));
  742. fastTavern = std::make_shared<LRClickableArea>(Rect(5, 6, 58, 64), [&]()
  743. {
  744. if(town->builtBuildings.count(BuildingID::TAVERN))
  745. LOCPLINT->showTavernWindow(town, nullptr, QueryID::NONE);
  746. });
  747. fastMarket = std::make_shared<LRClickableArea>(Rect(153, 6, 65, 64), []()
  748. {
  749. std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
  750. for(auto & town : towns)
  751. {
  752. if(town->builtBuildings.count(BuildingID::MARKETPLACE))
  753. {
  754. GH.windows().createAndPushWindow<CMarketWindow>(town, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
  755. return;
  756. }
  757. }
  758. LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
  759. });
  760. fastTown = std::make_shared<LRClickableArea>(Rect(67, 6, 165, 20), [&]()
  761. {
  762. GH.windows().createAndPushWindow<CCastleInterface>(town);
  763. });
  764. }
  765. void CTownItem::updateGarrisons()
  766. {
  767. garr->selectSlot(nullptr);
  768. garr->setArmy(town->getUpperArmy(), EGarrisonType::UPPER);
  769. garr->setArmy(town->visitingHero, EGarrisonType::LOWER);
  770. garr->recreateSlots();
  771. }
  772. bool CTownItem::holdsGarrison(const CArmedInstance * army)
  773. {
  774. return army == town || army == town->getUpperArmy() || army == town->visitingHero;
  775. }
  776. void CTownItem::update()
  777. {
  778. std::string incomeVal = std::to_string(town->dailyIncome()[EGameResID::GOLD]);
  779. if (incomeVal != income->getText())
  780. income->setText(incomeVal);
  781. heroes->update();
  782. for (size_t i=0; i<town->creatures.size(); i++)
  783. {
  784. growth[i]->update();
  785. available[i]->update();
  786. }
  787. }
  788. class ArtSlotsTab : public CIntObject
  789. {
  790. public:
  791. std::shared_ptr<CAnimImage> background;
  792. std::vector<std::shared_ptr<CHeroArtPlace>> arts;
  793. ArtSlotsTab()
  794. {
  795. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  796. background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 4);
  797. pos = background->pos;
  798. for(int i=0; i<9; i++)
  799. arts.push_back(std::make_shared<CHeroArtPlace>(Point(269+i*48, 66)));
  800. }
  801. };
  802. class BackpackTab : public CIntObject
  803. {
  804. public:
  805. std::shared_ptr<CAnimImage> background;
  806. std::vector<std::shared_ptr<CHeroArtPlace>> arts;
  807. std::shared_ptr<CButton> btnLeft;
  808. std::shared_ptr<CButton> btnRight;
  809. BackpackTab()
  810. {
  811. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  812. background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 5);
  813. pos = background->pos;
  814. btnLeft = std::make_shared<CButton>(Point(269, 66), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), 0);
  815. btnRight = std::make_shared<CButton>(Point(675, 66), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), 0);
  816. for(int i=0; i<8; i++)
  817. arts.push_back(std::make_shared<CHeroArtPlace>(Point(294+i*48, 66)));
  818. }
  819. };
  820. CHeroItem::CHeroItem(const CGHeroInstance * Hero)
  821. : hero(Hero)
  822. {
  823. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  824. artTabs.resize(3);
  825. auto arts1 = std::make_shared<ArtSlotsTab>();
  826. auto arts2 = std::make_shared<ArtSlotsTab>();
  827. auto backpack = std::make_shared<BackpackTab>();
  828. artTabs[0] = arts1;
  829. artTabs[1] = arts2;
  830. artTabs[2] = backpack;
  831. arts1->recActions = SHARE_POS;
  832. arts2->recActions = SHARE_POS;
  833. backpack->recActions = SHARE_POS;
  834. name = std::make_shared<CLabel>(75, 7, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero->getNameTranslated());
  835. //layout is not trivial: MACH4 - catapult - excluded, MISC[x] rearranged
  836. assert(arts1->arts.size() == 9);
  837. assert(arts2->arts.size() == 9);
  838. CArtifactsOfHeroMain::ArtPlaceMap arts =
  839. {
  840. {ArtifactPosition::HEAD, arts1->arts[0]},
  841. {ArtifactPosition::SHOULDERS,arts1->arts[1]},
  842. {ArtifactPosition::NECK,arts1->arts[2]},
  843. {ArtifactPosition::RIGHT_HAND,arts1->arts[3]},
  844. {ArtifactPosition::LEFT_HAND,arts1->arts[4]},
  845. {ArtifactPosition::TORSO, arts1->arts[5]},
  846. {ArtifactPosition::RIGHT_RING,arts1->arts[6]},
  847. {ArtifactPosition::LEFT_RING, arts1->arts[7]},
  848. {ArtifactPosition::FEET, arts1->arts[8]},
  849. {ArtifactPosition::MISC1, arts2->arts[0]},
  850. {ArtifactPosition::MISC2, arts2->arts[1]},
  851. {ArtifactPosition::MISC3, arts2->arts[2]},
  852. {ArtifactPosition::MISC4, arts2->arts[3]},
  853. {ArtifactPosition::MISC5, arts2->arts[4]},
  854. {ArtifactPosition::MACH1, arts2->arts[5]},
  855. {ArtifactPosition::MACH2, arts2->arts[6]},
  856. {ArtifactPosition::MACH3, arts2->arts[7]},
  857. {ArtifactPosition::SPELLBOOK, arts2->arts[8]}
  858. };
  859. heroArts = std::make_shared<CArtifactsOfHeroKingdom>(arts, backpack->arts, backpack->btnLeft, backpack->btnRight);
  860. heroArts->setHero(hero);
  861. artsTabs = std::make_shared<CTabbedInt>(std::bind(&CHeroItem::onTabSelected, this, _1));
  862. artButtons = std::make_shared<CToggleGroup>(0);
  863. for(size_t it = 0; it<3; it++)
  864. {
  865. int stringID[3] = {259, 261, 262};
  866. std::string hover = CGI->generaltexth->overview[13+it];
  867. std::string overlay = CGI->generaltexth->overview[8+it];
  868. auto button = std::make_shared<CToggleButton>(Point(364+(int)it*112, 46), AnimationPath::builtin("OVBUTN3"), CButton::tooltip(hover, overlay), 0);
  869. button->setTextOverlay(CGI->generaltexth->allTexts[stringID[it]], FONT_SMALL, Colors::YELLOW);
  870. artButtons->addToggle((int)it, button);
  871. }
  872. artButtons->addCallback(std::bind(&CTabbedInt::setActive, artsTabs, _1));
  873. artButtons->addCallback(std::bind(&CHeroItem::onArtChange, this, _1));
  874. artButtons->setSelected(0);
  875. garr = std::make_shared<CGarrisonInt>(Point(6, 78), 4, Point(), hero, nullptr, true, true);
  876. portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero->getIconIndex(), 0, 5, 6);
  877. heroArea = std::make_shared<CHeroArea>(5, 6, hero);
  878. name = std::make_shared<CLabel>(73, 7, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero->getNameTranslated());
  879. artsText = std::make_shared<CLabel>(320, 55, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[2]);
  880. for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
  881. {
  882. auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_PRIMARY_SKILL, hero, (int)i);
  883. heroInfo.push_back(std::make_shared<InfoBox>(Point(78+(int)i*36, 26), InfoBox::POS_DOWN, InfoBox::SIZE_SMALL, data));
  884. }
  885. for(size_t i=0; i<GameConstants::SKILL_PER_HERO; i++)
  886. {
  887. auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_SECONDARY_SKILL, hero, (int)i);
  888. heroInfo.push_back(std::make_shared<InfoBox>(Point(410+(int)i*36, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL, data));
  889. }
  890. {
  891. auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_SPECIAL, hero);
  892. heroInfo.push_back(std::make_shared<InfoBox>(Point(375, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL, data));
  893. data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_EXPERIENCE, hero);
  894. heroInfo.push_back(std::make_shared<InfoBox>(Point(330, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data));
  895. data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_MANA, hero);
  896. heroInfo.push_back(std::make_shared<InfoBox>(Point(280, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data));
  897. }
  898. morale = std::make_shared<MoraleLuckBox>(true, Rect(225, 53, 30, 22), true);
  899. luck = std::make_shared<MoraleLuckBox>(false, Rect(225, 28, 30, 22), true);
  900. morale->set(hero);
  901. luck->set(hero);
  902. }
  903. void CHeroItem::updateGarrisons()
  904. {
  905. garr->recreateSlots();
  906. }
  907. bool CHeroItem::holdsGarrison(const CArmedInstance * army)
  908. {
  909. return hero == army;
  910. }
  911. std::shared_ptr<CIntObject> CHeroItem::onTabSelected(size_t index)
  912. {
  913. return artTabs.at(index);
  914. }
  915. void CHeroItem::onArtChange(int tabIndex)
  916. {
  917. //redraw item after background change
  918. if(isActive())
  919. redraw();
  920. }