BattleInterfaceClasses.cpp 34 KB

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