2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CHeroWindow.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "CHeroWindow.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
#include "CCreatureWindow.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "CKingdomInterface.h"
|
|
|
|
#include "GUIClasses.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
|
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../gui/TextAlignment.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../widgets/MiscWidgets.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/CComponent.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
|
|
|
#include "../render/CAnimation.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CArtHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../lib/CHeroHandler.h"
|
2017-08-30 12:35:23 +02:00
|
|
|
#include "../lib/CSkillHandler.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "../lib/mapObjects/CGHeroInstance.h"
|
2014-01-16 23:24:06 +03:00
|
|
|
#include "../lib/NetPacksBase.h"
|
2010-07-13 08:25:40 +03:00
|
|
|
|
2020-10-01 07:55:41 +02:00
|
|
|
TConstBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector & selector, const CSelector & limit, const CBonusSystemNode * root, const std::string & cachingStr) const
|
2011-02-27 21:58:14 +02:00
|
|
|
{
|
2017-07-16 11:58:05 +02:00
|
|
|
TBonusListPtr out(new BonusList());
|
2020-10-01 07:55:41 +02:00
|
|
|
TConstBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero, cachingStr);
|
|
|
|
TConstBonusListPtr bonusesFromPickedUpArtifact;
|
2011-02-27 21:58:14 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CArtifactsOfHero::SCommonPart> cp = cww->getCommonPart();
|
2011-07-02 18:12:35 +03:00
|
|
|
if(cp && cp->src.art && cp->src.valid() && cp->src.AOH && cp->src.AOH->getHero() == hero)
|
2011-06-25 16:53:15 +03:00
|
|
|
bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero);
|
|
|
|
else
|
2017-07-16 11:58:05 +02:00
|
|
|
bonusesFromPickedUpArtifact = TBonusListPtr(new BonusList());
|
2011-02-27 21:58:14 +02:00
|
|
|
|
2020-10-01 07:55:41 +02:00
|
|
|
for(const auto & b : *heroBonuses)
|
2011-06-25 16:53:15 +03:00
|
|
|
out->push_back(b);
|
2020-03-17 23:06:07 +02:00
|
|
|
|
2020-10-01 07:55:41 +02:00
|
|
|
for(const auto & b : *bonusesFromPickedUpArtifact)
|
2020-03-17 23:06:07 +02:00
|
|
|
*out -= b;
|
2011-06-25 16:53:15 +03:00
|
|
|
return out;
|
2011-02-27 21:58:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t CHeroWithMaybePickedArtifact::getTreeVersion() const
|
|
|
|
{
|
|
|
|
return hero->getTreeVersion(); //this assumes that hero and artifact belongs to main bonus tree
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CHeroWithMaybePickedArtifact::CHeroWithMaybePickedArtifact(CWindowWithArtifacts * Cww, const CGHeroInstance * Hero)
|
|
|
|
: hero(Hero), cww(Cww)
|
2011-02-27 21:58:14 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-13 08:25:40 +03:00
|
|
|
void CHeroSwitcher::clickLeft(tribool down, bool previousState)
|
|
|
|
{
|
|
|
|
if(!down)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
//TODO: do not recreate window
|
|
|
|
#if 0
|
|
|
|
owner->update(hero, true);
|
|
|
|
#else
|
2022-12-07 18:06:47 +02:00
|
|
|
MAYBE_UNUSED(owner);
|
2012-05-13 18:04:21 +03:00
|
|
|
const CGHeroInstance * buf = hero;
|
2018-07-25 00:36:48 +02:00
|
|
|
GH.popInts(1);
|
|
|
|
GH.pushIntT<CHeroWindow>(buf);
|
2018-04-07 13:34:11 +02:00
|
|
|
#endif // 0
|
2010-07-13 08:25:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CHeroSwitcher::CHeroSwitcher(CHeroWindow * owner_, Point pos_, const CGHeroInstance * hero_)
|
|
|
|
: CIntObject(LCLICK),
|
|
|
|
owner(owner_),
|
|
|
|
hero(hero_)
|
2010-07-13 08:25:40 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
pos += pos_;
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
image = std::make_shared<CAnimImage>("PortraitsSmall", hero->portrait);
|
2012-05-13 18:04:21 +03:00
|
|
|
pos.w = image->pos.w;
|
|
|
|
pos.h = image->pos.h;
|
2010-07-13 08:25:40 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CHeroWindow::CHeroWindow(const CGHeroInstance * hero)
|
2022-10-01 10:21:16 +02:00
|
|
|
: CStatusbarWindow(PLAYER_COLORED, "HeroScr4"),
|
2012-06-15 20:08:19 +03:00
|
|
|
heroWArt(this, hero)
|
2008-01-10 21:01:25 +02:00
|
|
|
{
|
2014-08-03 14:16:19 +03:00
|
|
|
auto & heroscrn = CGI->generaltexth->heroscrn;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2011-01-06 22:00:19 +02:00
|
|
|
curHero = hero;
|
2009-06-18 18:05:00 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
banner = std::make_shared<CAnimImage>("CREST58", LOCPLINT->playerID.getNum(), 0, 606, 8);
|
2022-11-26 23:12:20 +02:00
|
|
|
name = std::make_shared<CLabel>(190, 38, EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW);
|
|
|
|
title = std::make_shared<CLabel>(190, 65, EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE);
|
2008-01-30 15:18:08 +02:00
|
|
|
|
2022-10-01 10:21:16 +02:00
|
|
|
statusbar = CGStatusBar::create(7, 559, "ADROLLVR.bmp", 660);
|
2008-01-12 14:55:45 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
quitButton = std::make_shared<CButton>(Point(609, 516), "hsbtns.def", CButton::tooltip(heroscrn[17]), [=](){ close(); }, SDLK_RETURN);
|
2011-09-22 17:21:53 +03:00
|
|
|
quitButton->assignedKeys.insert(SDLK_ESCAPE);
|
2008-09-24 11:15:49 +03:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
dismissLabel = std::make_shared<CTextBox>(CGI->generaltexth->jktexts[8], Rect(370, 430, 65, 35), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2018-04-07 13:34:11 +02:00
|
|
|
dismissButton = std::make_shared<CButton>(Point(454, 429), "hsbtns2.def", CButton::tooltip(heroscrn[28]), [=](){ dismissCurrent(); }, SDLK_d);
|
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
questlogLabel = std::make_shared<CTextBox>(CGI->generaltexth->jktexts[9], Rect(510, 430, 65, 35), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2018-04-07 13:34:11 +02:00
|
|
|
questlogButton = std::make_shared<CButton>(Point(314, 429), "hsbtns4.def", CButton::tooltip(heroscrn[0]), [=](){ LOCPLINT->showQuestLog(); }, SDLK_q);
|
2008-11-28 03:36:34 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
formations = std::make_shared<CToggleGroup>(0);
|
|
|
|
formations->addToggle(0, std::make_shared<CToggleButton>(Point(481, 483), "hsbtns6.def", std::make_pair(heroscrn[23], heroscrn[29]), 0, SDLK_t));
|
|
|
|
formations->addToggle(1, std::make_shared<CToggleButton>(Point(481, 519), "hsbtns7.def", std::make_pair(heroscrn[24], heroscrn[30]), 0, SDLK_l));
|
|
|
|
|
|
|
|
if(hero->commander)
|
2012-05-16 20:29:05 +03:00
|
|
|
{
|
2022-12-27 22:19:05 +02:00
|
|
|
commanderButton = std::make_shared<CButton>(Point(317, 18), "buttons/commander", CButton::tooltipLocalized("vcmi.heroWindow.openCommander"), [&](){ commanderWindow(); }, SDLK_c);
|
2012-05-16 20:29:05 +03:00
|
|
|
}
|
|
|
|
|
2009-06-19 15:10:36 +03:00
|
|
|
//right list of heroes
|
2012-05-13 18:04:21 +03:00
|
|
|
for(int i=0; i < std::min(LOCPLINT->cb->howManyHeroes(false), 8); i++)
|
2018-04-07 13:34:11 +02:00
|
|
|
heroList.push_back(std::make_shared<CHeroSwitcher>(this, Point(612, 87 + i * 54), LOCPLINT->cb->getHeroBySerial(i, false)));
|
2010-12-17 00:32:53 +02:00
|
|
|
|
2008-01-19 20:58:24 +02:00
|
|
|
//areas
|
2018-04-07 13:34:11 +02:00
|
|
|
portraitArea = std::make_shared<LRClickableAreaWText>(Rect(18, 18, 58, 64));
|
|
|
|
portraitImage = std::make_shared<CAnimImage>("PortraitsLarge", 0, 0, 19, 19);
|
2009-06-19 15:10:36 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(int v = 0; v < GameConstants::PRIMARY_SKILLS; ++v)
|
2008-01-27 18:07:27 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
auto area = std::make_shared<LRClickableAreaWTextComp>(Rect(30 + 70 * v, 109, 42, 64), CComponent::primskill);
|
2010-12-17 00:32:53 +02:00
|
|
|
area->text = CGI->generaltexth->arraytxt[2+v];
|
|
|
|
area->type = v;
|
|
|
|
area->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % CGI->generaltexth->primarySkillNames[v]);
|
|
|
|
primSkillAreas.push_back(area);
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
auto value = std::make_shared<CLabel>(53 + 70 * v, 166, FONT_SMALL, ETextAlignment::CENTER);
|
2018-04-07 13:34:11 +02:00
|
|
|
primSkillValues.push_back(value);
|
2010-02-01 01:30:47 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
auto primSkills = std::make_shared<CAnimation>("PSKIL42");
|
|
|
|
primSkills->preload();
|
|
|
|
primSkillImages.push_back(std::make_shared<CAnimImage>(primSkills, 0, 0, 32, 111));
|
|
|
|
primSkillImages.push_back(std::make_shared<CAnimImage>(primSkills, 1, 0, 102, 111));
|
|
|
|
primSkillImages.push_back(std::make_shared<CAnimImage>(primSkills, 2, 0, 172, 111));
|
|
|
|
primSkillImages.push_back(std::make_shared<CAnimImage>(primSkills, 3, 0, 162, 230));
|
|
|
|
primSkillImages.push_back(std::make_shared<CAnimImage>(primSkills, 4, 0, 20, 230));
|
|
|
|
primSkillImages.push_back(std::make_shared<CAnimImage>(primSkills, 5, 0, 242, 111));
|
|
|
|
|
|
|
|
specImage = std::make_shared<CAnimImage>("UN44", 0, 0, 18, 180);
|
|
|
|
specArea = std::make_shared<LRClickableAreaWText>(Rect(18, 180, 136, 42), CGI->generaltexth->heroscrn[27]);
|
|
|
|
specName = std::make_shared<CLabel>(69, 205);
|
|
|
|
|
|
|
|
expArea = std::make_shared<LRClickableAreaWText>(Rect(18, 228, 136, 42), CGI->generaltexth->heroscrn[9]);
|
|
|
|
morale = std::make_shared<MoraleLuckBox>(true, Rect(175, 179, 53, 45));
|
|
|
|
luck = std::make_shared<MoraleLuckBox>(false, Rect(233, 179, 53, 45));
|
|
|
|
spellPointsArea = std::make_shared<LRClickableAreaWText>(Rect(162,228, 136, 42), CGI->generaltexth->heroscrn[22]);
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
expValue = std::make_shared<CLabel>(68, 252);
|
|
|
|
manaValue = std::make_shared<CLabel>(211, 252);
|
2008-01-29 15:55:14 +02:00
|
|
|
|
2016-10-28 12:27:45 +02:00
|
|
|
auto secSkills = std::make_shared<CAnimation>("SECSKILL");
|
2011-02-23 17:51:33 +02:00
|
|
|
for(int i = 0; i < std::min<size_t>(hero->secSkills.size(), 8u); ++i)
|
2008-01-28 14:28:18 +02:00
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
Rect r = Rect(i%2 == 0 ? 18 : 162, 276 + 48 * (i/2), 136, 42);
|
2018-04-07 13:34:11 +02:00
|
|
|
secSkillAreas.push_back(std::make_shared<LRClickableAreaWTextComp>(r, CComponent::secskill));
|
|
|
|
secSkillImages.push_back(std::make_shared<CAnimImage>(secSkills, 0, 0, r.x, r.y));
|
2013-03-14 23:44:00 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
int x = (i % 2) ? 212 : 68;
|
|
|
|
int y = 280 + 48 * (i/2);
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
secSkillValues.push_back(std::make_shared<CLabel>(x, y, FONT_SMALL, ETextAlignment::TOPLEFT));
|
|
|
|
secSkillNames.push_back(std::make_shared<CLabel>(x, y+20, FONT_SMALL, ETextAlignment::TOPLEFT));
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2010-12-17 00:32:53 +02:00
|
|
|
|
2013-06-23 22:35:54 +03:00
|
|
|
// various texts
|
2022-11-26 23:12:20 +02:00
|
|
|
labels.push_back(std::make_shared<CLabel>(52, 99, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[1]));
|
|
|
|
labels.push_back(std::make_shared<CLabel>(123, 99, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[2]));
|
|
|
|
labels.push_back(std::make_shared<CLabel>(193, 99, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[3]));
|
|
|
|
labels.push_back(std::make_shared<CLabel>(262, 99, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[4]));
|
|
|
|
|
|
|
|
labels.push_back(std::make_shared<CLabel>(69, 183, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->jktexts[5]));
|
|
|
|
labels.push_back(std::make_shared<CLabel>(69, 232, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->jktexts[6]));
|
|
|
|
labels.push_back(std::make_shared<CLabel>(213, 232, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->jktexts[7]));
|
2013-06-23 22:35:54 +03:00
|
|
|
|
2011-01-06 22:00:19 +02:00
|
|
|
update(hero);
|
2008-01-10 21:01:25 +02:00
|
|
|
}
|
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
2014-08-03 14:16:19 +03:00
|
|
|
{
|
|
|
|
auto & heroscrn = CGI->generaltexth->heroscrn;
|
|
|
|
|
2008-01-28 14:28:18 +02:00
|
|
|
if(!hero) //something strange... no hero? it shouldn't happen
|
2010-12-17 00:32:53 +02:00
|
|
|
{
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->error("Set nullptr hero? no way...");
|
2010-12-17 00:32:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-07-21 22:50:15 +03:00
|
|
|
|
2011-01-06 22:00:19 +02:00
|
|
|
assert(hero == curHero);
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2023-01-02 13:27:03 +02:00
|
|
|
name->setText(curHero->getNameTranslated());
|
|
|
|
title->setText((boost::format(CGI->generaltexth->allTexts[342]) % curHero->level % curHero->type->heroClass->getNameTranslated()).str());
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-01-02 13:27:03 +02:00
|
|
|
specArea->text = curHero->type->getSpecialtyDescriptionTranslated();
|
2012-12-16 16:47:53 +03:00
|
|
|
specImage->setFrame(curHero->type->imageIndex);
|
2023-01-02 13:27:03 +02:00
|
|
|
specName->setText(curHero->type->getSpecialtyNameTranslated());
|
2008-11-28 03:36:34 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
tacticsButton = std::make_shared<CToggleButton>(Point(539, 483), "hsbtns8.def", std::make_pair(heroscrn[26], heroscrn[31]), 0, SDLK_b);
|
2014-08-03 14:16:19 +03:00
|
|
|
tacticsButton->addHoverText(CButton::HIGHLIGHTED, CGI->generaltexth->heroscrn[25]);
|
2008-01-31 14:10:59 +02:00
|
|
|
|
2023-01-02 13:27:03 +02:00
|
|
|
dismissButton->addHoverText(CButton::NORMAL, boost::str(boost::format(CGI->generaltexth->heroscrn[16]) % curHero->getNameTranslated() % curHero->type->heroClass->getNameTranslated()));
|
|
|
|
portraitArea->hoverText = boost::str(boost::format(CGI->generaltexth->allTexts[15]) % curHero->getNameTranslated() % curHero->type->heroClass->getNameTranslated());
|
|
|
|
portraitArea->text = curHero->getBiographyTranslated();
|
2012-05-13 18:04:21 +03:00
|
|
|
portraitImage->setFrame(curHero->portrait);
|
2008-01-19 15:19:58 +02:00
|
|
|
|
2010-12-17 00:32:53 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
2011-01-06 22:00:19 +02:00
|
|
|
if(!garr)
|
|
|
|
{
|
2014-08-03 14:16:19 +03:00
|
|
|
std::string helpBox = heroscrn[32];
|
|
|
|
boost::algorithm::replace_first(helpBox, "%s", CGI->generaltexth->allTexts[43]);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
garr = std::make_shared<CGarrisonInt>(15, 485, 8, Point(), curHero);
|
|
|
|
auto split = std::make_shared<CButton>(Point(539, 519), "hsbtns9.def", CButton::tooltip(CGI->generaltexth->allTexts[256], helpBox), [&](){ garr->splitClick(); });
|
2011-01-06 22:00:19 +02:00
|
|
|
garr->addSplitBtn(split);
|
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
if(!arts)
|
2011-01-06 22:00:19 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
arts = std::make_shared<CArtifactsOfHero>(Point(-65, -8), true);
|
2011-02-27 21:58:14 +02:00
|
|
|
arts->setHero(curHero);
|
2018-04-07 13:34:11 +02:00
|
|
|
addSet(arts);
|
2011-01-06 22:00:19 +02:00
|
|
|
}
|
2009-09-09 09:04:42 +03:00
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
int serial = LOCPLINT->cb->getHeroSerial(curHero, false);
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
listSelection.reset();
|
|
|
|
if(serial >= 0)
|
|
|
|
listSelection = std::make_shared<CPicture>("HPSYYY", 612, 33 + serial * 54);
|
2012-05-13 18:04:21 +03:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
|
2009-06-19 15:10:36 +03:00
|
|
|
//primary skills support
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t g=0; g<primSkillAreas.size(); ++g)
|
2008-01-27 18:07:27 +02:00
|
|
|
{
|
2013-02-06 13:16:44 +03:00
|
|
|
primSkillAreas[g]->bonusValue = heroWArt.getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(g));
|
2018-04-07 13:34:11 +02:00
|
|
|
primSkillValues[g]->setText(boost::lexical_cast<std::string>(primSkillAreas[g]->bonusValue));
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
2009-07-03 22:57:14 +03:00
|
|
|
|
2009-06-19 15:10:36 +03:00
|
|
|
//secondary skills support
|
2011-01-06 22:00:19 +02:00
|
|
|
for(size_t g=0; g< secSkillAreas.size(); ++g)
|
2008-01-28 14:28:18 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
int skill = curHero->secSkills[g].first;
|
|
|
|
int level = curHero->getSecSkillLevel(SecondarySkill(curHero->secSkills[g].first));
|
2023-01-01 22:20:41 +02:00
|
|
|
std::string skillName = CGI->skillh->getByIndex(skill)->getNameTranslated();
|
2018-04-07 13:34:11 +02:00
|
|
|
std::string skillValue = CGI->generaltexth->levels[level-1];
|
|
|
|
|
2009-07-03 22:57:14 +03:00
|
|
|
secSkillAreas[g]->type = skill;
|
2010-07-13 08:25:40 +03:00
|
|
|
secSkillAreas[g]->bonusValue = level;
|
2023-01-01 22:20:41 +02:00
|
|
|
secSkillAreas[g]->text = CGI->skillh->getByIndex(skill)->getDescriptionTranslated(level);
|
2018-04-07 13:34:11 +02:00
|
|
|
secSkillAreas[g]->hoverText = boost::str(boost::format(heroscrn[21]) % skillValue % skillName);
|
2012-05-13 18:04:21 +03:00
|
|
|
secSkillImages[g]->setFrame(skill*3 + level + 2);
|
2018-04-07 13:34:11 +02:00
|
|
|
secSkillNames[g]->setText(skillName);
|
|
|
|
secSkillValues[g]->setText(skillValue);
|
2008-01-28 14:28:18 +02:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::ostringstream expstr;
|
|
|
|
expstr << curHero->exp;
|
|
|
|
expValue->setText(expstr.str());
|
|
|
|
|
|
|
|
std::ostringstream manastr;
|
|
|
|
manastr << curHero->mana << '/' << heroWArt.manaLimit();
|
|
|
|
manaValue->setText(manastr.str());
|
|
|
|
|
2009-10-28 12:45:45 +02:00
|
|
|
//printing experience - original format does not support ui64
|
2010-12-17 00:32:53 +02:00
|
|
|
expArea->text = CGI->generaltexth->allTexts[2];
|
2011-02-27 21:58:14 +02:00
|
|
|
boost::replace_first(expArea->text, "%d", boost::lexical_cast<std::string>(curHero->level));
|
|
|
|
boost::replace_first(expArea->text, "%d", boost::lexical_cast<std::string>(CGI->heroh->reqExp(curHero->level+1)));
|
|
|
|
boost::replace_first(expArea->text, "%d", boost::lexical_cast<std::string>(curHero->exp));
|
2008-09-29 00:01:49 +03:00
|
|
|
|
2011-02-28 17:14:26 +02:00
|
|
|
//printing spell points, boost::format can't be used due to locale issues
|
|
|
|
spellPointsArea->text = CGI->generaltexth->allTexts[205];
|
2023-01-02 13:27:03 +02:00
|
|
|
boost::replace_first(spellPointsArea->text, "%s", boost::lexical_cast<std::string>(curHero->getNameTranslated()));
|
2011-02-28 17:14:26 +02:00
|
|
|
boost::replace_first(spellPointsArea->text, "%d", boost::lexical_cast<std::string>(curHero->mana));
|
|
|
|
boost::replace_first(spellPointsArea->text, "%d", boost::lexical_cast<std::string>(heroWArt.manaLimit()));
|
2008-01-30 12:55:43 +02:00
|
|
|
|
2011-02-27 21:58:14 +02:00
|
|
|
//if we have exchange window with this curHero open
|
2010-02-04 17:50:59 +02:00
|
|
|
bool noDismiss=false;
|
2018-07-25 00:36:48 +02:00
|
|
|
for(auto isa : GH.listInt)
|
2010-02-04 17:50:59 +02:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
if(CExchangeWindow * cew = dynamic_cast<CExchangeWindow*>(isa.get()))
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
|
|
|
for(int g=0; g < cew->heroInst.size(); ++g)
|
2011-02-27 21:58:14 +02:00
|
|
|
if(cew->heroInst[g] == curHero)
|
2010-12-17 00:32:53 +02:00
|
|
|
noDismiss = true;
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2010-12-17 00:32:53 +02:00
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
if(dynamic_cast<CKingdomInterface*>(isa.get()))
|
2010-12-17 00:32:53 +02:00
|
|
|
noDismiss = true;
|
2010-02-04 17:50:59 +02:00
|
|
|
}
|
2015-03-12 22:47:46 +02:00
|
|
|
//if player only have one hero and no towns
|
|
|
|
if(!LOCPLINT->cb->howManyTowns() && LOCPLINT->cb->howManyHeroes() == 1)
|
|
|
|
noDismiss = true;
|
|
|
|
|
2016-01-27 12:47:42 +02:00
|
|
|
if(curHero->isMissionCritical())
|
|
|
|
noDismiss = true;
|
|
|
|
|
2011-02-27 21:58:14 +02:00
|
|
|
dismissButton->block(!!curHero->visitedTown || noDismiss);
|
2010-12-17 00:32:53 +02:00
|
|
|
|
2013-02-04 22:43:16 +03:00
|
|
|
if(curHero->getSecSkillLevel(SecondarySkill::TACTICS) == 0)
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
2010-12-17 00:32:53 +02:00
|
|
|
tacticsButton->block(true);
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
else
|
|
|
|
{
|
2010-12-17 00:32:53 +02:00
|
|
|
tacticsButton->block(false);
|
2018-04-07 13:34:11 +02:00
|
|
|
tacticsButton->addCallback([&](bool on){curHero->tacticFormationEnabled = on;});
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
2008-09-24 11:15:49 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
formations->resetCallback();
|
2009-06-19 15:10:36 +03:00
|
|
|
//setting formations
|
2014-08-03 14:16:19 +03:00
|
|
|
formations->setSelected(curHero->formation);
|
2018-04-07 13:34:11 +02:00
|
|
|
formations->addCallback([=](int value){ LOCPLINT->cb->setFormation(curHero, value);});
|
2008-09-24 11:15:49 +03:00
|
|
|
|
2011-02-27 21:58:14 +02:00
|
|
|
morale->set(&heroWArt);
|
|
|
|
luck->set(&heroWArt);
|
2011-01-06 22:00:19 +02:00
|
|
|
|
|
|
|
if(redrawNeeded)
|
|
|
|
redraw();
|
2008-01-11 20:56:39 +02:00
|
|
|
}
|
|
|
|
|
2008-01-15 20:50:52 +02:00
|
|
|
void CHeroWindow::dismissCurrent()
|
|
|
|
{
|
2017-07-17 14:35:57 +02:00
|
|
|
CFunctionList<void()> ony = [=](){ close(); };
|
|
|
|
ony += [=](){ LOCPLINT->cb->dismissHero(curHero); };
|
2018-04-07 13:34:11 +02:00
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22], ony, nullptr);
|
2008-01-15 20:50:52 +02:00
|
|
|
}
|
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
void CHeroWindow::commanderWindow()
|
|
|
|
{
|
2012-05-28 22:29:32 +03:00
|
|
|
//bool artSelected = false;
|
2020-10-01 07:55:41 +02:00
|
|
|
std::shared_ptr<CArtifactsOfHero::SCommonPart> commonInfo = getCommonPart();
|
2012-05-20 11:39:19 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(const CArtifactInstance *art = commonInfo->src.art)
|
2012-05-20 11:39:19 +03:00
|
|
|
{
|
|
|
|
const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();
|
2012-05-28 22:29:32 +03:00
|
|
|
//artSelected = true;
|
2013-02-12 22:49:40 +03:00
|
|
|
ArtifactPosition freeSlot = art->firstAvailableSlot (curHero->commander);
|
2018-04-07 13:34:11 +02:00
|
|
|
if(freeSlot < ArtifactPosition::COMMANDER_AFTER_LAST) //we don't want to put it in commander's backpack!
|
2012-05-25 18:10:38 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
ArtifactLocation src(srcHero, commonInfo->src.slotID);
|
|
|
|
ArtifactLocation dst(curHero->commander.get(), freeSlot);
|
2012-05-25 18:10:38 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(art->canBePutAt(dst, true))
|
2012-05-25 18:10:38 +03:00
|
|
|
{ //equip clicked stack
|
|
|
|
if(dst.getArt())
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->swapArtifacts (dst, ArtifactLocation(srcHero, dst.getArt()->firstBackpackSlot(srcHero)));
|
|
|
|
}
|
|
|
|
LOCPLINT->cb->swapArtifacts(src, dst);
|
2012-05-20 11:39:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
GH.pushIntT<CStackWindow>(curHero->commander, false);
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
}
|
|
|
|
|
2016-09-19 18:54:05 +02:00
|
|
|
void CHeroWindow::updateGarrisons()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
garr->recreateSlots();
|
2016-09-19 18:54:05 +02:00
|
|
|
morale->set(&heroWArt);
|
|
|
|
}
|