CKingdomInterface.cpp 34 KB

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