mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Use meta string for messages
This commit is contained in:
parent
03c099d4fd
commit
ab373f08ab
@ -102,7 +102,7 @@ void MetaString::clear()
|
||||
|
||||
bool MetaString::empty() const
|
||||
{
|
||||
return message.empty();
|
||||
return message.empty() || toString().empty();
|
||||
}
|
||||
|
||||
std::string MetaString::getLocalString(const std::pair<EMetaText, ui32> & txt) const
|
||||
|
@ -35,7 +35,7 @@ void CGPandoraBox::init()
|
||||
{
|
||||
i.reward.removeObject = true;
|
||||
if(!message.empty() && i.message.empty())
|
||||
i.message = MetaString::createFromRawString(message);
|
||||
i.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
CRewardableObject::serializeJsonOptions(handler);
|
||||
|
||||
handler.serializeString("guardMessage", message);
|
||||
handler.serializeStruct("guardMessage", message);
|
||||
|
||||
if(!handler.saving)
|
||||
{
|
||||
@ -297,7 +297,7 @@ void CGEvent::init()
|
||||
{
|
||||
i.reward.removeObject = removeAfterVisit;
|
||||
if(!message.empty() && i.message.empty())
|
||||
i.message = MetaString::createFromRawString(message);
|
||||
i.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ void CGEvent::activated( const CGHeroInstance * h ) const
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
if(!message.empty())
|
||||
iw.text.appendRawString(message);
|
||||
iw.text = message;
|
||||
else
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 16);
|
||||
cb->showInfoDialog(&iw);
|
||||
|
@ -19,7 +19,7 @@ struct InfoWindow;
|
||||
class DLL_LINKAGE CGPandoraBox : public CRewardableObject
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
MetaString message;
|
||||
|
||||
void initObj(CRandomGenerator & rand) override;
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
|
@ -268,7 +268,7 @@ void CGResource::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
BlockingDialog ynd(true,false);
|
||||
ynd.player = h->getOwner();
|
||||
ynd.text.appendRawString(message);
|
||||
ynd.text = message;
|
||||
cb->showBlockingDialog(&ynd);
|
||||
}
|
||||
else
|
||||
@ -288,7 +288,7 @@ void CGResource::collectRes(const PlayerColor & player) const
|
||||
if(!message.empty())
|
||||
{
|
||||
sii.type = EInfoWindowMode::AUTO;
|
||||
sii.text.appendRawString(message);
|
||||
sii.text = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -320,7 +320,7 @@ void CGResource::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
if(!handler.saving && !handler.getCurrent()["guards"].Vector().empty())
|
||||
CCreatureSet::serializeJson(handler, "guards", 7);
|
||||
handler.serializeInt("amount", amount, 0);
|
||||
handler.serializeString("guardMessage", message);
|
||||
handler.serializeStruct("guardMessage", message);
|
||||
}
|
||||
|
||||
bool CGTeleport::isEntrance() const
|
||||
@ -728,8 +728,8 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
|
||||
case Obj::ARTIFACT:
|
||||
{
|
||||
iw.components.emplace_back(Component::EComponentType::ARTIFACT, subID, 0, 0);
|
||||
if(message.length())
|
||||
iw.text.appendRawString(message);
|
||||
if(!message.empty())
|
||||
iw.text = message;
|
||||
else
|
||||
iw.text.appendLocalString(EMetaText::ART_EVNTS, subID);
|
||||
}
|
||||
@ -738,8 +738,8 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
int spellID = storedArtifact->getScrollSpellID();
|
||||
iw.components.emplace_back(Component::EComponentType::SPELL, spellID, 0, 0);
|
||||
if(message.length())
|
||||
iw.text.appendRawString(message);
|
||||
if(!message.empty())
|
||||
iw.text = message;
|
||||
else
|
||||
{
|
||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT,135);
|
||||
@ -764,8 +764,8 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
BlockingDialog ynd(true,false);
|
||||
ynd.player = h->getOwner();
|
||||
if(message.length())
|
||||
ynd.text.appendRawString(message);
|
||||
if(!message.empty())
|
||||
ynd.text = message;
|
||||
else
|
||||
{
|
||||
// TODO: Guard text is more complex in H3, see mantis issue 2325 for details
|
||||
@ -779,11 +779,11 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
|
||||
break;
|
||||
case Obj::SPELL_SCROLL:
|
||||
{
|
||||
if(message.length())
|
||||
if(!message.empty())
|
||||
{
|
||||
BlockingDialog ynd(true,false);
|
||||
ynd.player = h->getOwner();
|
||||
ynd.text.appendRawString(message);
|
||||
ynd.text = message;
|
||||
cb->showBlockingDialog(&ynd);
|
||||
}
|
||||
else
|
||||
@ -828,7 +828,7 @@ void CGArtifact::afterAddToMap(CMap * map)
|
||||
|
||||
void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler)
|
||||
{
|
||||
handler.serializeString("guardMessage", message);
|
||||
handler.serializeStruct("guardMessage", message);
|
||||
CArmedInstance::serializeJsonOptions(handler);
|
||||
if(!handler.saving && !handler.getCurrent()["guards"].Vector().empty())
|
||||
CCreatureSet::serializeJson(handler, "guards", 7);
|
||||
@ -1046,7 +1046,7 @@ void CGSignBottle::initObj(CRandomGenerator & rand)
|
||||
{
|
||||
auto vector = VLC->generaltexth->findStringsWithPrefix("core.randsign");
|
||||
std::string messageIdentifier = *RandomGeneratorUtil::nextItem(vector, rand);
|
||||
message = VLC->generaltexth->translate(messageIdentifier);
|
||||
message.appendTextID(TextIdentifier("core", "randsign", messageIdentifier).get());
|
||||
}
|
||||
|
||||
if(ID == Obj::OCEAN_BOTTLE)
|
||||
@ -1059,7 +1059,7 @@ void CGSignBottle::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.player = h->getOwner();
|
||||
iw.text.appendRawString(message);
|
||||
iw.text = message;
|
||||
cb->showInfoDialog(&iw);
|
||||
|
||||
if(ID == Obj::OCEAN_BOTTLE)
|
||||
@ -1068,7 +1068,7 @@ void CGSignBottle::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
void CGSignBottle::serializeJsonOptions(JsonSerializeFormat& handler)
|
||||
{
|
||||
handler.serializeString("text", message);
|
||||
handler.serializeStruct("text", message);
|
||||
}
|
||||
|
||||
void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
MetaString message;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
void initObj(CRandomGenerator & rand) override;
|
||||
@ -119,7 +119,7 @@ class DLL_LINKAGE CGArtifact : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
CArtifactInstance * storedArtifact = nullptr;
|
||||
std::string message;
|
||||
MetaString message;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
|
||||
@ -149,7 +149,7 @@ public:
|
||||
static constexpr ui32 RANDOM_AMOUNT = 0;
|
||||
ui32 amount = RANDOM_AMOUNT; //0 if random
|
||||
|
||||
std::string message;
|
||||
MetaString message;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||
void initObj(CRandomGenerator & rand) override;
|
||||
|
@ -1135,7 +1135,7 @@ CGObjectInstance * CMapLoaderH3M::readMonster(const int3 & mapPosition, const Ob
|
||||
CGObjectInstance * CMapLoaderH3M::readSign(const int3 & mapPosition)
|
||||
{
|
||||
auto * object = new CGSignBottle();
|
||||
object->message = readLocalizedString(TextIdentifier("sign", mapPosition.x, mapPosition.y, mapPosition.z, "message"));
|
||||
object->message.appendTextID(readLocalizedString(TextIdentifier("sign", mapPosition.x, mapPosition.y, mapPosition.z, "message")));
|
||||
reader->skipZero(4);
|
||||
return object;
|
||||
}
|
||||
@ -2247,12 +2247,12 @@ void CMapLoaderH3M::readEvents()
|
||||
}
|
||||
}
|
||||
|
||||
void CMapLoaderH3M::readMessageAndGuards(std::string & message, CCreatureSet * guards, const int3 & position)
|
||||
void CMapLoaderH3M::readMessageAndGuards(MetaString & message, CCreatureSet * guards, const int3 & position)
|
||||
{
|
||||
bool hasMessage = reader->readBool();
|
||||
if(hasMessage)
|
||||
{
|
||||
message = readLocalizedString(TextIdentifier("guards", position.x, position.y, position.z, "message"));
|
||||
message.appendTextID(readLocalizedString(TextIdentifier("guards", position.x, position.y, position.z, "message")));
|
||||
bool hasGuards = reader->readBool();
|
||||
if(hasGuards)
|
||||
readCreatureSet(guards, 7);
|
||||
|
@ -17,6 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class CGHeroInstance;
|
||||
class MapReaderH3M;
|
||||
class MetaString;
|
||||
class CArtifactInstance;
|
||||
class CGObjectInstance;
|
||||
class CGSeerHut;
|
||||
@ -215,7 +216,7 @@ private:
|
||||
/**
|
||||
* read optional message and optional guards
|
||||
*/
|
||||
void readMessageAndGuards(std::string & message, CCreatureSet * guards, const int3 & position);
|
||||
void readMessageAndGuards(MetaString & message, CCreatureSet * guards, const int3 & position);
|
||||
|
||||
/// reads string from input stream and converts it to unicode
|
||||
std::string readBasicString();
|
||||
|
Loading…
Reference in New Issue
Block a user