From e7a774c465e5e2585b563600827b4f1c1b4f113f Mon Sep 17 00:00:00 2001 From: Dydzio Date: Thu, 2 Feb 2023 20:54:47 +0100 Subject: [PATCH 1/3] Improve creature numbers handling in castle interface bottom left part --- client/CPlayerInterface.cpp | 10 +++-- client/windows/CCastleInterface.cpp | 61 +++++++++++++++++++++++------ client/windows/CCastleInterface.h | 8 ++-- 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 5fcb149e4..63f10a8c2 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1220,9 +1220,13 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town ) EVENT_HANDLER_CALLED_BY_CLIENT; if (const CGTownInstance * townObj = dynamic_cast(town)) { - CFortScreen *fs = dynamic_cast(GH.topInt().get()); - if (fs) - fs->creaturesChanged(); + CFortScreen * fortScreen = dynamic_cast(GH.topInt().get()); + CCastleInterface * castleInterface = dynamic_cast(GH.topInt().get()); + + if (fortScreen) + fortScreen->creaturesChangedEventHandler(); + else if(castleInterface) + castleInterface->creaturesChangedEventHandler(); for(auto isa : GH.listInt) { diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 9de836afb..ee34b3f8b 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -45,6 +45,18 @@ #include +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) : CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME), parent(Par), @@ -834,7 +846,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(town, level, town, recruitCb, -87); } @@ -966,10 +981,10 @@ void CCastleBuildings::openTownHall() GH.pushIntT(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; @@ -990,7 +1005,7 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, boo if(showAvailable) value = boost::lexical_cast(town->creatures[level].first); else - value = boost::lexical_cast(town->creatureGrowth(level)); + value = std::string("+") + boost::lexical_cast(town->creatureGrowth(level)); if(compact) { @@ -1015,7 +1030,7 @@ void CCreaInfo::update() if(showAvailable) value = boost::lexical_cast(town->creatures[level].first); else - value = boost::lexical_cast(town->creatureGrowth(level)); + value = std::string("+") + boost::lexical_cast(town->creatureGrowth(level)); if(value != label->getText()) label->setText(value); @@ -1042,10 +1057,12 @@ void CCreaInfo::clickLeft(tribool down, bool previousState) if(previousState && (!down)) { int offset = LOCPLINT->castleInt? (-87) : 0; + auto recruitCb = [=](CreatureID id, int count) { LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level); }; + GH.pushIntT(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) : town(Town), building(nullptr) @@ -1248,11 +1270,15 @@ void CCastleInterface::recreateIcons() creainfo.clear(); - for(size_t i=0; i<4; i++) - creainfo.push_back(std::make_shared(Point(14+55*(int)i, 459), town, (int)i)); + //TODO: GUI option for these + bool compactCreatureInfo = useCompactCreatureBox(); + bool useAvailableCreaturesForLabel = useAvailableAmountAsCreatureLabel(); for(size_t i=0; i<4; i++) - creainfo.push_back(std::make_shared(Point(14+55*(int)i, 507), town, (int)i+4)); + creainfo.push_back(std::make_shared(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(Point(14+55*(int)i, 507), town, (int)i+4, compactCreatureInfo, useAvailableCreaturesForLabel)); } 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): town(Town), building(Building) @@ -1593,10 +1630,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): @@ -1686,7 +1725,7 @@ void CFortScreen::RecruitArea::hover(bool on) GH.statusbar->clear(); } -void CFortScreen::RecruitArea::creaturesChanged() +void CFortScreen::RecruitArea::creaturesChangedEventHandler() { if(availableCount) { diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index b8410856c..f17c27006 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -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 @@ -250,6 +251,7 @@ public: void addBuilding(BuildingID bid); void removeBuilding(BuildingID bid); void recreateIcons(); + void creaturesChangedEventHandler(); }; /// Hall window where you can build things @@ -339,7 +341,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; @@ -354,7 +356,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 From a4cc386a5ade604e8317afb19ab09c5c8a590762 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 5 Feb 2023 20:24:36 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Nordsoft91 --- client/windows/CCastleInterface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index ee34b3f8b..227ddfd1c 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1057,12 +1057,10 @@ void CCreaInfo::clickLeft(tribool down, bool previousState) if(previousState && (!down)) { int offset = LOCPLINT->castleInt? (-87) : 0; - auto recruitCb = [=](CreatureID id, int count) { LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level); }; - GH.pushIntT(town, level, town, recruitCb, offset); } } @@ -1275,10 +1273,12 @@ void CCastleInterface::recreateIcons() bool useAvailableCreaturesForLabel = useAvailableAmountAsCreatureLabel(); for(size_t i=0; i<4; i++) - creainfo.push_back(std::make_shared(Point(14+55*(int)i, 459), town, (int)i, compactCreatureInfo, useAvailableCreaturesForLabel)); + creainfo.push_back(std::make_shared(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(Point(14+55*(int)i, 507), town, (int)i+4, compactCreatureInfo, useAvailableCreaturesForLabel)); + creainfo.push_back(std::make_shared(Point(14 + 55 * (int)i, 507), town, (int)i + 4, compactCreatureInfo, useAvailableCreaturesForLabel)); + } void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key) From ade52239ea44f1cc83a10e7107e6f33523d38be4 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Wed, 15 Feb 2023 23:26:55 +0100 Subject: [PATCH 3/3] Use config value from new settings --- client/windows/CCastleInterface.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 227ddfd1c..0bbd3c1b0 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -47,14 +47,12 @@ static bool useCompactCreatureBox() { - //TODO: add UI for easier access - return settings["session"]["compactCreatureInfo"].isNumber() ? settings["session"]["compactCreatureInfo"].Bool() : false; + return settings["gameTweaks"]["compactTownCreatureInfo"].isNumber() ? settings["gameTweaks"]["compactTownCreatureInfo"].Bool() : false; } static bool useAvailableAmountAsCreatureLabel() { - //TODO: add UI for easier access - return settings["session"]["availableCreaturesAsLabel"].isNumber() ? settings["session"]["availableCreaturesAsLabel"].Bool() : false; + return settings["gameTweaks"]["availableCreaturesAsDwellingLabel"].isNumber() ? settings["gameTweaks"]["availableCreaturesAsDwellingLabel"].Bool() : false; } CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str) @@ -1268,7 +1266,6 @@ void CCastleInterface::recreateIcons() creainfo.clear(); - //TODO: GUI option for these bool compactCreatureInfo = useCompactCreatureBox(); bool useAvailableCreaturesForLabel = useAvailableAmountAsCreatureLabel();