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
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "../lib/CCreatureSet.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../lib/BattleState.h"
|
|
|
|
#include "../CCallback.h"
|
|
|
|
|
|
|
|
#include <SDL.h>
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/SDL_Extensions.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
#include "CBitmapHandler.h"
|
|
|
|
#include "CDefHandler.h"
|
|
|
|
#include "Graphics.h"
|
|
|
|
#include "CPlayerInterface.h"
|
2012-09-29 13:59:43 +03:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
#include "CAnimation.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-05-10 01:20:47 +03:00
|
|
|
#include "../lib/CGameState.h"
|
2011-08-06 10:05:04 +03:00
|
|
|
#include "../lib/BattleState.h"
|
2011-05-21 10:07:07 +03:00
|
|
|
#include "../lib/CSpellHandler.h"
|
2012-02-10 13:32:21 +03:00
|
|
|
#include "../lib/CArtHandler.h"
|
2012-04-17 17:50:23 +03:00
|
|
|
#include "../lib/NetPacks.h" //ArtifactLocation
|
2012-08-24 12:37:52 +03:00
|
|
|
#include "../lib/CModHandler.h"
|
2013-03-06 21:49:56 +03:00
|
|
|
#include "../lib/IBonusTypeHandler.h"
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/CGuiHandler.h"
|
|
|
|
#include "gui/CIntObjectClasses.h"
|
2011-12-17 21:59:59 +03:00
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-31 00:28:31 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (const CStack &stack, CreWinType Type):
|
|
|
|
CWindowObject(PLAYER_COLORED | (Type == OTHER ? RCLICK_POPUP : 0 ) ),
|
2012-06-15 20:08:19 +03:00
|
|
|
type(Type)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2011-05-13 17:33:48 +03:00
|
|
|
if (stack.base)
|
|
|
|
init(stack.base, &stack, dynamic_cast<const CGHeroInstance*>(stack.base->armyObj));
|
|
|
|
else
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto s = new CStackInstance(stack.type, 1); //TODO: war machines and summons should be regular stacks
|
2013-06-26 14:18:27 +03:00
|
|
|
init(s, &stack, nullptr);
|
2011-05-13 17:33:48 +03:00
|
|
|
delete s;
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2013-01-31 00:28:31 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (const CStackInstance &stack, CreWinType Type):
|
|
|
|
CWindowObject(PLAYER_COLORED | (Type == OTHER ? RCLICK_POPUP : 0 ) ),
|
2012-06-15 20:08:19 +03:00
|
|
|
type(Type)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
|
|
|
init(&stack, &stack, dynamic_cast<const CGHeroInstance*>(stack.armyObj));
|
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
CCreatureWindow::CCreatureWindow(CreatureID Cid, CreWinType Type, int creatureCount):
|
2013-01-31 00:28:31 +03:00
|
|
|
CWindowObject(PLAYER_COLORED | (Type == OTHER ? RCLICK_POPUP : 0 ) ),
|
2012-06-15 20:08:19 +03:00
|
|
|
type(Type)
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
auto stack = new CStackInstance(Cid, creatureCount); //TODO: simplify?
|
2013-06-26 14:18:27 +03:00
|
|
|
init(stack, CGI->creh->creatures[Cid], nullptr);
|
2011-03-06 14:12:22 +02:00
|
|
|
delete stack;
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
CCreatureWindow::CCreatureWindow(const CStackInstance &st, CreWinType Type, std::function<void()> Upg, std::function<void()> Dsm, UpgradeInfo *ui):
|
2013-01-31 00:28:31 +03:00
|
|
|
CWindowObject(PLAYER_COLORED | (Type == OTHER ? RCLICK_POPUP : 0 ) ),
|
2012-06-15 20:08:19 +03:00
|
|
|
type(Type),
|
2013-06-29 16:05:48 +03:00
|
|
|
dismiss(nullptr),
|
|
|
|
upgrade(nullptr),
|
|
|
|
ok(nullptr),
|
2012-06-15 20:08:19 +03:00
|
|
|
dsm(Dsm)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2011-04-09 22:34:48 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(&st, &st,dynamic_cast<const CGHeroInstance*>(st.armyObj));
|
|
|
|
|
|
|
|
//print abilities text - if r-click popup
|
|
|
|
if(type)
|
|
|
|
{
|
|
|
|
if(Upg && ui)
|
|
|
|
{
|
2011-07-05 09:14:07 +03:00
|
|
|
TResources upgradeCost = ui->cost[0] * st.count;
|
|
|
|
for(TResources::nziterator i(upgradeCost); i.valid(); i++)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
BLOCK_CAPTURING;
|
2012-02-16 20:10:58 +03:00
|
|
|
upgResCost.push_back(new CComponent(CComponent::resource, i->resType, i->resVal));
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2011-07-05 09:14:07 +03:00
|
|
|
if(LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost))
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
CFunctionList<void()> fs;
|
|
|
|
fs += Upg;
|
2013-07-02 18:23:32 +03:00
|
|
|
fs += boost::bind(&CCreatureWindow::close,this);
|
2011-04-09 22:34:48 +03:00
|
|
|
CFunctionList<void()> cfl;
|
2013-07-06 19:10:20 +03:00
|
|
|
cfl += boost::bind(&CPlayerInterface::showYesNoDialog,
|
|
|
|
LOCPLINT, CGI->generaltexth->allTexts[207], fs, nullptr, false, upgResCost);
|
2011-12-22 16:05:19 +03:00
|
|
|
upgrade = new CAdventureMapButton("",CGI->generaltexth->zelp[446].second,cfl,385, 148,"IVIEWCR.DEF",SDLK_u);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
upgrade = new CAdventureMapButton("",CGI->generaltexth->zelp[446].second,std::function<void()>(),385, 148,"IVIEWCR.DEF");
|
2011-04-09 22:34:48 +03:00
|
|
|
upgrade->callback.funcs.clear();
|
|
|
|
upgrade->setOffset(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(Dsm)
|
|
|
|
{
|
|
|
|
CFunctionList<void()> fs[2];
|
|
|
|
//on dismiss confirmed
|
|
|
|
fs[0] += Dsm; //dismiss
|
2013-07-02 18:23:32 +03:00
|
|
|
fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window
|
2011-04-09 22:34:48 +03:00
|
|
|
CFunctionList<void()> cfl;
|
2013-07-02 18:23:32 +03:00
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],fs[0],fs[1],false,std::vector<CComponent*>());
|
2011-12-22 16:05:19 +03:00
|
|
|
dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second,cfl,333, 148,"IVIEWCR2.DEF",SDLK_d);
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-20 19:10:50 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (const CCommanderInstance * Commander, const CStack * stack):
|
2012-06-15 20:08:19 +03:00
|
|
|
CWindowObject(PLAYER_COLORED),
|
|
|
|
commander (Commander)
|
2012-05-16 20:29:05 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2012-08-20 19:10:50 +03:00
|
|
|
if (stack)
|
|
|
|
{
|
|
|
|
type = COMMANDER_BATTLE;
|
|
|
|
init(commander, stack, dynamic_cast<const CGHeroInstance*>(commander->armyObj));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = COMMANDER;
|
|
|
|
init(commander, commander, dynamic_cast<const CGHeroInstance*>(commander->armyObj));
|
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
std::function<void()> Dsm;
|
2012-05-16 20:29:05 +03:00
|
|
|
CFunctionList<void()> fs[2];
|
|
|
|
//on dismiss confirmed
|
|
|
|
fs[0] += Dsm; //dismiss
|
2013-07-02 18:23:32 +03:00
|
|
|
fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window
|
2012-05-16 20:29:05 +03:00
|
|
|
CFunctionList<void()> cfl;
|
2013-07-02 18:23:32 +03:00
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],fs[0],fs[1],false,std::vector<CComponent*>());
|
2012-08-20 19:10:50 +03:00
|
|
|
if (type < COMMANDER_LEVEL_UP) //can dismiss only in regular window
|
|
|
|
dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, cfl, 333, 148,"IVIEWCR2.DEF", SDLK_d);
|
2012-05-16 20:29:05 +03:00
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
CCreatureWindow::CCreatureWindow (std::vector<ui32> &skills, const CCommanderInstance * Commander, std::function<void(ui32)> callback):
|
2012-07-03 11:07:34 +03:00
|
|
|
CWindowObject(PLAYER_COLORED),
|
|
|
|
type(COMMANDER_LEVEL_UP),
|
|
|
|
commander (Commander),
|
2012-07-06 23:19:54 +03:00
|
|
|
selectedOption (0), //choose something before drawing
|
|
|
|
upgradeOptions(skills), //copy skills to choose from
|
|
|
|
levelUp (callback)
|
2012-07-03 11:07:34 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
|
|
|
init(commander, commander, dynamic_cast<const CGHeroInstance*>(commander->armyObj));
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
std::function<void()> Dsm;
|
2012-07-03 11:07:34 +03:00
|
|
|
CFunctionList<void()> fs[2];
|
|
|
|
//on dismiss confirmed
|
|
|
|
fs[0] += Dsm; //dismiss
|
2013-07-02 18:23:32 +03:00
|
|
|
fs[0] += boost::bind(&CCreatureWindow::close,this);//close this window
|
2012-07-03 11:07:34 +03:00
|
|
|
CFunctionList<void()> cfl;
|
2013-07-02 18:23:32 +03:00
|
|
|
cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],fs[0],fs[1],false,std::vector<CComponent*>());
|
2012-08-20 19:10:50 +03:00
|
|
|
if (type < COMMANDER_LEVEL_UP) //can dismiss only in regular window
|
|
|
|
dismiss = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, cfl, 333, 148,"IVIEWCR2.DEF", SDLK_d);
|
2012-07-03 11:07:34 +03:00
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *StackNode, const CGHeroInstance *HeroOwner)
|
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
creatureArtifact = nullptr; //may be set later
|
|
|
|
artifactImage = nullptr;
|
2011-04-09 22:34:48 +03:00
|
|
|
stack = Stack;
|
2011-03-03 20:25:48 +02:00
|
|
|
c = stack->type;
|
2011-04-09 22:34:48 +03:00
|
|
|
if(!StackNode)
|
|
|
|
stackNode = c;
|
|
|
|
else
|
|
|
|
stackNode = StackNode;
|
2011-10-20 14:03:04 +03:00
|
|
|
const CStack *battleStack = dynamic_cast<const CStack*>(stackNode); //only during battle
|
2011-04-09 22:34:48 +03:00
|
|
|
heroOwner = HeroOwner;
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2012-02-20 11:19:03 +03:00
|
|
|
if (battleStack)
|
|
|
|
count = boost::lexical_cast<std::string>(battleStack->count);
|
|
|
|
else if (Stack->count)
|
2011-08-05 10:59:15 +03:00
|
|
|
count = boost::lexical_cast<std::string>(Stack->count);
|
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
if (type < COMMANDER)
|
2013-06-26 14:18:27 +03:00
|
|
|
commander = nullptr;
|
2012-05-16 20:29:05 +03:00
|
|
|
|
2012-05-22 20:16:37 +03:00
|
|
|
bool creArt = false;
|
|
|
|
displayedArtifact = ArtifactPosition::CREATURE_SLOT; // 0
|
|
|
|
|
2011-03-06 14:12:22 +02:00
|
|
|
//Basic graphics - need to calculate size
|
|
|
|
|
2012-05-18 22:44:15 +03:00
|
|
|
int commanderOffset = 0;
|
|
|
|
if (type >= COMMANDER)
|
|
|
|
commanderOffset = 74;
|
|
|
|
|
2012-07-04 17:41:53 +03:00
|
|
|
if (commander) //secondary skills
|
|
|
|
{
|
|
|
|
creArt = true;
|
|
|
|
for (int i = ECommander::ATTACK; i <= ECommander::SPELL_POWER; ++i)
|
|
|
|
{
|
|
|
|
if (commander->secondarySkills[i] || vstd::contains(upgradeOptions, i))
|
|
|
|
{
|
|
|
|
std::string file = skillToFile(i);
|
|
|
|
|
|
|
|
skillPictures.push_back(new CPicture(file, 0,0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == COMMANDER_LEVEL_UP)
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto option : upgradeOptions)
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
|
|
|
ui32 index = selectableSkills.size();
|
2013-06-29 16:05:48 +03:00
|
|
|
auto selectableSkill = new CSelectableSkill();
|
2013-07-02 18:23:32 +03:00
|
|
|
selectableSkill->callback = boost::bind(&CCreatureWindow::selectSkill, this, index);
|
2012-07-04 17:41:53 +03:00
|
|
|
|
|
|
|
if (option < 100)
|
|
|
|
{
|
|
|
|
selectableSkill->pos = skillPictures[index]->pos; //resize
|
|
|
|
selectableSkills.push_back (selectableSkill);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectableSkill->pos = Rect (95, 256, 55, 55); //TODO: scroll
|
2013-06-17 18:45:55 +03:00
|
|
|
const Bonus *b = CGI->creh->skillRequirements[option-100].first;
|
|
|
|
bonusItems.push_back (new CBonusItem (genRect(0, 0, 251, 57), stack->bonusToString(b, false), stack->bonusToString(b, true), stack->bonusToGraphics(b)));
|
2012-07-04 17:41:53 +03:00
|
|
|
selectableBonuses.push_back (selectableSkill); //insert these before other bonuses
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 21:39:02 +03:00
|
|
|
BonusList bl, blTemp;
|
2013-07-02 15:08:30 +03:00
|
|
|
blTemp = (*(stackNode->getBonuses(Selector::durationType(Bonus::PERMANENT).And(Selector::anyRange()))));
|
2012-02-16 20:10:58 +03:00
|
|
|
|
2011-07-13 21:39:02 +03:00
|
|
|
while (blTemp.size())
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
2011-07-13 21:39:02 +03:00
|
|
|
Bonus * b = blTemp.front();
|
2011-03-06 14:12:22 +02:00
|
|
|
|
|
|
|
bl.push_back (new Bonus(*b));
|
2011-07-13 21:39:02 +03:00
|
|
|
bl.back()->val = blTemp.valOfBonuses(Selector::typeSubtype(b->type, b->subtype)); //merge multiple bonuses into one
|
|
|
|
blTemp.remove_if (Selector::typeSubtype(b->type, b->subtype)); //remove used bonuses
|
2011-03-06 14:12:22 +02:00
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
std::string text;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(Bonus* b : bl)
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
|
|
|
text = stack->bonusToString(b, false);
|
2011-04-09 22:34:48 +03:00
|
|
|
if (text.size()) //if it's possible to give any description for this kind of bonus
|
2011-03-06 14:12:22 +02:00
|
|
|
{
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusItems.push_back (new CBonusItem(genRect(0, 0, 251, 57), text, stack->bonusToString(b, true), stack->bonusToGraphics(b)));
|
2011-03-06 14:12:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 21:49:56 +03:00
|
|
|
|
|
|
|
//handle Magic resistance separately :/
|
|
|
|
const IBonusBearer *temp = stack;
|
|
|
|
|
2011-10-20 14:03:04 +03:00
|
|
|
if (battleStack)
|
|
|
|
{
|
2013-03-06 21:49:56 +03:00
|
|
|
temp = battleStack;
|
2011-10-20 14:03:04 +03:00
|
|
|
}
|
2013-03-06 21:49:56 +03:00
|
|
|
|
|
|
|
int magicResistance = temp->magicResistance();
|
|
|
|
|
2011-10-20 14:03:04 +03:00
|
|
|
if (magicResistance)
|
|
|
|
{
|
|
|
|
Bonus b;
|
|
|
|
b.type = Bonus::MAGIC_RESISTANCE;
|
2013-03-06 21:49:56 +03:00
|
|
|
|
|
|
|
text = VLC->getBth()->bonusToString(&b,temp,false);
|
|
|
|
const std::string description = VLC->getBth()->bonusToString(&b,temp,true);
|
2011-10-20 14:03:04 +03:00
|
|
|
bonusItems.push_back (new CBonusItem(genRect(0, 0, 251, 57), text, description, stack->bonusToGraphics(&b)));
|
|
|
|
}
|
|
|
|
|
2012-01-12 18:23:00 +03:00
|
|
|
bonusRows = std::min ((int)((bonusItems.size() + 1) / 2), (screen->h - 230) / 60);
|
2012-05-16 20:29:05 +03:00
|
|
|
if (type >= COMMANDER)
|
|
|
|
vstd::amin(bonusRows, 3);
|
|
|
|
else
|
|
|
|
vstd::amin(bonusRows, 4);
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::amax(bonusRows, 1);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
if (type >= COMMANDER)
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
2012-06-15 20:08:19 +03:00
|
|
|
setBackground("CommWin" + boost::lexical_cast<std::string>(bonusRows) + ".pcx");
|
2012-07-04 17:41:53 +03:00
|
|
|
for (int i = 0; i < skillPictures.size(); ++i)
|
|
|
|
{
|
|
|
|
skillPictures[i]->moveTo (Point (pos.x + 37 + i * 84, pos.y + 224));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < selectableSkills.size(); ++i)
|
|
|
|
{
|
|
|
|
if (upgradeOptions[i] < skillPictures.size()) // it's secondary skill
|
|
|
|
{
|
|
|
|
selectableSkills[i]->pos = skillPictures[upgradeOptions[i]]->pos; //dirty workaround
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//print commander level
|
2012-11-11 15:23:31 +03:00
|
|
|
new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::YELLOW,
|
2012-07-04 17:41:53 +03:00
|
|
|
boost::lexical_cast<std::string>((ui16)(commander->level)));
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
new CLabel(488, 82, FONT_SMALL, CENTER, Colors::WHITE,
|
2012-07-04 17:41:53 +03:00
|
|
|
boost::lexical_cast<std::string>(stack->experience));
|
|
|
|
}
|
2012-05-16 20:29:05 +03:00
|
|
|
else
|
2012-06-15 20:08:19 +03:00
|
|
|
setBackground("CreWin" + boost::lexical_cast<std::string>(bonusRows) + ".pcx"); //1 to 4 rows for now
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
//Buttons
|
2013-07-02 18:23:32 +03:00
|
|
|
ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CCreatureWindow::close,this), 489, 148, "hsbtns.def", SDLK_RETURN);
|
2012-05-16 20:29:05 +03:00
|
|
|
ok->assignedKeys.insert(SDLK_ESCAPE);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
if (type <= BATTLE) //in battle or info window
|
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
upgrade = nullptr;
|
|
|
|
dismiss = nullptr;
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
2011-03-06 14:12:22 +02:00
|
|
|
anim = new CCreaturePic(22, 48, c);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
//Stats
|
2011-03-06 14:12:22 +02:00
|
|
|
morale = new MoraleLuckBox(true, genRect(42, 42, 335, 100));
|
2013-05-19 22:53:03 +03:00
|
|
|
morale->set(stackNode);
|
2011-03-06 14:12:22 +02:00
|
|
|
luck = new MoraleLuckBox(false, genRect(42, 42, 387, 100));
|
2013-05-19 22:53:03 +03:00
|
|
|
luck->set(stackNode);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2012-05-13 18:04:21 +03:00
|
|
|
new CAnimImage("PSKIL42", 4, 0, 387, 51); //exp icon - Print it always?
|
2011-03-21 10:14:23 +02:00
|
|
|
if (type) //not in fort window
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2012-08-24 12:37:52 +03:00
|
|
|
if (CGI->modh->modules.STACK_EXP && type < COMMANDER)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2011-03-21 10:14:23 +02:00
|
|
|
int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more
|
2012-11-11 15:23:31 +03:00
|
|
|
new CLabel(488, 82, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(stack->experience));
|
|
|
|
new CLabel(488, 62, FONT_MEDIUM, CENTER, Colors::YELLOW,
|
2012-06-15 20:08:19 +03:00
|
|
|
CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast<std::string>(rank) + "]");
|
2012-05-18 22:44:15 +03:00
|
|
|
|
2011-03-21 10:14:23 +02:00
|
|
|
if (type > BATTLE) //we need it only on adv. map
|
|
|
|
{
|
|
|
|
int tier = stack->type->level;
|
2011-12-14 00:23:17 +03:00
|
|
|
if (!vstd::iswithin(tier, 1, 7))
|
2011-03-21 10:14:23 +02:00
|
|
|
tier = 0;
|
|
|
|
int number;
|
|
|
|
std::string expText = CGI->generaltexth->zcrexp[324];
|
|
|
|
boost::replace_first (expText, "%s", c->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));
|
|
|
|
number = CGI->creh->expRanks[tier][rank] - stack->experience;
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number));
|
|
|
|
|
|
|
|
number = CGI->creh->maxExpPerBattle[tier]; //percent
|
|
|
|
boost::replace_first (expText, "%i%", boost::lexical_cast<std::string>(number));
|
|
|
|
number *= CGI->creh->expRanks[tier].back() / 100; //actual amount
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number));
|
|
|
|
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(stack->count)); //Number of Creatures in stack
|
|
|
|
|
|
|
|
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
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number)); //TODO
|
|
|
|
|
|
|
|
boost::replace_first (expText, "%.2f", boost::lexical_cast<std::string>(1)); //TODO Experience Multiplier
|
|
|
|
number = CGI->creh->expAfterUpgrade;
|
|
|
|
boost::replace_first (expText, "%.2f", boost::lexical_cast<std::string>(number) + "%"); //Upgrade Multiplier
|
|
|
|
|
|
|
|
expmin = CGI->creh->expRanks[tier][9];
|
|
|
|
int expmax = CGI->creh->expRanks[tier][10];
|
|
|
|
number = expmax - expmin;
|
2012-02-16 20:10:58 +03:00
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number)); //Experience after Rank 10
|
|
|
|
number = (stack->count * (expmax - expmin)) / expmin;
|
|
|
|
boost::replace_first (expText, "%i", boost::lexical_cast<std::string>(number)); //Maximum New Recruits to remain at Rank 10 if at Maximum Experience
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
expArea = new LRClickableAreaWTextComp(Rect(334, 49, 160, 44),CComponent::experience);
|
2011-05-21 10:07:07 +03:00
|
|
|
expArea->text = expText;
|
|
|
|
expArea->bonusValue = 0; //TDO: some specific value or no number at all
|
2011-03-21 10:14:23 +02:00
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 11:01:14 +03:00
|
|
|
if (CGI->modh->modules.STACK_ARTIFACT)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
creArt = true;
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-22 20:16:37 +03:00
|
|
|
if (creArt) //stack or commander artifacts
|
|
|
|
{
|
|
|
|
setArt (stack->getArt(ArtifactPosition::CREATURE_SLOT));
|
2012-08-20 19:10:50 +03:00
|
|
|
if (type > BATTLE && type < COMMANDER_BATTLE) //artifact buttons inactive in battle
|
2012-05-22 20:16:37 +03:00
|
|
|
{
|
|
|
|
//TODO: disable buttons if no artifact is equipped
|
2013-07-02 18:23:32 +03:00
|
|
|
leftArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, -1), 437, 98, "hsbtns3.def", SDLK_LEFT);
|
|
|
|
rightArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, +1), 516, 98, "hsbtns5.def", SDLK_RIGHT);
|
2012-05-22 20:16:37 +03:00
|
|
|
if (heroOwner)
|
2013-07-02 18:23:32 +03:00
|
|
|
passArtToHero = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::passArtifactToHero, this), 437, 148, "OVBUTN1.DEF", SDLK_HOME);
|
2012-05-22 20:16:37 +03:00
|
|
|
}
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-10-20 14:03:04 +03:00
|
|
|
if (battleStack) //only during battle
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
|
|
|
//spell effects
|
|
|
|
int printed=0; //how many effect pics have been printed
|
|
|
|
std::vector<si32> spells = battleStack->activeSpells();
|
2013-06-29 16:05:48 +03:00
|
|
|
for(si32 effect : spells)
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2011-05-21 10:07:07 +03:00
|
|
|
std::string spellText;
|
2011-05-13 12:02:16 +03:00
|
|
|
if (effect < graphics->spellEffectsPics->ourImages.size()) //not all effects have graphics (for eg. Acid Breath)
|
|
|
|
{
|
2012-02-16 20:10:58 +03:00
|
|
|
spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
|
2011-05-21 10:07:07 +03:00
|
|
|
boost::replace_first (spellText, "%s", CGI->spellh->spells[effect]->name);
|
2012-09-20 19:55:21 +03:00
|
|
|
int duration = battleStack->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain;
|
2012-02-16 20:10:58 +03:00
|
|
|
boost::replace_first (spellText, "%d", boost::lexical_cast<std::string>(duration));
|
2012-06-15 20:08:19 +03:00
|
|
|
|
|
|
|
new CAnimImage("SpellInt", effect + 1, 0, 20 + 52 * printed, 184);
|
2011-12-22 16:05:19 +03:00
|
|
|
spellEffects.push_back(new LRClickableAreaWText(Rect(20 + 52 * printed, 184, 50, 38), spellText, spellText));
|
2011-05-13 12:02:16 +03:00
|
|
|
if (++printed >= 10) //we can fit only 10 effects
|
|
|
|
break;
|
|
|
|
}
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
//print current health
|
|
|
|
printLine (5, CGI->generaltexth->allTexts[200], battleStack->firstHPleft);
|
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
if (bonusItems.size() > (bonusRows << 1)) //only after graphics are created
|
2011-03-03 20:25:48 +02:00
|
|
|
{
|
2013-07-02 18:23:32 +03:00
|
|
|
slider = new CSlider(528, 231 + commanderOffset, bonusRows*60, boost::bind (&CCreatureWindow::sliderMoved, this, _1),
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusRows, (bonusItems.size() + 1) >> 1, 0, false, 0);
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
else //slider automatically places bonus Items
|
|
|
|
recreateSkillList (0);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
2011-04-10 08:41:24 +03:00
|
|
|
showAll(screen2);
|
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
//AUIDAT.DEF
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::printLine(int nr, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
new CLabel(162, 48 + nr*19, FONT_SMALL, TOPLEFT, Colors::WHITE, text);
|
2011-03-03 20:25:48 +02:00
|
|
|
|
|
|
|
std::string hlp;
|
|
|
|
if(range && baseVal != val)
|
|
|
|
hlp = boost::str(boost::format("%d - %d") % baseVal % val);
|
|
|
|
else if(baseVal != val && val>=0)
|
|
|
|
hlp = boost::str(boost::format("%d (%d)") % baseVal % val);
|
|
|
|
else
|
|
|
|
hlp = boost::lexical_cast<std::string>(baseVal);
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
new CLabel(325, 64 + nr*19, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, hlp);
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
void CCreatureWindow::recreateSkillList(int Pos)
|
|
|
|
{
|
2012-05-16 20:29:05 +03:00
|
|
|
int commanderOffset = 0;
|
|
|
|
if (type >= COMMANDER)
|
|
|
|
commanderOffset = 74;
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
int n = 0, i = 0, j = 0;
|
|
|
|
int numSkills = std::min ((bonusRows + Pos) << 1, (int)bonusItems.size());
|
|
|
|
for (n = 0; n < Pos << 1; ++n)
|
|
|
|
{
|
|
|
|
bonusItems[n]->visible = false;
|
2012-07-04 17:41:53 +03:00
|
|
|
if (n < selectableBonuses.size())
|
|
|
|
selectableBonuses[n]->deactivate(); //we assume that bonuses are at front of the list
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
for (n = Pos << 1; n < numSkills; ++n)
|
|
|
|
{
|
2011-04-10 13:31:42 +03:00
|
|
|
int offsetx = 257*j - (bonusRows == 4 ? 1 : 0);
|
2012-05-16 20:29:05 +03:00
|
|
|
int offsety = 60*i + (bonusRows > 1 ? 1 : 0) + commanderOffset; //lack of precision :/
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bonusItems[n]->moveTo (Point(pos.x + offsetx + 10, pos.y + offsety + 230), true);
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusItems[n]->visible = true;
|
2012-07-04 17:41:53 +03:00
|
|
|
if (n < selectableBonuses.size())
|
|
|
|
{
|
|
|
|
selectableBonuses[n]->moveTo (Point(bonusItems[n]->pos.x + 12, bonusItems[n]->pos.y + 2)); //for some reason bonusItems have dimensions 0?
|
|
|
|
//selectableBonuses[n]->pos = bonusItems[n]->bonusGraphics->pos;
|
|
|
|
selectableBonuses[n]->activate();
|
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
|
|
|
|
if (++j > 1) //next line
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (n = numSkills; n < bonusItems.size(); ++n)
|
|
|
|
{
|
|
|
|
bonusItems[n]->visible = false;
|
2012-08-30 17:57:24 +03:00
|
|
|
if (n < selectableBonuses.size())
|
|
|
|
selectableBonuses[n]->deactivate();
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::showAll(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
CIntObject::showAll(to);
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
printAtMiddleLoc((type >= COMMANDER ? c->nameSing : c->namePl), 180, 30, FONT_SMALL, Colors::YELLOW, to); //creature name
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2011-05-13 12:02:16 +03:00
|
|
|
printLine(0, CGI->generaltexth->primarySkillNames[0], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->Attack());
|
|
|
|
printLine(1, CGI->generaltexth->primarySkillNames[1], c->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->Defense());
|
2011-06-18 18:43:28 +03:00
|
|
|
|
2012-05-07 15:54:22 +03:00
|
|
|
if (stackNode->valOfBonuses(Bonus::SHOTS) && stackNode->hasBonusOfType(Bonus::SHOOTER))
|
2011-08-06 10:05:04 +03:00
|
|
|
{//only for shooting units - important with wog exp shooters
|
|
|
|
if (type == BATTLE)
|
2013-01-31 00:28:31 +03:00
|
|
|
printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS), dynamic_cast<const CStack*>(stackNode)->shots);
|
2011-08-06 10:05:04 +03:00
|
|
|
else
|
|
|
|
printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS));
|
|
|
|
}
|
2012-05-07 15:54:22 +03:00
|
|
|
if (stackNode->valOfBonuses(Bonus::CASTS))
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
printAtMiddleLoc(CGI->generaltexth->allTexts[399], 356, 62, FONT_SMALL, Colors::WHITE, to);
|
2012-05-07 15:54:22 +03:00
|
|
|
std::string casts;
|
|
|
|
if (type == BATTLE)
|
|
|
|
casts = boost::lexical_cast<std::string>((ui16)dynamic_cast<const CStack*>(stackNode)->casts); //ui8 is converted to char :(
|
|
|
|
else
|
|
|
|
casts = boost::lexical_cast<std::string>(stackNode->valOfBonuses(Bonus::CASTS));
|
2012-11-11 15:23:31 +03:00
|
|
|
printAtMiddleLoc(casts, 356, 82, FONT_SMALL, Colors::WHITE, to);
|
2012-05-07 15:54:22 +03:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
|
|
|
|
//TODO
|
|
|
|
int dmgMultiply = 1;
|
|
|
|
if(heroOwner && stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
2012-02-16 20:10:58 +03:00
|
|
|
dmgMultiply += heroOwner->Attack();
|
2011-04-09 22:34:48 +03:00
|
|
|
|
|
|
|
printLine(3, CGI->generaltexth->allTexts[199], stackNode->getMinDamage() * dmgMultiply, stackNode->getMaxDamage() * dmgMultiply, true);
|
|
|
|
printLine(4, CGI->generaltexth->allTexts[388], c->valOfBonuses(Bonus::STACK_HEALTH), stackNode->valOfBonuses(Bonus::STACK_HEALTH));
|
2013-07-22 13:39:11 +03:00
|
|
|
printLine(6, CGI->generaltexth->zelp[441].first, c->Speed(), stackNode->Speed());
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(CBonusItem* b : bonusItems)
|
2011-04-09 22:34:48 +03:00
|
|
|
b->showAll (to);
|
2012-07-03 11:07:34 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto s : selectableSkills)
|
2012-07-03 11:07:34 +03:00
|
|
|
s->showAll (to);
|
|
|
|
|
|
|
|
for (int i = 0; i < skillPictures.size(); i++)
|
|
|
|
{
|
|
|
|
skillPictures[i]->bg = BitmapHandler::loadBitmap (skillToFile(i));
|
|
|
|
skillPictures[i]->showAll (to);
|
|
|
|
}
|
2012-07-04 17:41:53 +03:00
|
|
|
|
2013-01-17 21:15:00 +03:00
|
|
|
if (upgradeOptions.size() && (type == COMMANDER_LEVEL_UP && upgradeOptions[selectedOption] >= 100)) //add frame to selected skill
|
2012-07-04 17:41:53 +03:00
|
|
|
{
|
|
|
|
int index = selectedOption - selectableSkills.size(); //this is screwed
|
2012-11-20 20:53:45 +03:00
|
|
|
CSDL_Ext::drawBorder(to, Rect::around(selectableBonuses[index]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
|
2012-07-04 17:41:53 +03:00
|
|
|
}
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
2011-08-05 10:59:15 +03:00
|
|
|
void CCreatureWindow::show(SDL_Surface * to)
|
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
CIntObject::show(to);
|
|
|
|
if (!count.empty()) //army stack
|
|
|
|
graphics->fonts[FONT_TIMES]->renderTextRight(to, count, Colors::WHITE, Point(pos.x + 114, pos.y + 174));
|
2011-08-05 10:59:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
void CCreatureWindow::close()
|
|
|
|
{
|
|
|
|
if (upgradeOptions.size()) //a skill for commander was chosen
|
2012-07-04 17:41:53 +03:00
|
|
|
levelUp (selectedOption); //callback value is vector index
|
2012-07-03 11:07:34 +03:00
|
|
|
|
|
|
|
GH.popIntTotally(this);
|
|
|
|
}
|
|
|
|
|
2011-04-09 22:34:48 +03:00
|
|
|
void CCreatureWindow::sliderMoved(int newpos)
|
|
|
|
{
|
|
|
|
recreateSkillList(newpos); //move components
|
|
|
|
redraw();
|
|
|
|
}
|
2011-03-06 14:12:22 +02:00
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
std::string CCreatureWindow::skillToFile (int skill)
|
|
|
|
{
|
|
|
|
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 = boost::lexical_cast<std::string>((int)(commander->secondarySkills[skill])); //casting ui8 causes ascii char conversion
|
|
|
|
if (type == COMMANDER_LEVEL_UP)
|
|
|
|
{
|
|
|
|
if (upgradeOptions.size() && upgradeOptions[selectedOption] == skill)//that one specific skill is selected
|
|
|
|
sufix += "="; //level-up highlight
|
|
|
|
else if (!vstd::contains(upgradeOptions, skill))
|
|
|
|
sufix = "no"; //not avaliable - no number
|
|
|
|
}
|
|
|
|
file += sufix += ".bmp";
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2012-05-22 20:16:37 +03:00
|
|
|
void CCreatureWindow::setArt(const CArtifactInstance *art)
|
2012-05-13 18:04:21 +03:00
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
creatureArtifact = art;
|
2012-05-13 18:04:21 +03:00
|
|
|
if (creatureArtifact)
|
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
if (artifactImage == nullptr)
|
2012-12-14 18:32:53 +03:00
|
|
|
artifactImage = new CAnimImage("ARTIFACT", creatureArtifact->artType->iconIndex, 0, 466, 100);
|
2012-05-13 18:04:21 +03:00
|
|
|
else
|
2012-12-14 18:32:53 +03:00
|
|
|
artifactImage->setFrame(creatureArtifact->artType->iconIndex);
|
2012-05-13 18:04:21 +03:00
|
|
|
}
|
|
|
|
else
|
2013-06-26 14:18:27 +03:00
|
|
|
artifactImage = nullptr;
|
2012-05-22 20:16:37 +03:00
|
|
|
|
|
|
|
redraw();
|
2012-05-13 18:04:21 +03:00
|
|
|
}
|
|
|
|
|
2011-03-03 20:25:48 +02:00
|
|
|
void CCreatureWindow::scrollArt(int dir)
|
|
|
|
{
|
2012-02-10 13:32:21 +03:00
|
|
|
//TODO: get next artifact
|
2012-05-22 20:16:37 +03:00
|
|
|
int size = stack->artifactsWorn.size();
|
2013-02-13 00:32:55 +03:00
|
|
|
displayedArtifact = size ? static_cast<ArtifactPosition>((displayedArtifact + dir) % size)
|
|
|
|
: static_cast<ArtifactPosition>(ArtifactPosition::CREATURE_SLOT);
|
2012-05-22 20:16:37 +03:00
|
|
|
setArt (stack->getArt(displayedArtifact));
|
2012-02-10 13:32:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::passArtifactToHero()
|
|
|
|
{
|
2012-04-17 17:50:23 +03:00
|
|
|
const CGHeroInstance * h = dynamic_cast<const CGHeroInstance *>(stack->armyObj);
|
|
|
|
if (h && creatureArtifact)
|
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
LOCPLINT->cb->swapArtifacts (ArtifactLocation (stack, displayedArtifact), ArtifactLocation(h, creatureArtifact->firstBackpackSlot(h)));
|
2012-04-17 17:50:23 +03:00
|
|
|
}
|
|
|
|
else
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->warnStream() << "Pass artifact to hero should be disabled, no hero or no artifact!";
|
2012-04-17 17:50:23 +03:00
|
|
|
|
|
|
|
//redraw is handled via CArtifactHolder interface
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreatureWindow::artifactRemoved (const ArtifactLocation &artLoc)
|
|
|
|
{
|
2012-05-25 18:10:38 +03:00
|
|
|
//align artifacts to remove holes
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto al : stack->artifactsWorn)
|
2012-05-25 18:10:38 +03:00
|
|
|
{
|
2013-02-12 22:49:40 +03:00
|
|
|
ArtifactPosition freeSlot = al.second.artifact->firstAvailableSlot(stack);
|
2012-05-25 18:10:38 +03:00
|
|
|
if (freeSlot < al.first)
|
|
|
|
LOCPLINT->cb->swapArtifacts (ArtifactLocation(stack, al.first), ArtifactLocation(stack, freeSlot));
|
|
|
|
}
|
2012-05-22 20:16:37 +03:00
|
|
|
int size = stack->artifactsWorn.size();
|
2013-02-13 00:32:55 +03:00
|
|
|
displayedArtifact = size ? static_cast<ArtifactPosition>(displayedArtifact % size)
|
|
|
|
: static_cast<ArtifactPosition>(ArtifactPosition::CREATURE_SLOT); //0
|
2012-05-22 20:16:37 +03:00
|
|
|
setArt (stack->getArt(displayedArtifact));
|
2012-04-17 17:50:23 +03:00
|
|
|
}
|
|
|
|
void CCreatureWindow::artifactMoved (const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)
|
|
|
|
{
|
2012-05-22 20:16:37 +03:00
|
|
|
artifactRemoved (artLoc); //same code
|
2011-03-03 20:25:48 +02:00
|
|
|
}
|
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
void CCreatureWindow::selectSkill (ui32 which)
|
|
|
|
{
|
|
|
|
selectedOption = which;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2011-03-06 14:12:22 +02:00
|
|
|
CCreatureWindow::~CCreatureWindow()
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : upgResCost)
|
|
|
|
delete elem;
|
2011-04-09 22:34:48 +03:00
|
|
|
bonusItems.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
CBonusItem::CBonusItem()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
CBonusItem::CBonusItem(const Rect &Pos, const std::string &Name, const std::string &Description, const std::string &graphicsName)
|
2011-04-09 22:34:48 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
|
|
|
visible = false;
|
|
|
|
|
|
|
|
name = Name;
|
|
|
|
description = Description;
|
|
|
|
if (graphicsName.size())
|
|
|
|
bonusGraphics = new CPicture(graphicsName, 26, 232);
|
|
|
|
else
|
2013-06-26 14:18:27 +03:00
|
|
|
bonusGraphics = nullptr;
|
2011-04-09 22:34:48 +03:00
|
|
|
|
2012-06-02 18:16:54 +03:00
|
|
|
removeUsedEvents(ALL); //no actions atm
|
2011-04-09 22:34:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusItem::showAll (SDL_Surface * to)
|
|
|
|
{
|
|
|
|
if (visible)
|
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
graphics->fonts[FONT_SMALL]->renderTextLeft(to, name, Colors::YELLOW, Point(pos.x + 72, pos.y + 6));
|
2013-01-21 12:32:51 +03:00
|
|
|
graphics->fonts[FONT_SMALL]->renderTextLeft(to, description, Colors::WHITE, Point(pos.x + 72, pos.y + 30));
|
2011-04-09 22:34:48 +03:00
|
|
|
if (bonusGraphics && bonusGraphics->bg)
|
|
|
|
blitAtLoc(bonusGraphics->bg, 12, 2, to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBonusItem::~CBonusItem()
|
|
|
|
{
|
|
|
|
//delete bonusGraphics; //automatic destruction
|
2011-03-13 18:06:20 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2012-07-03 11:07:34 +03:00
|
|
|
void CSelectableSkill::clickLeft(tribool down, bool previousState)
|
|
|
|
{
|
|
|
|
if (down)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CCreInfoWindow::show(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
CIntObject::show(to);
|
|
|
|
creatureCount->showAll(to);
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
CCreInfoWindow::CCreInfoWindow(const CStackInstance &stack, bool LClicked, std::function<void()> upgradeFunc, std::function<void()> dismissFunc, UpgradeInfo *upgradeInfo):
|
2012-06-15 20:08:19 +03:00
|
|
|
CWindowObject(PLAYER_COLORED | (LClicked ? 0 : RCLICK_POPUP), "CRSTKPU")
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(stack.type, &stack, dynamic_cast<const CGHeroInstance*>(stack.armyObj), stack.count, LClicked);
|
|
|
|
|
|
|
|
//additional buttons if opened with left click
|
|
|
|
if(LClicked)
|
|
|
|
{
|
2013-07-02 18:23:32 +03:00
|
|
|
std::function<void()> closeFunc = boost::bind(&CCreInfoWindow::close,this);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
if(upgradeFunc && upgradeInfo)
|
|
|
|
{
|
|
|
|
TResources upgradeCost = upgradeInfo->cost[0] * stack.count;
|
|
|
|
for(TResources::nziterator i(upgradeCost); i.valid(); i++)
|
|
|
|
{
|
|
|
|
BLOCK_CAPTURING;
|
2012-02-16 20:10:58 +03:00
|
|
|
upgResCost.push_back(new CComponent(CComponent::resource, i->resType, i->resVal));
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CFunctionList<void()> onUpgrade;
|
|
|
|
onUpgrade += upgradeFunc;
|
|
|
|
onUpgrade += closeFunc;
|
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
std::function<void()> dialog = boost::bind(&CPlayerInterface::showYesNoDialog,
|
2011-12-22 16:05:19 +03:00
|
|
|
LOCPLINT,
|
|
|
|
CGI->generaltexth->allTexts[207],
|
2012-04-09 05:53:50 +03:00
|
|
|
onUpgrade, 0, false,
|
2013-07-02 18:23:32 +03:00
|
|
|
boost::ref(upgResCost));
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
upgrade = new CAdventureMapButton("", CGI->generaltexth->zelp[446].second, dialog, 76, 237, "IVIEWCR", SDLK_u);
|
|
|
|
upgrade->block(!LOCPLINT->cb->getResourceAmount().canAfford(upgradeCost));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dismissFunc)
|
|
|
|
{
|
|
|
|
CFunctionList<void()> onDismiss;
|
|
|
|
onDismiss += dismissFunc;
|
|
|
|
onDismiss += closeFunc;
|
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
std::function<void()> dialog = boost::bind(&CPlayerInterface::showYesNoDialog,
|
2011-12-22 16:05:19 +03:00
|
|
|
LOCPLINT,
|
2012-02-16 20:10:58 +03:00
|
|
|
CGI->generaltexth->allTexts[12],
|
2012-04-09 05:53:50 +03:00
|
|
|
onDismiss, 0, true, std::vector<CComponent*>());
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
dismiss = new CAdventureMapButton("", CGI->generaltexth->zelp[445].second, dialog, 21, 237, "IVIEWCR2",SDLK_d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreInfoWindow::CCreInfoWindow(int creatureID, bool LClicked, int creatureCount):
|
|
|
|
CWindowObject(PLAYER_COLORED | (LClicked ? 0 : RCLICK_POPUP), "CRSTKPU")
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
const CCreature *creature = CGI->creh->creatures[creatureID];
|
2013-06-26 14:18:27 +03:00
|
|
|
init(creature, nullptr, nullptr, creatureCount, LClicked);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CCreInfoWindow::CCreInfoWindow(const CStack &stack, bool LClicked):
|
|
|
|
CWindowObject(PLAYER_COLORED | (LClicked ? 0 : RCLICK_POPUP), "CRSTKPU")
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
init(stack.getCreature(), &stack, stack.getMyHero(), stack.count, LClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCreInfoWindow::~CCreInfoWindow()
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(CComponent* object : upgResCost)
|
2011-12-22 16:05:19 +03:00
|
|
|
delete object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCreInfoWindow::printLine(int position, const std::string &text, int baseVal, int val/*=-1*/, bool range/*=false*/)
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
infoTexts[position].first = new CLabel(155, 48 + position*19, FONT_SMALL, TOPLEFT, Colors::WHITE, text);
|
2011-12-22 16:05:19 +03:00
|
|
|
std::string valueStr;
|
|
|
|
|
|
|
|
if(range && baseVal != val)
|
|
|
|
valueStr = boost::str(boost::format("%d - %d") % baseVal % val);
|
|
|
|
|
|
|
|
else if(baseVal != val && val>=0)
|
|
|
|
valueStr = boost::str(boost::format("%d (%d)") % baseVal % val);
|
|
|
|
|
|
|
|
else
|
|
|
|
valueStr = boost::lexical_cast<std::string>(baseVal);
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
infoTexts[position].second = new CLabel(276, 63 + position*19, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, valueStr);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCreInfoWindow::init(const CCreature *creature, const CBonusSystemNode *stackNode, const CGHeroInstance *heroOwner, int count, bool LClicked)
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
removeUsedEvents(ALL);
|
2011-12-22 16:05:19 +03:00
|
|
|
if (!LClicked)
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(RCLICK);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
if(!stackNode)
|
|
|
|
stackNode = creature;
|
|
|
|
|
|
|
|
animation = new CCreaturePic(21, 48, creature);
|
|
|
|
|
|
|
|
std::string countStr = boost::lexical_cast<std::string>(count);
|
2012-11-11 15:23:31 +03:00
|
|
|
creatureCount = new CLabel(114, 174, FONT_TIMES, BOTTOMRIGHT, Colors::WHITE, countStr);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
creatureName = new CLabel(149, 30, FONT_SMALL, CENTER, Colors::YELLOW, creature->namePl);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
printLine(0, CGI->generaltexth->primarySkillNames[0], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK));
|
|
|
|
printLine(1, CGI->generaltexth->primarySkillNames[1], creature->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE), stackNode->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE));
|
|
|
|
|
|
|
|
if(stackNode->valOfBonuses(Bonus::SHOTS))
|
|
|
|
printLine(2, CGI->generaltexth->allTexts[198], stackNode->valOfBonuses(Bonus::SHOTS));
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
int dmgMultiply = 1;
|
|
|
|
if(heroOwner && stackNode->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
2012-02-16 20:10:58 +03:00
|
|
|
dmgMultiply += heroOwner->Attack();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
printLine(3, CGI->generaltexth->allTexts[199], stackNode->getMinDamage() * dmgMultiply, stackNode->getMaxDamage() * dmgMultiply, true);
|
|
|
|
printLine(4, CGI->generaltexth->allTexts[388], creature->valOfBonuses(Bonus::STACK_HEALTH), stackNode->valOfBonuses(Bonus::STACK_HEALTH));
|
|
|
|
printLine(6, CGI->generaltexth->zelp[441].first, creature->valOfBonuses(Bonus::STACKS_SPEED), stackNode->valOfBonuses(Bonus::STACKS_SPEED));
|
|
|
|
|
|
|
|
//setting morale
|
|
|
|
morale = new MoraleLuckBox(true, genRect(42, 42, 22, 186));
|
|
|
|
morale->set(stackNode);
|
|
|
|
//setting luck
|
|
|
|
luck = new MoraleLuckBox(false, genRect(42, 42, 75, 186));
|
|
|
|
luck->set(stackNode);
|
|
|
|
|
|
|
|
if(!LClicked)
|
2012-03-31 00:36:07 +03:00
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
abilityText = new CLabel(17, 231, FONT_SMALL, TOPLEFT, Colors::WHITE, creature->abilityText);
|
2012-03-31 00:36:07 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
2012-03-31 00:36:07 +03:00
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
abilityText = nullptr;
|
2012-03-31 00:36:07 +03:00
|
|
|
ok = new CAdventureMapButton("", CGI->generaltexth->zelp[445].second,
|
2013-07-02 18:23:32 +03:00
|
|
|
boost::bind(&CCreInfoWindow::close,this), 216, 237, "IOKAY.DEF", SDLK_RETURN);
|
2012-05-16 20:29:05 +03:00
|
|
|
ok->assignedKeys.insert(SDLK_ESCAPE);
|
2012-03-31 00:36:07 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
//if we are displying window fo r stack in battle, there are several more things that we need to display
|
|
|
|
if(const CStack *battleStack = dynamic_cast<const CStack*>(stackNode))
|
|
|
|
{
|
|
|
|
//print at most 3 spell effects
|
|
|
|
std::vector<si32> spells = battleStack->activeSpells();
|
|
|
|
for (size_t i=0; i< std::min(spells.size(), size_t(3)); i++)
|
|
|
|
effects.push_back(new CAnimImage("SpellInt", spells[i]+1, 0, 127 + 52*i, 186));
|
|
|
|
|
|
|
|
//print current health
|
|
|
|
printLine(5, CGI->generaltexth->allTexts[200], battleStack->firstHPleft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 20:29:05 +03:00
|
|
|
CIntObject * createCreWindow(
|
|
|
|
const CStack *s, bool lclick/* = false*/)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2012-08-20 19:10:50 +03:00
|
|
|
auto c = dynamic_cast<const CCommanderInstance *>(s->base);
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
return new CCreatureWindow (c, s);
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
2012-08-20 19:10:50 +03:00
|
|
|
{
|
|
|
|
if(settings["general"]["classicCreatureWindow"].Bool())
|
|
|
|
return new CCreInfoWindow(*s, lclick);
|
|
|
|
else
|
2013-01-31 00:28:31 +03:00
|
|
|
return new CCreatureWindow(*s, LOCPLINT->battleInt ? CCreatureWindow::BATTLE : CCreatureWindow::OTHER);
|
2012-08-20 19:10:50 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
CIntObject * createCreWindow(CreatureID Cid, CCreatureWindow::CreWinType Type, int creatureCount)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
if(settings["general"]["classicCreatureWindow"].Bool())
|
2011-12-22 16:05:19 +03:00
|
|
|
return new CCreInfoWindow(Cid, Type, creatureCount);
|
|
|
|
else
|
|
|
|
return new CCreatureWindow(Cid, Type, creatureCount);
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
CIntObject * createCreWindow(const CStackInstance *s, CCreatureWindow::CreWinType type, std::function<void()> Upg, std::function<void()> Dsm, UpgradeInfo *ui)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2012-01-12 18:23:00 +03:00
|
|
|
if(settings["general"]["classicCreatureWindow"].Bool())
|
2013-01-31 00:28:31 +03:00
|
|
|
return new CCreInfoWindow(*s, type==CCreatureWindow::HERO, Upg, Dsm, ui);
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
|
|
|
return new CCreatureWindow(*s, type, Upg, Dsm, ui);
|
|
|
|
}
|