BattleInterfaceClasses.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /*
  2. * BattleInterfaceClasses.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 "BattleInterfaceClasses.h"
  12. #include "BattleInterface.h"
  13. #include "BattleActionsController.h"
  14. #include "BattleRenderer.h"
  15. #include "BattleSiegeController.h"
  16. #include "BattleFieldController.h"
  17. #include "BattleStacksController.h"
  18. #include "BattleWindow.h"
  19. #include "../CGameInfo.h"
  20. #include "../CPlayerInterface.h"
  21. #include "../gui/CursorHandler.h"
  22. #include "../gui/CGuiHandler.h"
  23. #include "../gui/Shortcut.h"
  24. #include "../gui/MouseButton.h"
  25. #include "../gui/WindowHandler.h"
  26. #include "../media/IMusicPlayer.h"
  27. #include "../render/Canvas.h"
  28. #include "../render/IImage.h"
  29. #include "../render/IFont.h"
  30. #include "../render/Graphics.h"
  31. #include "../widgets/Buttons.h"
  32. #include "../widgets/Images.h"
  33. #include "../widgets/Slider.h"
  34. #include "../widgets/TextControls.h"
  35. #include "../widgets/VideoWidget.h"
  36. #include "../widgets/GraphicalPrimitiveCanvas.h"
  37. #include "../windows/CMessage.h"
  38. #include "../windows/CCreatureWindow.h"
  39. #include "../windows/CSpellWindow.h"
  40. #include "../render/CAnimation.h"
  41. #include "../render/IRenderHandler.h"
  42. #include "../adventureMap/CInGameConsole.h"
  43. #include "../../CCallback.h"
  44. #include "../../lib/CStack.h"
  45. #include "../../lib/CConfigHandler.h"
  46. #include "../../lib/CCreatureHandler.h"
  47. #include "../../lib/gameState/InfoAboutArmy.h"
  48. #include "../../lib/CGeneralTextHandler.h"
  49. #include "../../lib/CTownHandler.h"
  50. #include "../../lib/CHeroHandler.h"
  51. #include "../../lib/StartInfo.h"
  52. #include "../../lib/CondSh.h"
  53. #include "../../lib/mapObjects/CGTownInstance.h"
  54. #include "../../lib/networkPacks/PacksForClientBattle.h"
  55. #include "../../lib/TextOperations.h"
  56. void BattleConsole::showAll(Canvas & to)
  57. {
  58. CIntObject::showAll(to);
  59. Point line1 (pos.x + pos.w/2, pos.y + 8);
  60. Point line2 (pos.x + pos.w/2, pos.y + 24);
  61. auto visibleText = getVisibleText();
  62. if(visibleText.size() > 0)
  63. to.drawText(line1, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, visibleText[0]);
  64. if(visibleText.size() > 1)
  65. to.drawText(line2, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, visibleText[1]);
  66. }
  67. std::vector<std::string> BattleConsole::getVisibleText()
  68. {
  69. // high priority texts that hide battle log entries
  70. for(const auto & text : {consoleText, hoverText})
  71. {
  72. if (text.empty())
  73. continue;
  74. auto result = CMessage::breakText(text, pos.w, FONT_SMALL);
  75. if(result.size() > 2)
  76. result.resize(2);
  77. return result;
  78. }
  79. // log is small enough to fit entirely - display it as such
  80. if (logEntries.size() < 3)
  81. return logEntries;
  82. return { logEntries[scrollPosition - 1], logEntries[scrollPosition] };
  83. }
  84. std::vector<std::string> BattleConsole::splitText(const std::string &text)
  85. {
  86. std::vector<std::string> lines;
  87. std::vector<std::string> output;
  88. boost::split(lines, text, boost::is_any_of("\n"));
  89. for(const auto & line : lines)
  90. {
  91. if (graphics->fonts[FONT_SMALL]->getStringWidth(text) < pos.w)
  92. {
  93. output.push_back(line);
  94. }
  95. else
  96. {
  97. std::vector<std::string> substrings = CMessage::breakText(line, pos.w, FONT_SMALL);
  98. output.insert(output.end(), substrings.begin(), substrings.end());
  99. }
  100. }
  101. return output;
  102. }
  103. bool BattleConsole::addText(const std::string & text)
  104. {
  105. logGlobal->trace("CBattleConsole message: %s", text);
  106. auto newLines = splitText(text);
  107. logEntries.insert(logEntries.end(), newLines.begin(), newLines.end());
  108. scrollPosition = (int)logEntries.size()-1;
  109. redraw();
  110. return true;
  111. }
  112. void BattleConsole::scrollUp(ui32 by)
  113. {
  114. if(scrollPosition > static_cast<int>(by))
  115. scrollPosition -= by;
  116. redraw();
  117. }
  118. void BattleConsole::scrollDown(ui32 by)
  119. {
  120. if(scrollPosition + by < logEntries.size())
  121. scrollPosition += by;
  122. redraw();
  123. }
  124. BattleConsole::BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size)
  125. : CIntObject(LCLICK)
  126. , owner(owner)
  127. , scrollPosition(-1)
  128. , enteringText(false)
  129. {
  130. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  131. pos += objectPos;
  132. pos.w = size.x;
  133. pos.h = size.y;
  134. background = std::make_shared<CPicture>(backgroundSource->getSurface(), Rect(imagePos, size), 0, 0 );
  135. }
  136. void BattleConsole::deactivate()
  137. {
  138. if (enteringText)
  139. LOCPLINT->cingconsole->endEnteringText(false);
  140. CIntObject::deactivate();
  141. }
  142. void BattleConsole::clickPressed(const Point & cursorPosition)
  143. {
  144. if(owner.makingTurn() && !owner.openingPlaying())
  145. {
  146. GH.windows().createAndPushWindow<BattleConsoleWindow>(boost::algorithm::join(logEntries, "\n"));
  147. }
  148. }
  149. void BattleConsole::setEnteringMode(bool on)
  150. {
  151. consoleText.clear();
  152. if (on)
  153. {
  154. assert(enteringText == false);
  155. GH.startTextInput(pos);
  156. }
  157. else
  158. {
  159. assert(enteringText == true);
  160. GH.stopTextInput();
  161. }
  162. enteringText = on;
  163. redraw();
  164. }
  165. void BattleConsole::setEnteredText(const std::string & text)
  166. {
  167. assert(enteringText == true);
  168. consoleText = text;
  169. redraw();
  170. }
  171. void BattleConsole::write(const std::string & Text)
  172. {
  173. hoverText = Text;
  174. redraw();
  175. }
  176. void BattleConsole::clearIfMatching(const std::string & Text)
  177. {
  178. if (hoverText == Text)
  179. clear();
  180. }
  181. void BattleConsole::clear()
  182. {
  183. write({});
  184. }
  185. BattleConsoleWindow::BattleConsoleWindow(const std::string & text)
  186. : CWindowObject(BORDERED)
  187. {
  188. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  189. pos.w = 429;
  190. pos.h = 434;
  191. updateShadow();
  192. center();
  193. backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
  194. buttonOk = std::make_shared<CButton>(Point(183, 388), AnimationPath::builtin("IOKAY"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT);
  195. Rect textArea(18, 17, 393, 354);
  196. textBoxBackgroundBorder = std::make_shared<TransparentFilledRectangle>(textArea, ColorRGBA(0, 0, 0, 75), ColorRGBA(128, 100, 75));
  197. textBox = std::make_shared<CTextBox>(text, textArea.resize(-5), CSlider::BROWN);
  198. if(textBox->slider)
  199. textBox->slider->scrollToMax();
  200. }
  201. const CGHeroInstance * BattleHero::instance()
  202. {
  203. return hero;
  204. }
  205. void BattleHero::tick(uint32_t msPassed)
  206. {
  207. size_t groupIndex = static_cast<size_t>(phase);
  208. float timePassed = msPassed / 1000.f;
  209. flagCurrentFrame += currentSpeed * timePassed;
  210. currentFrame += currentSpeed * timePassed;
  211. if(flagCurrentFrame >= flagAnimation->size(0))
  212. flagCurrentFrame -= flagAnimation->size(0);
  213. if(currentFrame >= animation->size(groupIndex))
  214. {
  215. currentFrame -= animation->size(groupIndex);
  216. switchToNextPhase();
  217. }
  218. }
  219. void BattleHero::render(Canvas & canvas)
  220. {
  221. size_t groupIndex = static_cast<size_t>(phase);
  222. auto flagFrame = flagAnimation->getImage(flagCurrentFrame, 0, true);
  223. auto heroFrame = animation->getImage(currentFrame, groupIndex, true);
  224. Point heroPosition = pos.center() - parent->pos.topLeft() - heroFrame->dimensions() / 2;
  225. Point flagPosition = pos.center() - parent->pos.topLeft() - flagFrame->dimensions() / 2;
  226. if(defender)
  227. flagPosition += Point(-4, -41);
  228. else
  229. flagPosition += Point(4, -41);
  230. canvas.draw(flagFrame, flagPosition);
  231. canvas.draw(heroFrame, heroPosition);
  232. }
  233. void BattleHero::pause()
  234. {
  235. currentSpeed = 0.f;
  236. }
  237. void BattleHero::play()
  238. {
  239. //H3 speed: 10 fps ( 100 ms per frame)
  240. currentSpeed = 10.f;
  241. }
  242. float BattleHero::getFrame() const
  243. {
  244. return currentFrame;
  245. }
  246. void BattleHero::collectRenderableObjects(BattleRenderer & renderer)
  247. {
  248. auto hex = defender ? BattleHex(GameConstants::BFIELD_WIDTH-1) : BattleHex(0);
  249. renderer.insert(EBattleFieldLayer::HEROES, hex, [this](BattleRenderer::RendererRef canvas)
  250. {
  251. render(canvas);
  252. });
  253. }
  254. void BattleHero::onPhaseFinished(const std::function<void()> & callback)
  255. {
  256. phaseFinishedCallback = callback;
  257. }
  258. void BattleHero::setPhase(EHeroAnimType newPhase)
  259. {
  260. nextPhase = newPhase;
  261. switchToNextPhase(); //immediately switch to next phase and then restore idling phase
  262. nextPhase = EHeroAnimType::HOLDING;
  263. }
  264. void BattleHero::heroLeftClicked()
  265. {
  266. if(owner.actionsController->spellcastingModeActive()) //we are casting a spell
  267. return;
  268. if(!hero || !owner.makingTurn())
  269. return;
  270. if(owner.getBattle()->battleCanCastSpell(hero, spells::Mode::HERO) == ESpellCastProblem::OK) //check conditions
  271. {
  272. CCS->curh->set(Cursor::Map::POINTER);
  273. GH.windows().createAndPushWindow<CSpellWindow>(hero, owner.getCurrentPlayerInterface());
  274. }
  275. }
  276. void BattleHero::heroRightClicked()
  277. {
  278. if(settings["battle"]["stickyHeroInfoWindows"].Bool())
  279. return;
  280. Point windowPosition;
  281. if(GH.screenDimensions().x < 1000)
  282. {
  283. windowPosition.x = (!defender) ? owner.fieldController->pos.left() + 1 : owner.fieldController->pos.right() - 79;
  284. windowPosition.y = owner.fieldController->pos.y + 135;
  285. }
  286. else
  287. {
  288. windowPosition.x = (!defender) ? owner.fieldController->pos.left() - 93 : owner.fieldController->pos.right() + 15;
  289. windowPosition.y = owner.fieldController->pos.y;
  290. }
  291. InfoAboutHero targetHero;
  292. if(owner.makingTurn() || settings["session"]["spectate"].Bool())
  293. {
  294. auto h = defender ? owner.defendingHeroInstance : owner.attackingHeroInstance;
  295. targetHero.initFromHero(h, InfoAboutHero::EInfoLevel::INBATTLE);
  296. GH.windows().createAndPushWindow<HeroInfoWindow>(targetHero, &windowPosition);
  297. }
  298. }
  299. void BattleHero::switchToNextPhase()
  300. {
  301. phase = nextPhase;
  302. currentFrame = 0.f;
  303. auto copy = phaseFinishedCallback;
  304. phaseFinishedCallback.clear();
  305. copy();
  306. }
  307. BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender):
  308. defender(defender),
  309. hero(hero),
  310. owner(owner),
  311. phase(EHeroAnimType::HOLDING),
  312. nextPhase(EHeroAnimType::HOLDING),
  313. currentSpeed(0.f),
  314. currentFrame(0.f),
  315. flagCurrentFrame(0.f)
  316. {
  317. AnimationPath animationPath;
  318. if(!hero->type->battleImage.empty())
  319. animationPath = hero->type->battleImage;
  320. else
  321. if(hero->gender == EHeroGender::FEMALE)
  322. animationPath = hero->type->heroClass->imageBattleFemale;
  323. else
  324. animationPath = hero->type->heroClass->imageBattleMale;
  325. animation = GH.renderHandler().loadAnimation(animationPath);
  326. animation->preload();
  327. pos.w = 64;
  328. pos.h = 136;
  329. pos.x = owner.fieldController->pos.x + (defender ? (owner.fieldController->pos.w - pos.w) : 0);
  330. pos.y = owner.fieldController->pos.y;
  331. if(defender)
  332. animation->verticalFlip();
  333. if(defender)
  334. flagAnimation = GH.renderHandler().loadAnimation(AnimationPath::builtin("CMFLAGR"));
  335. else
  336. flagAnimation = GH.renderHandler().loadAnimation(AnimationPath::builtin("CMFLAGL"));
  337. flagAnimation->preload();
  338. flagAnimation->playerColored(hero->tempOwner);
  339. switchToNextPhase();
  340. play();
  341. addUsedEvents(TIME);
  342. }
  343. HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, Point * position, bool initializeBackground)
  344. : CIntObject(0)
  345. {
  346. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  347. if (position != nullptr)
  348. moveTo(*position);
  349. if(initializeBackground)
  350. {
  351. background = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
  352. background->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
  353. background->colorize(hero.owner);
  354. }
  355. initializeData(hero);
  356. }
  357. void HeroInfoBasicPanel::initializeData(const InfoAboutHero & hero)
  358. {
  359. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  360. auto attack = hero.details->primskills[0];
  361. auto defense = hero.details->primskills[1];
  362. auto power = hero.details->primskills[2];
  363. auto knowledge = hero.details->primskills[3];
  364. auto morale = hero.details->morale;
  365. auto luck = hero.details->luck;
  366. auto currentSpellPoints = hero.details->mana;
  367. auto maxSpellPoints = hero.details->manaLimit;
  368. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero.getIconIndex(), 0, 10, 6));
  369. //primary stats
  370. labels.push_back(std::make_shared<CLabel>(9, 75, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[380] + ":"));
  371. labels.push_back(std::make_shared<CLabel>(9, 87, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[381] + ":"));
  372. labels.push_back(std::make_shared<CLabel>(9, 99, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[382] + ":"));
  373. labels.push_back(std::make_shared<CLabel>(9, 111, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[383] + ":"));
  374. labels.push_back(std::make_shared<CLabel>(69, 87, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(attack)));
  375. labels.push_back(std::make_shared<CLabel>(69, 99, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(defense)));
  376. labels.push_back(std::make_shared<CLabel>(69, 111, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(power)));
  377. labels.push_back(std::make_shared<CLabel>(69, 123, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(knowledge)));
  378. //morale+luck
  379. labels.push_back(std::make_shared<CLabel>(9, 131, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[384] + ":"));
  380. labels.push_back(std::make_shared<CLabel>(9, 143, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[385] + ":"));
  381. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("IMRL22"), morale + 3, 0, 47, 131));
  382. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ILCK22"), luck + 3, 0, 47, 143));
  383. //spell points
  384. labels.push_back(std::make_shared<CLabel>(39, 174, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[387]));
  385. labels.push_back(std::make_shared<CLabel>(39, 186, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, std::to_string(currentSpellPoints) + "/" + std::to_string(maxSpellPoints)));
  386. }
  387. void HeroInfoBasicPanel::update(const InfoAboutHero & updatedInfo)
  388. {
  389. icons.clear();
  390. labels.clear();
  391. initializeData(updatedInfo);
  392. }
  393. void HeroInfoBasicPanel::show(Canvas & to)
  394. {
  395. showAll(to);
  396. CIntObject::show(to);
  397. }
  398. StackInfoBasicPanel::StackInfoBasicPanel(const CStack * stack, bool initializeBackground)
  399. : CIntObject(0)
  400. {
  401. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  402. if(initializeBackground)
  403. {
  404. background = std::make_shared<CPicture>(ImagePath::builtin("CCRPOP"));
  405. background->pos.y += 37;
  406. background->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
  407. background->colorize(stack->getOwner());
  408. background2 = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
  409. background2->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
  410. background2->colorize(stack->getOwner());
  411. }
  412. initializeData(stack);
  413. }
  414. void StackInfoBasicPanel::initializeData(const CStack * stack)
  415. {
  416. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  417. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("TWCRPORT"), stack->creatureId() + 2, 0, 10, 6));
  418. labels.push_back(std::make_shared<CLabel>(10 + 58, 6 + 64, FONT_MEDIUM, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, TextOperations::formatMetric(stack->getCount(), 4)));
  419. auto attack = std::to_string(CGI->creatures()->getByIndex(stack->creatureIndex())->getAttack(stack->isShooter())) + "(" + std::to_string(stack->getAttack(stack->isShooter())) + ")";
  420. auto defense = std::to_string(CGI->creatures()->getByIndex(stack->creatureIndex())->getDefense(stack->isShooter())) + "(" + std::to_string(stack->getDefense(stack->isShooter())) + ")";
  421. auto damage = std::to_string(CGI->creatures()->getByIndex(stack->creatureIndex())->getMinDamage(stack->isShooter())) + "-" + std::to_string(stack->getMaxDamage(stack->isShooter()));
  422. auto health = CGI->creatures()->getByIndex(stack->creatureIndex())->getMaxHealth();
  423. auto morale = stack->moraleVal();
  424. auto luck = stack->luckVal();
  425. auto killed = stack->getKilled();
  426. auto healthRemaining = TextOperations::formatMetric(std::max(stack->getAvailableHealth() - (stack->getCount() - 1) * health, (si64)0), 4);
  427. //primary stats*/
  428. labels.push_back(std::make_shared<CLabel>(9, 75, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[380] + ":"));
  429. labels.push_back(std::make_shared<CLabel>(9, 87, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[381] + ":"));
  430. labels.push_back(std::make_shared<CLabel>(9, 99, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[386] + ":"));
  431. labels.push_back(std::make_shared<CLabel>(9, 111, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[389] + ":"));
  432. labels.push_back(std::make_shared<CLabel>(69, 87, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, attack));
  433. labels.push_back(std::make_shared<CLabel>(69, 99, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, defense));
  434. labels.push_back(std::make_shared<CLabel>(69, 111, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, damage));
  435. labels.push_back(std::make_shared<CLabel>(69, 123, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(health)));
  436. //morale+luck
  437. labels.push_back(std::make_shared<CLabel>(9, 131, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[384] + ":"));
  438. labels.push_back(std::make_shared<CLabel>(9, 143, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[385] + ":"));
  439. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("IMRL22"), morale + 3, 0, 47, 131));
  440. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ILCK22"), luck + 3, 0, 47, 143));
  441. //extra information
  442. labels.push_back(std::make_shared<CLabel>(9, 168, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, VLC->generaltexth->translate("vcmi.battleWindow.killed") + ":"));
  443. labels.push_back(std::make_shared<CLabel>(9, 180, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[389] + ":"));
  444. labels.push_back(std::make_shared<CLabel>(69, 180, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(killed)));
  445. labels.push_back(std::make_shared<CLabel>(69, 192, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, healthRemaining));
  446. //spells
  447. static const Point firstPos(15, 206); // position of 1st spell box
  448. static const Point offset(0, 38); // offset of each spell box from previous
  449. for(int i = 0; i < 3; i++)
  450. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SpellInt"), 78, 0, firstPos.x + offset.x * i, firstPos.y + offset.y * i));
  451. int printed=0; //how many effect pics have been printed
  452. std::vector<SpellID> spells = stack->activeSpells();
  453. for(SpellID effect : spells)
  454. {
  455. //not all effects have graphics (for eg. Acid Breath)
  456. //for modded spells iconEffect is added to SpellInt.def
  457. const bool hasGraphics = (effect < SpellID::THUNDERBOLT) || (effect >= SpellID::AFTER_LAST);
  458. if (hasGraphics)
  459. {
  460. //FIXME: support permanent duration
  461. int duration = stack->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain;
  462. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed));
  463. if(settings["general"]["enableUiEnhancements"].Bool())
  464. labels.push_back(std::make_shared<CLabel>(firstPos.x + offset.x * printed + 46, firstPos.y + offset.y * printed + 36, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(duration)));
  465. if(++printed >= 3 || (printed == 2 && spells.size() > 3)) // interface limit reached
  466. break;
  467. }
  468. }
  469. if(spells.size() == 0)
  470. labelsMultiline.push_back(std::make_shared<CMultiLineLabel>(Rect(firstPos.x, firstPos.y, 48, 36), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[674]));
  471. if(spells.size() > 3)
  472. labelsMultiline.push_back(std::make_shared<CMultiLineLabel>(Rect(firstPos.x + offset.x * 2, firstPos.y + offset.y * 2 - 4, 48, 36), EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "..."));
  473. }
  474. void StackInfoBasicPanel::update(const CStack * updatedInfo)
  475. {
  476. icons.clear();
  477. labels.clear();
  478. labelsMultiline.clear();
  479. initializeData(updatedInfo);
  480. }
  481. void StackInfoBasicPanel::show(Canvas & to)
  482. {
  483. showAll(to);
  484. CIntObject::show(to);
  485. }
  486. HeroInfoWindow::HeroInfoWindow(const InfoAboutHero & hero, Point * position)
  487. : CWindowObject(RCLICK_POPUP | SHADOW_DISABLED, ImagePath::builtin("CHRPOP"))
  488. {
  489. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  490. if (position != nullptr)
  491. moveTo(*position);
  492. background->colorize(hero.owner); //maybe add this functionality to base class?
  493. content = std::make_shared<HeroInfoBasicPanel>(hero, nullptr, false);
  494. }
  495. BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface & _owner, bool allowReplay)
  496. : owner(_owner)
  497. {
  498. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  499. background = std::make_shared<CPicture>(ImagePath::builtin("CPRESULT"));
  500. background->colorize(owner.playerID);
  501. pos = center(background->pos);
  502. exit = std::make_shared<CButton>(Point(384, 505), AnimationPath::builtin("iok6432.def"), std::make_pair("", ""), [&](){ bExitf();}, EShortcut::GLOBAL_ACCEPT);
  503. exit->setBorderColor(Colors::METALLIC_GOLD);
  504. if(allowReplay || owner.cb->getStartInfo()->extraOptionsInfo.unlimitedReplay)
  505. {
  506. repeat = std::make_shared<CButton>(Point(24, 505), AnimationPath::builtin("icn6432.def"), std::make_pair("", ""), [&](){ bRepeatf();}, EShortcut::GLOBAL_CANCEL);
  507. repeat->setBorderColor(Colors::METALLIC_GOLD);
  508. labels.push_back(std::make_shared<CLabel>(232, 520, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->translate("vcmi.battleResultsWindow.applyResultsLabel")));
  509. }
  510. if(br.winner == 0) //attacker won
  511. {
  512. labels.push_back(std::make_shared<CLabel>(59, 124, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]));
  513. }
  514. else
  515. {
  516. labels.push_back(std::make_shared<CLabel>(59, 124, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]));
  517. }
  518. if(br.winner == 1)
  519. {
  520. labels.push_back(std::make_shared<CLabel>(412, 124, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[410]));
  521. }
  522. else
  523. {
  524. labels.push_back(std::make_shared<CLabel>(408, 124, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[411]));
  525. }
  526. labels.push_back(std::make_shared<CLabel>(232, 302, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[407]));
  527. labels.push_back(std::make_shared<CLabel>(232, 332, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[408]));
  528. labels.push_back(std::make_shared<CLabel>(232, 428, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[409]));
  529. std::string sideNames[2] = {"N/A", "N/A"};
  530. for(int i = 0; i < 2; i++)
  531. {
  532. auto heroInfo = owner.cb->getBattle(br.battleID)->battleGetHeroInfo(i);
  533. const int xs[] = {21, 392};
  534. if(heroInfo.portraitSource.isValid()) //attacking hero
  535. {
  536. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), heroInfo.getIconIndex(), 0, xs[i], 38));
  537. sideNames[i] = heroInfo.name;
  538. }
  539. else
  540. {
  541. auto stacks = owner.cb->getBattle(br.battleID)->battleGetAllStacks();
  542. vstd::erase_if(stacks, [i](const CStack * stack) //erase stack of other side and not coming from garrison
  543. {
  544. return stack->unitSide() != i || !stack->base;
  545. });
  546. auto best = vstd::maxElementByFun(stacks, [](const CStack * stack)
  547. {
  548. return stack->unitType()->getAIValue();
  549. });
  550. if(best != stacks.end()) //should be always but to be safe...
  551. {
  552. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("TWCRPORT"), (*best)->unitType()->getIconIndex(), 0, xs[i], 38));
  553. sideNames[i] = (*best)->unitType()->getNamePluralTranslated();
  554. }
  555. }
  556. }
  557. //printing attacker and defender's names
  558. labels.push_back(std::make_shared<CLabel>(89, 37, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, sideNames[0]));
  559. labels.push_back(std::make_shared<CLabel>(381, 53, FONT_SMALL, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, sideNames[1]));
  560. //printing casualties
  561. for(int step = 0; step < 2; ++step)
  562. {
  563. if(br.casualties[step].size()==0)
  564. {
  565. labels.push_back(std::make_shared<CLabel>(235, 360 + 97 * step, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[523]));
  566. }
  567. else
  568. {
  569. int xPos = 235 - ((int)br.casualties[step].size()*32 + ((int)br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture
  570. int yPos = 344 + step * 97;
  571. for(auto & elem : br.casualties[step])
  572. {
  573. auto creature = CGI->creatures()->getByIndex(elem.first);
  574. if (creature->getId() == CreatureID::ARROW_TOWERS )
  575. continue; // do not show destroyed towers in battle results
  576. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("CPRSMALL"), creature->getIconIndex(), 0, xPos, yPos));
  577. std::ostringstream amount;
  578. amount<<elem.second;
  579. labels.push_back(std::make_shared<CLabel>(xPos + 16, yPos + 42, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, amount.str()));
  580. xPos += 42;
  581. }
  582. }
  583. }
  584. auto resources = getResources(br);
  585. description = std::make_shared<CTextBox>(resources.resultText.toString(), Rect(69, 203, 330, 68), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
  586. videoPlayer = std::make_shared<VideoWidget>(Point(107, 70), resources.prologueVideo, resources.loopedVideo, false);
  587. CCS->musich->playMusic(resources.musicName, false, true);
  588. }
  589. BattleResultResources BattleResultWindow::getResources(const BattleResult & br)
  590. {
  591. //printing result description
  592. bool weAreAttacker = !(owner.cb->getBattle(br.battleID)->battleGetMySide());
  593. bool weAreDefender = !weAreAttacker;
  594. bool weWon = (br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker);
  595. bool isSiege = owner.cb->getBattle(br.battleID)->battleGetDefendedTown() != nullptr;
  596. BattleResultResources resources;
  597. if(weWon)
  598. {
  599. if(isSiege && weAreDefender)
  600. {
  601. resources.musicName = AudioPath::builtin("Music/Defend Castle");
  602. resources.prologueVideo = VideoPath::builtin("DEFENDALL.BIK");
  603. resources.loopedVideo = VideoPath::builtin("defendloop.bik");
  604. }
  605. else
  606. {
  607. resources.musicName = AudioPath::builtin("Music/Win Battle");
  608. resources.prologueVideo = VideoPath();
  609. resources.loopedVideo = VideoPath::builtin("WIN3.BIK");
  610. }
  611. switch(br.result)
  612. {
  613. case EBattleResult::NORMAL:
  614. resources.resultText.appendTextID("core.genrltxt.304");
  615. break;
  616. case EBattleResult::ESCAPE:
  617. resources.resultText.appendTextID("core.genrltxt.303");
  618. break;
  619. case EBattleResult::SURRENDER:
  620. resources.resultText.appendTextID("core.genrltxt.302");
  621. break;
  622. default:
  623. throw std::runtime_error("Invalid battle result!");
  624. }
  625. const CGHeroInstance * ourHero = owner.cb->getBattle(br.battleID)->battleGetMyHero();
  626. if (ourHero)
  627. {
  628. resources.resultText.appendTextID("core.genrltxt.305");
  629. resources.resultText.replaceTextID(ourHero->getNameTranslated());
  630. resources.resultText.replaceNumber(br.exp[weAreAttacker ? 0 : 1]);
  631. }
  632. }
  633. else // we lose
  634. {
  635. switch(br.result)
  636. {
  637. case EBattleResult::NORMAL:
  638. resources.resultText.appendTextID("core.genrltxt.311");
  639. resources.musicName = AudioPath::builtin("Music/LoseCombat");
  640. resources.prologueVideo = VideoPath::builtin("LBSTART.BIK");
  641. resources.loopedVideo = VideoPath::builtin("LBLOOP.BIK");
  642. break;
  643. case EBattleResult::ESCAPE:
  644. resources.resultText.appendTextID("core.genrltxt.310");
  645. resources.musicName = AudioPath::builtin("Music/Retreat Battle");
  646. resources.prologueVideo = VideoPath::builtin("RTSTART.BIK");
  647. resources.loopedVideo = VideoPath::builtin("RTLOOP.BIK");
  648. break;
  649. case EBattleResult::SURRENDER:
  650. resources.resultText.appendTextID("core.genrltxt.309");
  651. resources.musicName = AudioPath::builtin("Music/Surrender Battle");
  652. resources.prologueVideo = VideoPath();
  653. resources.loopedVideo = VideoPath::builtin("SURRENDER.BIK");
  654. break;
  655. default:
  656. throw std::runtime_error("Invalid battle result!");
  657. }
  658. if(isSiege && weAreDefender)
  659. {
  660. resources.musicName = AudioPath::builtin("Music/LoseCastle");
  661. resources.prologueVideo = VideoPath::builtin("LOSECSTL.BIK");
  662. resources.loopedVideo = VideoPath::builtin("LOSECSLP.BIK");
  663. }
  664. }
  665. return resources;
  666. }
  667. void BattleResultWindow::activate()
  668. {
  669. owner.showingDialog->set(true);
  670. CIntObject::activate();
  671. }
  672. void BattleResultWindow::buttonPressed(int button)
  673. {
  674. if (resultCallback)
  675. resultCallback(button);
  676. CPlayerInterface &intTmp = owner; //copy reference because "this" will be destructed soon
  677. close();
  678. if(GH.windows().topWindow<BattleWindow>())
  679. GH.windows().popWindows(1); //pop battle interface if present
  680. //Result window and battle interface are gone. We requested all dialogs to be closed before opening the battle,
  681. //so we can be sure that there is no dialogs left on GUI stack.
  682. intTmp.showingDialog->setn(false);
  683. }
  684. void BattleResultWindow::bExitf()
  685. {
  686. buttonPressed(0);
  687. }
  688. void BattleResultWindow::bRepeatf()
  689. {
  690. buttonPressed(1);
  691. }
  692. StackQueue::StackQueue(bool Embedded, BattleInterface & owner)
  693. : embedded(Embedded),
  694. owner(owner)
  695. {
  696. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  697. uint32_t queueSize = QUEUE_SIZE_BIG;
  698. if(embedded)
  699. {
  700. int32_t queueSmallOutsideYOffset = 65;
  701. bool queueSmallOutside = settings["battle"]["queueSmallOutside"].Bool() && (pos.y - queueSmallOutsideYOffset) >= 0;
  702. queueSize = std::clamp(static_cast<int>(settings["battle"]["queueSmallSlots"].Float()), 1, queueSmallOutside ? GH.screenDimensions().x / 41 : 19);
  703. pos.w = queueSize * 41;
  704. pos.h = 49;
  705. pos.x += parent->pos.w/2 - pos.w/2;
  706. pos.y += queueSmallOutside ? -queueSmallOutsideYOffset : 10;
  707. icons = GH.renderHandler().loadAnimation(AnimationPath::builtin("CPRSMALL"));
  708. stateIcons = GH.renderHandler().loadAnimation(AnimationPath::builtin("VCMI/BATTLEQUEUE/STATESSMALL"));
  709. }
  710. else
  711. {
  712. pos.w = 800;
  713. pos.h = 85;
  714. pos.x += 0;
  715. pos.y -= pos.h;
  716. background = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h));
  717. icons = GH.renderHandler().loadAnimation(AnimationPath::builtin("TWCRPORT"));
  718. stateIcons = GH.renderHandler().loadAnimation(AnimationPath::builtin("VCMI/BATTLEQUEUE/STATESSMALL"));
  719. //TODO: where use big icons?
  720. //stateIcons = GH.renderHandler().loadAnimation("VCMI/BATTLEQUEUE/STATESBIG");
  721. }
  722. stateIcons->preload();
  723. stackBoxes.resize(queueSize);
  724. for (int i = 0; i < stackBoxes.size(); i++)
  725. {
  726. stackBoxes[i] = std::make_shared<StackBox>(this);
  727. stackBoxes[i]->moveBy(Point(1 + (embedded ? 41 : 80) * i, 0));
  728. }
  729. }
  730. void StackQueue::show(Canvas & to)
  731. {
  732. if (embedded)
  733. showAll(to);
  734. CIntObject::show(to);
  735. }
  736. void StackQueue::update()
  737. {
  738. std::vector<battle::Units> queueData;
  739. owner.getBattle()->battleGetTurnOrder(queueData, stackBoxes.size(), 0);
  740. size_t boxIndex = 0;
  741. ui32 tmpTurn = -1;
  742. for(size_t turn = 0; turn < queueData.size() && boxIndex < stackBoxes.size(); turn++)
  743. {
  744. for(size_t unitIndex = 0; unitIndex < queueData[turn].size() && boxIndex < stackBoxes.size(); boxIndex++, unitIndex++)
  745. {
  746. ui32 currentTurn = owner.round + turn;
  747. stackBoxes[boxIndex]->setUnit(queueData[turn][unitIndex], turn, tmpTurn != currentTurn && owner.round != 0 && (!embedded || tmpTurn != -1) ? (std::optional<ui32>)currentTurn : std::nullopt);
  748. tmpTurn = currentTurn;
  749. }
  750. }
  751. for(; boxIndex < stackBoxes.size(); boxIndex++)
  752. stackBoxes[boxIndex]->setUnit(nullptr);
  753. }
  754. int32_t StackQueue::getSiegeShooterIconID()
  755. {
  756. return owner.siegeController->getSiegedTown()->town->faction->getIndex();
  757. }
  758. std::optional<uint32_t> StackQueue::getHoveredUnitIdIfAny() const
  759. {
  760. for(const auto & stackBox : stackBoxes)
  761. {
  762. if(stackBox->isHovered())
  763. {
  764. return stackBox->getBoundUnitID();
  765. }
  766. }
  767. return std::nullopt;
  768. }
  769. StackQueue::StackBox::StackBox(StackQueue * owner):
  770. CIntObject(SHOW_POPUP | HOVER), owner(owner)
  771. {
  772. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  773. background = std::make_shared<CPicture>(ImagePath::builtin(owner->embedded ? "StackQueueSmall" : "StackQueueLarge"));
  774. pos.w = background->pos.w;
  775. pos.h = background->pos.h;
  776. if(owner->embedded)
  777. {
  778. icon = std::make_shared<CAnimImage>(owner->icons, 0, 0, 5, 2);
  779. amount = std::make_shared<CLabel>(pos.w/2, pos.h - 7, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
  780. roundRect = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, 2, 48), ColorRGBA(0, 0, 0, 255), ColorRGBA(0, 255, 0, 255));
  781. }
  782. else
  783. {
  784. icon = std::make_shared<CAnimImage>(owner->icons, 0, 0, 9, 1);
  785. amount = std::make_shared<CLabel>(pos.w/2, pos.h - 8, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
  786. roundRect = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, 15, 18), ColorRGBA(0, 0, 0, 255), ColorRGBA(241, 216, 120, 255));
  787. round = std::make_shared<CLabel>(4, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
  788. int icon_x = pos.w - 17;
  789. int icon_y = pos.h - 18;
  790. stateIcon = std::make_shared<CAnimImage>(owner->stateIcons, 0, 0, icon_x, icon_y);
  791. stateIcon->visible = false;
  792. }
  793. roundRect->disable();
  794. }
  795. void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn, std::optional<ui32> currentTurn)
  796. {
  797. if(unit)
  798. {
  799. boundUnitID = unit->unitId();
  800. background->colorize(unit->unitOwner());
  801. icon->visible = true;
  802. // temporary code for mod compatibility:
  803. // first, set icon that should definitely exist (arrow tower icon in base vcmi mod)
  804. // second, try to switch to icon that should be provided by mod
  805. // if mod is not up to date and does have arrow tower icon yet - second setFrame call will fail and retain previously set image
  806. // for 1.2 release & later next line should be moved into 'else' block
  807. icon->setFrame(unit->creatureIconIndex(), 0);
  808. if (unit->unitType()->getId() == CreatureID::ARROW_TOWERS)
  809. icon->setFrame(owner->getSiegeShooterIconID(), 1);
  810. roundRect->setEnabled(currentTurn.has_value());
  811. if(!owner->embedded)
  812. round->setEnabled(currentTurn.has_value());
  813. amount->setText(TextOperations::formatMetric(unit->getCount(), 4));
  814. if(currentTurn && !owner->embedded)
  815. {
  816. std::string tmp = std::to_string(*currentTurn);
  817. int len = graphics->fonts[FONT_SMALL]->getStringWidth(tmp);
  818. roundRect->pos.w = len + 6;
  819. round->setText(tmp);
  820. }
  821. if(stateIcon)
  822. {
  823. if(unit->defended((int)turn) || (turn > 0 && unit->defended((int)turn - 1)))
  824. {
  825. stateIcon->setFrame(0, 0);
  826. stateIcon->visible = true;
  827. }
  828. else if(unit->waited((int)turn))
  829. {
  830. stateIcon->setFrame(1, 0);
  831. stateIcon->visible = true;
  832. }
  833. else
  834. {
  835. stateIcon->visible = false;
  836. }
  837. }
  838. }
  839. else
  840. {
  841. boundUnitID = std::nullopt;
  842. background->colorize(PlayerColor::NEUTRAL);
  843. icon->visible = false;
  844. icon->setFrame(0);
  845. amount->setText("");
  846. if(stateIcon)
  847. stateIcon->visible = false;
  848. }
  849. }
  850. std::optional<uint32_t> StackQueue::StackBox::getBoundUnitID() const
  851. {
  852. return boundUnitID;
  853. }
  854. bool StackQueue::StackBox::isBoundUnitHighlighted() const
  855. {
  856. auto unitIdsToHighlight = owner->owner.stacksController->getHoveredStacksUnitIds();
  857. return vstd::contains(unitIdsToHighlight, getBoundUnitID());
  858. }
  859. void StackQueue::StackBox::showAll(Canvas & to)
  860. {
  861. CIntObject::showAll(to);
  862. if(isBoundUnitHighlighted())
  863. to.drawBorder(background->pos, Colors::CYAN, 2);
  864. }
  865. void StackQueue::StackBox::show(Canvas & to)
  866. {
  867. CIntObject::show(to);
  868. if(isBoundUnitHighlighted())
  869. to.drawBorder(background->pos, Colors::CYAN, 2);
  870. }
  871. void StackQueue::StackBox::showPopupWindow(const Point & cursorPosition)
  872. {
  873. auto stacks = owner->owner.getBattle()->battleGetAllStacks();
  874. for(const CStack * stack : stacks)
  875. if(boundUnitID.has_value() && stack->unitId() == *boundUnitID)
  876. GH.windows().createAndPushWindow<CStackWindow>(stack, true);
  877. }