From edf43f5702e1cf8adf47049b25b93f83a97645fd Mon Sep 17 00:00:00 2001 From: MichalZr6 Date: Tue, 24 Sep 2024 18:28:17 +0200 Subject: [PATCH] Get and translate messages on client side --- Mods/vcmi/config/vcmi/english.json | 2 +- Mods/vcmi/config/vcmi/polish.json | 4 +++- client/windows/GUIClasses.cpp | 8 +++++--- .../HillFortInstanceConstructor.cpp | 7 ------- lib/mapObjects/MiscObjects.cpp | 10 ++++++++++ lib/mapObjects/MiscObjects.h | 15 ++------------- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index e93bf8b95..52c3499af 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -517,7 +517,7 @@ "core.seerhut.quest.reachDate.visit.4" : "Closed till %s.", "core.seerhut.quest.reachDate.visit.5" : "Closed till %s.", - "mapObject.core.hillFort.object.description" : "Upgrades creatures. Levels 1 - 4 are less expensive than in associated town", + "mapObject.core.hillFort.object.description" : "Upgrades creatures. Levels 1 - 4 are less expensive than in associated town.", "core.bonus.ADDITIONAL_ATTACK.name": "Double Strike", "core.bonus.ADDITIONAL_ATTACK.description": "Attacks twice", diff --git a/Mods/vcmi/config/vcmi/polish.json b/Mods/vcmi/config/vcmi/polish.json index 77c830446..fae832498 100644 --- a/Mods/vcmi/config/vcmi/polish.json +++ b/Mods/vcmi/config/vcmi/polish.json @@ -513,7 +513,9 @@ "core.seerhut.quest.reachDate.visit.3" : "Zamknięte do %s.", "core.seerhut.quest.reachDate.visit.4" : "Zamknięte do %s.", "core.seerhut.quest.reachDate.visit.5" : "Zamknięte do %s.", - "mapObject.core.hillFort.object.description" : "Ulepsza jednostki. Koszt ulepszenia dla poziomów 1 - 4 jest bardziej korzystny niż w mieście", + + "mapObject.core.hillFort.object.description" : "Ulepsza jednostki. Koszt ulepszenia dla poziomów 1 - 4 jest bardziej korzystny niż w mieście.", + "core.bonus.ADDITIONAL_ATTACK.name": "Podwójne Uderzenie", "core.bonus.ADDITIONAL_ATTACK.description": "Atakuje dwa razy", "core.bonus.ADDITIONAL_RETALIATION.name": "Dodatkowy odwet", diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 6ded1b692..7dcaae593 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -1130,7 +1130,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance * visitor, const CGObjectI garr = std::make_shared(Point(108, 60), 18, Point(), hero, nullptr); - statusbar->write(dynamic_cast(fort)->getDescriptionToolTip()); + statusbar->write(VLC->generaltexth->translate(dynamic_cast(fort)->getDescriptionToolTip())); updateGarrisons(); } @@ -1270,9 +1270,11 @@ void CHillFortWindow::makeDeal(SlotID slot) LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314 + offset], std::vector>(), soundBase::sound_todo); break; case State::UNAVAILABLE: - LOCPLINT->showInfoDialog(dynamic_cast(fort)->getUnavailableUpgradeMessage(), - std::vector>(), soundBase::sound_todo); + { + std::string message = VLC->generaltexth->translate(dynamic_cast(fort)->getUnavailableUpgradeMessage()); + LOCPLINT->showInfoDialog(message, std::vector>(), soundBase::sound_todo); break; + } case State::MAKE_UPGRADE: for(int i = 0; i < slotsCount; i++) { diff --git a/lib/mapObjectConstructors/HillFortInstanceConstructor.cpp b/lib/mapObjectConstructors/HillFortInstanceConstructor.cpp index be01c9b65..f71f4990e 100644 --- a/lib/mapObjectConstructors/HillFortInstanceConstructor.cpp +++ b/lib/mapObjectConstructors/HillFortInstanceConstructor.cpp @@ -25,13 +25,6 @@ void HillFortInstanceConstructor::initTypeData(const JsonNode & config) void HillFortInstanceConstructor::initializeObject(HillFort * fort) const { fort->upgradeCostPercentage = parameters["upgradeCostFactor"].convertTo>(); - fort->descriptionToolTip = VLC->generaltexth->translate(TextIdentifier(getBaseTextID(), "description").get()); - if (fort->descriptionToolTip.empty()) - fort->descriptionToolTip = parameters["description"].String(); - - fort->unavailableUpgradeMessage = VLC->generaltexth->translate(TextIdentifier(getBaseTextID(), "unavailableUpgradeMessage").get()); - if (fort->unavailableUpgradeMessage.empty()) - fort->unavailableUpgradeMessage = parameters["unavailableUpgradeMessage"].String(); } VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index ab5fc3d50..73648b77b 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -1403,4 +1403,14 @@ void HillFort::fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) } } +std::string HillFort::getDescriptionToolTip() const +{ + return TextIdentifier(getObjectHandler()->getBaseTextID(), "description").get(); +} + +std::string HillFort::getUnavailableUpgradeMessage() const +{ + return TextIdentifier(getObjectHandler()->getBaseTextID(), "unavailableUpgradeMessage").get(); +} + VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index d52ae021e..475122310 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -451,8 +451,6 @@ class DLL_LINKAGE HillFort : public CGObjectInstance, public ICreatureUpgrader friend class HillFortInstanceConstructor; std::vector upgradeCostPercentage; - std::string descriptionToolTip; - std::string unavailableUpgradeMessage; protected: void onHeroVisit(const CGHeroInstance * h) const override; @@ -461,22 +459,13 @@ protected: public: using CGObjectInstance::CGObjectInstance; - const std::string & getDescriptionToolTip() const - { - return descriptionToolTip; - } - - const std::string & getUnavailableUpgradeMessage() const - { - return unavailableUpgradeMessage; - } + std::string getDescriptionToolTip() const; + std::string getUnavailableUpgradeMessage() const; template void serialize(Handler &h) { h & static_cast(*this); h & upgradeCostPercentage; - h & descriptionToolTip; - h & unavailableUpgradeMessage; } };