2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2010-01-25 23:25:14 +02:00
|
|
|
#include "CKingdomInterface.h"
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
#include "../CCallback.h"
|
|
|
|
#include "../lib/CCreatureHandler.h" //creatures name for objects list
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
2012-09-05 15:49:23 +03:00
|
|
|
#include "../lib/CModHandler.h" //for buildings per turn
|
2011-07-22 19:22:22 +03:00
|
|
|
#include "../lib/CObjectHandler.h" //Hero/Town objects
|
2011-07-23 09:14:05 +03:00
|
|
|
#include "../lib/CHeroHandler.h" // only for calculating required xp? worth it?
|
2012-09-22 18:10:15 +03:00
|
|
|
#include "../lib/CTownHandler.h"
|
2011-07-22 19:22:22 +03:00
|
|
|
#include "CAnimation.h" //CAnimImage
|
|
|
|
#include "CAdvmapInterface.h" //CResDataBar
|
|
|
|
#include "CCastleInterface.h" //various town-specific classes
|
2012-09-29 13:59:43 +03:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2011-07-22 19:22:22 +03:00
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "CPlayerInterface.h" //LOCPLINT
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/CGuiHandler.h"
|
|
|
|
#include "gui/CIntObjectClasses.h"
|
2013-04-04 17:58:54 +03:00
|
|
|
#include "CMT.h"
|
2010-01-25 23:25:14 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CKingdomInterface.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
|
|
|
|
*
|
2010-01-26 13:56:29 +02:00
|
|
|
*/
|
2010-01-31 14:10:13 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, IInfoBoxData *Data):
|
2011-07-22 19:22:22 +03:00
|
|
|
size(Size),
|
|
|
|
infoPos(Pos),
|
|
|
|
data(Data),
|
2013-06-26 14:18:27 +03:00
|
|
|
value(nullptr),
|
|
|
|
name(nullptr)
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
assert(data);
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(LCLICK | RCLICK);
|
2011-07-22 19:22:22 +03:00
|
|
|
EFonts font = (size < SIZE_MEDIUM)? FONT_SMALL: FONT_MEDIUM;
|
|
|
|
|
2010-01-26 13:56:29 +02:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2011-07-22 19:22:22 +03:00
|
|
|
pos+=position;
|
2010-01-26 13:56:29 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
image = new CAnimImage(data->getImageName(size), data->getImageIndex());
|
|
|
|
pos = image->pos;
|
2010-01-28 18:15:46 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
if (infoPos == POS_CORNER)
|
2012-11-11 15:23:31 +03:00
|
|
|
value = new CLabel(pos.w, pos.h, font, BOTTOMRIGHT, Colors::WHITE, data->getValueText());
|
2010-01-28 18:15:46 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
if (infoPos == POS_INSIDE)
|
2012-11-11 15:23:31 +03:00
|
|
|
value = new CLabel(pos.w/2, pos.h-6, font, CENTER, Colors::WHITE, data->getValueText());
|
2010-01-28 18:15:46 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
if (infoPos == POS_UP_DOWN || infoPos == POS_DOWN)
|
2012-11-11 15:23:31 +03:00
|
|
|
value = new CLabel(pos.w/2, pos.h+8, font, CENTER, Colors::WHITE, data->getValueText());
|
2010-01-28 18:15:46 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
if (infoPos == POS_UP_DOWN)
|
2012-11-11 15:23:31 +03:00
|
|
|
name = new CLabel(pos.w/2, -12, font, CENTER, Colors::WHITE, data->getNameText());
|
2010-01-28 18:15:46 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
if (infoPos == POS_RIGHT)
|
2010-02-01 01:30:47 +02:00
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
name = new CLabel(pos.w+6, 6, font, TOPLEFT, Colors::WHITE, data->getNameText());
|
|
|
|
value = new CLabel(pos.w+6, pos.h-16, font, TOPLEFT, Colors::WHITE, data->getValueText());
|
2010-01-28 18:15:46 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
pos = image->pos;
|
|
|
|
if (name)
|
|
|
|
pos = pos | name->pos;
|
|
|
|
if (value)
|
|
|
|
pos = pos | value->pos;
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
hover = new CHoverableArea;
|
2011-07-22 19:22:22 +03:00
|
|
|
hover->hoverText = data->getHoverText();
|
|
|
|
hover->pos = pos;
|
|
|
|
}
|
2010-02-01 01:30:47 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
InfoBox::~InfoBox()
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
}
|
2010-02-01 01:30:47 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void InfoBox::clickRight(tribool down, bool previousState)
|
|
|
|
{
|
|
|
|
if (down)
|
|
|
|
{
|
2012-09-30 13:35:17 +03:00
|
|
|
CComponent *comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string text;
|
|
|
|
data->prepareMessage(text, &comp);
|
|
|
|
if (comp)
|
|
|
|
CRClickPopup::createAndPush(text, CInfoWindow::TCompsInfo(1, comp));
|
2012-09-30 13:35:17 +03:00
|
|
|
else if (!text.empty())
|
2011-07-22 19:22:22 +03:00
|
|
|
adventureInt->handleRightClick(text, down);
|
2011-06-24 20:43:02 +03:00
|
|
|
}
|
2010-01-28 18:15:46 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void InfoBox::clickLeft(tribool down, bool previousState)
|
2010-01-28 18:15:46 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
if((!down) && previousState)
|
2010-01-28 18:15:46 +02:00
|
|
|
{
|
2012-09-30 13:35:17 +03:00
|
|
|
CComponent *comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string text;
|
|
|
|
data->prepareMessage(text, &comp);
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
std::vector<CComponent*> compVector;
|
2011-07-22 19:22:22 +03:00
|
|
|
if (comp)
|
2012-09-30 13:35:17 +03:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
compVector.push_back(comp);
|
2012-09-30 13:35:17 +03:00
|
|
|
LOCPLINT->showInfoDialog(text, compVector);
|
|
|
|
}
|
2010-01-28 18:15:46 +02:00
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
//TODO?
|
|
|
|
/*
|
|
|
|
void InfoBox::update()
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
|
|
|
*/
|
2010-01-26 13:56:29 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
IInfoBoxData::IInfoBoxData(InfoType Type):
|
|
|
|
type(Type)
|
|
|
|
{
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
InfoBoxAbstractHeroData::InfoBoxAbstractHeroData(InfoType Type):
|
|
|
|
IInfoBoxData(Type)
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string InfoBoxAbstractHeroData::getValueText()
|
2010-02-06 15:27:58 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch (type)
|
2010-02-13 17:56:34 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return boost::lexical_cast<std::string>(getValue());
|
|
|
|
case HERO_SPECIAL:
|
2013-01-12 22:28:38 +03:00
|
|
|
return CGI->generaltexth->jktexts[5];
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
{
|
|
|
|
si64 value = getValue();
|
|
|
|
if (value)
|
|
|
|
return CGI->generaltexth->levels[value];
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0);
|
2010-02-06 15:27:58 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
return "";
|
2010-02-06 15:27:58 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string InfoBoxAbstractHeroData::getNameText()
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch (type)
|
2010-01-28 18:15:46 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return CGI->generaltexth->primarySkillNames[getSubID()];
|
|
|
|
case HERO_MANA:
|
|
|
|
return CGI->generaltexth->allTexts[387];
|
|
|
|
case HERO_EXPERIENCE:
|
2013-01-12 22:28:38 +03:00
|
|
|
return CGI->generaltexth->jktexts[6];
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_SPECIAL:
|
2012-12-16 16:47:53 +03:00
|
|
|
return CGI->heroh->heroes[getSubID()]->specName;
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
if (getValue())
|
|
|
|
return CGI->generaltexth->skillName[getSubID()];
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
default:
|
|
|
|
assert(0);
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
return "";
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string InfoBoxAbstractHeroData::getImageName(InfoBox::InfoSize size)
|
|
|
|
{
|
|
|
|
//TODO: sizes
|
|
|
|
switch(size)
|
2010-02-01 01:30:47 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case InfoBox::SIZE_SMALL:
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return "PSKIL32";
|
|
|
|
case HERO_SPECIAL:
|
|
|
|
return "UN32";
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
return "SECSK32";
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case InfoBox::SIZE_BIG:
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return "PSKIL42";
|
|
|
|
case HERO_SPECIAL:
|
|
|
|
return "UN44";
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
return "SECSKILL";
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0);
|
2010-02-01 01:30:47 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
return "";
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string InfoBoxAbstractHeroData::getHoverText()
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
//TODO: any texts here?
|
|
|
|
return "";
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
size_t InfoBoxAbstractHeroData::getImageIndex()
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_SPECIAL:
|
2012-12-16 16:47:53 +03:00
|
|
|
return VLC->heroh->heroes[getSubID()]->imageIndex;
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return getSubID();
|
|
|
|
case HERO_MANA:
|
|
|
|
return 5;
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return 4;
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
{
|
|
|
|
si64 value = getValue();
|
|
|
|
if (value)
|
|
|
|
return getSubID()*3 + value + 2;
|
|
|
|
else
|
|
|
|
return 0;//FIXME: Should be transparent instead of empty
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bool InfoBoxAbstractHeroData::prepareMessage(std::string &text, CComponent **comp)
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_SPECIAL:
|
2012-12-16 16:47:53 +03:00
|
|
|
text = CGI->heroh->heroes[getSubID()]->specDescr;
|
2013-06-26 14:18:27 +03:00
|
|
|
*comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
text = CGI->generaltexth->arraytxt[2+getSubID()];
|
2011-12-22 16:05:19 +03:00
|
|
|
*comp =new CComponent(CComponent::primskill, getSubID(), getValue());
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
case HERO_MANA:
|
|
|
|
text = CGI->generaltexth->allTexts[149];
|
2013-06-26 14:18:27 +03:00
|
|
|
*comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
text = CGI->generaltexth->allTexts[241];
|
2013-06-26 14:18:27 +03:00
|
|
|
*comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
{
|
|
|
|
si64 value = getValue();
|
|
|
|
int subID = getSubID();
|
|
|
|
if (!value)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
text = CGI->generaltexth->skillInfoTexts[subID][value-1];
|
2011-12-22 16:05:19 +03:00
|
|
|
*comp = new CComponent(CComponent::secskill, subID, value);
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
InfoBoxHeroData::InfoBoxHeroData(InfoType Type, const CGHeroInstance * Hero, int Index):
|
|
|
|
InfoBoxAbstractHeroData(Type),
|
|
|
|
hero(Hero),
|
|
|
|
index(Index)
|
|
|
|
{
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
int InfoBoxHeroData::getSubID()
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch(type)
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return index;
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
if (hero->secSkills.size() > index)
|
|
|
|
return hero->secSkills[index].first;
|
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
case HERO_SPECIAL:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
2010-01-26 13:56:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
si64 InfoBoxHeroData::getValue()
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch(type)
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_PRIMARY_SKILL:
|
2013-02-06 13:16:44 +03:00
|
|
|
return hero->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(index));
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_MANA:
|
|
|
|
return hero->mana;
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return hero->exp;
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
if (hero->secSkills.size() > index)
|
|
|
|
return hero->secSkills[index].second;
|
|
|
|
case HERO_SPECIAL:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
2010-01-26 13:56:29 +02:00
|
|
|
}
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string InfoBoxHeroData::getHoverText()
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch (type)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return boost::str(boost::format(CGI->generaltexth->heroscrn[1]) % CGI->generaltexth->primarySkillNames[index]);
|
|
|
|
case HERO_MANA:
|
|
|
|
return CGI->generaltexth->heroscrn[22];
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return CGI->generaltexth->heroscrn[9];
|
|
|
|
case HERO_SPECIAL:
|
|
|
|
return CGI->generaltexth->heroscrn[27];
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
{
|
|
|
|
if (hero->secSkills.size() > index)
|
|
|
|
{
|
|
|
|
std::string level = CGI->generaltexth->levels[hero->secSkills[index].second-1];
|
|
|
|
std::string skill = CGI->generaltexth->skillName[hero->secSkills[index].first];
|
|
|
|
return boost::str(boost::format(CGI->generaltexth->heroscrn[21]) % level % skill);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return InfoBoxAbstractHeroData::getHoverText();
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string InfoBoxHeroData::getValueText()
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch (type)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_MANA:
|
|
|
|
if (hero)
|
|
|
|
return boost::lexical_cast<std::string>(hero->mana) + '/' +
|
|
|
|
boost::lexical_cast<std::string>(hero->manaLimit());
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return boost::lexical_cast<std::string>(hero->exp);
|
|
|
|
default:
|
|
|
|
return InfoBoxAbstractHeroData::getValueText();
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bool InfoBoxHeroData::prepareMessage(std::string &text, CComponent**comp)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
switch(type)
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
case HERO_MANA:
|
|
|
|
text = CGI->generaltexth->allTexts[205];
|
|
|
|
boost::replace_first(text, "%s", boost::lexical_cast<std::string>(hero->name));
|
|
|
|
boost::replace_first(text, "%d", boost::lexical_cast<std::string>(hero->mana));
|
|
|
|
boost::replace_first(text, "%d", boost::lexical_cast<std::string>(hero->manaLimit()));
|
2013-06-26 14:18:27 +03:00
|
|
|
*comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
text = CGI->generaltexth->allTexts[2];
|
|
|
|
boost::replace_first(text, "%d", boost::lexical_cast<std::string>(hero->level));
|
|
|
|
boost::replace_first(text, "%d", boost::lexical_cast<std::string>(CGI->heroh->reqExp(hero->level+1)));
|
|
|
|
boost::replace_first(text, "%d", boost::lexical_cast<std::string>(hero->exp));
|
2013-06-26 14:18:27 +03:00
|
|
|
*comp = nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InfoBoxAbstractHeroData::prepareMessage(text, comp);
|
2010-01-26 13:56:29 +02:00
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
InfoBoxCustomHeroData::InfoBoxCustomHeroData(InfoType Type, int SubID, si64 Value):
|
|
|
|
InfoBoxAbstractHeroData(Type),
|
|
|
|
subID(SubID),
|
|
|
|
value(Value)
|
2010-01-26 13:56:29 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
int InfoBoxCustomHeroData::getSubID()
|
|
|
|
{
|
|
|
|
return subID;
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
si64 InfoBoxCustomHeroData::getValue()
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
InfoBoxCustom::InfoBoxCustom(std::string ValueText, std::string NameText, std::string ImageName, size_t ImageIndex, std::string HoverText):
|
|
|
|
IInfoBoxData(CUSTOM),
|
|
|
|
valueText(ValueText),
|
|
|
|
nameText(NameText),
|
|
|
|
imageName(ImageName),
|
|
|
|
hoverText(HoverText),
|
|
|
|
imageIndex(ImageIndex)
|
|
|
|
{
|
|
|
|
}
|
2010-01-26 13:56:29 +02:00
|
|
|
|
2011-07-23 09:14:05 +03:00
|
|
|
std::string InfoBoxCustom::getHoverText()
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-07-23 09:14:05 +03:00
|
|
|
return hoverText;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t InfoBoxCustom::getImageIndex()
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-07-23 09:14:05 +03:00
|
|
|
return imageIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxCustom::getImageName(InfoBox::InfoSize size)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-07-23 09:14:05 +03:00
|
|
|
return imageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxCustom::getNameText()
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-07-23 09:14:05 +03:00
|
|
|
return nameText;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxCustom::getValueText()
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-07-23 09:14:05 +03:00
|
|
|
return valueText;
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bool InfoBoxCustom::prepareMessage(std::string &text, CComponent **comp)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CKingdomInterface::CKingdomInterface():
|
|
|
|
CWindowObject(PLAYER_COLORED | BORDERED, conf.go()->ac.overviewBg)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 footerPos = conf.go()->ac.overviewSize * 116;
|
2010-01-31 14:10:13 +02:00
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
tabArea = new CTabbedInt(boost::bind(&CKingdomInterface::createMainTab, this, _1), CTabbedInt::DestroyFunc(), Point(4,4));
|
2010-01-30 21:08:26 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::vector<const CGObjectInstance * > ownedObjects = LOCPLINT->cb->getMyObjects();
|
|
|
|
generateObjectsList(ownedObjects);
|
|
|
|
generateMinesList(ownedObjects);
|
|
|
|
generateButtons();
|
2010-02-01 01:30:47 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
statusbar = new CGStatusBar(new CPicture("KSTATBAR", 10,pos.h - 45));
|
|
|
|
resdatabar= new CResDataBar("KRESBAR", 3, 111+footerPos, 32, 2, 76, 76);
|
|
|
|
}
|
2010-01-30 21:08:26 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 footerPos = conf.go()->ac.overviewSize * 116;
|
2011-07-22 19:22:22 +03:00
|
|
|
size_t dwellSize = (footerPos - 64)/57;
|
|
|
|
|
|
|
|
//Map used to determine image number for several objects
|
|
|
|
std::map<std::pair<int,int>,int> idToImage;
|
|
|
|
idToImage[std::make_pair( 20, 1)] = 81;//Golem factory
|
|
|
|
idToImage[std::make_pair( 42, 0)] = 82;//Lighthouse
|
|
|
|
idToImage[std::make_pair( 33, 0)] = 83;//Garrison
|
|
|
|
idToImage[std::make_pair(219, 0)] = 83;//Garrison
|
|
|
|
idToImage[std::make_pair( 33, 1)] = 84;//Anti-magic Garrison
|
|
|
|
idToImage[std::make_pair(219, 1)] = 84;//Anti-magic Garrison
|
|
|
|
idToImage[std::make_pair( 53, 7)] = 85;//Abandoned mine
|
|
|
|
idToImage[std::make_pair( 20, 0)] = 86;//Conflux
|
|
|
|
idToImage[std::make_pair( 87, 0)] = 87;//Harbor
|
|
|
|
|
|
|
|
std::map<int, OwnedObjectInfo> visibleObjects;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const CGObjectInstance * object : ownedObjects)
|
2010-01-30 21:08:26 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
//Dwellings
|
2012-09-23 21:01:04 +03:00
|
|
|
if ( object->ID == Obj::CREATURE_GENERATOR1 )
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
|
|
|
OwnedObjectInfo &info = visibleObjects[object->subID];
|
|
|
|
if (info.count++ == 0)
|
|
|
|
{
|
2012-05-11 22:03:40 +03:00
|
|
|
info.hoverText = CGI->creh->creatures[CGI->objh->cregens.find(object->subID)->second]->namePl;
|
2011-07-22 19:22:22 +03:00
|
|
|
info.imageID = object->subID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Special objects from idToImage map that should be displayed in objects list
|
2013-06-29 16:05:48 +03:00
|
|
|
auto iter = idToImage.find(std::make_pair(object->ID, object->subID));
|
2011-07-22 19:22:22 +03:00
|
|
|
if (iter != idToImage.end())
|
|
|
|
{
|
|
|
|
OwnedObjectInfo &info = visibleObjects[iter->second];
|
|
|
|
if (info.count++ == 0)
|
|
|
|
{
|
|
|
|
info.hoverText = object->hoverName;
|
|
|
|
info.imageID = iter->second;
|
|
|
|
}
|
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
2011-11-27 16:14:20 +03:00
|
|
|
objects.reserve(visibleObjects.size());
|
2010-01-30 21:08:26 +02:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & element : visibleObjects)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-11-27 16:14:20 +03:00
|
|
|
objects.push_back(element.second);
|
|
|
|
}
|
2013-07-02 18:23:32 +03:00
|
|
|
dwellingsList = new CListBox(boost::bind(&CKingdomInterface::createOwnedObject, this, _1), CListBox::DestroyFunc(),
|
2011-12-22 16:05:19 +03:00
|
|
|
Point(740,44), Point(0,57), dwellSize, visibleObjects.size());
|
2011-11-27 16:14:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CIntObject* CKingdomInterface::createOwnedObject(size_t index)
|
|
|
|
{
|
|
|
|
if (index < objects.size())
|
|
|
|
{
|
|
|
|
OwnedObjectInfo &obj = objects[index];
|
|
|
|
std::string value = boost::lexical_cast<std::string>(obj.count);
|
2011-12-22 16:05:19 +03:00
|
|
|
return new InfoBox(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL,
|
2011-11-27 16:14:20 +03:00
|
|
|
new InfoBoxCustom(value,"", "FLAGPORT", obj.imageID, obj.hoverText));
|
|
|
|
}
|
2013-06-26 14:18:27 +03:00
|
|
|
return nullptr;
|
2011-11-27 16:14:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CIntObject * CKingdomInterface::createMainTab(size_t index)
|
|
|
|
{
|
|
|
|
size_t size = conf.go()->ac.overviewSize;
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case 0: return new CKingdHeroList(size);
|
|
|
|
case 1: return new CKingdTownList(size);
|
2013-06-26 14:18:27 +03:00
|
|
|
default:return nullptr;
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstance * > &ownedObjects)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 footerPos = conf.go()->ac.overviewSize * 116;
|
|
|
|
std::vector<int> minesCount(GameConstants::RESOURCE_QUANTITY, 0);
|
2011-07-22 19:22:22 +03:00
|
|
|
int totalIncome=0;
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const CGObjectInstance * object : ownedObjects)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
//Mines
|
2012-09-23 21:01:04 +03:00
|
|
|
if ( object->ID == Obj::MINE )
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
const CGMine *mine = dynamic_cast<const CGMine*>(object);
|
|
|
|
assert(mine);
|
|
|
|
minesCount[mine->producedResource]++;
|
|
|
|
|
|
|
|
if (mine->producedResource == Res::GOLD)
|
|
|
|
totalIncome += mine->producedQuantity;
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2013-01-17 21:15:00 +03:00
|
|
|
//Heroes can produce gold as well - skill, specialty or arts
|
2011-07-22 19:22:22 +03:00
|
|
|
std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & heroe : heroes)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
totalIncome += heroe->valOfBonuses(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::ESTATES));
|
|
|
|
totalIncome += heroe->valOfBonuses(Selector::typeSubtype(Bonus::GENERATE_RESOURCE, Res::GOLD));
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
//Add town income of all towns
|
|
|
|
std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & town : towns)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
totalIncome += town->dailyIncome();
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
for (int i=0; i<7; i++)
|
|
|
|
{
|
|
|
|
std::string value = boost::lexical_cast<std::string>(minesCount[i]);
|
2011-12-22 16:05:19 +03:00
|
|
|
minesBox[i] = new InfoBox(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL,
|
2011-07-22 19:22:22 +03:00
|
|
|
new InfoBoxCustom(value, "", "OVMINES", i, CGI->generaltexth->mines[i].first));
|
2012-03-31 02:39:44 +03:00
|
|
|
|
2012-06-02 18:16:54 +03:00
|
|
|
minesBox[i]->removeUsedEvents(LCLICK|RCLICK); //fixes #890 - mines boxes ignore clicks
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
incomeArea = new CHoverableArea;
|
|
|
|
incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68);
|
2011-07-22 19:22:22 +03:00
|
|
|
incomeArea->hoverText = CGI->generaltexth->allTexts[255];
|
2012-11-11 15:23:31 +03:00
|
|
|
incomeAmount = new CLabel(628, footerPos + 70, FONT_SMALL, TOPLEFT, Colors::WHITE, boost::lexical_cast<std::string>(totalIncome));
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdomInterface::generateButtons()
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 footerPos = conf.go()->ac.overviewSize * 116;
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
//Main control buttons
|
2011-12-22 16:05:19 +03:00
|
|
|
btnHeroes = new CAdventureMapButton (CGI->generaltexth->overview[11], CGI->generaltexth->overview[6],
|
2013-07-02 18:23:32 +03:00
|
|
|
boost::bind(&CKingdomInterface::activateTab, this, 0),748,28+footerPos,"OVBUTN1.DEF", SDLK_h);
|
2011-07-22 19:22:22 +03:00
|
|
|
btnHeroes->block(true);
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
btnTowns = new CAdventureMapButton (CGI->generaltexth->overview[12], CGI->generaltexth->overview[7],
|
2013-07-02 18:23:32 +03:00
|
|
|
boost::bind(&CKingdomInterface::activateTab, this, 1),748,64+footerPos,"OVBUTN6.DEF", SDLK_t);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
btnExit = new CAdventureMapButton (CGI->generaltexth->allTexts[600],"",
|
2013-07-02 18:23:32 +03:00
|
|
|
boost::bind(&CKingdomInterface::close, this),748,99+footerPos,"OVBUTN1.DEF", SDLK_RETURN);
|
2011-07-22 19:22:22 +03:00
|
|
|
btnExit->assignedKeys.insert(SDLK_ESCAPE);
|
|
|
|
btnExit->setOffset(3);
|
|
|
|
|
|
|
|
//Object list control buttons
|
2013-07-02 18:23:32 +03:00
|
|
|
dwellTop = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToPos, dwellingsList, 0),
|
2011-07-22 19:22:22 +03:00
|
|
|
733, 4, "OVBUTN4.DEF");
|
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
dwellBottom = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToPos, dwellingsList, -1),
|
2011-07-22 19:22:22 +03:00
|
|
|
733, footerPos+2, "OVBUTN4.DEF");
|
|
|
|
dwellBottom->setOffset(2);
|
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
dwellUp = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToPrev, dwellingsList),
|
2011-07-22 19:22:22 +03:00
|
|
|
733, 24, "OVBUTN4.DEF");
|
|
|
|
dwellUp->setOffset(4);
|
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
dwellDown = new CAdventureMapButton ("", "", boost::bind(&CListBox::moveToNext, dwellingsList),
|
2011-07-22 19:22:22 +03:00
|
|
|
733, footerPos-18, "OVBUTN4.DEF");
|
|
|
|
dwellDown->setOffset(6);
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdomInterface::activateTab(size_t which)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
btnHeroes->block(which == 0);
|
|
|
|
btnTowns->block(which == 1);
|
|
|
|
tabArea->setActive(which);
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdomInterface::townChanged(const CGTownInstance *town)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
if (CKingdTownList * townList = dynamic_cast<CKingdTownList*>(tabArea->getItem()))
|
|
|
|
townList->townChanged(town);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::updateGarrisons()
|
|
|
|
{
|
|
|
|
if (CGarrisonHolder * garrison = dynamic_cast<CGarrisonHolder*>(tabArea->getItem()))
|
|
|
|
garrison->updateGarrisons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::artifactAssembled(const ArtifactLocation& artLoc)
|
|
|
|
{
|
|
|
|
if (CArtifactHolder * arts = dynamic_cast<CArtifactHolder*>(tabArea->getItem()))
|
|
|
|
arts->artifactAssembled(artLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::artifactDisassembled(const ArtifactLocation& artLoc)
|
|
|
|
{
|
|
|
|
if (CArtifactHolder * arts = dynamic_cast<CArtifactHolder*>(tabArea->getItem()))
|
|
|
|
arts->artifactDisassembled(artLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::artifactMoved(const ArtifactLocation& artLoc, const ArtifactLocation& destLoc)
|
|
|
|
{
|
|
|
|
if (CArtifactHolder * arts = dynamic_cast<CArtifactHolder*>(tabArea->getItem()))
|
|
|
|
arts->artifactMoved(artLoc, destLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::artifactRemoved(const ArtifactLocation& artLoc)
|
|
|
|
{
|
|
|
|
if (CArtifactHolder * arts = dynamic_cast<CArtifactHolder*>(tabArea->getItem()))
|
|
|
|
arts->artifactRemoved(artLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
CKingdHeroList::CKingdHeroList(size_t maxSize)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
title = new CPicture("OVTITLE",16,0);
|
|
|
|
title->colorize(LOCPLINT->playerID);
|
2012-11-11 15:23:31 +03:00
|
|
|
heroLabel = new CLabel(150, 10, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[0]);
|
|
|
|
skillsLabel = new CLabel(500, 10, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[1]);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 townCount = LOCPLINT->cb->howManyHeroes(false);
|
|
|
|
ui32 size = conf.go()->ac.overviewSize*116 + 19;
|
2013-07-02 18:23:32 +03:00
|
|
|
heroes = new CListBox(boost::bind(&CKingdHeroList::createHeroItem, this, _1), boost::bind(&CKingdHeroList::destroyHeroItem, this, _1),
|
2011-12-22 16:05:19 +03:00
|
|
|
Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) );
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdHeroList::updateGarrisons()
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
std::list<CIntObject*> list = heroes->getItems();
|
2013-06-29 16:05:48 +03:00
|
|
|
for(CIntObject* object : list)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
if (CGarrisonHolder * garrison = dynamic_cast<CGarrisonHolder*>(object) )
|
|
|
|
garrison->updateGarrisons();
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
CIntObject* CKingdHeroList::createHeroItem(size_t index)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 picCount = conf.go()->ac.overviewPics;
|
2011-11-27 16:14:20 +03:00
|
|
|
size_t heroesCount = LOCPLINT->cb->howManyHeroes(false);
|
|
|
|
|
|
|
|
if (index < heroesCount)
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto hero = new CHeroItem(LOCPLINT->cb->getHeroBySerial(index, false), &artsCommonPart);
|
2011-11-27 16:14:20 +03:00
|
|
|
artsCommonPart.participants.insert(hero->heroArts);
|
|
|
|
artSets.push_back(hero->heroArts);
|
|
|
|
return hero;
|
|
|
|
}
|
|
|
|
else
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-11-27 16:14:20 +03:00
|
|
|
return new CAnimImage("OVSLOT", (index-2) % picCount );
|
|
|
|
}
|
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
void CKingdHeroList::destroyHeroItem(CIntObject *object)
|
|
|
|
{
|
|
|
|
if (CHeroItem * hero = dynamic_cast<CHeroItem*>(object))
|
|
|
|
{
|
|
|
|
artSets.erase(std::find(artSets.begin(), artSets.end(), hero->heroArts));
|
|
|
|
artsCommonPart.participants.erase(hero->heroArts);
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
2011-11-27 16:14:20 +03:00
|
|
|
delete object;
|
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
CKingdTownList::CKingdTownList(size_t maxSize)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
title = new CPicture("OVTITLE",16,0);
|
|
|
|
title->colorize(LOCPLINT->playerID);
|
2012-11-11 15:23:31 +03:00
|
|
|
townLabel = new CLabel(146,10,FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[3]);
|
|
|
|
garrHeroLabel = new CLabel(375,10,FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[4]);
|
|
|
|
visitHeroLabel = new CLabel(608,10,FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->overview[5]);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 townCount = LOCPLINT->cb->howManyTowns();
|
|
|
|
ui32 size = conf.go()->ac.overviewSize*116 + 19;
|
2013-07-02 18:23:32 +03:00
|
|
|
towns = new CListBox(boost::bind(&CKingdTownList::createTownItem, this, _1), CListBox::DestroyFunc(),
|
2011-12-22 16:05:19 +03:00
|
|
|
Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size) );
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdTownList::townChanged(const CGTownInstance *town)
|
2010-01-31 14:10:13 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
std::list<CIntObject*> list = towns->getItems();
|
2013-06-29 16:05:48 +03:00
|
|
|
for(CIntObject* object : list)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
|
|
|
CTownItem * townItem = dynamic_cast<CTownItem*>(object);
|
|
|
|
if ( townItem && townItem->town == town)
|
|
|
|
townItem->update();
|
|
|
|
}
|
2010-01-30 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CKingdTownList::updateGarrisons()
|
2010-01-25 23:25:14 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
std::list<CIntObject*> list = towns->getItems();
|
2013-06-29 16:05:48 +03:00
|
|
|
for(CIntObject* object : list)
|
2011-07-22 19:22:22 +03:00
|
|
|
{
|
|
|
|
if (CGarrisonHolder * garrison = dynamic_cast<CGarrisonHolder*>(object) )
|
|
|
|
garrison->updateGarrisons();
|
|
|
|
}
|
2010-01-25 23:25:14 +02:00
|
|
|
}
|
2010-01-30 21:08:26 +02:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
CIntObject* CKingdTownList::createTownItem(size_t index)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 picCount = conf.go()->ac.overviewPics;
|
2011-11-27 16:14:20 +03:00
|
|
|
size_t townsCount = LOCPLINT->cb->howManyTowns();
|
|
|
|
|
|
|
|
if (index < townsCount)
|
|
|
|
return new CTownItem(LOCPLINT->cb->getTownBySerial(index));
|
|
|
|
else
|
|
|
|
return new CAnimImage("OVSLOT", (index-2) % picCount );
|
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
CTownItem::CTownItem(const CGTownInstance* Town):
|
|
|
|
town(Town)
|
2010-02-01 01:30:47 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
background = new CAnimImage("OVSLOT", 6);
|
2012-11-11 15:23:31 +03:00
|
|
|
name = new CLabel(74, 8, FONT_SMALL, TOPLEFT, Colors::WHITE, town->name);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
income = new CLabel( 190, 60, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(town->dailyIncome()));
|
2011-07-22 19:22:22 +03:00
|
|
|
hall = new CTownInfo( 69, 31, town, true);
|
|
|
|
fort = new CTownInfo(111, 31, town, false);
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
garr = new CGarrisonInt(313, 3, 4, Point(232,0), nullptr, Point(313,2), town->getUpperArmy(), town->visitingHero, true, true, true);
|
2011-12-22 16:05:19 +03:00
|
|
|
heroes = new HeroSlots(town, Point(244,6), Point(475,6), garr, false);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2012-09-22 18:10:15 +03:00
|
|
|
size_t iconIndex = town->town->clientInfo.icons[town->hasFort()][town->builded >= CGI->modh->settings.MAX_BUILDING_PER_TURN];
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
picture = new CAnimImage("ITPT", iconIndex, 0, 5, 6);
|
|
|
|
townArea = new LRClickableAreaOpenTown;
|
2011-12-22 16:05:19 +03:00
|
|
|
townArea->pos = Rect(pos.x+5, pos.y+6, 58, 64);
|
2011-07-22 19:22:22 +03:00
|
|
|
townArea->town = town;
|
|
|
|
|
|
|
|
for (size_t i=0; i<town->creatures.size(); i++)
|
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
growth.push_back(new CCreaInfo(Point(401+37*i, 78), town, i, true, true));
|
|
|
|
available.push_back(new CCreaInfo(Point(48+37*i, 78), town, i, true, false));
|
2010-01-30 21:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CTownItem::updateGarrisons()
|
2010-01-30 21:08:26 +02:00
|
|
|
{
|
2012-12-11 15:12:46 +03:00
|
|
|
garr->selectSlot(nullptr);
|
2011-07-22 19:22:22 +03:00
|
|
|
garr->setArmy(town->getUpperArmy(), 0);
|
|
|
|
garr->setArmy(town->visitingHero, 1);
|
|
|
|
garr->recreateSlots();
|
2010-01-30 21:08:26 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CTownItem::update()
|
2010-01-30 21:08:26 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
std::string incomeVal = boost::lexical_cast<std::string>(town->dailyIncome());
|
|
|
|
if (incomeVal != income->text)
|
|
|
|
income->setTxt(incomeVal);
|
|
|
|
|
|
|
|
heroes->update();
|
|
|
|
|
|
|
|
for (size_t i=0; i<town->creatures.size(); i++)
|
|
|
|
{
|
|
|
|
growth[i]->update();
|
|
|
|
available[i]->update();
|
|
|
|
}
|
2010-01-31 14:10:13 +02:00
|
|
|
}
|
2010-02-01 01:30:47 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
class ArtSlotsTab : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CAnimImage * background;
|
|
|
|
std::vector<CArtPlace*> arts;
|
|
|
|
|
|
|
|
ArtSlotsTab()
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
background = new CAnimImage("OVSLOT", 4);
|
|
|
|
pos = background->pos;
|
|
|
|
for (size_t i=0; i<9; i++)
|
2011-12-22 16:05:19 +03:00
|
|
|
arts.push_back(new CArtPlace(Point(270+i*48, 65)));
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
|
|
|
};
|
2010-02-01 01:30:47 +02:00
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
class BackpackTab : public CIntObject
|
2010-02-01 01:30:47 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
public:
|
|
|
|
CAnimImage * background;
|
|
|
|
std::vector<CArtPlace*> arts;
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *btnLeft;
|
|
|
|
CAdventureMapButton *btnRight;
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
BackpackTab()
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
background = new CAnimImage("OVSLOT", 5);
|
|
|
|
pos = background->pos;
|
2011-12-22 16:05:19 +03:00
|
|
|
btnLeft = new CAdventureMapButton(std::string(), std::string(), CFunctionList<void()>(), 269, 66, "HSBTNS3");
|
|
|
|
btnRight = new CAdventureMapButton(std::string(), std::string(), CFunctionList<void()>(), 675, 66, "HSBTNS5");
|
2011-07-22 19:22:22 +03:00
|
|
|
for (size_t i=0; i<8; i++)
|
2011-12-22 16:05:19 +03:00
|
|
|
arts.push_back(new CArtPlace(Point(295+i*48, 65)));
|
2011-07-22 19:22:22 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CHeroItem::CHeroItem(const CGHeroInstance* Hero, CArtifactsOfHero::SCommonPart * artsCommonPart):
|
|
|
|
hero(Hero)
|
2010-02-01 01:30:47 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
artTabs.resize(3);
|
2013-06-29 16:05:48 +03:00
|
|
|
auto arts1 = new ArtSlotsTab;
|
|
|
|
auto arts2 = new ArtSlotsTab;
|
|
|
|
auto backpack = new BackpackTab;
|
2011-11-27 16:14:20 +03:00
|
|
|
artTabs[0] = arts1;
|
|
|
|
artTabs[1] = arts2;
|
|
|
|
artTabs[2] = backpack;
|
|
|
|
arts1->recActions = DISPOSE | SHARE_POS;
|
|
|
|
arts2->recActions = DISPOSE | SHARE_POS;
|
|
|
|
backpack->recActions = DISPOSE | SHARE_POS;
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
name = new CLabel(75, 7, FONT_SMALL, TOPLEFT, Colors::WHITE, hero->name);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
std::vector<CArtPlace*> arts;
|
2011-11-27 16:14:20 +03:00
|
|
|
arts.insert(arts.end(), arts1->arts.begin(), arts1->arts.end());
|
|
|
|
arts.insert(arts.end(), arts2->arts.begin(), arts2->arts.end());
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
heroArts = new CArtifactsOfHero(arts, backpack->arts, backpack->btnLeft, backpack->btnRight, false);
|
2011-07-22 19:22:22 +03:00
|
|
|
heroArts->commonInfo = artsCommonPart;
|
|
|
|
heroArts->setHero(hero);
|
|
|
|
|
2013-07-02 18:23:32 +03:00
|
|
|
artsTabs = new CTabbedInt(boost::bind(&CHeroItem::onTabSelected, this, _1), boost::bind(&CHeroItem::onTabDeselected, this, _1));
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
artButtons = new CHighlightableButtonsGroup(0);
|
|
|
|
for (size_t it = 0; it<3; it++)
|
2010-02-04 17:50:59 +02:00
|
|
|
{
|
2013-01-12 22:28:38 +03:00
|
|
|
int stringID[3] = {259, 261, 262};
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
std::map<int,std::string> tooltip;
|
|
|
|
tooltip[0] = CGI->generaltexth->overview[13+it];
|
|
|
|
std::string overlay = CGI->generaltexth->overview[8+it];
|
|
|
|
|
|
|
|
artButtons->addButton(tooltip, overlay, "OVBUTN3",364+it*112, 46, it);
|
2013-01-12 22:28:38 +03:00
|
|
|
artButtons->buttons[it]->addTextOverlay(CGI->generaltexth->allTexts[stringID[it]], FONT_SMALL, Colors::YELLOW);
|
2010-02-04 17:50:59 +02:00
|
|
|
}
|
2013-07-02 18:23:32 +03:00
|
|
|
artButtons->onChange += boost::bind(&CTabbedInt::setActive, artsTabs, _1);
|
|
|
|
artButtons->onChange += boost::bind(&CHeroItem::onArtChange, this, _1);
|
2011-07-22 19:22:22 +03:00
|
|
|
artButtons->select(0,0);
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
garr = new CGarrisonInt(6, 78, 4, Point(), nullptr, Point(), hero, nullptr, true, true);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2012-12-16 16:47:53 +03:00
|
|
|
portrait = new CAnimImage("PortraitsLarge", hero->portrait, 0, 5, 6);
|
2011-07-22 19:22:22 +03:00
|
|
|
heroArea = new CHeroArea(5, 6, hero);
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
name = new CLabel(73, 7, FONT_SMALL, TOPLEFT, Colors::WHITE, hero->name);
|
|
|
|
artsText = new CLabel(320, 55, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->overview[2]);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
for (size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
|
2011-12-22 16:05:19 +03:00
|
|
|
heroInfo.push_back(new InfoBox(Point(78+i*36, 26), InfoBox::POS_DOWN, InfoBox::SIZE_SMALL,
|
2011-07-22 19:22:22 +03:00
|
|
|
new InfoBoxHeroData(IInfoBoxData::HERO_PRIMARY_SKILL, hero, i)));
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
for (size_t i=0; i<GameConstants::SKILL_PER_HERO; i++)
|
2011-12-22 16:05:19 +03:00
|
|
|
heroInfo.push_back(new InfoBox(Point(410+i*36, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL,
|
2011-07-22 19:22:22 +03:00
|
|
|
new InfoBoxHeroData(IInfoBoxData::HERO_SECONDARY_SKILL, hero, i)));
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
heroInfo.push_back(new InfoBox(Point(375, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL,
|
2011-07-22 19:22:22 +03:00
|
|
|
new InfoBoxHeroData(IInfoBoxData::HERO_SPECIAL, hero)));
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
heroInfo.push_back(new InfoBox(Point(330, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL,
|
2011-07-22 19:22:22 +03:00
|
|
|
new InfoBoxHeroData(IInfoBoxData::HERO_EXPERIENCE, hero)));
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
heroInfo.push_back(new InfoBox(Point(280, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL,
|
2011-07-22 19:22:22 +03:00
|
|
|
new InfoBoxHeroData(IInfoBoxData::HERO_MANA, hero)));
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
morale = new MoraleLuckBox(true, Rect(225, 53, 30, 22), true);
|
|
|
|
luck = new MoraleLuckBox(false, Rect(225, 28, 30, 22), true);
|
2011-07-22 19:22:22 +03:00
|
|
|
|
|
|
|
morale->set(hero);
|
|
|
|
luck->set(hero);
|
2010-02-01 01:30:47 +02:00
|
|
|
}
|
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
CIntObject * CHeroItem::onTabSelected(size_t index)
|
|
|
|
{
|
|
|
|
return artTabs[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroItem::onTabDeselected(CIntObject *object)
|
|
|
|
{
|
|
|
|
addChild(object, false);
|
2013-01-16 17:28:49 +03:00
|
|
|
object->deactivate();
|
2011-11-27 16:14:20 +03:00
|
|
|
object->recActions = DISPOSE | SHARE_POS;
|
|
|
|
}
|
|
|
|
|
2011-07-22 19:22:22 +03:00
|
|
|
void CHeroItem::onArtChange(int tabIndex)
|
2010-02-01 01:30:47 +02:00
|
|
|
{
|
2011-07-22 19:22:22 +03:00
|
|
|
//redraw item after background change
|
|
|
|
if (active)
|
|
|
|
redraw();
|
2010-02-01 01:30:47 +02:00
|
|
|
}
|