1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

Improve creature numbers handling in castle interface bottom left part

This commit is contained in:
Dydzio 2023-02-02 20:54:47 +01:00
parent f1ea88ae9a
commit e7a774c465
3 changed files with 62 additions and 17 deletions

View File

@ -1220,9 +1220,13 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
if (const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town)) if (const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town))
{ {
CFortScreen *fs = dynamic_cast<CFortScreen*>(GH.topInt().get()); CFortScreen * fortScreen = dynamic_cast<CFortScreen*>(GH.topInt().get());
if (fs) CCastleInterface * castleInterface = dynamic_cast<CCastleInterface*>(GH.topInt().get());
fs->creaturesChanged();
if (fortScreen)
fortScreen->creaturesChangedEventHandler();
else if(castleInterface)
castleInterface->creaturesChangedEventHandler();
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {

View File

@ -45,6 +45,18 @@
#include <SDL_events.h> #include <SDL_events.h>
static bool useCompactCreatureBox()
{
//TODO: add UI for easier access
return settings["session"]["compactCreatureInfo"].isNumber() ? settings["session"]["compactCreatureInfo"].Bool() : false;
}
static bool useAvailableAmountAsCreatureLabel()
{
//TODO: add UI for easier access
return settings["session"]["availableCreaturesAsLabel"].isNumber() ? settings["session"]["availableCreaturesAsLabel"].Bool() : false;
}
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str) CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str)
: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME), : CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME),
parent(Par), parent(Par),
@ -834,7 +846,10 @@ void CCastleBuildings::enterCastleGate()
void CCastleBuildings::enterDwelling(int level) void CCastleBuildings::enterDwelling(int level)
{ {
assert(level >= 0 && level < town->creatures.size()); assert(level >= 0 && level < town->creatures.size());
auto recruitCb = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level); }; auto recruitCb = [=](CreatureID id, int count)
{
LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level);
};
GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, -87); GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, -87);
} }
@ -966,10 +981,10 @@ void CCastleBuildings::openTownHall()
GH.pushIntT<CHallInterface>(town); GH.pushIntT<CHallInterface>(town);
} }
CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact, bool ShowAvailable): CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact, bool _showAvailable):
town(Town), town(Town),
level(Level), level(Level),
showAvailable(ShowAvailable) showAvailable(_showAvailable)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
pos += position; pos += position;
@ -990,7 +1005,7 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, boo
if(showAvailable) if(showAvailable)
value = boost::lexical_cast<std::string>(town->creatures[level].first); value = boost::lexical_cast<std::string>(town->creatures[level].first);
else else
value = boost::lexical_cast<std::string>(town->creatureGrowth(level)); value = std::string("+") + boost::lexical_cast<std::string>(town->creatureGrowth(level));
if(compact) if(compact)
{ {
@ -1015,7 +1030,7 @@ void CCreaInfo::update()
if(showAvailable) if(showAvailable)
value = boost::lexical_cast<std::string>(town->creatures[level].first); value = boost::lexical_cast<std::string>(town->creatures[level].first);
else else
value = boost::lexical_cast<std::string>(town->creatureGrowth(level)); value = std::string("+") + boost::lexical_cast<std::string>(town->creatureGrowth(level));
if(value != label->getText()) if(value != label->getText())
label->setText(value); label->setText(value);
@ -1042,10 +1057,12 @@ void CCreaInfo::clickLeft(tribool down, bool previousState)
if(previousState && (!down)) if(previousState && (!down))
{ {
int offset = LOCPLINT->castleInt? (-87) : 0; int offset = LOCPLINT->castleInt? (-87) : 0;
auto recruitCb = [=](CreatureID id, int count) auto recruitCb = [=](CreatureID id, int count)
{ {
LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level); LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level);
}; };
GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, offset); GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, offset);
} }
} }
@ -1072,6 +1089,11 @@ void CCreaInfo::clickRight(tribool down, bool previousState)
} }
} }
bool CCreaInfo::getShowAvailable()
{
return showAvailable;
}
CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance * Town, bool townHall) CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance * Town, bool townHall)
: town(Town), : town(Town),
building(nullptr) building(nullptr)
@ -1248,11 +1270,15 @@ void CCastleInterface::recreateIcons()
creainfo.clear(); creainfo.clear();
for(size_t i=0; i<4; i++) //TODO: GUI option for these
creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 459), town, (int)i)); bool compactCreatureInfo = useCompactCreatureBox();
bool useAvailableCreaturesForLabel = useAvailableAmountAsCreatureLabel();
for(size_t i=0; i<4; i++) for(size_t i=0; i<4; i++)
creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 507), town, (int)i+4)); creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 459), town, (int)i, compactCreatureInfo, useAvailableCreaturesForLabel));
for(size_t i=0; i<4; i++)
creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 507), town, (int)i+4, compactCreatureInfo, useAvailableCreaturesForLabel));
} }
void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key) void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key)
@ -1279,6 +1305,17 @@ void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key)
} }
} }
void CCastleInterface::creaturesChangedEventHandler()
{
for(auto creatureInfoBox : creainfo)
{
if(creatureInfoBox->getShowAvailable())
{
creatureInfoBox->update();
}
}
}
CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building): CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building):
town(Town), town(Town),
building(Building) building(Building)
@ -1593,10 +1630,12 @@ std::string CFortScreen::getBgName(const CGTownInstance * town)
return "TPCASTL8"; return "TPCASTL8";
} }
void CFortScreen::creaturesChanged() void CFortScreen::creaturesChangedEventHandler()
{ {
for(auto & elem : recAreas) for(auto & elem : recAreas)
elem->creaturesChanged(); elem->creaturesChangedEventHandler();
LOCPLINT->castleInt->creaturesChangedEventHandler();
} }
CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * Town, int Level): CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * Town, int Level):
@ -1686,7 +1725,7 @@ void CFortScreen::RecruitArea::hover(bool on)
GH.statusbar->clear(); GH.statusbar->clear();
} }
void CFortScreen::RecruitArea::creaturesChanged() void CFortScreen::RecruitArea::creaturesChangedEventHandler()
{ {
if(availableCount) if(availableCount)
{ {

View File

@ -186,12 +186,13 @@ class CCreaInfo : public CIntObject
std::string genGrowthText(); std::string genGrowthText();
public: public:
CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact=false, bool showAvailable=false); CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact=false, bool _showAvailable=false);
void update(); void update();
void hover(bool on) override; void hover(bool on) override;
void clickLeft(tribool down, bool previousState) override; void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override;
bool getShowAvailable();
}; };
/// Town hall and fort icons for town screen /// Town hall and fort icons for town screen
@ -250,6 +251,7 @@ public:
void addBuilding(BuildingID bid); void addBuilding(BuildingID bid);
void removeBuilding(BuildingID bid); void removeBuilding(BuildingID bid);
void recreateIcons(); void recreateIcons();
void creaturesChangedEventHandler();
}; };
/// Hall window where you can build things /// Hall window where you can build things
@ -339,7 +341,7 @@ class CFortScreen : public CStatusbarWindow
public: public:
RecruitArea(int posX, int posY, const CGTownInstance *town, int level); RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
void creaturesChanged(); void creaturesChangedEventHandler();
void hover(bool on) override; void hover(bool on) override;
void clickLeft(tribool down, bool previousState) override; void clickLeft(tribool down, bool previousState) override;
void clickRight(tribool down, bool previousState) override; void clickRight(tribool down, bool previousState) override;
@ -354,7 +356,7 @@ class CFortScreen : public CStatusbarWindow
public: public:
CFortScreen(const CGTownInstance * town); CFortScreen(const CGTownInstance * town);
void creaturesChanged(); void creaturesChangedEventHandler();
}; };
/// The mage guild screen where you can see which spells you have /// The mage guild screen where you can see which spells you have