BattleInterfaceClasses.cpp 34 KB

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