From 0ac893b80f57cc75dd1a7a73953ca1bb21c72731 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Wed, 27 Sep 2023 23:22:45 +0200 Subject: [PATCH] Rumors meta string --- client/windows/GUIClasses.cpp | 3 +-- lib/CGameInfoCallback.cpp | 19 ++++++++++--------- lib/mapping/CMap.cpp | 2 +- lib/mapping/CMap.h | 3 ++- lib/mapping/MapFormatH3M.cpp | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 419dea97f..8bf9052c1 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -456,8 +456,7 @@ CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj) heroDescription = std::make_shared("", Rect(30, 373, 233, 35), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE); heroesForHire = std::make_shared(145, 283, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[38]); - auto rumorText = boost::str(boost::format(CGI->generaltexth->allTexts[216]) % LOCPLINT->cb->getTavernRumor(tavernObj)); - rumor = std::make_shared(rumorText, Rect(32, 188, 330, 66), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE); + rumor = std::make_shared(LOCPLINT->cb->getTavernRumor(tavernObj), Rect(32, 188, 330, 66), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE); statusbar = CGStatusBar::create(std::make_shared(background->getSurface(), Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26)); cancel = std::make_shared(Point(310, 428), AnimationPath::builtin("ICANCEL.DEF"), CButton::tooltip(CGI->generaltexth->tavernInfo[7]), std::bind(&CTavernWindow::close, this), EShortcut::GLOBAL_CANCEL); diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index b50d59e9b..bc3dfebe3 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -649,33 +649,34 @@ EPlayerStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbos std::string CGameInfoCallback::getTavernRumor(const CGObjectInstance * townOrTavern) const { - std::string text; + MetaString text; + text.appendLocalString(EMetaText::GENERAL_TXT, 216); + std::string extraText; if(gs->rumor.type == RumorState::TYPE_NONE) - return text; + return text.toString(); auto rumor = gs->rumor.last[gs->rumor.type]; switch(gs->rumor.type) { case RumorState::TYPE_SPECIAL: + text.replaceLocalString(EMetaText::GENERAL_TXT, rumor.first); if(rumor.first == RumorState::RUMOR_GRAIL) - extraText = VLC->generaltexth->arraytxt[158 + rumor.second]; + text.replaceTextID(TextIdentifier("core", "genrltxt", "arraytxt", 158 + rumor.second).get()); else - extraText = VLC->generaltexth->capColors[rumor.second]; - - text = boost::str(boost::format(VLC->generaltexth->allTexts[rumor.first]) % extraText); + text.replaceTextID(TextIdentifier("core", "genrltxt", "capitalColors", rumor.second).get()); break; case RumorState::TYPE_MAP: - text = gs->map->rumors[rumor.first].text; + text.replaceRawString(gs->map->rumors[rumor.first].text.toString()); break; case RumorState::TYPE_RAND: - text = VLC->generaltexth->tavernRumors[rumor.first]; + text.replaceTextID(TextIdentifier("core", "genrltxt", "randtvrn", rumor.first).get()); break; } - return text; + return text.toString(); } PlayerRelations CGameInfoCallback::getPlayerRelations( PlayerColor color1, PlayerColor color2 ) const diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index 811a52e02..71feca889 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -32,7 +32,7 @@ VCMI_LIB_NAMESPACE_BEGIN void Rumor::serializeJson(JsonSerializeFormat & handler) { handler.serializeString("name", name); - handler.serializeString("text", text); + handler.serializeStruct("text", text); } DisposedHero::DisposedHero() : heroId(0), portrait(255) diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index c3cd0bfdb..abed40d06 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -11,6 +11,7 @@ #pragma once #include "CMapHeader.h" +#include "../MetaString.h" #include "../mapObjects/MiscObjects.h" // To serialize static props #include "../mapObjects/CQuest.h" // To serialize static props #include "../mapObjects/CGTownInstance.h" // To serialize static props @@ -36,7 +37,7 @@ struct TeleportChannel; struct DLL_LINKAGE Rumor { std::string name; - std::string text; + MetaString text; Rumor() = default; ~Rumor() = default; diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 90b6b8dfc..0d1e00ed5 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -807,7 +807,7 @@ void CMapLoaderH3M::readRumors() { Rumor ourRumor; ourRumor.name = readBasicString(); - ourRumor.text = readLocalizedString(TextIdentifier("header", "rumor", it, "text")); + ourRumor.text.appendTextID(readLocalizedString(TextIdentifier("header", "rumor", it, "text"))); map->rumors.push_back(ourRumor); } }