CCreatureWindow.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #include "StdInc.h"
  2. #include "CCreatureWindow.h"
  3. #include "CGameInfo.h"
  4. #include "CPlayerInterface.h"
  5. #include "GUIClasses.h"
  6. #include "../CCallback.h"
  7. #include "../lib/BattleState.h"
  8. #include "../lib/CBonusTypeHandler.h"
  9. #include "../lib/CGeneralTextHandler.h"
  10. #include "../lib/CModHandler.h"
  11. #include "../lib/CSpellHandler.h"
  12. #include "gui/CGuiHandler.h"
  13. #include "gui/CIntObjectClasses.h"
  14. using namespace CSDL_Ext;
  15. class CCreatureArtifactInstance;
  16. class CSelectableSkill;
  17. /*
  18. * CCreatureWindow.cpp, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. namespace
  27. {
  28. namespace EStat
  29. {
  30. enum EStat
  31. {
  32. ATTACK,
  33. DEFENCE,
  34. SHOTS,
  35. DAMAGE,
  36. HEALTH,
  37. HEALTH_LEFT,
  38. SPEED,
  39. MANA
  40. };
  41. }
  42. }
  43. StackWindowInfo::StackWindowInfo():
  44. creature(nullptr),
  45. commander(nullptr),
  46. stackNode(nullptr),
  47. owner(nullptr),
  48. creatureCount(0),
  49. popupWindow(false)
  50. {
  51. }
  52. void CStackWindow::CWindowSection::createBackground(std::string path)
  53. {
  54. background = new CPicture("stackWindow/" + path);
  55. pos = background->pos;
  56. }
  57. void CStackWindow::CWindowSection::printStatString(int index, std::string name, std::string value)
  58. {
  59. new CLabel(145, 32 + index*19, FONT_SMALL, TOPLEFT, Colors::WHITE, name);
  60. new CLabel(307, 48 + index*19, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, value);
  61. }
  62. void CStackWindow::CWindowSection::printStatRange(int index, std::string name, int min, int max)
  63. {
  64. if(min != max)
  65. printStatString(index, name, boost::str(boost::format("%d - %d") % min % max));
  66. else
  67. printStatString(index, name, boost::str(boost::format("%d") % min));
  68. }
  69. void CStackWindow::CWindowSection::printStatBase(int index, std::string name, int base, int current)
  70. {
  71. if(base != current)
  72. printStatString(index, name, boost::str(boost::format("%d (%d)") % base % current));
  73. else
  74. printStatString(index, name, boost::str(boost::format("%d") % base));
  75. }
  76. void CStackWindow::CWindowSection::printStat(int index, std::string name, int value)
  77. {
  78. printStatBase(index, name, value, value);
  79. }
  80. void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
  81. {
  82. OBJ_CONSTRUCTION_CAPTURING_ALL;
  83. if (showExp && showArt)
  84. createBackground("info-panel-2");
  85. else if (showExp || showArt)
  86. createBackground("info-panel-1");
  87. else
  88. createBackground("info-panel-0");
  89. new CCreaturePic(5, 41, parent->info.creature);
  90. std::string visibleName;
  91. if (parent->info.commander != nullptr)
  92. visibleName = parent->info.commander->type->nameSing;
  93. else
  94. visibleName = parent->info.creature->namePl;
  95. new CLabel(215, 12, FONT_SMALL, CENTER, Colors::YELLOW, visibleName);
  96. int dmgMultiply = 1;
  97. if(parent->info.owner && parent->info.stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
  98. dmgMultiply += parent->info.owner->Attack();
  99. new CPicture("stackWindow/icons", 117, 32);
  100. printStatBase(EStat::ATTACK, CGI->generaltexth->primarySkillNames[0], parent->info.creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), parent->info.stackNode->Attack());
  101. printStatBase(EStat::DEFENCE, CGI->generaltexth->primarySkillNames[1], parent->info.creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), parent->info.stackNode->Defense());
  102. printStatRange(EStat::DAMAGE, CGI->generaltexth->allTexts[199], parent->info.stackNode->getMinDamage() * dmgMultiply, parent->info.stackNode->getMaxDamage() * dmgMultiply);
  103. printStatBase(EStat::HEALTH, CGI->generaltexth->allTexts[388], parent->info.creature->valOfBonuses(Bonus::STACK_HEALTH), parent->info.stackNode->valOfBonuses(Bonus::STACK_HEALTH));
  104. printStatBase(EStat::SPEED, CGI->generaltexth->zelp[441].first, parent->info.creature->Speed(), parent->info.stackNode->Speed());
  105. const CStack * battleStack = dynamic_cast<const CStack*>(parent->info.stackNode);
  106. bool shooter = parent->info.stackNode->hasBonusOfType(Bonus::SHOOTER) && parent->info.stackNode->valOfBonuses(Bonus::SHOTS);
  107. bool caster = parent->info.stackNode->valOfBonuses(Bonus::CASTS);
  108. if (battleStack != nullptr) // in battle
  109. {
  110. if (shooter)
  111. printStatBase(EStat::SHOTS, CGI->generaltexth->allTexts[198], battleStack->valOfBonuses(Bonus::SHOTS), battleStack->shots);
  112. if (caster)
  113. printStatBase(EStat::MANA, CGI->generaltexth->allTexts[399], battleStack->valOfBonuses(Bonus::CASTS), battleStack->casts);
  114. printStat(EStat::HEALTH_LEFT, CGI->generaltexth->allTexts[200], battleStack->firstHPleft);
  115. }
  116. else
  117. {
  118. if (shooter)
  119. printStat(EStat::SHOTS, CGI->generaltexth->allTexts[198], parent->info.stackNode->valOfBonuses(Bonus::SHOTS));
  120. if (caster)
  121. printStat(EStat::MANA, CGI->generaltexth->allTexts[399], parent->info.stackNode->valOfBonuses(Bonus::CASTS));
  122. }
  123. auto morale = new MoraleLuckBox(true, genRect(42, 42, 321, 110));
  124. morale->set(parent->info.stackNode);
  125. auto luck = new MoraleLuckBox(false, genRect(42, 42, 375, 110));
  126. luck->set(parent->info.stackNode);
  127. }
  128. void CStackWindow::CWindowSection::createActiveSpells()
  129. {
  130. static const Point firstPos(7 ,4); // position of 1st spell box
  131. static const Point offset(54, 0); // offset of each spell box from previous
  132. OBJ_CONSTRUCTION_CAPTURING_ALL;
  133. createBackground("spell-effects");
  134. const CStack * battleStack = dynamic_cast<const CStack*>(parent->info.stackNode);
  135. assert(battleStack); // Section should be created only for battles
  136. //spell effects
  137. int printed=0; //how many effect pics have been printed
  138. std::vector<si32> spells = battleStack->activeSpells();
  139. for(si32 effect : spells)
  140. {
  141. std::string spellText;
  142. if (effect < 77) //not all effects have graphics (for eg. Acid Breath)
  143. {
  144. spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
  145. boost::replace_first (spellText, "%s", CGI->spellh->objects[effect]->name);
  146. int duration = battleStack->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain;
  147. boost::replace_first (spellText, "%d", boost::lexical_cast<std::string>(duration));
  148. new CAnimImage("SpellInt", effect + 1, 0, firstPos.x + offset.x * printed, firstPos.x + offset.y * printed);
  149. new LRClickableAreaWText(Rect(firstPos + offset * printed, Point(50, 38)), spellText, spellText);
  150. if (++printed >= 8) // interface limit reached
  151. break;
  152. }
  153. }
  154. }
  155. void CStackWindow::CWindowSection::createCommanderSection()
  156. {
  157. OBJ_CONSTRUCTION_CAPTURING_ALL;
  158. auto onCreate = [=](size_t index) -> CIntObject *
  159. {
  160. return parent->switchTab(index);
  161. };
  162. auto onDestroy = [=](CIntObject * obj)
  163. {
  164. delete obj;
  165. };
  166. new CTabbedInt(onCreate, onDestroy, Point(0,0), 0);
  167. pos.w = parent->pos.w;
  168. pos.h = 177; //fixed height
  169. }
  170. static std::string skillToFile (int skill, int level, bool canUpgrade, bool selected)
  171. {
  172. std::string file = "zvs/Lib1.res/_";
  173. switch (skill)
  174. {
  175. case ECommander::ATTACK:
  176. file += "AT";
  177. break;
  178. case ECommander::DEFENSE:
  179. file += "DF";
  180. break;
  181. case ECommander::HEALTH:
  182. file += "HP";
  183. break;
  184. case ECommander::DAMAGE:
  185. file += "DM";
  186. break;
  187. case ECommander::SPEED:
  188. file += "SP";
  189. break;
  190. case ECommander::SPELL_POWER:
  191. file += "MP";
  192. break;
  193. }
  194. std::string sufix = boost::lexical_cast<std::string>((int)level);
  195. if (selected)
  196. sufix += "="; //level-up highlight
  197. else if (canUpgrade && level == 0)
  198. sufix = "no"; //not avaliable - no number
  199. file += sufix + ".bmp";
  200. return file;
  201. }
  202. void CStackWindow::CWindowSection::createCommander()
  203. {/*
  204. OBJ_CONSTRUCTION_CAPTURING_ALL;
  205. createBackground("commander-bg");
  206. auto getSkillPos = [&](int index)
  207. {
  208. return Point(10 + 80 * (index%3), 20 + 80 * (index/3));
  209. };
  210. for (int i = ECommander::ATTACK; i <= ECommander::SPELL_POWER; ++i)
  211. {
  212. bool haveSkill = parent->info.commander->secondarySkills[i] != 0;
  213. bool canLevel = parent->info.levelupInfo && vstd::contains(parent->info.levelupInfo->skills, i);
  214. Point skillPos = getSkillPos(i);
  215. if (canLevel)
  216. new CPicture(skillToFile(i, parent->info.commander->secondarySkills[i], true, false), skillPos.x, skillPos.y);
  217. if (haveSkill && !canLevel)
  218. new CPicture(skillToFile(i, parent->info.commander->secondarySkills[i], false, false), skillPos.x, skillPos.y);
  219. }
  220. bool createAbilities = false;
  221. if (parent->info.levelupInfo)
  222. {
  223. for (auto option : parent->info.levelupInfo->skills)
  224. {
  225. if (option < 100)
  226. {
  227. auto selectableSkill = new CStackWindow::CSelectableSkill();
  228. if (option == parent->selectedSkill)
  229. selectedIcon = selectableSkill;
  230. selectableSkill->callback = std::bind(parent->info.levelupInfo->callback, option);
  231. selectableSkill->pos = Rect(getSkillPos(option), Point(70, 70)); //resize
  232. }
  233. else
  234. createAbilities = true;
  235. }
  236. }*/
  237. }
  238. void CStackWindow::CWindowSection::createCommanderAbilities()
  239. {/*
  240. for (auto option : parent->info.levelupInfo->skills)
  241. {
  242. }
  243. selectableSkill->pos = Rect (95, 256, 55, 55); //TODO: scroll
  244. const Bonus *b = CGI->creh->skillRequirements[option-100].first;
  245. bonusItems.push_back (new CBonusItem (genRect(0, 0, 251, 57), stack->bonusToString(b, false), stack->bonusToString(b, true), stack->bonusToGraphics(b)));
  246. selectableBonuses.push_back (selectableSkill); //insert these before other bonuses
  247. */
  248. }
  249. void CStackWindow::CWindowSection::createBonuses(boost::optional<size_t> preferredSize)
  250. {
  251. // size of single image for an item
  252. static const int itemHeight = 59;
  253. OBJ_CONSTRUCTION_CAPTURING_ALL;
  254. size_t totalSize = (parent->activeBonuses.size() + 1) / 2;
  255. size_t visibleSize = preferredSize ? preferredSize.get() : std::min<size_t>(3, totalSize);
  256. pos.w = parent->pos.w;
  257. pos.h = itemHeight * visibleSize;
  258. auto onCreate = [=](size_t index) -> CIntObject *
  259. {
  260. return parent->createBonusEntry(index);
  261. };
  262. auto onDestroy = [=](CIntObject * obj)
  263. {
  264. delete obj;
  265. };
  266. new CListBox(onCreate, onDestroy, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, 1, Rect(pos.w - 15, 0, pos.h, pos.h));
  267. }
  268. void CStackWindow::CWindowSection::createButtonPanel()
  269. {
  270. //TODO: localization, place creature icon on button, proper path to animation-button
  271. OBJ_CONSTRUCTION_CAPTURING_ALL;
  272. createBackground("button-panel");
  273. if (parent->info.dismissInfo)
  274. {
  275. auto onDismiss = [=]()
  276. {
  277. parent->info.dismissInfo->callback();
  278. parent->close();
  279. };
  280. auto onClick = [=] ()
  281. {
  282. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[12], onDismiss, 0, false, std::vector<CComponent*>());
  283. };
  284. new CAdventureMapButton(CGI->generaltexth->zelp[445], onClick, 5, 5,"IVIEWCR2.DEF",SDLK_d);
  285. }
  286. if (parent->info.upgradeInfo)
  287. {
  288. // used space overlaps with commander switch button
  289. // besides - should commander really be upgradeable?
  290. assert(!parent->info.commander);
  291. StackWindowInfo::StackUpgradeInfo & upgradeInfo = parent->info.upgradeInfo.get();
  292. size_t buttonsToCreate = std::min<size_t>(upgradeInfo.info.newID.size(), 3); // no more than 3 windows on UI - space limit
  293. for (size_t i=0; i<buttonsToCreate; i++)
  294. {
  295. TResources totalCost = upgradeInfo.info.cost[i] * parent->info.creatureCount;
  296. auto onUpgrade = [=]()
  297. {
  298. upgradeInfo.callback(upgradeInfo.info.newID[i]);
  299. parent->close();
  300. };
  301. auto onClick = [=]()
  302. {
  303. std::vector<CComponent*> resComps;
  304. for(TResources::nziterator i(totalCost); i.valid(); i++)
  305. {
  306. resComps.push_back(new CComponent(CComponent::resource, i->resType, i->resVal));
  307. }
  308. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[207], onUpgrade, nullptr, true, resComps);
  309. };
  310. auto upgradeBtn = new CAdventureMapButton(CGI->generaltexth->zelp[446], onClick, 221 + i * 40, 5, "stackWindow/upgradeButton", SDLK_1);
  311. upgradeBtn->addOverlay(new CAnimImage("CPRSMALL", VLC->creh->creatures[upgradeInfo.info.newID[i]]->iconIndex));
  312. if (!LOCPLINT->cb->getResourceAmount().canAfford(totalCost))
  313. upgradeBtn->block(true);
  314. }
  315. }
  316. if (parent->info.commander)
  317. {
  318. //TODO: replace with 3 buttons, using upgrade button as base + sec skill image:
  319. // 0) Switch to commander skills: Basic Offence
  320. // 1) Switch to upgradable skills: Advanced mysticism (level-up only)
  321. // 2) Switch to bonuses view: Basic Sorcery
  322. auto onSwitch = [=]()
  323. {
  324. parent->commanderTab->setActive(parent->activeTab == 0 ? 1 : 0);
  325. };
  326. new CAdventureMapButton(std::make_pair("switch to commander", "help box"), onSwitch, 280, 5, "stackWindow/commanderToggle", SDLK_TAB);
  327. }
  328. auto exitBtn = new CAdventureMapButton(CGI->generaltexth->zelp[445], [=]{ parent->close(); }, 382, 5, "hsbtns.def", SDLK_RETURN);
  329. exitBtn->assignedKeys.insert(SDLK_ESCAPE);
  330. }
  331. CStackWindow::CWindowSection::CWindowSection(CStackWindow * parent):
  332. parent(parent)
  333. {
  334. }
  335. void CStackWindow::CSelectableSkill::clickLeft(tribool down, bool previousState)
  336. {
  337. if (down)
  338. callback();
  339. }
  340. CIntObject * CStackWindow::createBonusEntry(size_t index)
  341. {
  342. auto section = new CWindowSection(this);
  343. section->createBonusEntry(index);
  344. return section;
  345. }
  346. void CStackWindow::CWindowSection::createBonusEntry(size_t index)
  347. {
  348. OBJ_CONSTRUCTION_CAPTURING_ALL;
  349. createBackground("bonus-effects");
  350. createBonusItem(index * 2, Point(6, 4));
  351. createBonusItem(index * 2 + 1, Point(214, 4));
  352. }
  353. void CStackWindow::CWindowSection::createBonusItem(size_t index, Point position)
  354. {
  355. if (parent->activeBonuses.size() > index)
  356. {
  357. BonusInfo & bi = parent->activeBonuses[index];
  358. new CPicture(bi.imagePath, position.x, position.y);
  359. new CLabel(position.x + 60, position.y + 2, FONT_SMALL, TOPLEFT, Colors::WHITE, bi.name);
  360. new CLabel(position.x + 60, position.y + 25, FONT_SMALL, TOPLEFT, Colors::WHITE, bi.description);
  361. }
  362. }
  363. CIntObject * CStackWindow::switchTab(size_t index)
  364. {
  365. switch (index)
  366. {
  367. case 0:
  368. {
  369. activeTab = 0;
  370. auto ret = new CWindowSection(this);
  371. ret->createCommanderSection();
  372. return ret;
  373. }
  374. case 1:
  375. {
  376. activeTab = 1;
  377. auto ret = new CWindowSection(this);
  378. ret->createBonuses(3);
  379. return ret;
  380. }
  381. case 2:
  382. {
  383. activeTab = 2;
  384. auto ret = new CWindowSection(this);
  385. ret->createCommanderAbilities();
  386. return ret;
  387. }
  388. default:
  389. {
  390. return nullptr;
  391. }
  392. }
  393. }
  394. void CStackWindow::initSections()
  395. {
  396. OBJ_CONSTRUCTION_CAPTURING_ALL;
  397. CWindowSection * currentSection;
  398. bool showArt = CGI->modh->modules.STACK_ARTIFACT && info.commander == nullptr;
  399. bool showExp = CGI->modh->modules.STACK_EXP || info.commander != nullptr;
  400. currentSection = new CWindowSection(this);
  401. currentSection->createStackInfo(showExp, showArt);
  402. pos.w = currentSection->pos.w;
  403. pos.h += currentSection->pos.h;
  404. if (dynamic_cast<const CStack*>(info.stackNode)) // in battle
  405. {
  406. currentSection = new CWindowSection(this);
  407. currentSection->pos.y += pos.h;
  408. currentSection->createActiveSpells();
  409. pos.h += currentSection->pos.h;
  410. }
  411. if (info.commander)
  412. {
  413. currentSection = new CWindowSection(this);
  414. currentSection->pos.y += pos.h;
  415. currentSection->createCommanderSection();
  416. pos.h += currentSection->pos.h;
  417. }
  418. if (!info.commander && !activeBonuses.empty())
  419. {
  420. currentSection = new CWindowSection(this);
  421. currentSection->pos.y += pos.h;
  422. currentSection->createBonuses();
  423. pos.h += currentSection->pos.h;
  424. }
  425. if (!info.popupWindow)
  426. {
  427. currentSection = new CWindowSection(this);
  428. currentSection->pos.y += pos.h;
  429. currentSection->createButtonPanel();
  430. pos.h += currentSection->pos.h;
  431. }
  432. updateShadow();
  433. pos = center(pos);
  434. }
  435. void CStackWindow::initBonusesList()
  436. {
  437. BonusList output, input;
  438. input = *(info.stackNode->getBonuses(Selector::durationType(Bonus::PERMANENT).And(Selector::anyRange())));
  439. while (!input.empty())
  440. {
  441. Bonus * b = input.front();
  442. output.push_back(new Bonus(*b));
  443. output.back()->val = input.valOfBonuses(Selector::typeSubtype(b->type, b->subtype)); //merge multiple bonuses into one
  444. input.remove_if (Selector::typeSubtype(b->type, b->subtype)); //remove used bonuses
  445. }
  446. BonusInfo bonusInfo;
  447. for(Bonus* b : output)
  448. {
  449. bonusInfo.name = info.stackNode->bonusToString(b, false);
  450. bonusInfo.imagePath = info.stackNode->bonusToGraphics(b);
  451. //if it's possible to give any description or image for this kind of bonus
  452. //TODO: figure out why half of bonuses don't have proper description
  453. if (!bonusInfo.name.empty() || !bonusInfo.imagePath.empty())
  454. activeBonuses.push_back(bonusInfo);
  455. }
  456. //handle Magic resistance separately :/
  457. int magicResistance = info.stackNode->magicResistance();
  458. if (magicResistance)
  459. {
  460. BonusInfo bonusInfo;
  461. Bonus b;
  462. b.type = Bonus::MAGIC_RESISTANCE;
  463. bonusInfo.name = VLC->getBth()->bonusToString(&b, info.stackNode, false);
  464. bonusInfo.description = VLC->getBth()->bonusToString(&b, info.stackNode, true);
  465. bonusInfo.imagePath = info.stackNode->bonusToGraphics(&b);
  466. activeBonuses.push_back(bonusInfo);
  467. }
  468. }
  469. void CStackWindow::init()
  470. {
  471. selectedIcon = nullptr;
  472. selectedSkill = 0;
  473. if (info.levelupInfo)
  474. selectedSkill = info.levelupInfo->skills.front();
  475. commanderTab = nullptr;
  476. activeTab = 0;
  477. initBonusesList();
  478. initSections();
  479. }
  480. CStackWindow::CStackWindow(const CStack * stack, bool popup):
  481. CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0))
  482. {
  483. info.stackNode = stack->base;
  484. info.creature = stack->type;
  485. info.creatureCount = stack->count;
  486. info.popupWindow = popup;
  487. init();
  488. }
  489. CStackWindow::CStackWindow(const CCreature * creature, bool popup):
  490. CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0))
  491. {
  492. info.stackNode = new CStackInstance(creature, 1); // FIXME: free data
  493. info.creature = creature;
  494. info.popupWindow = popup;
  495. init();
  496. }
  497. CStackWindow::CStackWindow(const CStackInstance * stack, bool popup):
  498. CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0))
  499. {
  500. info.stackNode = stack;
  501. info.creature = stack->type;
  502. info.creatureCount = stack->count;
  503. info.popupWindow = popup;
  504. init();
  505. }
  506. CStackWindow::CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & upgradeInfo, std::function<void(CreatureID)> callback):
  507. CWindowObject(BORDERED)
  508. {
  509. info.stackNode = stack;
  510. info.creature = stack->type;
  511. info.creatureCount = stack->count;
  512. info.upgradeInfo = StackWindowInfo::StackUpgradeInfo();
  513. info.dismissInfo = StackWindowInfo::StackDismissInfo();
  514. info.upgradeInfo->info = upgradeInfo;
  515. info.upgradeInfo->callback = callback;
  516. info.dismissInfo->callback = dismiss;
  517. init();
  518. }
  519. CStackWindow::CStackWindow(const CCommanderInstance * commander, bool popup):
  520. CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0))
  521. {
  522. info.stackNode = commander;
  523. info.creature = commander->type;
  524. info.commander = commander;
  525. info.creatureCount = 1;
  526. info.popupWindow = popup;
  527. init();
  528. }
  529. CStackWindow::CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback):
  530. CWindowObject(BORDERED)
  531. {
  532. info.stackNode = commander;
  533. info.creature = commander->type;
  534. info.commander = commander;
  535. info.creatureCount = 1;
  536. init();
  537. }