MiscWidgets.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*
  2. * MiscWidgets.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 "MiscWidgets.h"
  12. #include "CComponent.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../gui/CursorHandler.h"
  15. #include "../CPlayerInterface.h"
  16. #include "../CGameInfo.h"
  17. #include "../widgets/TextControls.h"
  18. #include "../widgets/CGarrisonInt.h"
  19. #include "../windows/CCastleInterface.h"
  20. #include "../windows/InfoWindows.h"
  21. #include "../render/Canvas.h"
  22. #include "../../CCallback.h"
  23. #include "../../lib/CConfigHandler.h"
  24. #include "../../lib/gameState/InfoAboutArmy.h"
  25. #include "../../lib/CGeneralTextHandler.h"
  26. #include "../../lib/GameSettings.h"
  27. #include "../../lib/TextOperations.h"
  28. #include "../../lib/mapObjects/CGHeroInstance.h"
  29. #include "../../lib/mapObjects/CGTownInstance.h"
  30. void CHoverableArea::hover (bool on)
  31. {
  32. if (on)
  33. GH.statusbar()->write(hoverText);
  34. else
  35. GH.statusbar()->clearIfMatching(hoverText);
  36. }
  37. CHoverableArea::CHoverableArea()
  38. {
  39. addUsedEvents(HOVER);
  40. }
  41. CHoverableArea::~CHoverableArea()
  42. {
  43. }
  44. void LRClickableAreaWText::clickPressed(const Point & cursorPosition)
  45. {
  46. if(!text.empty())
  47. LOCPLINT->showInfoDialog(text);
  48. }
  49. void LRClickableAreaWText::showPopupWindow(const Point & cursorPosition)
  50. {
  51. if (!text.empty())
  52. CRClickPopup::createAndPush(text);
  53. }
  54. LRClickableAreaWText::LRClickableAreaWText()
  55. {
  56. init();
  57. }
  58. LRClickableAreaWText::LRClickableAreaWText(const Rect &Pos, const std::string &HoverText, const std::string &ClickText)
  59. {
  60. init();
  61. pos = Pos + pos.topLeft();
  62. hoverText = HoverText;
  63. text = ClickText;
  64. }
  65. LRClickableAreaWText::~LRClickableAreaWText()
  66. {
  67. }
  68. void LRClickableAreaWText::init()
  69. {
  70. addUsedEvents(LCLICK | SHOW_POPUP | HOVER);
  71. }
  72. void LRClickableAreaWTextComp::clickPressed(const Point & cursorPosition)
  73. {
  74. std::vector<std::shared_ptr<CComponent>> comp(1, createComponent());
  75. LOCPLINT->showInfoDialog(text, comp);
  76. }
  77. LRClickableAreaWTextComp::LRClickableAreaWTextComp(const Rect &Pos, int BaseType)
  78. : LRClickableAreaWText(Pos), baseType(BaseType), bonusValue(-1)
  79. {
  80. type = -1;
  81. }
  82. std::shared_ptr<CComponent> LRClickableAreaWTextComp::createComponent() const
  83. {
  84. if(baseType >= 0)
  85. return std::make_shared<CComponent>(CComponent::Etype(baseType), type, bonusValue);
  86. else
  87. return std::shared_ptr<CComponent>();
  88. }
  89. void LRClickableAreaWTextComp::showPopupWindow(const Point & cursorPosition)
  90. {
  91. if(auto comp = createComponent())
  92. {
  93. CRClickPopup::createAndPush(text, CInfoWindow::TCompsInfo(1, comp));
  94. return;
  95. }
  96. LRClickableAreaWText::showPopupWindow(cursorPosition); //only if with-component variant not occurred
  97. }
  98. CHeroArea::CHeroArea(int x, int y, const CGHeroInstance * hero)
  99. : CIntObject(LCLICK | HOVER),
  100. hero(hero),
  101. clickFunctor(nullptr)
  102. {
  103. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  104. pos.x += x;
  105. pos.w = 58;
  106. pos.y += y;
  107. pos.h = 64;
  108. if(hero)
  109. {
  110. portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero->portrait);
  111. clickFunctor = [hero]() -> void
  112. {
  113. LOCPLINT->openHeroWindow(hero);
  114. };
  115. }
  116. }
  117. void CHeroArea::addClickCallback(ClickFunctor callback)
  118. {
  119. clickFunctor = callback;
  120. }
  121. void CHeroArea::clickPressed(const Point & cursorPosition)
  122. {
  123. if(clickFunctor)
  124. clickFunctor();
  125. }
  126. void CHeroArea::hover(bool on)
  127. {
  128. if (on && hero)
  129. GH.statusbar()->write(hero->getObjectName());
  130. else
  131. GH.statusbar()->clear();
  132. }
  133. void LRClickableAreaOpenTown::clickPressed(const Point & cursorPosition)
  134. {
  135. if(town)
  136. {
  137. LOCPLINT->openTownWindow(town);
  138. if ( type == 2 )
  139. LOCPLINT->castleInt->builds->buildingClicked(BuildingID::VILLAGE_HALL);
  140. else if ( type == 3 && town->fortLevel() )
  141. LOCPLINT->castleInt->builds->buildingClicked(BuildingID::FORT);
  142. }
  143. }
  144. LRClickableAreaOpenTown::LRClickableAreaOpenTown(const Rect & Pos, const CGTownInstance * Town)
  145. : LRClickableAreaWTextComp(Pos, -1), town(Town)
  146. {
  147. }
  148. void CMinorResDataBar::show(Canvas & to)
  149. {
  150. }
  151. std::string CMinorResDataBar::buildDateString()
  152. {
  153. std::string pattern = "%s: %d, %s: %d, %s: %d";
  154. auto formatted = boost::format(pattern)
  155. % CGI->generaltexth->translate("core.genrltxt.62") % LOCPLINT->cb->getDate(Date::MONTH)
  156. % CGI->generaltexth->translate("core.genrltxt.63") % LOCPLINT->cb->getDate(Date::WEEK)
  157. % CGI->generaltexth->translate("core.genrltxt.64") % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
  158. return boost::str(formatted);
  159. }
  160. void CMinorResDataBar::showAll(Canvas & to)
  161. {
  162. CIntObject::showAll(to);
  163. for (GameResID i=EGameResID::WOOD; i<=EGameResID::GOLD; ++i)
  164. {
  165. std::string text = std::to_string(LOCPLINT->cb->getResourceAmount(i));
  166. Point target(pos.x + 50 + 76 * GameResID(i), pos.y + pos.h/2);
  167. to.drawText(target, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, text);
  168. }
  169. Point target(pos.x+545+(pos.w-545)/2,pos.y+pos.h/2);
  170. to.drawText(target, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, buildDateString());
  171. }
  172. CMinorResDataBar::CMinorResDataBar()
  173. {
  174. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  175. pos.x = 7;
  176. pos.y = 575;
  177. background = std::make_shared<CPicture>(ImagePath::builtin("KRESBAR.bmp"));
  178. background->colorize(LOCPLINT->playerID);
  179. pos.w = background->pos.w;
  180. pos.h = background->pos.h;
  181. }
  182. CMinorResDataBar::~CMinorResDataBar() = default;
  183. void CArmyTooltip::init(const InfoAboutArmy &army)
  184. {
  185. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  186. title = std::make_shared<CLabel>(66, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, army.name);
  187. std::vector<Point> slotsPos;
  188. slotsPos.push_back(Point(36, 73));
  189. slotsPos.push_back(Point(72, 73));
  190. slotsPos.push_back(Point(108, 73));
  191. slotsPos.push_back(Point(18, 122));
  192. slotsPos.push_back(Point(54, 122));
  193. slotsPos.push_back(Point(90, 122));
  194. slotsPos.push_back(Point(126, 122));
  195. for(auto & slot : army.army)
  196. {
  197. if(slot.first.getNum() >= GameConstants::ARMY_SIZE)
  198. {
  199. logGlobal->warn("%s has stack in slot %d", army.name, slot.first.getNum());
  200. continue;
  201. }
  202. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("CPRSMALL"), slot.second.type->getIconIndex(), 0, slotsPos[slot.first.getNum()].x, slotsPos[slot.first.getNum()].y));
  203. std::string subtitle;
  204. if(army.army.isDetailed)
  205. {
  206. subtitle = TextOperations::formatMetric(slot.second.count, 4);
  207. }
  208. else
  209. {
  210. //if =0 - we have no information about stack size at all
  211. if(slot.second.count)
  212. {
  213. if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
  214. {
  215. subtitle = CCreature::getQuantityRangeStringForId((CCreature::CreatureQuantityId)slot.second.count);
  216. }
  217. else
  218. {
  219. subtitle = CGI->generaltexth->arraytxt[171 + 3*(slot.second.count)];
  220. }
  221. }
  222. }
  223. subtitles.push_back(std::make_shared<CLabel>(slotsPos[slot.first.getNum()].x + 17, slotsPos[slot.first.getNum()].y + 39, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, subtitle));
  224. }
  225. }
  226. CArmyTooltip::CArmyTooltip(Point pos, const InfoAboutArmy & army):
  227. CIntObject(0, pos)
  228. {
  229. init(army);
  230. }
  231. CArmyTooltip::CArmyTooltip(Point pos, const CArmedInstance * army):
  232. CIntObject(0, pos)
  233. {
  234. init(InfoAboutArmy(army, true));
  235. }
  236. void CHeroTooltip::init(const InfoAboutHero & hero)
  237. {
  238. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  239. portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero.portrait, 0, 3, 2);
  240. if(hero.details)
  241. {
  242. for(size_t i = 0; i < hero.details->primskills.size(); i++)
  243. labels.push_back(std::make_shared<CLabel>(75 + 28 * (int)i, 58, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE,
  244. std::to_string(hero.details->primskills[i])));
  245. labels.push_back(std::make_shared<CLabel>(158, 98, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, std::to_string(hero.details->mana)));
  246. morale = std::make_shared<CAnimImage>(AnimationPath::builtin("IMRL22"), hero.details->morale + 3, 0, 5, 74);
  247. luck = std::make_shared<CAnimImage>(AnimationPath::builtin("ILCK22"), hero.details->luck + 3, 0, 5, 91);
  248. }
  249. }
  250. CHeroTooltip::CHeroTooltip(Point pos, const InfoAboutHero &hero):
  251. CArmyTooltip(pos, hero)
  252. {
  253. init(hero);
  254. }
  255. CHeroTooltip::CHeroTooltip(Point pos, const CGHeroInstance * hero):
  256. CArmyTooltip(pos, InfoAboutHero(hero, InfoAboutHero::EInfoLevel::DETAILED))
  257. {
  258. init(InfoAboutHero(hero, InfoAboutHero::EInfoLevel::DETAILED));
  259. }
  260. CInteractableHeroTooltip::CInteractableHeroTooltip(Point pos, const CGHeroInstance * hero)
  261. {
  262. init(InfoAboutHero(hero, InfoAboutHero::EInfoLevel::DETAILED));
  263. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  264. garrison = std::make_shared<CGarrisonInt>(pos + Point(0, 73), 4, Point(0, 0), hero, nullptr, true, true, CGarrisonInt::ESlotsLayout::REVERSED_TWO_ROWS);
  265. }
  266. void CInteractableHeroTooltip::init(const InfoAboutHero & hero)
  267. {
  268. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  269. portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero.portrait, 0, 3, 2);
  270. title = std::make_shared<CLabel>(66, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero.name);
  271. if(hero.details)
  272. {
  273. for(size_t i = 0; i < hero.details->primskills.size(); i++)
  274. labels.push_back(std::make_shared<CLabel>(75 + 28 * (int)i, 58, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE,
  275. std::to_string(hero.details->primskills[i])));
  276. labels.push_back(std::make_shared<CLabel>(158, 98, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, std::to_string(hero.details->mana)));
  277. morale = std::make_shared<CAnimImage>(AnimationPath::builtin("IMRL22"), hero.details->morale + 3, 0, 5, 74);
  278. luck = std::make_shared<CAnimImage>(AnimationPath::builtin("ILCK22"), hero.details->luck + 3, 0, 5, 91);
  279. }
  280. }
  281. void CTownTooltip::init(const InfoAboutTown & town)
  282. {
  283. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  284. //order of icons in def: fort, citadel, castle, no fort
  285. size_t fortIndex = town.fortLevel ? town.fortLevel - 1 : 3;
  286. fort = std::make_shared<CAnimImage>(AnimationPath::builtin("ITMCLS"), fortIndex, 0, 105, 31);
  287. assert(town.tType);
  288. size_t iconIndex = town.tType->clientInfo.icons[town.fortLevel > 0][town.built >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
  289. build = std::make_shared<CAnimImage>(AnimationPath::builtin("itpt"), iconIndex, 0, 3, 2);
  290. if(town.details)
  291. {
  292. hall = std::make_shared<CAnimImage>(AnimationPath::builtin("ITMTLS"), town.details->hallLevel, 0, 67, 31);
  293. if(town.details->goldIncome)
  294. {
  295. income = std::make_shared<CLabel>(157, 58, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE,
  296. std::to_string(town.details->goldIncome));
  297. }
  298. if(town.details->garrisonedHero) //garrisoned hero icon
  299. garrisonedHero = std::make_shared<CPicture>(ImagePath::builtin("TOWNQKGH"), 149, 76);
  300. if(town.details->customRes)//silo is built
  301. {
  302. if(town.tType->primaryRes == EGameResID::WOOD_AND_ORE )// wood & ore
  303. {
  304. res1 = std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), GameResID(EGameResID::WOOD), 0, 7, 75);
  305. res2 = std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), GameResID(EGameResID::ORE), 0, 7, 88);
  306. }
  307. else
  308. {
  309. res1 = std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), town.tType->primaryRes, 0, 7, 81);
  310. }
  311. }
  312. }
  313. }
  314. CTownTooltip::CTownTooltip(Point pos, const InfoAboutTown & town)
  315. : CArmyTooltip(pos, town)
  316. {
  317. init(town);
  318. }
  319. CTownTooltip::CTownTooltip(Point pos, const CGTownInstance * town)
  320. : CArmyTooltip(pos, InfoAboutTown(town, true))
  321. {
  322. init(InfoAboutTown(town, true));
  323. }
  324. CInteractableTownTooltip::CInteractableTownTooltip(Point pos, const CGTownInstance * town)
  325. {
  326. init(InfoAboutTown(town, true));
  327. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  328. garrison = std::make_shared<CGarrisonInt>(pos + Point(0, 73), 4, Point(0, 0), town->getUpperArmy(), nullptr, true, true, CGarrisonInt::ESlotsLayout::REVERSED_TWO_ROWS);
  329. }
  330. void CInteractableTownTooltip::init(const InfoAboutTown & town)
  331. {
  332. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  333. //order of icons in def: fort, citadel, castle, no fort
  334. size_t fortIndex = town.fortLevel ? town.fortLevel - 1 : 3;
  335. fort = std::make_shared<CAnimImage>(AnimationPath::builtin("ITMCLS"), fortIndex, 0, 105, 31);
  336. assert(town.tType);
  337. size_t iconIndex = town.tType->clientInfo.icons[town.fortLevel > 0][town.built >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
  338. build = std::make_shared<CAnimImage>(AnimationPath::builtin("itpt"), iconIndex, 0, 3, 2);
  339. title = std::make_shared<CLabel>(66, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, town.name);
  340. if(town.details)
  341. {
  342. hall = std::make_shared<CAnimImage>(AnimationPath::builtin("ITMTLS"), town.details->hallLevel, 0, 67, 31);
  343. if(town.details->goldIncome)
  344. {
  345. income = std::make_shared<CLabel>(157, 58, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE,
  346. std::to_string(town.details->goldIncome));
  347. }
  348. if(town.details->garrisonedHero) //garrisoned hero icon
  349. garrisonedHero = std::make_shared<CPicture>(ImagePath::builtin("TOWNQKGH"), 149, 76);
  350. if(town.details->customRes)//silo is built
  351. {
  352. if(town.tType->primaryRes == EGameResID::WOOD_AND_ORE )// wood & ore
  353. {
  354. res1 = std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), GameResID(EGameResID::WOOD), 0, 7, 75);
  355. res2 = std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), GameResID(EGameResID::ORE), 0, 7, 88);
  356. }
  357. else
  358. {
  359. res1 = std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), town.tType->primaryRes, 0, 7, 81);
  360. }
  361. }
  362. }
  363. }
  364. void MoraleLuckBox::set(const AFactionMember * node)
  365. {
  366. OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
  367. const int textId[] = {62, 88}; //eg %s \n\n\n {Current Luck Modifiers:}
  368. const int noneTxtId = 108; //Russian version uses same text for neutral morale\luck
  369. const int neutralDescr[] = {60, 86}; //eg {Neutral Morale} \n\n Neutral morale means your armies will neither be blessed with extra attacks or freeze in combat.
  370. const int componentType[] = {CComponent::luck, CComponent::morale};
  371. const int hoverTextBase[] = {7, 4};
  372. TConstBonusListPtr modifierList = std::make_shared<const BonusList>();
  373. bonusValue = 0;
  374. if(node)
  375. bonusValue = morale ? node->moraleValAndBonusList(modifierList) : node->luckValAndBonusList(modifierList);
  376. int mrlt = (bonusValue>0)-(bonusValue<0); //signum: -1 - bad luck / morale, 0 - neutral, 1 - good
  377. hoverText = CGI->generaltexth->heroscrn[hoverTextBase[morale] - mrlt];
  378. baseType = componentType[morale];
  379. text = CGI->generaltexth->arraytxt[textId[morale]];
  380. boost::algorithm::replace_first(text,"%s",CGI->generaltexth->arraytxt[neutralDescr[morale]-mrlt]);
  381. if (morale && node && (node->getBonusBearer()->hasBonusOfType(BonusType::UNDEAD)
  382. || node->getBonusBearer()->hasBonusOfType(BonusType::NON_LIVING)))
  383. {
  384. text += CGI->generaltexth->arraytxt[113]; //unaffected by morale
  385. bonusValue = 0;
  386. }
  387. else if(morale && node && node->getBonusBearer()->hasBonusOfType(BonusType::NO_MORALE))
  388. {
  389. auto noMorale = node->getBonusBearer()->getBonus(Selector::type()(BonusType::NO_MORALE));
  390. text += "\n" + noMorale->Description();
  391. bonusValue = 0;
  392. }
  393. else if (!morale && node && node->getBonusBearer()->hasBonusOfType(BonusType::NO_LUCK))
  394. {
  395. auto noLuck = node->getBonusBearer()->getBonus(Selector::type()(BonusType::NO_LUCK));
  396. text += "\n" + noLuck->Description();
  397. bonusValue = 0;
  398. }
  399. else
  400. {
  401. std::string addInfo = "";
  402. for(auto & bonus : * modifierList)
  403. {
  404. if(bonus->val)
  405. addInfo += "\n" + bonus->Description();
  406. }
  407. text = addInfo.empty()
  408. ? text + CGI->generaltexth->arraytxt[noneTxtId]
  409. : text + addInfo;
  410. }
  411. std::string imageName;
  412. if (small)
  413. imageName = morale ? "IMRL30": "ILCK30";
  414. else
  415. imageName = morale ? "IMRL42" : "ILCK42";
  416. image = std::make_shared<CAnimImage>(AnimationPath::builtin(imageName), bonusValue + 3);
  417. image->moveBy(Point(pos.w/2 - image->pos.w/2, pos.h/2 - image->pos.h/2));//center icon
  418. }
  419. MoraleLuckBox::MoraleLuckBox(bool Morale, const Rect &r, bool Small)
  420. : morale(Morale),
  421. small(Small)
  422. {
  423. bonusValue = 0;
  424. pos = r + pos.topLeft();
  425. defActions = 255-DISPOSE;
  426. }
  427. CCreaturePic::CCreaturePic(int x, int y, const CCreature * cre, bool Big, bool Animated)
  428. {
  429. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  430. pos.x+=x;
  431. pos.y+=y;
  432. auto faction = cre->getFaction();
  433. assert(CGI->townh->size() > faction);
  434. if(Big)
  435. bg = std::make_shared<CPicture>((*CGI->townh)[faction]->creatureBg130);
  436. else
  437. bg = std::make_shared<CPicture>((*CGI->townh)[faction]->creatureBg120);
  438. anim = std::make_shared<CCreatureAnim>(0, 0, cre->animDefName);
  439. anim->clipRect(cre->isDoubleWide()?170:150, 155, bg->pos.w, bg->pos.h);
  440. anim->startPreview(cre->hasBonusOfType(BonusType::SIEGE_WEAPON));
  441. amount = std::make_shared<CLabel>(bg->pos.w, bg->pos.h, FONT_MEDIUM, ETextAlignment::BOTTOMRIGHT, Colors::WHITE);
  442. pos.w = bg->pos.w;
  443. pos.h = bg->pos.h;
  444. }
  445. void CCreaturePic::show(Canvas & to)
  446. {
  447. // redraw everything in a proper order
  448. bg->showAll(to);
  449. anim->show(to);
  450. amount->showAll(to);
  451. }
  452. void CCreaturePic::setAmount(int newAmount)
  453. {
  454. if(newAmount != 0)
  455. amount->setText(std::to_string(newAmount));
  456. else
  457. amount->setText("");
  458. }