1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Implement interactable town tooltip

This commit is contained in:
Dydzio 2023-07-16 10:17:37 +02:00
parent 013d4cd208
commit dbfcb5a749
4 changed files with 73 additions and 2 deletions

View File

@ -62,7 +62,11 @@ CInfoBar::VisibleTownInfo::VisibleTownInfo(const CGTownInstance * town)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background = std::make_shared<CPicture>("ADSTATCS");
townTooltip = std::make_shared<CTownTooltip>(Point(0,0), town);
if(settings["gameTweaks"]["infoBoxCreatureManagement"].Bool())
townTooltip = std::make_shared<CInteractableTownTooltip>(Point(0,0), town);
else
townTooltip = std::make_shared<CTownTooltip>(Point(0,0), town);
}
CInfoBar::VisibleDateInfo::VisibleDateInfo()

View File

@ -27,6 +27,7 @@ class CComponentBox;
class CHeroTooltip;
class CInteractableHeroTooltip;
class CTownTooltip;
class CInteractableTownTooltip;
class CLabel;
class CMultiLineLabel;
@ -74,7 +75,7 @@ private:
class VisibleTownInfo : public CVisibleInfo
{
std::shared_ptr<CTownTooltip> townTooltip;
std::variant<std::shared_ptr<CTownTooltip>, std::shared_ptr<CInteractableTownTooltip>> townTooltip;
public:
VisibleTownInfo(const CGTownInstance * town);
};

View File

@ -382,6 +382,55 @@ CTownTooltip::CTownTooltip(Point pos, const CGTownInstance * town)
init(InfoAboutTown(town, true));
}
CInteractableTownTooltip::CInteractableTownTooltip(Point pos, const CGTownInstance * town)
: CGarrisonInt(pos.x, pos.y+73, 4, Point(0, 0), town->getUpperArmy(), nullptr, true, true, CGarrisonInt::EGarrisonIntSlotsLayout::REVERSED_TWO_ROWS)
{
init(InfoAboutTown(town, true));
}
void CInteractableTownTooltip::init(const InfoAboutTown & town)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
//order of icons in def: fort, citadel, castle, no fort
size_t fortIndex = town.fortLevel ? town.fortLevel - 1 : 3;
fort = std::make_shared<CAnimImage>("ITMCLS", fortIndex, 0, 105, 31-73);
assert(town.tType);
size_t iconIndex = town.tType->clientInfo.icons[town.fortLevel > 0][town.built >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];
build = std::make_shared<CAnimImage>("itpt", iconIndex, 0, 3, 2-73);
title = std::make_shared<CLabel>(66, 2-73, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, town.name);
if(town.details)
{
hall = std::make_shared<CAnimImage>("ITMTLS", town.details->hallLevel, 0, 67, 31-73);
if(town.details->goldIncome)
{
income = std::make_shared<CLabel>(157, 58-73, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE,
std::to_string(town.details->goldIncome));
}
if(town.details->garrisonedHero) //garrisoned hero icon
garrisonedHero = std::make_shared<CPicture>("TOWNQKGH", 149, 76-73);
if(town.details->customRes)//silo is built
{
if(town.tType->primaryRes == EGameResID::WOOD_AND_ORE )// wood & ore
{
res1 = std::make_shared<CAnimImage>("SMALRES", GameResID(EGameResID::WOOD), 0, 7, 75-73);
res2 = std::make_shared<CAnimImage>("SMALRES", GameResID(EGameResID::ORE), 0, 7, 88-73);
}
else
{
res1 = std::make_shared<CAnimImage>("SMALRES", town.tType->primaryRes, 0, 7, 81-73);
}
}
}
}
void MoraleLuckBox::set(const AFactionMember * node)
{
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);

View File

@ -114,6 +114,23 @@ public:
CTownTooltip(Point pos, const CGTownInstance * town);
};
/// Class for HD mod-like interactable infobox tooltip. Does not have any background!
class CInteractableTownTooltip : public CGarrisonInt
{
std::shared_ptr<CLabel> title;
std::shared_ptr<CAnimImage> fort;
std::shared_ptr<CAnimImage> hall;
std::shared_ptr<CAnimImage> build;
std::shared_ptr<CLabel> income;
std::shared_ptr<CPicture> garrisonedHero;
std::shared_ptr<CAnimImage> res1;
std::shared_ptr<CAnimImage> res2;
void init(const InfoAboutTown & town);
public:
CInteractableTownTooltip(Point pos, const CGTownInstance * town);
};
/// draws picture with creature on background, use Animated=true to get animation
class CCreaturePic : public CIntObject
{