mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Merge pull request #1545 from dydzio0614/town-panel-number-formatting
Improve creature numbers handling in castle interface bottom left part
This commit is contained in:
commit
195eac3375
@ -1225,9 +1225,13 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
|
||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||
if (const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town))
|
||||
{
|
||||
CFortScreen *fs = dynamic_cast<CFortScreen*>(GH.topInt().get());
|
||||
if (fs)
|
||||
fs->creaturesChanged();
|
||||
CFortScreen * fortScreen = dynamic_cast<CFortScreen*>(GH.topInt().get());
|
||||
CCastleInterface * castleInterface = dynamic_cast<CCastleInterface*>(GH.topInt().get());
|
||||
|
||||
if (fortScreen)
|
||||
fortScreen->creaturesChangedEventHandler();
|
||||
else if(castleInterface)
|
||||
castleInterface->creaturesChangedEventHandler();
|
||||
|
||||
for(auto isa : GH.listInt)
|
||||
{
|
||||
|
@ -46,6 +46,16 @@
|
||||
#include "../../lib/mapObjects/CGTownInstance.h"
|
||||
|
||||
|
||||
static bool useCompactCreatureBox()
|
||||
{
|
||||
return settings["gameTweaks"]["compactTownCreatureInfo"].isNumber() ? settings["gameTweaks"]["compactTownCreatureInfo"].Bool() : false;
|
||||
}
|
||||
|
||||
static bool useAvailableAmountAsCreatureLabel()
|
||||
{
|
||||
return settings["gameTweaks"]["availableCreaturesAsDwellingLabel"].isNumber() ? settings["gameTweaks"]["availableCreaturesAsDwellingLabel"].Bool() : false;
|
||||
}
|
||||
|
||||
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str)
|
||||
: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME),
|
||||
parent(Par),
|
||||
@ -835,7 +845,10 @@ void CCastleBuildings::enterCastleGate()
|
||||
void CCastleBuildings::enterDwelling(int level)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -967,10 +980,10 @@ void CCastleBuildings::openTownHall()
|
||||
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),
|
||||
level(Level),
|
||||
showAvailable(ShowAvailable)
|
||||
showAvailable(_showAvailable)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
pos += position;
|
||||
@ -991,7 +1004,7 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, boo
|
||||
if(showAvailable)
|
||||
value = boost::lexical_cast<std::string>(town->creatures[level].first);
|
||||
else
|
||||
value = boost::lexical_cast<std::string>(town->creatureGrowth(level));
|
||||
value = std::string("+") + boost::lexical_cast<std::string>(town->creatureGrowth(level));
|
||||
|
||||
if(compact)
|
||||
{
|
||||
@ -1016,7 +1029,7 @@ void CCreaInfo::update()
|
||||
if(showAvailable)
|
||||
value = boost::lexical_cast<std::string>(town->creatures[level].first);
|
||||
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())
|
||||
label->setText(value);
|
||||
@ -1073,6 +1086,11 @@ void CCreaInfo::clickRight(tribool down, bool previousState)
|
||||
}
|
||||
}
|
||||
|
||||
bool CCreaInfo::getShowAvailable()
|
||||
{
|
||||
return showAvailable;
|
||||
}
|
||||
|
||||
CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance * Town, bool townHall)
|
||||
: town(Town),
|
||||
building(nullptr)
|
||||
@ -1249,11 +1267,16 @@ void CCastleInterface::recreateIcons()
|
||||
|
||||
creainfo.clear();
|
||||
|
||||
for(size_t i=0; i<4; i++)
|
||||
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++)
|
||||
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_Keycode & key)
|
||||
@ -1278,6 +1301,17 @@ void CCastleInterface::keyPressed(const SDL_Keycode & 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):
|
||||
town(Town),
|
||||
building(Building)
|
||||
@ -1592,10 +1626,12 @@ std::string CFortScreen::getBgName(const CGTownInstance * town)
|
||||
return "TPCASTL8";
|
||||
}
|
||||
|
||||
void CFortScreen::creaturesChanged()
|
||||
void CFortScreen::creaturesChangedEventHandler()
|
||||
{
|
||||
for(auto & elem : recAreas)
|
||||
elem->creaturesChanged();
|
||||
elem->creaturesChangedEventHandler();
|
||||
|
||||
LOCPLINT->castleInt->creaturesChangedEventHandler();
|
||||
}
|
||||
|
||||
CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * Town, int Level):
|
||||
@ -1685,7 +1721,7 @@ void CFortScreen::RecruitArea::hover(bool on)
|
||||
GH.statusbar->clear();
|
||||
}
|
||||
|
||||
void CFortScreen::RecruitArea::creaturesChanged()
|
||||
void CFortScreen::RecruitArea::creaturesChangedEventHandler()
|
||||
{
|
||||
if(availableCount)
|
||||
{
|
||||
|
@ -186,12 +186,13 @@ class CCreaInfo : public CIntObject
|
||||
std::string genGrowthText();
|
||||
|
||||
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 hover(bool on) override;
|
||||
void clickLeft(tribool down, bool previousState) override;
|
||||
void clickRight(tribool down, bool previousState) override;
|
||||
bool getShowAvailable();
|
||||
};
|
||||
|
||||
/// Town hall and fort icons for town screen
|
||||
@ -251,6 +252,7 @@ public:
|
||||
void addBuilding(BuildingID bid);
|
||||
void removeBuilding(BuildingID bid);
|
||||
void recreateIcons();
|
||||
void creaturesChangedEventHandler();
|
||||
};
|
||||
|
||||
/// Hall window where you can build things
|
||||
@ -340,7 +342,7 @@ class CFortScreen : public CStatusbarWindow
|
||||
public:
|
||||
RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
|
||||
|
||||
void creaturesChanged();
|
||||
void creaturesChangedEventHandler();
|
||||
void hover(bool on) override;
|
||||
void clickLeft(tribool down, bool previousState) override;
|
||||
void clickRight(tribool down, bool previousState) override;
|
||||
@ -355,7 +357,7 @@ class CFortScreen : public CStatusbarWindow
|
||||
public:
|
||||
CFortScreen(const CGTownInstance * town);
|
||||
|
||||
void creaturesChanged();
|
||||
void creaturesChangedEventHandler();
|
||||
};
|
||||
|
||||
/// The mage guild screen where you can see which spells you have
|
||||
|
Loading…
Reference in New Issue
Block a user