2017-07-13 10:26:03 +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
|
|
|
|
*
|
|
|
|
*/
|
2014-04-23 18:12:35 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CKingdomInterface.h"
|
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "CCastleInterface.h"
|
2024-04-15 21:18:45 +02:00
|
|
|
#include "CPlayerState.h"
|
2022-09-18 14:47:49 +02:00
|
|
|
#include "InfoWindows.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2023-07-15 14:47:24 +02:00
|
|
|
#include "../PlayerLocalState.h"
|
2023-02-10 15:50:46 +02:00
|
|
|
#include "../adventureMap/CResDataBar.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-10-13 00:21:58 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/CComponent.h"
|
2023-07-07 00:08:29 +02:00
|
|
|
#include "../widgets/CGarrisonInt.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../widgets/MiscWidgets.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
2023-02-10 15:50:46 +02:00
|
|
|
#include "../widgets/ObjectLists.h"
|
2024-02-03 13:26:24 +02:00
|
|
|
#include "../windows/CMarketWindow.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CCreatureHandler.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CHeroHandler.h"
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "../../lib/GameSettings.h"
|
2017-08-30 12:35:23 +02:00
|
|
|
#include "../../lib/CSkillHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../../lib/CTownHandler.h"
|
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
|
|
|
#include "../../lib/mapObjects/MiscObjects.h"
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
static const std::string OVERVIEW_BACKGROUND = "OvCast.pcx";
|
|
|
|
static const size_t OVERVIEW_SIZE = 4;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
InfoBox::InfoBox(Point position, InfoPos Pos, InfoSize Size, std::shared_ptr<IInfoBoxData> Data):
|
2014-04-23 18:12:35 +03:00
|
|
|
size(Size),
|
|
|
|
infoPos(Pos),
|
|
|
|
data(Data),
|
|
|
|
value(nullptr),
|
|
|
|
name(nullptr)
|
|
|
|
{
|
|
|
|
assert(data);
|
2023-06-13 18:33:35 +02:00
|
|
|
addUsedEvents(LCLICK | SHOW_POPUP);
|
2014-04-23 18:12:35 +03:00
|
|
|
EFonts font = (size < SIZE_MEDIUM)? FONT_SMALL: FONT_MEDIUM;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2014-04-23 18:12:35 +03:00
|
|
|
pos+=position;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
image = std::make_shared<CAnimImage>(data->getImageName(size), data->getImageIndex());
|
2014-04-23 18:12:35 +03:00
|
|
|
pos = image->pos;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
switch(infoPos)
|
|
|
|
{
|
|
|
|
case POS_CORNER:
|
2022-11-26 23:12:20 +02:00
|
|
|
value = std::make_shared<CLabel>(pos.w, pos.h, font, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, data->getValueText());
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
|
|
|
case POS_INSIDE:
|
2022-11-26 23:12:20 +02:00
|
|
|
value = std::make_shared<CLabel>(pos.w/2, pos.h-6, font, ETextAlignment::CENTER, Colors::WHITE, data->getValueText());
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
|
|
|
case POS_UP_DOWN:
|
2022-11-26 23:12:20 +02:00
|
|
|
name = std::make_shared<CLabel>(pos.w/2, -12, font, ETextAlignment::CENTER, Colors::WHITE, data->getNameText());
|
2023-04-10 16:44:41 +02:00
|
|
|
[[fallthrough]];
|
2018-04-07 13:34:11 +02:00
|
|
|
case POS_DOWN:
|
2022-11-26 23:12:20 +02:00
|
|
|
value = std::make_shared<CLabel>(pos.w/2, pos.h+8, font, ETextAlignment::CENTER, Colors::WHITE, data->getValueText());
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
|
|
|
case POS_RIGHT:
|
2022-11-26 23:12:20 +02:00
|
|
|
name = std::make_shared<CLabel>(pos.w+6, 6, font, ETextAlignment::TOPLEFT, Colors::WHITE, data->getNameText());
|
|
|
|
value = std::make_shared<CLabel>(pos.w+6, pos.h-16, font, ETextAlignment::TOPLEFT, Colors::WHITE, data->getValueText());
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name)
|
2023-01-17 22:01:35 +02:00
|
|
|
pos = pos.include(name->pos);
|
2018-04-07 13:34:11 +02:00
|
|
|
if(value)
|
2023-01-17 22:01:35 +02:00
|
|
|
pos = pos.include(value->pos);
|
2016-11-23 13:47:57 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
hover = std::make_shared<CHoverableArea>();
|
2014-04-23 18:12:35 +03:00
|
|
|
hover->hoverText = data->getHoverText();
|
|
|
|
hover->pos = pos;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
InfoBox::~InfoBox() = default;
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void InfoBox::showPopupWindow(const Point & cursorPosition)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-06-11 17:20:10 +02:00
|
|
|
std::shared_ptr<CComponent> comp;
|
|
|
|
std::string text;
|
|
|
|
data->prepareMessage(text, comp);
|
|
|
|
if (comp)
|
|
|
|
CRClickPopup::createAndPush(text, CInfoWindow::TCompsInfo(1, comp));
|
|
|
|
else if (!text.empty())
|
|
|
|
CRClickPopup::createAndPush(text);
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2023-07-09 16:48:25 +02:00
|
|
|
void InfoBox::clickPressed(const Point & cursorPosition)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-07-08 13:33:04 +02:00
|
|
|
std::shared_ptr<CComponent> comp;
|
|
|
|
std::string text;
|
|
|
|
data->prepareMessage(text, comp);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
if(comp)
|
|
|
|
LOCPLINT->showInfoDialog(text, CInfoWindow::TCompsInfo(1, comp));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
IInfoBoxData::IInfoBoxData(InfoType Type)
|
|
|
|
: type(Type)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
InfoBoxAbstractHeroData::InfoBoxAbstractHeroData(InfoType Type)
|
|
|
|
: IInfoBoxData(Type)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxAbstractHeroData::getValueText()
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
case HERO_PRIMARY_SKILL:
|
2023-03-09 15:36:46 +02:00
|
|
|
return std::to_string(getValue());
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SPECIAL:
|
|
|
|
return CGI->generaltexth->jktexts[5];
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
{
|
|
|
|
si64 value = getValue();
|
|
|
|
if (value)
|
|
|
|
return CGI->generaltexth->levels[value];
|
2016-11-25 21:28:16 +02:00
|
|
|
else
|
|
|
|
return "";
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
default:
|
2016-11-25 21:28:16 +02:00
|
|
|
logGlobal->error("Invalid InfoBox info type");
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxAbstractHeroData::getNameText()
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return CGI->generaltexth->primarySkillNames[getSubID()];
|
|
|
|
case HERO_MANA:
|
|
|
|
return CGI->generaltexth->allTexts[387];
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return CGI->generaltexth->jktexts[6];
|
|
|
|
case HERO_SPECIAL:
|
2023-01-02 13:27:03 +02:00
|
|
|
return CGI->heroh->objects[getSubID()]->getSpecialtyNameTranslated();
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
if (getValue())
|
2023-01-01 22:20:41 +02:00
|
|
|
return CGI->skillh->getByIndex(getSubID())->getNameTranslated();
|
2014-04-23 18:12:35 +03:00
|
|
|
else
|
|
|
|
return "";
|
|
|
|
default:
|
2016-11-25 21:28:16 +02:00
|
|
|
logGlobal->error("Invalid InfoBox info type");
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath InfoBoxAbstractHeroData::getImageName(InfoBox::InfoSize size)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
|
|
|
//TODO: sizes
|
|
|
|
switch(size)
|
|
|
|
{
|
|
|
|
case InfoBox::SIZE_SMALL:
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("PSKIL32");
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SPECIAL:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("UN32");
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SECONDARY_SKILL:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("SECSK32");
|
2014-04-23 18:12:35 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case InfoBox::SIZE_BIG:
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("PSKIL42");
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SPECIAL:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("UN44");
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SECONDARY_SKILL:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("SECSKILL");
|
2014-04-23 18:12:35 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2023-08-23 14:07:50 +02:00
|
|
|
return {};
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxAbstractHeroData::getHoverText()
|
|
|
|
{
|
|
|
|
//TODO: any texts here?
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t InfoBoxAbstractHeroData::getImageIndex()
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_SPECIAL:
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return CGI->heroh->objects[getSubID()]->imageIndex;
|
2014-04-23 18:12:35 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void InfoBoxAbstractHeroData::prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
comp.reset();
|
2014-04-23 18:12:35 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_SPECIAL:
|
2023-01-02 13:27:03 +02:00
|
|
|
text = CGI->heroh->objects[getSubID()]->getSpecialtyDescriptionTranslated();
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
text = CGI->generaltexth->arraytxt[2+getSubID()];
|
2023-10-31 11:09:56 +02:00
|
|
|
comp = std::make_shared<CComponent>(ComponentType::PRIM_SKILL, PrimarySkill(getSubID()), getValue());
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_MANA:
|
|
|
|
text = CGI->generaltexth->allTexts[149];
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
text = CGI->generaltexth->allTexts[241];
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
{
|
|
|
|
si64 value = getValue();
|
|
|
|
int subID = getSubID();
|
2018-04-07 13:34:11 +02:00
|
|
|
if(value)
|
|
|
|
{
|
2023-01-01 22:20:41 +02:00
|
|
|
text = CGI->skillh->getByIndex(subID)->getDescriptionTranslated((int)value);
|
2023-10-31 11:09:56 +02:00
|
|
|
comp = std::make_shared<CComponent>(ComponentType::SEC_SKILL, SecondarySkill(subID), (int)value);
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
default:
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoBoxHeroData::InfoBoxHeroData(InfoType Type, const CGHeroInstance * Hero, int Index):
|
|
|
|
InfoBoxAbstractHeroData(Type),
|
|
|
|
hero(Hero),
|
|
|
|
index(Index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int InfoBoxHeroData::getSubID()
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2018-02-09 21:12:21 +02:00
|
|
|
case HERO_PRIMARY_SKILL:
|
|
|
|
return index;
|
|
|
|
case HERO_SECONDARY_SKILL:
|
|
|
|
if(hero->secSkills.size() > index)
|
|
|
|
return hero->secSkills[index].first;
|
|
|
|
else
|
2014-04-23 18:12:35 +03:00
|
|
|
return 0;
|
2018-02-09 21:12:21 +02:00
|
|
|
case HERO_SPECIAL:
|
2023-01-02 13:27:03 +02:00
|
|
|
return hero->type->getIndex();
|
2018-02-09 21:12:21 +02:00
|
|
|
case HERO_MANA:
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
si64 InfoBoxHeroData::getValue()
|
|
|
|
{
|
2022-09-24 16:29:29 +02:00
|
|
|
if(!hero)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-23 18:12:35 +03:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case HERO_PRIMARY_SKILL:
|
2023-08-19 20:43:50 +02:00
|
|
|
return hero->getPrimSkillLevel(static_cast<PrimarySkill>(index));
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_MANA:
|
|
|
|
return hero->mana;
|
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
return hero->exp;
|
|
|
|
case HERO_SECONDARY_SKILL:
|
2018-02-09 21:12:21 +02:00
|
|
|
if(hero->secSkills.size() > index)
|
2014-04-23 18:12:35 +03:00
|
|
|
return hero->secSkills[index].second;
|
2018-02-09 21:12:21 +02:00
|
|
|
else
|
2014-04-23 18:12:35 +03:00
|
|
|
return 0;
|
2018-02-09 21:12:21 +02:00
|
|
|
case HERO_SPECIAL:
|
|
|
|
return 0;
|
2014-04-23 18:12:35 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxHeroData::getHoverText()
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
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];
|
2023-01-01 22:20:41 +02:00
|
|
|
std::string skill = CGI->skillh->getByIndex(hero->secSkills[index].first)->getNameTranslated();
|
2014-04-23 18:12:35 +03:00
|
|
|
return boost::str(boost::format(CGI->generaltexth->heroscrn[21]) % level % skill);
|
|
|
|
}
|
|
|
|
else
|
2018-02-09 21:12:21 +02:00
|
|
|
{
|
2014-04-23 18:12:35 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return InfoBoxAbstractHeroData::getHoverText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxHeroData::getValueText()
|
|
|
|
{
|
|
|
|
if (hero)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case HERO_MANA:
|
2023-03-09 15:36:46 +02:00
|
|
|
return std::to_string(hero->mana) + '/' +
|
|
|
|
std::to_string(hero->manaLimit());
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_EXPERIENCE:
|
2023-03-09 15:36:46 +02:00
|
|
|
return std::to_string(hero->exp);
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return InfoBoxAbstractHeroData::getValueText();
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void InfoBoxHeroData::prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
comp.reset();
|
2014-04-23 18:12:35 +03:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case HERO_MANA:
|
|
|
|
text = CGI->generaltexth->allTexts[205];
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(text, "%s", hero->getNameTranslated());
|
|
|
|
boost::replace_first(text, "%d", std::to_string(hero->mana));
|
|
|
|
boost::replace_first(text, "%d", std::to_string(hero->manaLimit()));
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
case HERO_EXPERIENCE:
|
|
|
|
text = CGI->generaltexth->allTexts[2];
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::replace_first(text, "%d", std::to_string(hero->level));
|
|
|
|
boost::replace_first(text, "%d", std::to_string(CGI->heroh->reqExp(hero->level+1)));
|
|
|
|
boost::replace_first(text, "%d", std::to_string(hero->exp));
|
2018-04-07 13:34:11 +02:00
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
default:
|
2018-04-07 13:34:11 +02:00
|
|
|
InfoBoxAbstractHeroData::prepareMessage(text, comp);
|
|
|
|
break;
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoBoxCustomHeroData::InfoBoxCustomHeroData(InfoType Type, int SubID, si64 Value):
|
|
|
|
InfoBoxAbstractHeroData(Type),
|
|
|
|
subID(SubID),
|
|
|
|
value(Value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int InfoBoxCustomHeroData::getSubID()
|
|
|
|
{
|
|
|
|
return subID;
|
|
|
|
}
|
|
|
|
|
|
|
|
si64 InfoBoxCustomHeroData::getValue()
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-09-04 13:29:02 +02:00
|
|
|
InfoBoxCustom::InfoBoxCustom(std::string ValueText, std::string NameText, const AnimationPath & ImageName, size_t ImageIndex, std::string HoverText):
|
2014-04-23 18:12:35 +03:00
|
|
|
IInfoBoxData(CUSTOM),
|
|
|
|
valueText(ValueText),
|
|
|
|
nameText(NameText),
|
|
|
|
imageName(ImageName),
|
|
|
|
hoverText(HoverText),
|
|
|
|
imageIndex(ImageIndex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxCustom::getHoverText()
|
|
|
|
{
|
|
|
|
return hoverText;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t InfoBoxCustom::getImageIndex()
|
|
|
|
{
|
|
|
|
return imageIndex;
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath InfoBoxCustom::getImageName(InfoBox::InfoSize size)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
|
|
|
return imageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxCustom::getNameText()
|
|
|
|
{
|
|
|
|
return nameText;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoBoxCustom::getValueText()
|
|
|
|
{
|
|
|
|
return valueText;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void InfoBoxCustom::prepareMessage(std::string & text, std::shared_ptr<CComponent> & comp)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CKingdomInterface::CKingdomInterface()
|
2023-08-23 14:07:50 +02:00
|
|
|
: CWindowObject(PLAYER_COLORED | BORDERED, ImagePath::builtin(OVERVIEW_BACKGROUND))
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 footerPos = OVERVIEW_SIZE * 116;
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
tabArea = std::make_shared<CTabbedInt>(std::bind(&CKingdomInterface::createMainTab, this, _1), Point(4,4));
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
std::vector<const CGObjectInstance * > ownedObjects = LOCPLINT->cb->getMyObjects();
|
|
|
|
generateObjectsList(ownedObjects);
|
|
|
|
generateMinesList(ownedObjects);
|
|
|
|
generateButtons();
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
statusbar = CGStatusBar::create(std::make_shared<CPicture>(ImagePath::builtin("KSTATBAR"), 10,pos.h - 45));
|
|
|
|
resdatabar = std::make_shared<CResDataBar>(ImagePath::builtin("KRESBAR"), 7, 111+footerPos, 29, 5, 76, 81);
|
2023-10-13 00:21:58 +02:00
|
|
|
|
|
|
|
activateTab(persistentStorage["gui"]["lastKindomInterface"].Integer());
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::generateObjectsList(const std::vector<const CGObjectInstance * > &ownedObjects)
|
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 footerPos = OVERVIEW_SIZE * 116;
|
2014-04-23 18:12:35 +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;
|
|
|
|
for(const CGObjectInstance * object : ownedObjects)
|
|
|
|
{
|
|
|
|
//Dwellings
|
2018-04-07 13:34:11 +02:00
|
|
|
if(object->ID == Obj::CREATURE_GENERATOR1)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OwnedObjectInfo & info = visibleObjects[object->subID];
|
|
|
|
if(info.count++ == 0)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
info.hoverText = object->getObjectName();
|
2014-04-23 18:12:35 +03:00
|
|
|
info.imageID = object->subID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Special objects from idToImage map that should be displayed in objects list
|
|
|
|
auto iter = idToImage.find(std::make_pair(object->ID, object->subID));
|
2018-04-07 13:34:11 +02:00
|
|
|
if(iter != idToImage.end())
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OwnedObjectInfo & info = visibleObjects[iter->second];
|
|
|
|
if(info.count++ == 0)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
info.hoverText = object->getObjectName();
|
2014-04-23 18:12:35 +03:00
|
|
|
info.imageID = iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
objects.reserve(visibleObjects.size());
|
|
|
|
|
|
|
|
for(auto & element : visibleObjects)
|
|
|
|
{
|
|
|
|
objects.push_back(element.second);
|
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
dwellingsList = std::make_shared<CListBox>(std::bind(&CKingdomInterface::createOwnedObject, this, _1),
|
|
|
|
Point(740,44), Point(0,57), dwellSize, visibleObjects.size());
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> CKingdomInterface::createOwnedObject(size_t index)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(index < objects.size())
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OwnedObjectInfo & obj = objects[index];
|
2023-03-09 15:36:46 +02:00
|
|
|
std::string value = std::to_string(obj.count);
|
2023-09-04 13:29:02 +02:00
|
|
|
auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("FLAGPORT"), obj.imageID, obj.hoverText);
|
2018-04-07 13:34:11 +02:00
|
|
|
return std::make_shared<InfoBox>(Point(), InfoBox::POS_CORNER, InfoBox::SIZE_SMALL, data);
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
return std::shared_ptr<CIntObject>();
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> CKingdomInterface::createMainTab(size_t index)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
size_t size = OVERVIEW_SIZE;
|
2018-04-07 13:34:11 +02:00
|
|
|
switch(index)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
case 0:
|
2024-05-20 11:47:25 +02:00
|
|
|
return std::make_shared<CKingdHeroList>(size, [this](const CWindowWithArtifacts::CArtifactsOfHeroPtr & newHeroSet)
|
2024-04-23 15:21:45 +02:00
|
|
|
{
|
2024-05-20 14:31:07 +02:00
|
|
|
newHeroSet->clickPressedCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
|
2024-05-20 11:47:25 +02:00
|
|
|
{
|
|
|
|
clickPressedOnArtPlace(newHeroSet->getHero(), artPlace.slot, false, false, false);
|
|
|
|
};
|
|
|
|
newHeroSet->showPopupCallback = [this, newHeroSet](CArtPlace & artPlace, const Point & cursorPosition)
|
|
|
|
{
|
|
|
|
showArtifactAssembling(*newHeroSet, artPlace, cursorPosition);
|
|
|
|
};
|
2024-05-20 14:31:07 +02:00
|
|
|
newHeroSet->gestureCallback = [this, newHeroSet](const CArtPlace & artPlace, const Point & cursorPosition)
|
2024-05-20 11:47:25 +02:00
|
|
|
{
|
|
|
|
showQuickBackpackWindow(newHeroSet->getHero(), artPlace.slot, cursorPosition);
|
|
|
|
};
|
|
|
|
addSet(newHeroSet);
|
2024-04-23 15:21:45 +02:00
|
|
|
});
|
2018-04-07 13:34:11 +02:00
|
|
|
case 1:
|
|
|
|
return std::make_shared<CKingdTownList>(size);
|
|
|
|
default:
|
|
|
|
return std::shared_ptr<CIntObject>();
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstance *> & ownedObjects)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 footerPos = OVERVIEW_SIZE * 116;
|
2023-08-19 21:09:02 +02:00
|
|
|
ResourceSet minesCount = ResourceSet();
|
2014-04-23 18:12:35 +03:00
|
|
|
int totalIncome=0;
|
|
|
|
|
|
|
|
for(const CGObjectInstance * object : ownedObjects)
|
|
|
|
{
|
|
|
|
//Mines
|
2016-11-23 13:47:57 +02:00
|
|
|
if(object->ID == Obj::MINE || object->ID == Obj::ABANDONED_MINE)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
const CGMine * mine = dynamic_cast<const CGMine *>(object);
|
2014-04-23 18:12:35 +03:00
|
|
|
assert(mine);
|
|
|
|
minesCount[mine->producedResource]++;
|
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
if (mine->producedResource == EGameResID::GOLD)
|
2014-04-23 18:12:35 +03:00
|
|
|
totalIncome += mine->producedQuantity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Heroes can produce gold as well - skill, specialty or arts
|
|
|
|
std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
|
2024-04-15 21:18:45 +02:00
|
|
|
for(auto & hero : heroes)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2024-04-15 21:18:45 +02:00
|
|
|
totalIncome += hero->valOfBonuses(Selector::typeSubtype(BonusType::GENERATE_RESOURCE, BonusSubtypeID(GameResID(EGameResID::GOLD))));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//Add town income of all towns
|
|
|
|
std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
|
|
|
|
for(auto & town : towns)
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
totalIncome += town->dailyIncome()[EGameResID::GOLD];
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
2024-04-15 21:18:45 +02:00
|
|
|
|
|
|
|
//if player has some modded boosts we want to show that as well
|
|
|
|
totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD)));
|
|
|
|
totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size();
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(int i=0; i<7; i++)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-03-09 15:36:46 +02:00
|
|
|
std::string value = std::to_string(minesCount[i]);
|
2023-09-04 13:29:02 +02:00
|
|
|
auto data = std::make_shared<InfoBoxCustom>(value, "", AnimationPath::builtin("OVMINES"), i, CGI->generaltexth->translate("core.minename", i));
|
2018-04-07 13:34:11 +02:00
|
|
|
minesBox[i] = std::make_shared<InfoBox>(Point(20+i*80, 31+footerPos), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data);
|
2023-06-13 18:33:35 +02:00
|
|
|
minesBox[i]->removeUsedEvents(LCLICK|SHOW_POPUP); //fixes #890 - mines boxes ignore clicks
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
incomeArea = std::make_shared<CHoverableArea>();
|
2014-04-23 18:12:35 +03:00
|
|
|
incomeArea->pos = Rect(pos.x+580, pos.y+31+footerPos, 136, 68);
|
|
|
|
incomeArea->hoverText = CGI->generaltexth->allTexts[255];
|
2023-03-09 15:36:46 +02:00
|
|
|
incomeAmount = std::make_shared<CLabel>(628, footerPos + 70, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, std::to_string(totalIncome));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::generateButtons()
|
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 footerPos = OVERVIEW_SIZE * 116;
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
//Main control buttons
|
2023-08-23 14:07:50 +02:00
|
|
|
btnHeroes = std::make_shared<CButton>(Point(748, 28+footerPos), AnimationPath::builtin("OVBUTN1.DEF"), CButton::tooltip(CGI->generaltexth->overview[11], CGI->generaltexth->overview[6]),
|
2023-04-28 13:22:03 +02:00
|
|
|
std::bind(&CKingdomInterface::activateTab, this, 0), EShortcut::KINGDOM_HEROES_TAB);
|
2014-04-23 18:12:35 +03:00
|
|
|
btnHeroes->block(true);
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
btnTowns = std::make_shared<CButton>(Point(748, 64+footerPos), AnimationPath::builtin("OVBUTN6.DEF"), CButton::tooltip(CGI->generaltexth->overview[12], CGI->generaltexth->overview[7]),
|
2023-04-28 13:22:03 +02:00
|
|
|
std::bind(&CKingdomInterface::activateTab, this, 1), EShortcut::KINGDOM_TOWNS_TAB);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
btnExit = std::make_shared<CButton>(Point(748,99+footerPos), AnimationPath::builtin("OVBUTN1.DEF"), CButton::tooltip(CGI->generaltexth->allTexts[600]),
|
2023-04-27 19:21:06 +02:00
|
|
|
std::bind(&CKingdomInterface::close, this), EShortcut::GLOBAL_RETURN);
|
2014-08-03 14:16:19 +03:00
|
|
|
btnExit->setImageOrder(3, 4, 5, 6);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
//Object list control buttons
|
2023-08-23 14:07:50 +02:00
|
|
|
dwellTop = std::make_shared<CButton>(Point(733, 4), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPos(0);});
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
dwellBottom = std::make_shared<CButton>(Point(733, footerPos+2), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPos(-1); });
|
2014-08-03 14:16:19 +03:00
|
|
|
dwellBottom->setImageOrder(2, 3, 4, 5);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
dwellUp = std::make_shared<CButton>(Point(733, 24), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToPrev(); });
|
2014-08-03 14:16:19 +03:00
|
|
|
dwellUp->setImageOrder(4, 5, 6, 7);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
dwellDown = std::make_shared<CButton>(Point(733, footerPos-18), AnimationPath::builtin("OVBUTN4.DEF"), CButton::tooltip(), [&](){ dwellingsList->moveToNext(); });
|
2014-08-03 14:16:19 +03:00
|
|
|
dwellDown->setImageOrder(6, 7, 8, 9);
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdomInterface::activateTab(size_t which)
|
|
|
|
{
|
2023-10-13 00:21:58 +02:00
|
|
|
Settings s = persistentStorage.write["gui"]["lastKindomInterface"];
|
|
|
|
s->Integer() = which;
|
|
|
|
|
2014-04-23 18:12:35 +03:00
|
|
|
btnHeroes->block(which == 0);
|
|
|
|
btnTowns->block(which == 1);
|
|
|
|
tabArea->setActive(which);
|
|
|
|
}
|
|
|
|
|
2023-10-14 23:41:12 +02:00
|
|
|
void CKingdomInterface::buildChanged()
|
|
|
|
{
|
|
|
|
tabArea->reset();
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:12:35 +03:00
|
|
|
void CKingdomInterface::townChanged(const CGTownInstance *town)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(auto townList = std::dynamic_pointer_cast<CKingdTownList>(tabArea->getItem()))
|
2014-04-23 18:12:35 +03:00
|
|
|
townList->townChanged(town);
|
|
|
|
}
|
|
|
|
|
2023-07-15 14:47:24 +02:00
|
|
|
void CKingdomInterface::heroRemoved()
|
|
|
|
{
|
|
|
|
tabArea->reset();
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:12:35 +03:00
|
|
|
void CKingdomInterface::updateGarrisons()
|
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
if(auto garrison = std::dynamic_pointer_cast<IGarrisonHolder>(tabArea->getItem()))
|
2014-04-23 18:12:35 +03:00
|
|
|
garrison->updateGarrisons();
|
|
|
|
}
|
|
|
|
|
2023-11-09 00:01:48 +02:00
|
|
|
bool CKingdomInterface::holdsGarrison(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
return army->getOwner() == LOCPLINT->playerID;
|
|
|
|
}
|
|
|
|
|
2024-04-23 15:21:45 +02:00
|
|
|
CKingdHeroList::CKingdHeroList(size_t maxSize, const CreateHeroItemFunctor & onCreateHeroItemCallback)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-08-23 14:07:50 +02:00
|
|
|
title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"),16,0);
|
2014-04-23 18:12:35 +03:00
|
|
|
title->colorize(LOCPLINT->playerID);
|
2022-11-26 23:12:20 +02:00
|
|
|
heroLabel = std::make_shared<CLabel>(150, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[0]);
|
|
|
|
skillsLabel = std::make_shared<CLabel>(500, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[1]);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
ui32 townCount = LOCPLINT->cb->howManyHeroes(false);
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 size = OVERVIEW_SIZE*116 + 19;
|
2024-04-23 15:21:45 +02:00
|
|
|
heroes = std::make_shared<CListBox>([onCreateHeroItemCallback](size_t idx) -> std::shared_ptr<CIntObject>
|
|
|
|
{
|
|
|
|
auto heroesList = LOCPLINT->localState->getWanderingHeroes();
|
|
|
|
if(idx < heroesList.size())
|
|
|
|
{
|
|
|
|
auto hero = std::make_shared<CHeroItem>(heroesList[idx]);
|
|
|
|
onCreateHeroItemCallback(hero->heroArts);
|
|
|
|
return hero;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (idx - 2) % GameConstants::KINGDOM_WINDOW_HEROES_SLOTS);
|
|
|
|
}
|
|
|
|
}, Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdHeroList::updateGarrisons()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
for(std::shared_ptr<CIntObject> object : heroes->getItems())
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
|
2014-04-23 18:12:35 +03:00
|
|
|
garrison->updateGarrisons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-09 00:01:48 +02:00
|
|
|
bool CKingdHeroList::holdsGarrison(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
for(std::shared_ptr<CIntObject> object : heroes->getItems())
|
|
|
|
if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
|
|
|
|
if (garrison->holdsGarrison(army))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:12:35 +03:00
|
|
|
CKingdTownList::CKingdTownList(size_t maxSize)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-08-23 14:07:50 +02:00
|
|
|
title = std::make_shared<CPicture>(ImagePath::builtin("OVTITLE"), 16, 0);
|
2014-04-23 18:12:35 +03:00
|
|
|
title->colorize(LOCPLINT->playerID);
|
2022-11-26 23:12:20 +02:00
|
|
|
townLabel = std::make_shared<CLabel>(146, 10,FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[3]);
|
|
|
|
garrHeroLabel = std::make_shared<CLabel>(375, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[4]);
|
|
|
|
visitHeroLabel = std::make_shared<CLabel>(608, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[5]);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
ui32 townCount = LOCPLINT->cb->howManyTowns();
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 size = OVERVIEW_SIZE*116 + 19;
|
2018-04-07 13:34:11 +02:00
|
|
|
towns = std::make_shared<CListBox>(std::bind(&CKingdTownList::createTownItem, this, _1),
|
|
|
|
Point(19,21), Point(0,116), maxSize, townCount, 0, 1, Rect(-19, -21, size, size));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CKingdTownList::townChanged(const CGTownInstance * town)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
for(std::shared_ptr<CIntObject> object : towns->getItems())
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
CTownItem * townItem = dynamic_cast<CTownItem *>(object.get());
|
|
|
|
if(townItem && townItem->town == town)
|
2014-04-23 18:12:35 +03:00
|
|
|
townItem->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKingdTownList::updateGarrisons()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
for(std::shared_ptr<CIntObject> object : towns->getItems())
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
|
2014-04-23 18:12:35 +03:00
|
|
|
garrison->updateGarrisons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-09 00:01:48 +02:00
|
|
|
bool CKingdTownList::holdsGarrison(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
for(std::shared_ptr<CIntObject> object : towns->getItems())
|
|
|
|
if(IGarrisonHolder * garrison = dynamic_cast<IGarrisonHolder*>(object.get()))
|
|
|
|
if (garrison->holdsGarrison(army))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> CKingdTownList::createTownItem(size_t index)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
ui32 picCount = 4; // OVSLOT contains 4 images
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-07-15 14:47:24 +02:00
|
|
|
auto townsList = LOCPLINT->localState->getOwnedTowns();
|
|
|
|
|
|
|
|
if(index < townsList.size())
|
|
|
|
return std::make_shared<CTownItem>(townsList[index]);
|
2014-04-23 18:12:35 +03:00
|
|
|
else
|
2023-08-23 14:07:50 +02:00
|
|
|
return std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), (index-2) % picCount );
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CTownItem::CTownItem(const CGTownInstance * Town)
|
|
|
|
: town(Town)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-08-23 14:07:50 +02:00
|
|
|
background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 6);
|
2023-01-04 15:17:50 +02:00
|
|
|
name = std::make_shared<CLabel>(74, 8, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, town->getNameTranslated());
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
income = std::make_shared<CLabel>( 190, 60, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string(town->dailyIncome()[EGameResID::GOLD]));
|
2018-04-07 13:34:11 +02:00
|
|
|
hall = std::make_shared<CTownInfo>( 69, 31, town, true);
|
|
|
|
fort = std::make_shared<CTownInfo>(111, 31, town, false);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
garr = std::make_shared<CGarrisonInt>(Point(313, 3), 4, Point(232,0), town->getUpperArmy(), town->visitingHero, true, true, CGarrisonInt::ESlotsLayout::TWO_ROWS);
|
2018-04-07 13:34:11 +02:00
|
|
|
heroes = std::make_shared<HeroSlots>(town, Point(244,6), Point(475,6), garr, false);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-03-15 23:47:26 +02:00
|
|
|
size_t iconIndex = town->town->clientInfo.icons[town->hasFort()][town->builded >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
picture = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPT"), iconIndex, 0, 5, 6);
|
2018-04-07 13:34:11 +02:00
|
|
|
openTown = std::make_shared<LRClickableAreaOpenTown>(Rect(5, 6, 58, 64), town);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(size_t i=0; i<town->creatures.size(); i++)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
growth.push_back(std::make_shared<CCreaInfo>(Point(401+37*(int)i, 78), town, (int)i, true, true));
|
|
|
|
available.push_back(std::make_shared<CCreaInfo>(Point(48+37*(int)i, 78), town, (int)i, true, false));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
2023-10-13 01:38:33 +02:00
|
|
|
|
2024-04-14 12:09:11 +02:00
|
|
|
fastTownHall = std::make_shared<CButton>(Point(69, 31), AnimationPath::builtin("castleInterfaceQuickAccess"), CButton::tooltip(), [this]() { std::make_shared<CCastleBuildings>(town)->enterTownHall(); });
|
2024-02-28 22:24:19 +02:00
|
|
|
fastTownHall->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("ITMTL"), town->hallLevel()));
|
|
|
|
|
2023-11-25 03:58:06 +02:00
|
|
|
int imageIndex = town->fortLevel() == CGTownInstance::EFortLevel::NONE ? 3 : town->fortLevel() - 1;
|
2024-04-14 12:09:11 +02:00
|
|
|
fastArmyPurchase = std::make_shared<CButton>(Point(111, 31), AnimationPath::builtin("castleInterfaceQuickAccess"), CButton::tooltip(), [this]() { std::make_shared<CCastleBuildings>(town)->enterToTheQuickRecruitmentWindow(); });
|
2024-02-28 22:24:19 +02:00
|
|
|
fastArmyPurchase->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("itmcl"), imageIndex));
|
|
|
|
|
2023-10-13 01:38:33 +02:00
|
|
|
fastTavern = std::make_shared<LRClickableArea>(Rect(5, 6, 58, 64), [&]()
|
|
|
|
{
|
|
|
|
if(town->builtBuildings.count(BuildingID::TAVERN))
|
|
|
|
LOCPLINT->showTavernWindow(town, nullptr, QueryID::NONE);
|
2024-04-12 23:35:39 +02:00
|
|
|
}, [&]{
|
|
|
|
if(!town->town->faction->getDescriptionTranslated().empty())
|
|
|
|
CRClickPopup::createAndPush(town->town->faction->getDescriptionTranslated());
|
2023-10-13 01:38:33 +02:00
|
|
|
});
|
|
|
|
fastMarket = std::make_shared<LRClickableArea>(Rect(153, 6, 65, 64), []()
|
|
|
|
{
|
|
|
|
std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
|
|
|
|
for(auto & town : towns)
|
|
|
|
{
|
|
|
|
if(town->builtBuildings.count(BuildingID::MARKETPLACE))
|
|
|
|
{
|
2024-02-03 13:26:24 +02:00
|
|
|
GH.windows().createAndPushWindow<CMarketWindow>(town, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
|
2023-10-13 01:38:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
|
|
|
|
});
|
2023-10-15 00:41:17 +02:00
|
|
|
fastTown = std::make_shared<LRClickableArea>(Rect(67, 6, 165, 20), [&]()
|
|
|
|
{
|
|
|
|
GH.windows().createAndPushWindow<CCastleInterface>(town);
|
|
|
|
});
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTownItem::updateGarrisons()
|
|
|
|
{
|
|
|
|
garr->selectSlot(nullptr);
|
2023-07-07 00:08:29 +02:00
|
|
|
garr->setArmy(town->getUpperArmy(), EGarrisonType::UPPER);
|
|
|
|
garr->setArmy(town->visitingHero, EGarrisonType::LOWER);
|
2014-04-23 18:12:35 +03:00
|
|
|
garr->recreateSlots();
|
|
|
|
}
|
|
|
|
|
2023-11-09 00:01:48 +02:00
|
|
|
bool CTownItem::holdsGarrison(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
return army == town || army == town->getUpperArmy() || army == town->visitingHero;
|
|
|
|
}
|
|
|
|
|
2014-04-23 18:12:35 +03:00
|
|
|
void CTownItem::update()
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
std::string incomeVal = std::to_string(town->dailyIncome()[EGameResID::GOLD]);
|
2022-12-19 22:04:50 +02:00
|
|
|
if (incomeVal != income->getText())
|
2014-04-23 18:12:35 +03:00
|
|
|
income->setText(incomeVal);
|
|
|
|
|
|
|
|
heroes->update();
|
|
|
|
|
|
|
|
for (size_t i=0; i<town->creatures.size(); i++)
|
|
|
|
{
|
|
|
|
growth[i]->update();
|
|
|
|
available[i]->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ArtSlotsTab : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> background;
|
2024-05-21 19:00:13 +02:00
|
|
|
std::vector<std::shared_ptr<CArtPlace>> arts;
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
ArtSlotsTab()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-08-23 14:07:50 +02:00
|
|
|
background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 4);
|
2014-04-23 18:12:35 +03:00
|
|
|
pos = background->pos;
|
2020-10-01 10:38:06 +02:00
|
|
|
for(int i=0; i<9; i++)
|
2024-05-21 19:00:13 +02:00
|
|
|
arts.push_back(std::make_shared<CArtPlace>(Point(269+i*48, 66)));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BackpackTab : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CAnimImage> background;
|
2024-05-21 19:00:13 +02:00
|
|
|
std::vector<std::shared_ptr<CArtPlace>> arts;
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CButton> btnLeft;
|
|
|
|
std::shared_ptr<CButton> btnRight;
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
BackpackTab()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-08-23 14:07:50 +02:00
|
|
|
background = std::make_shared<CAnimImage>(AnimationPath::builtin("OVSLOT"), 5);
|
2014-04-23 18:12:35 +03:00
|
|
|
pos = background->pos;
|
2023-08-23 14:07:50 +02:00
|
|
|
btnLeft = std::make_shared<CButton>(Point(269, 66), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), 0);
|
|
|
|
btnRight = std::make_shared<CButton>(Point(675, 66), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), 0);
|
2020-10-01 10:38:06 +02:00
|
|
|
for(int i=0; i<8; i++)
|
2024-05-21 19:00:13 +02:00
|
|
|
arts.push_back(std::make_shared<CArtPlace>(Point(294+i*48, 66)));
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CHeroItem::CHeroItem(const CGHeroInstance * Hero)
|
|
|
|
: hero(Hero)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
artTabs.resize(3);
|
2018-04-07 13:34:11 +02:00
|
|
|
auto arts1 = std::make_shared<ArtSlotsTab>();
|
|
|
|
auto arts2 = std::make_shared<ArtSlotsTab>();
|
|
|
|
auto backpack = std::make_shared<BackpackTab>();
|
2014-04-23 18:12:35 +03:00
|
|
|
artTabs[0] = arts1;
|
|
|
|
artTabs[1] = arts2;
|
|
|
|
artTabs[2] = backpack;
|
2018-04-07 13:34:11 +02:00
|
|
|
arts1->recActions = SHARE_POS;
|
|
|
|
arts2->recActions = SHARE_POS;
|
|
|
|
backpack->recActions = SHARE_POS;
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-01-02 13:27:03 +02:00
|
|
|
name = std::make_shared<CLabel>(75, 7, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero->getNameTranslated());
|
2016-11-23 13:47:57 +02:00
|
|
|
|
2015-02-14 17:34:27 +02:00
|
|
|
//layout is not trivial: MACH4 - catapult - excluded, MISC[x] rearranged
|
|
|
|
assert(arts1->arts.size() == 9);
|
2016-11-23 13:47:57 +02:00
|
|
|
assert(arts2->arts.size() == 9);
|
|
|
|
|
2023-04-23 13:33:47 +02:00
|
|
|
CArtifactsOfHeroMain::ArtPlaceMap arts =
|
2016-11-23 13:47:57 +02:00
|
|
|
{
|
|
|
|
{ArtifactPosition::HEAD, arts1->arts[0]},
|
|
|
|
{ArtifactPosition::SHOULDERS,arts1->arts[1]},
|
|
|
|
{ArtifactPosition::NECK,arts1->arts[2]},
|
|
|
|
{ArtifactPosition::RIGHT_HAND,arts1->arts[3]},
|
|
|
|
{ArtifactPosition::LEFT_HAND,arts1->arts[4]},
|
2015-02-14 17:34:27 +02:00
|
|
|
{ArtifactPosition::TORSO, arts1->arts[5]},
|
|
|
|
{ArtifactPosition::RIGHT_RING,arts1->arts[6]},
|
|
|
|
{ArtifactPosition::LEFT_RING, arts1->arts[7]},
|
|
|
|
{ArtifactPosition::FEET, arts1->arts[8]},
|
2016-11-23 13:47:57 +02:00
|
|
|
|
2015-02-14 17:34:27 +02:00
|
|
|
{ArtifactPosition::MISC1, arts2->arts[0]},
|
|
|
|
{ArtifactPosition::MISC2, arts2->arts[1]},
|
|
|
|
{ArtifactPosition::MISC3, arts2->arts[2]},
|
|
|
|
{ArtifactPosition::MISC4, arts2->arts[3]},
|
|
|
|
{ArtifactPosition::MISC5, arts2->arts[4]},
|
|
|
|
{ArtifactPosition::MACH1, arts2->arts[5]},
|
|
|
|
{ArtifactPosition::MACH2, arts2->arts[6]},
|
|
|
|
{ArtifactPosition::MACH3, arts2->arts[7]},
|
|
|
|
{ArtifactPosition::SPELLBOOK, arts2->arts[8]}
|
|
|
|
};
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
|
2023-04-23 13:33:47 +02:00
|
|
|
heroArts = std::make_shared<CArtifactsOfHeroKingdom>(arts, backpack->arts, backpack->btnLeft, backpack->btnRight);
|
2014-04-23 18:12:35 +03:00
|
|
|
heroArts->setHero(hero);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
artsTabs = std::make_shared<CTabbedInt>(std::bind(&CHeroItem::onTabSelected, this, _1));
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
artButtons = std::make_shared<CToggleGroup>(0);
|
|
|
|
for(size_t it = 0; it<3; it++)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
|
|
|
int stringID[3] = {259, 261, 262};
|
|
|
|
|
2014-08-03 14:16:19 +03:00
|
|
|
std::string hover = CGI->generaltexth->overview[13+it];
|
2014-04-23 18:12:35 +03:00
|
|
|
std::string overlay = CGI->generaltexth->overview[8+it];
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
auto button = std::make_shared<CToggleButton>(Point(364+(int)it*112, 46), AnimationPath::builtin("OVBUTN3"), CButton::tooltip(hover, overlay), 0);
|
2024-02-27 22:19:09 +02:00
|
|
|
button->setTextOverlay(CGI->generaltexth->allTexts[stringID[it]], FONT_SMALL, Colors::YELLOW);
|
2020-10-01 10:38:06 +02:00
|
|
|
artButtons->addToggle((int)it, button);
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
2014-08-09 15:14:31 +03:00
|
|
|
artButtons->addCallback(std::bind(&CTabbedInt::setActive, artsTabs, _1));
|
|
|
|
artButtons->addCallback(std::bind(&CHeroItem::onArtChange, this, _1));
|
2014-08-03 14:16:19 +03:00
|
|
|
artButtons->setSelected(0);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
garr = std::make_shared<CGarrisonInt>(Point(6, 78), 4, Point(), hero, nullptr, true, true);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
portrait = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero->getIconIndex(), 0, 5, 6);
|
2018-04-07 13:34:11 +02:00
|
|
|
heroArea = std::make_shared<CHeroArea>(5, 6, hero);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2023-01-02 13:27:03 +02:00
|
|
|
name = std::make_shared<CLabel>(73, 7, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, hero->getNameTranslated());
|
2022-11-26 23:12:20 +02:00
|
|
|
artsText = std::make_shared<CLabel>(320, 55, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->overview[2]);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(size_t i=0; i<GameConstants::PRIMARY_SKILLS; i++)
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_PRIMARY_SKILL, hero, (int)i);
|
|
|
|
heroInfo.push_back(std::make_shared<InfoBox>(Point(78+(int)i*36, 26), InfoBox::POS_DOWN, InfoBox::SIZE_SMALL, data));
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(size_t i=0; i<GameConstants::SKILL_PER_HERO; i++)
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_SECONDARY_SKILL, hero, (int)i);
|
|
|
|
heroInfo.push_back(std::make_shared<InfoBox>(Point(410+(int)i*36, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL, data));
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
|
|
|
auto data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_SPECIAL, hero);
|
|
|
|
heroInfo.push_back(std::make_shared<InfoBox>(Point(375, 5), InfoBox::POS_NONE, InfoBox::SIZE_SMALL, data));
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_EXPERIENCE, hero);
|
|
|
|
heroInfo.push_back(std::make_shared<InfoBox>(Point(330, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data));
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
data = std::make_shared<InfoBoxHeroData>(IInfoBoxData::HERO_MANA, hero);
|
|
|
|
heroInfo.push_back(std::make_shared<InfoBox>(Point(280, 5), InfoBox::POS_INSIDE, InfoBox::SIZE_SMALL, data));
|
|
|
|
}
|
2014-04-23 18:12:35 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
morale = std::make_shared<MoraleLuckBox>(true, Rect(225, 53, 30, 22), true);
|
|
|
|
luck = std::make_shared<MoraleLuckBox>(false, Rect(225, 28, 30, 22), true);
|
2014-04-23 18:12:35 +03:00
|
|
|
|
|
|
|
morale->set(hero);
|
|
|
|
luck->set(hero);
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
void CHeroItem::updateGarrisons()
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
garr->recreateSlots();
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
2023-11-09 00:01:48 +02:00
|
|
|
bool CHeroItem::holdsGarrison(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
return hero == army;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> CHeroItem::onTabSelected(size_t index)
|
2014-04-23 18:12:35 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
return artTabs.at(index);
|
2014-04-23 18:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroItem::onArtChange(int tabIndex)
|
|
|
|
{
|
|
|
|
//redraw item after background change
|
2023-05-17 22:22:45 +02:00
|
|
|
if(isActive())
|
2014-04-23 18:12:35 +03:00
|
|
|
redraw();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|