2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "CCreatureWindow.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/Buttons.h"
|
2016-11-04 18:54:09 +02:00
|
|
|
#include "../widgets/CArtifactHolder.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/CComponent.h"
|
|
|
|
#include "../widgets/Images.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../widgets/ObjectLists.h"
|
2014-07-14 17:44:15 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/BattleState.h"
|
2014-07-14 17:23:24 +03:00
|
|
|
#include "../../lib/CBonusTypeHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CModHandler.h"
|
2014-07-14 17:23:24 +03:00
|
|
|
#include "../../lib/CHeroHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "../../lib/spells/CSpellHandler.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../../lib/CGameState.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
using namespace CSDL_Ext;
|
|
|
|
|
2012-02-10 13:32:21 +03:00
|
|
|
class CCreatureArtifactInstance;
|
2012-07-03 11:07:34 +03:00
|
|
|
class CSelectableSkill;
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
/*
|
|
|
|
* CCreatureWindow.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
struct StackWindowInfo
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
// helper structs
|
|
|
|
struct CommanderLevelInfo
|
2011-05-13 17:33:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
std::vector<ui32> skills;
|
|
|
|
std::function<void(ui32)> callback;
|
|
|
|
};
|
|
|
|
struct StackDismissInfo
|
|
|
|
{
|
|
|
|
std::function<void()> callback;
|
|
|
|
};
|
|
|
|
struct StackUpgradeInfo
|
|
|
|
{
|
|
|
|
UpgradeInfo info;
|
|
|
|
std::function<void(CreatureID)> callback;
|
|
|
|
};
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
// pointers to permament objects in game state
|
|
|
|
const CCreature * creature;
|
|
|
|
const CCommanderInstance * commander;
|
|
|
|
const CStackInstance * stackNode;
|
2014-09-19 16:31:01 +03:00
|
|
|
const CStack * stack;
|
2014-06-27 18:33:30 +03:00
|
|
|
const CGHeroInstance * owner;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
// temporary objects which should be kept as copy if needed
|
|
|
|
boost::optional<CommanderLevelInfo> levelupInfo;
|
|
|
|
boost::optional<StackDismissInfo> dismissInfo;
|
|
|
|
boost::optional<StackUpgradeInfo> upgradeInfo;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
// misc fields
|
|
|
|
unsigned int creatureCount;
|
|
|
|
bool popupWindow;
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
StackWindowInfo();
|
|
|
|
};
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
namespace
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
namespace EStat
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
enum EStat
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
ATTACK,
|
|
|
|
DEFENCE,
|
|
|
|
SHOTS,
|
|
|
|
DAMAGE,
|
|
|
|
HEALTH,
|
|
|
|
HEALTH_LEFT,
|
|
|
|
SPEED,
|
|
|
|
MANA
|
|
|
|
};
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
StackWindowInfo::StackWindowInfo():
|
|
|
|
creature(nullptr),
|
|
|
|
commander(nullptr),
|
|
|
|
stackNode(nullptr),
|
2014-09-19 16:31:01 +03:00
|
|
|
stack(nullptr),
|
2014-06-26 22:07:33 +03:00
|
|
|
owner(nullptr),
|
|
|
|
creatureCount(0),
|
|
|
|
popupWindow(false)
|
2012-05-16 20:29:05 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createBackground(std::string path)
|
2012-07-03 11:07:34 +03:00
|
|
|
{
|
2016-11-27 18:00:16 +02:00
|
|
|
CPicture * background = new CPicture("stackWindow/" + path);
|
2014-06-26 22:07:33 +03:00
|
|
|
pos = background->pos;
|
|
|
|
}
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::printStatString(int index, std::string name, std::string value)
|
|
|
|
{
|
|
|
|
new CLabel(145, 32 + index*19, FONT_SMALL, TOPLEFT, Colors::WHITE, name);
|
|
|
|
new CLabel(307, 48 + index*19, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, value);
|
|
|
|
}
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::printStatRange(int index, std::string name, int min, int max)
|
|
|
|
{
|
|
|
|
if(min != max)
|
|
|
|
printStatString(index, name, boost::str(boost::format("%d - %d") % min % max));
|
|
|
|
else
|
|
|
|
printStatString(index, name, boost::str(boost::format("%d") % min));
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::printStatBase(int index, std::string name, int base, int current)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
if(base != current)
|
|
|
|
printStatString(index, name, boost::str(boost::format("%d (%d)") % base % current));
|
2011-04-09 22:34:48 +03:00
|
|
|
else
|
2014-06-26 22:07:33 +03:00
|
|
|
printStatString(index, name, boost::str(boost::format("%d") % base));
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::printStat(int index, std::string name, int value)
|
|
|
|
{
|
|
|
|
printStatBase(index, name, value, value);
|
|
|
|
}
|
2011-08-05 10:59:15 +03:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
std::string CStackWindow::generateStackExpDescription()
|
|
|
|
{
|
|
|
|
const CStackInstance * stack = info->stackNode;
|
|
|
|
const CCreature * creature = info->creature;
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
int tier = stack->type->level;
|
|
|
|
int rank = stack->getExpRank();
|
|
|
|
if (!vstd::iswithin(tier, 1, 7))
|
|
|
|
tier = 0;
|
|
|
|
int number;
|
|
|
|
std::string expText = CGI->generaltexth->zcrexp[325];
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%s", creature->namePl);
|
|
|
|
boost::replace_first(expText, "%s", CGI->generaltexth->zcrexp[rank]);
|
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(rank));
|
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(stack->experience));
|
2014-07-04 12:48:09 +03:00
|
|
|
number = CGI->creh->expRanks[tier][rank] - stack->experience;
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(number));
|
2012-05-22 20:16:37 +03:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
number = CGI->creh->maxExpPerBattle[tier]; //percent
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i%", boost::lexical_cast<std::string>(number));
|
2014-07-04 12:48:09 +03:00
|
|
|
number *= CGI->creh->expRanks[tier].back() / 100; //actual amount
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(number));
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(stack->count)); //Number of Creatures in stack
|
2012-05-18 22:44:15 +03:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
int expmin = std::max(CGI->creh->expRanks[tier][std::max(rank-1, 0)], (ui32)1);
|
|
|
|
number = (stack->count * (stack->experience - expmin)) / expmin; //Maximum New Recruits without losing current Rank
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(number)); //TODO
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%.2f", boost::lexical_cast<std::string>(1)); //TODO Experience Multiplier
|
2014-07-04 12:48:09 +03:00
|
|
|
number = CGI->creh->expAfterUpgrade;
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%.2f", boost::lexical_cast<std::string>(number) + "%"); //Upgrade Multiplier
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
expmin = CGI->creh->expRanks[tier][9];
|
|
|
|
int expmax = CGI->creh->expRanks[tier][10];
|
|
|
|
number = expmax - expmin;
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(number)); //Experience after Rank 10
|
2014-07-04 12:48:09 +03:00
|
|
|
number = (stack->count * (expmax - expmin)) / expmin;
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(expText, "%i", boost::lexical_cast<std::string>(number)); //Maximum New Recruits to remain at Rank 10 if at Maximum Experience
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
return expText;
|
|
|
|
}
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2014-07-05 11:48:03 +03:00
|
|
|
void CStackWindow::removeStackArtifact(ArtifactPosition pos)
|
|
|
|
{
|
|
|
|
auto art = info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT);
|
|
|
|
LOCPLINT->cb->swapArtifacts(ArtifactLocation(info->stackNode, pos),
|
|
|
|
ArtifactLocation(info->owner, art->firstBackpackSlot(info->owner)));
|
2016-10-30 17:32:28 +02:00
|
|
|
stackArtifactButton.reset();
|
|
|
|
stackArtifactHelp.reset();
|
|
|
|
stackArtifactIcon.reset();
|
|
|
|
redraw();
|
2014-07-05 11:48:03 +03:00
|
|
|
}
|
2013-03-06 21:49:56 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
if (showExp && showArt)
|
|
|
|
createBackground("info-panel-2");
|
|
|
|
else if (showExp || showArt)
|
|
|
|
createBackground("info-panel-1");
|
|
|
|
else
|
|
|
|
createBackground("info-panel-0");
|
2014-03-07 16:21:09 +03:00
|
|
|
|
2014-09-19 16:31:01 +03:00
|
|
|
auto pic = new CCreaturePic(5, 41, parent->info->creature);
|
|
|
|
|
|
|
|
if (parent->info->stackNode != nullptr && parent->info->commander == nullptr)
|
|
|
|
{
|
|
|
|
//normal stack, not a commander and not non-existing stack (e.g. recruitment dialog)
|
2015-08-25 11:16:47 +02:00
|
|
|
pic->setAmount(parent->info->creatureCount);
|
2014-09-19 16:31:01 +03:00
|
|
|
}
|
2013-03-06 21:49:56 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
std::string visibleName;
|
2014-06-27 18:33:30 +03:00
|
|
|
if (parent->info->commander != nullptr)
|
|
|
|
visibleName = parent->info->commander->type->nameSing;
|
2014-06-26 22:07:33 +03:00
|
|
|
else
|
2014-06-27 18:33:30 +03:00
|
|
|
visibleName = parent->info->creature->namePl;
|
2014-06-26 22:07:33 +03:00
|
|
|
new CLabel(215, 12, FONT_SMALL, CENTER, Colors::YELLOW, visibleName);
|
2014-03-07 16:21:09 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
int dmgMultiply = 1;
|
2014-06-27 18:33:30 +03:00
|
|
|
if(parent->info->owner && parent->info->stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
|
|
|
dmgMultiply += parent->info->owner->Attack();
|
2014-03-07 16:21:09 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
new CPicture("stackWindow/icons", 117, 32);
|
2011-10-20 14:03:04 +03:00
|
|
|
|
2014-09-19 16:31:01 +03:00
|
|
|
const CStack * battleStack = parent->info->stack;
|
2014-06-27 18:33:30 +03:00
|
|
|
bool shooter = parent->info->stackNode->hasBonusOfType(Bonus::SHOOTER) && parent->info->stackNode->valOfBonuses(Bonus::SHOTS);
|
|
|
|
bool caster = parent->info->stackNode->valOfBonuses(Bonus::CASTS);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
if (battleStack != nullptr) // in battle
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
2015-04-11 13:05:00 +02:00
|
|
|
printStatBase(EStat::ATTACK, CGI->generaltexth->primarySkillNames[0], parent->info->creature->Attack(), battleStack->Attack());
|
|
|
|
printStatBase(EStat::DEFENCE, CGI->generaltexth->primarySkillNames[1], parent->info->creature->Defense(false), battleStack->Defense());
|
|
|
|
printStatRange(EStat::DAMAGE, CGI->generaltexth->allTexts[199], parent->info->stackNode->getMinDamage() * dmgMultiply, battleStack->getMaxDamage() * dmgMultiply);
|
|
|
|
printStatBase(EStat::HEALTH, CGI->generaltexth->allTexts[388], parent->info->creature->valOfBonuses(Bonus::STACK_HEALTH), battleStack->valOfBonuses(Bonus::STACK_HEALTH));
|
|
|
|
printStatBase(EStat::SPEED, CGI->generaltexth->zelp[441].first, parent->info->creature->Speed(), battleStack->Speed());
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
if (shooter)
|
|
|
|
printStatBase(EStat::SHOTS, CGI->generaltexth->allTexts[198], battleStack->valOfBonuses(Bonus::SHOTS), battleStack->shots);
|
|
|
|
if (caster)
|
|
|
|
printStatBase(EStat::MANA, CGI->generaltexth->allTexts[399], battleStack->valOfBonuses(Bonus::CASTS), battleStack->casts);
|
|
|
|
printStat(EStat::HEALTH_LEFT, CGI->generaltexth->allTexts[200], battleStack->firstHPleft);
|
2012-07-04 17:41:53 +03:00
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
else
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2015-04-11 13:05:00 +02:00
|
|
|
printStatBase(EStat::ATTACK, CGI->generaltexth->primarySkillNames[0], parent->info->creature->Attack(), parent->info->stackNode->Attack());
|
|
|
|
printStatBase(EStat::DEFENCE, CGI->generaltexth->primarySkillNames[1], parent->info->creature->Defense(false), parent->info->stackNode->Defense());
|
|
|
|
printStatRange(EStat::DAMAGE, CGI->generaltexth->allTexts[199], parent->info->stackNode->getMinDamage() * dmgMultiply, parent->info->stackNode->getMaxDamage() * dmgMultiply);
|
|
|
|
printStatBase(EStat::HEALTH, CGI->generaltexth->allTexts[388], parent->info->creature->valOfBonuses(Bonus::STACK_HEALTH), parent->info->stackNode->valOfBonuses(Bonus::STACK_HEALTH));
|
|
|
|
printStatBase(EStat::SPEED, CGI->generaltexth->zelp[441].first, parent->info->creature->Speed(), parent->info->stackNode->Speed());
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
if (shooter)
|
2014-06-27 18:33:30 +03:00
|
|
|
printStat(EStat::SHOTS, CGI->generaltexth->allTexts[198], parent->info->stackNode->valOfBonuses(Bonus::SHOTS));
|
2014-06-26 22:07:33 +03:00
|
|
|
if (caster)
|
2014-06-27 18:33:30 +03:00
|
|
|
printStat(EStat::MANA, CGI->generaltexth->allTexts[399], parent->info->stackNode->valOfBonuses(Bonus::CASTS));
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
auto morale = new MoraleLuckBox(true, genRect(42, 42, 321, 110));
|
2014-06-27 18:33:30 +03:00
|
|
|
morale->set(parent->info->stackNode);
|
2014-06-26 22:07:33 +03:00
|
|
|
auto luck = new MoraleLuckBox(false, genRect(42, 42, 375, 110));
|
2014-06-27 18:33:30 +03:00
|
|
|
luck->set(parent->info->stackNode);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-07-04 12:48:09 +03:00
|
|
|
if (showExp)
|
2012-05-22 20:16:37 +03:00
|
|
|
{
|
2014-07-04 12:48:09 +03:00
|
|
|
const CStackInstance * stack = parent->info->stackNode;
|
|
|
|
Point pos = showArt ? Point(321, 32) : Point(347, 32);
|
|
|
|
if (parent->info->commander)
|
2012-05-22 20:16:37 +03:00
|
|
|
{
|
2014-07-04 12:48:09 +03:00
|
|
|
const CCommanderInstance * commander = parent->info->commander;
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->expRankIcon = new CAnimImage("PSKIL42", 4, 0, pos.x, pos.y); // experience icon
|
2016-10-30 17:32:28 +02:00
|
|
|
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->expArea = new LRClickableAreaWTextComp(Rect(
|
|
|
|
pos.x, pos.y, 44, 44), CComponent::experience);
|
2016-10-30 17:32:28 +02:00
|
|
|
parent->expArea->text = CGI->generaltexth->allTexts[2];
|
2016-10-30 23:21:26 +02:00
|
|
|
reinterpret_cast<LRClickableAreaWTextComp*>(parent->expArea)->bonusValue =
|
2016-10-30 17:32:28 +02:00
|
|
|
commander->getExpRank();
|
|
|
|
boost::replace_first(parent->expArea->text, "%d",
|
|
|
|
boost::lexical_cast<std::string>(commander->getExpRank()));
|
|
|
|
boost::replace_first(parent->expArea->text, "%d",
|
|
|
|
boost::lexical_cast<std::string>(CGI->heroh->reqExp(commander->getExpRank() + 1)));
|
|
|
|
boost::replace_first(parent->expArea->text, "%d",
|
|
|
|
boost::lexical_cast<std::string>(commander->experience));
|
2012-05-22 20:16:37 +03:00
|
|
|
}
|
2014-07-04 12:48:09 +03:00
|
|
|
else
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->expRankIcon = new CAnimImage(
|
|
|
|
"stackWindow/levels", stack->getExpRank(), 0, pos.x, pos.y);
|
|
|
|
parent->expArea = new LRClickableAreaWText(Rect(pos.x, pos.y, 44, 44));
|
2016-10-30 17:32:28 +02:00
|
|
|
parent->expArea->text = parent->generateStackExpDescription();
|
|
|
|
}
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->expLabel = new CLabel(
|
2016-10-30 17:32:28 +02:00
|
|
|
pos.x + 21, pos.y + 52, FONT_SMALL, CENTER, Colors::WHITE,
|
2016-10-30 23:21:26 +02:00
|
|
|
makeNumberShort<TExpType>(stack->experience, 6));
|
2016-10-30 17:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (showArt)
|
|
|
|
{
|
|
|
|
Point pos = showExp ? Point(375, 32) : Point(347, 32);
|
|
|
|
// ALARMA: do not refactor this into a separate function
|
|
|
|
// otherwise, artifact icon is drawn near the hero's portrait
|
|
|
|
// this is really strange
|
|
|
|
auto art = parent->info->stackNode->getArt(ArtifactPosition::CREATURE_SLOT);
|
|
|
|
if (art)
|
|
|
|
{
|
|
|
|
parent->stackArtifactIcon.reset(new CAnimImage(
|
|
|
|
"ARTIFACT", art->artType->iconIndex, 0, pos.x, pos.y));
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->stackArtifactIcon->recActions &= ~DISPOSE;
|
2016-10-30 17:32:28 +02:00
|
|
|
parent->stackArtifactHelp.reset(new LRClickableAreaWTextComp(Rect(
|
|
|
|
pos, Point(44, 44)), CComponent::artifact));
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->stackArtifactHelp->recActions &= ~DISPOSE;
|
2016-10-30 17:32:28 +02:00
|
|
|
parent->stackArtifactHelp->type = art->artType->id;
|
|
|
|
const JsonNode & text =
|
|
|
|
VLC->generaltexth->localizedTexts["creatureWindow"]["returnArtifact"];
|
|
|
|
|
|
|
|
if (parent->info->owner)
|
|
|
|
{
|
|
|
|
parent->stackArtifactButton.reset(new CButton(
|
|
|
|
Point(pos.x - 2 , pos.y + 46), "stackWindow/cancelButton",
|
|
|
|
CButton::tooltip(text),
|
|
|
|
[=]{ parent->removeStackArtifact(ArtifactPosition::CREATURE_SLOT); }));
|
2016-10-30 23:21:26 +02:00
|
|
|
parent->stackArtifactButton->recActions &= ~DISPOSE;
|
2016-10-30 17:32:28 +02:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createActiveSpells()
|
|
|
|
{
|
2014-09-19 16:31:01 +03:00
|
|
|
static const Point firstPos(6, 2); // position of 1st spell box
|
2014-06-26 22:07:33 +03:00
|
|
|
static const Point offset(54, 0); // offset of each spell box from previous
|
|
|
|
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
createBackground("spell-effects");
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-09-19 16:31:01 +03:00
|
|
|
const CStack * battleStack = parent->info->stack;
|
2011-04-10 08:41:24 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
assert(battleStack); // Section should be created only for battles
|
|
|
|
|
|
|
|
//spell effects
|
|
|
|
int printed=0; //how many effect pics have been printed
|
|
|
|
std::vector<si32> spells = battleStack->activeSpells();
|
|
|
|
for(si32 effect : spells)
|
|
|
|
{
|
2015-01-18 18:38:35 +02:00
|
|
|
const CSpell * sp = CGI->spellh->objects[effect];
|
2016-10-01 08:07:18 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
std::string spellText;
|
2016-10-01 08:07:18 +02:00
|
|
|
|
2015-01-18 18:38:35 +02:00
|
|
|
//not all effects have graphics (for eg. Acid Breath)
|
|
|
|
//for modded spells iconEffect is added to SpellInt.def
|
2016-10-01 08:07:18 +02:00
|
|
|
const bool hasGraphics = (effect < SpellID::THUNDERBOLT) || (effect >= SpellID::AFTER_LAST);
|
|
|
|
|
|
|
|
if (hasGraphics)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(spellText, "%s", sp->name);
|
2014-06-26 22:07:33 +03:00
|
|
|
int duration = battleStack->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain;
|
2016-10-30 17:32:28 +02:00
|
|
|
boost::replace_first(spellText, "%d", boost::lexical_cast<std::string>(duration));
|
2014-06-26 22:07:33 +03:00
|
|
|
|
2014-09-19 16:31:01 +03:00
|
|
|
new CAnimImage("SpellInt", effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed);
|
2014-06-26 22:07:33 +03:00
|
|
|
new LRClickableAreaWText(Rect(firstPos + offset * printed, Point(50, 38)), spellText, spellText);
|
|
|
|
if (++printed >= 8) // interface limit reached
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createCommanderSection()
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
auto onCreate = [=](size_t index) -> CIntObject *
|
|
|
|
{
|
|
|
|
return parent->switchTab(index);
|
|
|
|
};
|
|
|
|
auto onDestroy = [=](CIntObject * obj)
|
|
|
|
{
|
|
|
|
delete obj;
|
|
|
|
};
|
2014-06-27 18:33:30 +03:00
|
|
|
parent->commanderTab = new CTabbedInt(onCreate, onDestroy, Point(0,0), 0);
|
2014-06-26 22:07:33 +03:00
|
|
|
pos.w = parent->pos.w;
|
2014-07-03 19:05:19 +03:00
|
|
|
pos.h = 177; // height of commander info
|
|
|
|
if (parent->info->levelupInfo)
|
|
|
|
pos.h += 59; // height of abilities selection
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
static std::string skillToFile (int skill, int level, bool selected)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
// FIXME: is this a correct hadling?
|
|
|
|
// level 0 = skill not present, use image with "no" suffix
|
|
|
|
// level 1-5 = skill available, mapped to images indexed as 0-4
|
|
|
|
// selecting skill means that it will appear one level higher (as if alredy upgraded)
|
|
|
|
std::string file = "zvs/Lib1.res/_";
|
|
|
|
switch (skill)
|
|
|
|
{
|
|
|
|
case ECommander::ATTACK:
|
|
|
|
file += "AT";
|
|
|
|
break;
|
|
|
|
case ECommander::DEFENSE:
|
|
|
|
file += "DF";
|
|
|
|
break;
|
|
|
|
case ECommander::HEALTH:
|
|
|
|
file += "HP";
|
|
|
|
break;
|
|
|
|
case ECommander::DAMAGE:
|
|
|
|
file += "DM";
|
|
|
|
break;
|
|
|
|
case ECommander::SPEED:
|
|
|
|
file += "SP";
|
|
|
|
break;
|
|
|
|
case ECommander::SPELL_POWER:
|
|
|
|
file += "MP";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string sufix;
|
|
|
|
if (selected)
|
|
|
|
level++; // UI will display resulting level
|
|
|
|
if (level == 0)
|
|
|
|
sufix = "no"; //not avaliable - no number
|
2011-03-03 20:25:48 +02:00
|
|
|
else
|
2014-06-27 18:33:30 +03:00
|
|
|
sufix = boost::lexical_cast<std::string>(level-1);
|
|
|
|
if (selected)
|
|
|
|
sufix += "="; //level-up highlight
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
return file + sufix + ".bmp";
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createCommander()
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
createBackground("commander-bg");
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2016-11-03 15:25:17 +02:00
|
|
|
auto getSkillPos = [](int index)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
return Point(10 + 80 * (index%3), 20 + 80 * (index/3));
|
|
|
|
};
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
auto getSkillImage = [this](int skillIndex) -> std::string
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
bool selected = ((parent->selectedSkill == skillIndex) && parent->info->levelupInfo );
|
|
|
|
return skillToFile(skillIndex, parent->info->commander->secondarySkills[skillIndex], selected);
|
|
|
|
};
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
for (int index = ECommander::ATTACK; index <= ECommander::SPELL_POWER; ++index)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
Point skillPos = getSkillPos(index);
|
|
|
|
|
|
|
|
auto icon = new CClickableObject(new CPicture(getSkillImage(index), skillPos.x, skillPos.y), [=]{});
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
if (parent->selectedSkill == index)
|
|
|
|
parent->selectedIcon = icon;
|
|
|
|
|
|
|
|
if (parent->info->levelupInfo && vstd::contains(parent->info->levelupInfo->skills, index)) // can be upgraded - enable selection switch
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
icon->callback = [=]
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-07-03 19:05:19 +03:00
|
|
|
parent->setSelection(index, icon);
|
2014-06-27 18:33:30 +03:00
|
|
|
};
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-11-03 15:25:17 +02:00
|
|
|
|
|
|
|
auto getArtifactPos = [](int index)
|
|
|
|
{
|
|
|
|
return Point(269 + 47 * (index % 3), 22 + 47 * (index / 3));
|
|
|
|
};
|
|
|
|
for (auto equippedArtifact : parent->info->commander->artifactsWorn)
|
|
|
|
{
|
|
|
|
Point artPos = getArtifactPos(equippedArtifact.first);
|
2016-11-06 14:02:00 +02:00
|
|
|
auto icon = new CCommanderArtPlace(artPos, parent->info->owner, equippedArtifact.first, equippedArtifact.second.artifact);
|
2016-11-03 15:25:17 +02:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-07-04 20:58:18 +03:00
|
|
|
CIntObject * CStackWindow::createSkillEntry(int index)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-07-04 20:58:18 +03:00
|
|
|
for (auto skillID : info->levelupInfo->skills)
|
2012-05-07 15:54:22 +03:00
|
|
|
{
|
2014-07-04 20:58:18 +03:00
|
|
|
if (index == 0 && skillID >= 100)
|
|
|
|
{
|
2016-09-19 23:36:35 +02:00
|
|
|
const auto bonus = CGI->creh->skillRequirements[skillID-100].first;
|
2014-07-04 20:58:18 +03:00
|
|
|
const CStackInstance *stack = info->commander;
|
|
|
|
CClickableObject * icon = new CClickableObject(new CPicture(stack->bonusToGraphics(bonus)), []{});
|
|
|
|
icon->callback = [=]
|
|
|
|
{
|
|
|
|
setSelection(skillID, icon);
|
|
|
|
};
|
|
|
|
icon->text = stack->bonusToString(bonus, true);
|
|
|
|
icon->hoverText = stack->bonusToString(bonus, false);
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
if (skillID >= 100)
|
|
|
|
index--;
|
2012-05-07 15:54:22 +03:00
|
|
|
}
|
2014-07-04 20:58:18 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createCommanderAbilities()
|
2014-07-03 19:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2014-07-03 19:05:19 +03:00
|
|
|
auto bg2 = new CPicture("stackWindow/commander-abilities.png");
|
|
|
|
bg2->moveBy(Point(0, pos.h));
|
|
|
|
size_t abilitiesCount = boost::range::count_if(parent->info->levelupInfo->skills, [](ui32 skillID)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-07-03 19:05:19 +03:00
|
|
|
return skillID >= 100;
|
|
|
|
});
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2014-07-04 20:58:18 +03:00
|
|
|
auto list = new CListBox([=] (int index)
|
2012-07-03 11:07:34 +03:00
|
|
|
{
|
2014-07-04 20:58:18 +03:00
|
|
|
return parent->createSkillEntry(index);
|
2014-07-03 19:05:19 +03:00
|
|
|
},
|
|
|
|
[=] (CIntObject * elem)
|
|
|
|
{
|
|
|
|
delete elem;
|
|
|
|
},
|
|
|
|
Point(38, 3+pos.h), Point(63, 0), 6, abilitiesCount);
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2014-08-03 14:16:19 +03:00
|
|
|
auto leftBtn = new CButton(Point(10, pos.h + 6), "hsbtns3.def", CButton::tooltip(), [=]{ list->moveToPrev(); }, SDLK_LEFT);
|
|
|
|
auto rightBtn = new CButton(Point(411, pos.h + 6), "hsbtns5.def", CButton::tooltip(), [=]{ list->moveToNext(); }, SDLK_RIGHT);
|
2014-07-03 19:05:19 +03:00
|
|
|
|
|
|
|
if (abilitiesCount <= 6)
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
2014-07-03 19:05:19 +03:00
|
|
|
leftBtn->block(true);
|
|
|
|
rightBtn->block(true);
|
2012-07-04 17:41:53 +03:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-07-03 19:05:19 +03:00
|
|
|
void CStackWindow::setSelection(si32 newSkill, CClickableObject * newIcon)
|
2011-08-05 10:59:15 +03:00
|
|
|
{
|
2014-07-03 19:05:19 +03:00
|
|
|
auto getSkillImage = [this](int skillIndex) -> std::string
|
|
|
|
{
|
|
|
|
bool selected = ((selectedSkill == skillIndex) && info->levelupInfo );
|
|
|
|
return skillToFile(skillIndex, info->commander->secondarySkills[skillIndex], selected);
|
|
|
|
};
|
2011-08-05 10:59:15 +03:00
|
|
|
|
2014-07-03 19:05:19 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
int oldSelection = selectedSkill; // update selection
|
|
|
|
selectedSkill = newSkill;
|
2011-08-05 10:59:15 +03:00
|
|
|
|
2014-07-03 19:05:19 +03:00
|
|
|
if (selectedIcon && oldSelection < 100) // recreate image on old selection, only for skills
|
|
|
|
selectedIcon->setObject(new CPicture(getSkillImage(oldSelection)));
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2014-07-03 19:05:19 +03:00
|
|
|
selectedIcon = newIcon; // update new selection
|
|
|
|
if (newSkill < 100)
|
|
|
|
newIcon->setObject(new CPicture(getSkillImage(newSkill)));
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createBonuses(boost::optional<size_t> preferredSize)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
// size of single image for an item
|
|
|
|
static const int itemHeight = 59;
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
size_t totalSize = (parent->activeBonuses.size() + 1) / 2;
|
|
|
|
size_t visibleSize = preferredSize ? preferredSize.get() : std::min<size_t>(3, totalSize);
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
pos.w = parent->pos.w;
|
|
|
|
pos.h = itemHeight * visibleSize;
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
auto onCreate = [=](size_t index) -> CIntObject *
|
|
|
|
{
|
|
|
|
return parent->createBonusEntry(index);
|
|
|
|
};
|
|
|
|
auto onDestroy = [=](CIntObject * obj)
|
|
|
|
{
|
|
|
|
delete obj;
|
|
|
|
};
|
|
|
|
new CListBox(onCreate, onDestroy, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, 1, Rect(pos.w - 15, 0, pos.h, pos.h));
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createButtonPanel()
|
2012-05-13 18:04:21 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
createBackground("button-panel");
|
|
|
|
|
2014-12-27 05:29:09 +02:00
|
|
|
if (parent->info->dismissInfo && parent->info->dismissInfo->callback)
|
2012-05-13 18:04:21 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
auto onDismiss = [=]()
|
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
parent->info->dismissInfo->callback();
|
2014-06-26 22:07:33 +03:00
|
|
|
parent->close();
|
|
|
|
};
|
|
|
|
auto onClick = [=] ()
|
|
|
|
{
|
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[12], onDismiss, 0, false, std::vector<CComponent*>());
|
|
|
|
};
|
2014-08-03 14:16:19 +03:00
|
|
|
new CButton(Point(5, 5),"IVIEWCR2.DEF", CGI->generaltexth->zelp[445], onClick, SDLK_d);
|
2012-05-13 18:04:21 +03:00
|
|
|
}
|
2014-06-27 18:33:30 +03:00
|
|
|
if (parent->info->upgradeInfo)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
// used space overlaps with commander switch button
|
|
|
|
// besides - should commander really be upgradeable?
|
2014-06-27 18:33:30 +03:00
|
|
|
assert(!parent->info->commander);
|
2014-03-07 16:21:09 +03:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
StackWindowInfo::StackUpgradeInfo & upgradeInfo = parent->info->upgradeInfo.get();
|
2014-06-26 22:07:33 +03:00
|
|
|
size_t buttonsToCreate = std::min<size_t>(upgradeInfo.info.newID.size(), 3); // no more than 3 windows on UI - space limit
|
2012-05-13 18:04:21 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
for (size_t i=0; i<buttonsToCreate; i++)
|
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
TResources totalCost = upgradeInfo.info.cost[i] * parent->info->creatureCount;
|
2012-02-10 13:32:21 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
auto onUpgrade = [=]()
|
|
|
|
{
|
|
|
|
upgradeInfo.callback(upgradeInfo.info.newID[i]);
|
|
|
|
parent->close();
|
|
|
|
};
|
|
|
|
auto onClick = [=]()
|
|
|
|
{
|
|
|
|
std::vector<CComponent*> resComps;
|
|
|
|
for(TResources::nziterator i(totalCost); i.valid(); i++)
|
|
|
|
{
|
|
|
|
resComps.push_back(new CComponent(CComponent::resource, i->resType, i->resVal));
|
|
|
|
}
|
2016-09-30 20:45:23 +02:00
|
|
|
|
|
|
|
if(LOCPLINT->cb->getResourceAmount().canAfford(totalCost))
|
2016-10-01 08:07:18 +02:00
|
|
|
{
|
2016-09-30 20:45:23 +02:00
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[207], onUpgrade, nullptr, true, resComps);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314], resComps);
|
2014-06-26 22:07:33 +03:00
|
|
|
};
|
2014-08-03 14:16:19 +03:00
|
|
|
auto upgradeBtn = new CButton(Point(221 + i * 40, 5), "stackWindow/upgradeButton", CGI->generaltexth->zelp[446], onClick, SDLK_1);
|
2012-04-17 17:50:23 +03:00
|
|
|
|
2014-06-26 23:27:04 +03:00
|
|
|
upgradeBtn->addOverlay(new CAnimImage("CPRSMALL", VLC->creh->creatures[upgradeInfo.info.newID[i]]->iconIndex));
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
if (parent->info->commander)
|
2012-05-25 18:10:38 +03:00
|
|
|
{
|
2014-07-03 19:05:19 +03:00
|
|
|
for (size_t i=0; i<2; i++)
|
2014-06-27 18:33:30 +03:00
|
|
|
{
|
2014-07-03 21:09:17 +03:00
|
|
|
std::string btnIDs[2] = { "showSkills", "showBonuses" };
|
2014-06-27 18:33:30 +03:00
|
|
|
auto onSwitch = [&, i]()
|
|
|
|
{
|
|
|
|
parent->switchButtons[parent->activeTab]->enable();
|
|
|
|
parent->commanderTab->setActive(i);
|
|
|
|
parent->switchButtons[i]->disable();
|
|
|
|
parent->redraw(); // FIXME: enable/disable don't redraw screen themselves
|
|
|
|
};
|
|
|
|
|
2014-07-03 21:09:17 +03:00
|
|
|
const JsonNode & text = VLC->generaltexth->localizedTexts["creatureWindow"][btnIDs[i]];
|
2014-08-03 14:16:19 +03:00
|
|
|
parent->switchButtons[i] = new CButton(Point(302 + i*40, 5), "stackWindow/upgradeButton", CButton::tooltip(text), onSwitch);
|
2014-06-27 18:33:30 +03:00
|
|
|
parent->switchButtons[i]->addOverlay(new CAnimImage("stackWindow/switchModeIcons", i));
|
|
|
|
}
|
|
|
|
parent->switchButtons[parent->activeTab]->disable();
|
2012-05-25 18:10:38 +03:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2014-12-23 06:10:33 +02:00
|
|
|
auto exitBtn = new CButton(Point(382, 5), "hsbtns.def", CGI->generaltexth->zelp[447], [=]{ parent->close(); }, SDLK_RETURN);
|
2014-06-26 22:07:33 +03:00
|
|
|
exitBtn->assignedKeys.insert(SDLK_ESCAPE);
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CWindowSection::CWindowSection(CStackWindow * parent):
|
|
|
|
parent(parent)
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
CClickableObject::CClickableObject(CIntObject *object, std::function<void()> callback):
|
|
|
|
object(nullptr),
|
|
|
|
callback(callback)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
pos = object->pos;
|
|
|
|
setObject(object);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
void CClickableObject::setObject(CIntObject *newObject)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
delete object;
|
|
|
|
object = newObject;
|
|
|
|
addChild(object);
|
|
|
|
object->moveTo(pos.topLeft());
|
|
|
|
redraw();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
void CClickableObject::clickLeft(tribool down, bool previousState)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
if (down)
|
|
|
|
callback();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CIntObject * CStackWindow::createBonusEntry(size_t index)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
auto section = new CWindowSection(this);
|
|
|
|
section->createBonusEntry(index);
|
|
|
|
return section;
|
2011-03-13 18:06:20 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createBonusEntry(size_t index)
|
2012-07-03 11:07:34 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
createBackground("bonus-effects");
|
|
|
|
createBonusItem(index * 2, Point(6, 4));
|
|
|
|
createBonusItem(index * 2 + 1, Point(214, 4));
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::CWindowSection::createBonusItem(size_t index, Point position)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
if (parent->activeBonuses.size() > index)
|
|
|
|
{
|
|
|
|
BonusInfo & bi = parent->activeBonuses[index];
|
|
|
|
new CPicture(bi.imagePath, position.x, position.y);
|
|
|
|
new CLabel(position.x + 60, position.y + 2, FONT_SMALL, TOPLEFT, Colors::WHITE, bi.name);
|
2014-11-15 21:45:58 +02:00
|
|
|
new CMultiLineLabel(Rect(position.x + 60, position.y + 17, 137,30), FONT_SMALL, TOPLEFT, Colors::WHITE, bi.description);
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CIntObject * CStackWindow::switchTab(size_t index)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
switch (index)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
case 0:
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
activeTab = 0;
|
|
|
|
auto ret = new CWindowSection(this);
|
2014-06-27 18:33:30 +03:00
|
|
|
ret->createCommander();
|
2014-07-03 21:09:17 +03:00
|
|
|
if (info->levelupInfo)
|
|
|
|
ret->createCommanderAbilities();
|
2014-06-26 22:07:33 +03:00
|
|
|
return ret;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2014-06-26 22:07:33 +03:00
|
|
|
case 1:
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
activeTab = 1;
|
|
|
|
auto ret = new CWindowSection(this);
|
2014-07-03 19:05:19 +03:00
|
|
|
if (info->levelupInfo)
|
|
|
|
ret->createBonuses(4);
|
|
|
|
else
|
|
|
|
ret->createBonuses(3);
|
2014-06-26 22:07:33 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return nullptr;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::initSections()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2014-06-26 22:07:33 +03:00
|
|
|
CWindowSection * currentSection;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-07-05 01:22:56 +03:00
|
|
|
bool showArt = CGI->modh->modules.STACK_ARTIFACT && info->commander == nullptr && info->stackNode;
|
|
|
|
bool showExp = (CGI->modh->modules.STACK_EXP || info->commander != nullptr) && info->stackNode;
|
2014-06-26 22:07:33 +03:00
|
|
|
currentSection = new CWindowSection(this);
|
|
|
|
currentSection->createStackInfo(showExp, showArt);
|
|
|
|
pos.w = currentSection->pos.w;
|
|
|
|
pos.h += currentSection->pos.h;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-09-19 16:31:01 +03:00
|
|
|
if (info->stack) // in battle
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
currentSection = new CWindowSection(this);
|
|
|
|
currentSection->pos.y += pos.h;
|
|
|
|
currentSection->createActiveSpells();
|
|
|
|
pos.h += currentSection->pos.h;
|
|
|
|
}
|
2014-06-27 18:33:30 +03:00
|
|
|
if (info->commander)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
currentSection = new CWindowSection(this);
|
|
|
|
currentSection->pos.y += pos.h;
|
|
|
|
currentSection->createCommanderSection();
|
|
|
|
pos.h += currentSection->pos.h;
|
|
|
|
}
|
2014-06-27 18:33:30 +03:00
|
|
|
if (!info->commander && !activeBonuses.empty())
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
currentSection = new CWindowSection(this);
|
|
|
|
currentSection->pos.y += pos.h;
|
|
|
|
currentSection->createBonuses();
|
|
|
|
pos.h += currentSection->pos.h;
|
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
if (!info->popupWindow)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
|
|
|
currentSection = new CWindowSection(this);
|
|
|
|
currentSection->pos.y += pos.h;
|
|
|
|
currentSection->createButtonPanel();
|
|
|
|
pos.h += currentSection->pos.h;
|
2014-06-27 18:33:30 +03:00
|
|
|
//FIXME: add status bar to image?
|
2014-06-26 22:07:33 +03:00
|
|
|
}
|
|
|
|
updateShadow();
|
|
|
|
pos = center(pos);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::initBonusesList()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-26 22:07:33 +03:00
|
|
|
BonusList output, input;
|
2016-10-01 08:07:18 +02:00
|
|
|
input = *(info->stackNode->getBonuses(CSelector(Bonus::Permanent), Selector::all));
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
while (!input.empty())
|
|
|
|
{
|
2016-09-19 23:36:35 +02:00
|
|
|
auto b = input.front();
|
|
|
|
output.push_back(std::make_shared<Bonus>(*b));
|
2014-06-26 22:07:33 +03:00
|
|
|
output.back()->val = input.valOfBonuses(Selector::typeSubtype(b->type, b->subtype)); //merge multiple bonuses into one
|
|
|
|
input.remove_if (Selector::typeSubtype(b->type, b->subtype)); //remove used bonuses
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
BonusInfo bonusInfo;
|
2016-09-19 23:36:35 +02:00
|
|
|
for(auto b : output)
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
bonusInfo.name = info->stackNode->bonusToString(b, false);
|
2014-11-15 19:22:50 +02:00
|
|
|
bonusInfo.description = info->stackNode->bonusToString(b, true);
|
2014-06-27 18:33:30 +03:00
|
|
|
bonusInfo.imagePath = info->stackNode->bonusToGraphics(b);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
//if it's possible to give any description or image for this kind of bonus
|
|
|
|
//TODO: figure out why half of bonuses don't have proper description
|
2014-11-15 19:39:21 +02:00
|
|
|
if ((!bonusInfo.name.empty() || !bonusInfo.imagePath.empty())&& b->type != Bonus::MAGIC_RESISTANCE)
|
2014-06-26 22:07:33 +03:00
|
|
|
activeBonuses.push_back(bonusInfo);
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
//handle Magic resistance separately :/
|
2014-06-27 18:33:30 +03:00
|
|
|
int magicResistance = info->stackNode->magicResistance();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
if (magicResistance)
|
|
|
|
{
|
|
|
|
BonusInfo bonusInfo;
|
2016-09-19 23:36:35 +02:00
|
|
|
auto b = std::make_shared<Bonus>();
|
|
|
|
b->type = Bonus::MAGIC_RESISTANCE;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2016-09-19 23:36:35 +02:00
|
|
|
bonusInfo.name = VLC->getBth()->bonusToString(b, info->stackNode, false);
|
|
|
|
bonusInfo.description = VLC->getBth()->bonusToString(b, info->stackNode, true);
|
|
|
|
bonusInfo.imagePath = info->stackNode->bonusToGraphics(b);
|
2014-06-26 22:07:33 +03:00
|
|
|
activeBonuses.push_back(bonusInfo);
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
void CStackWindow::init()
|
|
|
|
{
|
2016-11-25 18:28:00 +02:00
|
|
|
expRankIcon = nullptr;
|
|
|
|
expArea = nullptr;
|
|
|
|
expLabel = nullptr;
|
2014-08-11 16:28:15 +03:00
|
|
|
if (!info->stackNode)
|
|
|
|
info->stackNode = new CStackInstance(info->creature, 1);// FIXME: free data
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
selectedIcon = nullptr;
|
|
|
|
selectedSkill = 0;
|
2014-06-27 18:33:30 +03:00
|
|
|
if (info->levelupInfo)
|
|
|
|
selectedSkill = info->levelupInfo->skills.front();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
commanderTab = nullptr;
|
|
|
|
activeTab = 0;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
initBonusesList();
|
|
|
|
initSections();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CStackWindow(const CStack * stack, bool popup):
|
2014-08-11 15:57:15 +03:00
|
|
|
CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new StackWindowInfo())
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-09-19 16:31:01 +03:00
|
|
|
info->stack = stack;
|
2014-06-27 18:33:30 +03:00
|
|
|
info->stackNode = stack->base;
|
|
|
|
info->creature = stack->type;
|
|
|
|
info->creatureCount = stack->count;
|
|
|
|
info->popupWindow = popup;
|
2014-06-26 22:07:33 +03:00
|
|
|
init();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CStackWindow(const CCreature * creature, bool popup):
|
2014-06-27 18:33:30 +03:00
|
|
|
CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new StackWindowInfo())
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
info->creature = creature;
|
|
|
|
info->popupWindow = popup;
|
2014-06-26 22:07:33 +03:00
|
|
|
init();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CStackWindow(const CStackInstance * stack, bool popup):
|
2014-06-27 18:33:30 +03:00
|
|
|
CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new StackWindowInfo())
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
info->stackNode = stack;
|
|
|
|
info->creature = stack->type;
|
|
|
|
info->creatureCount = stack->count;
|
|
|
|
info->popupWindow = popup;
|
2016-10-01 08:07:18 +02:00
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (stack->armyObj);
|
2014-06-26 22:07:33 +03:00
|
|
|
init();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CStackWindow(const CStackInstance * stack, std::function<void()> dismiss, const UpgradeInfo & upgradeInfo, std::function<void(CreatureID)> callback):
|
2014-06-27 18:33:30 +03:00
|
|
|
CWindowObject(BORDERED),
|
|
|
|
info(new StackWindowInfo())
|
2014-06-26 22:07:33 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
info->stackNode = stack;
|
|
|
|
info->creature = stack->type;
|
|
|
|
info->creatureCount = stack->count;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
info->upgradeInfo = StackWindowInfo::StackUpgradeInfo();
|
|
|
|
info->dismissInfo = StackWindowInfo::StackDismissInfo();
|
|
|
|
info->upgradeInfo->info = upgradeInfo;
|
|
|
|
info->upgradeInfo->callback = callback;
|
|
|
|
info->dismissInfo->callback = dismiss;
|
2014-11-15 20:54:45 +02:00
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (stack->armyObj);
|
2014-06-26 22:07:33 +03:00
|
|
|
init();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CStackWindow(const CCommanderInstance * commander, bool popup):
|
2014-06-27 18:33:30 +03:00
|
|
|
CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
|
|
|
|
info(new StackWindowInfo())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
info->stackNode = commander;
|
|
|
|
info->creature = commander->type;
|
|
|
|
info->commander = commander;
|
|
|
|
info->creatureCount = 1;
|
|
|
|
info->popupWindow = popup;
|
2016-10-01 08:07:18 +02:00
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
|
2014-06-26 22:07:33 +03:00
|
|
|
init();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2014-06-26 22:07:33 +03:00
|
|
|
CStackWindow::CStackWindow(const CCommanderInstance * commander, std::vector<ui32> &skills, std::function<void(ui32)> callback):
|
2014-06-27 18:33:30 +03:00
|
|
|
CWindowObject(BORDERED),
|
|
|
|
info(new StackWindowInfo())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
info->stackNode = commander;
|
|
|
|
info->creature = commander->type;
|
|
|
|
info->commander = commander;
|
|
|
|
info->creatureCount = 1;
|
|
|
|
info->levelupInfo = StackWindowInfo::CommanderLevelInfo();
|
|
|
|
info->levelupInfo->skills = skills;
|
|
|
|
info->levelupInfo->callback = callback;
|
2016-10-01 08:07:18 +02:00
|
|
|
info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
|
2014-06-26 22:07:33 +03:00
|
|
|
init();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:33:30 +03:00
|
|
|
CStackWindow::~CStackWindow()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2014-06-27 18:33:30 +03:00
|
|
|
if (info->levelupInfo)
|
2014-07-03 01:00:16 +03:00
|
|
|
info->levelupInfo->callback(vstd::find_pos(info->levelupInfo->skills, selectedSkill));
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|