From 62dd5681f55d55676c3c31a5fde6dc3af9b77c68 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 3 Jun 2024 13:37:35 +0000 Subject: [PATCH] Fixes crash on accessing recruitment window via click on creature icon --- client/windows/CCastleInterface.cpp | 27 +++++++++++++++++---------- client/windows/CCastleInterface.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 14626c67a..a26c2cecd 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -1085,9 +1085,9 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, boo } addUsedEvents(LCLICK | SHOW_POPUP | HOVER); - CreatureID creatureID = town->creatures[level].second.back(); + creature = town->creatures[level].second.back(); - picture = std::make_shared(AnimationPath::builtin("CPRSMALL"), creatureID.toEntity(VLC)->getIconIndex(), 0, 8, 0); + picture = std::make_shared(AnimationPath::builtin("CPRSMALL"), creature.toEntity(VLC)->getIconIndex(), 0, 8, 0); std::string value; if(showAvailable) @@ -1127,16 +1127,17 @@ void CCreaInfo::update() void CCreaInfo::hover(bool on) { - std::string message = CGI->generaltexth->allTexts[588]; - boost::algorithm::replace_first(message, "%s", creature->getNamePluralTranslated()); + MetaString message; + message.appendTextID("core.genrltxt.588"); + message.replaceNameSingular(creature); if(on) { - GH.statusbar()->write(message); + GH.statusbar()->write(message.toString()); } else { - GH.statusbar()->clearIfMatching(message); + GH.statusbar()->clearIfMatching(message.toString()); } } @@ -1153,12 +1154,18 @@ void CCreaInfo::clickPressed(const Point & cursorPosition) std::string CCreaInfo::genGrowthText() { GrowthInfo gi = town->getGrowthInfo(level); - std::string descr = boost::str(boost::format(CGI->generaltexth->allTexts[589]) % creature->getNameSingularTranslated() % gi.totalGrowth()); + MetaString descr; + descr.appendTextID("core.genrltxt.589"); + descr.replaceNameSingular(creature); + descr.replaceNumber(gi.totalGrowth()); for(const GrowthInfo::Entry & entry : gi.entries) - descr +="\n" + entry.description; + { + descr.appendEOL(); + descr.appendRawString(entry.description); + } - return descr; + return descr.toString(); } void CCreaInfo::showPopupWindow(const Point & cursorPosition) @@ -1166,7 +1173,7 @@ void CCreaInfo::showPopupWindow(const Point & cursorPosition) if (showAvailable) GH.windows().createAndPushWindow(GH.screenDimensions().x / 2, GH.screenDimensions().y / 2, town, level); else - CRClickPopup::createAndPush(genGrowthText(), std::make_shared(ComponentType::CREATURE, creature->getId())); + CRClickPopup::createAndPush(genGrowthText(), std::make_shared(ComponentType::CREATURE, creature)); } bool CCreaInfo::getShowAvailable() diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 7c3b62add..6accc8dde 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -181,7 +181,7 @@ public: class CCreaInfo : public CIntObject { const CGTownInstance * town; - const CCreature * creature; + CreatureID creature; int level; bool showAvailable;