2
0

MiscWidgets.cpp 18 KB

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