CKingdomInterface.cpp 36 KB

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