1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Inspector widgets set string ID

This commit is contained in:
nordsoft 2023-09-28 14:03:58 +02:00
parent 232b3e8cf6
commit 60df49236f
3 changed files with 36 additions and 27 deletions

View File

@ -301,26 +301,17 @@ void TextLocalizationContainer::registerString(const std::string & modContext, c
if(stringsLocalizations.count(UID.get()) > 0)
{
auto & value = stringsLocalizations[UID.get()];
if(value.baseLanguage.empty())
{
value.baseLanguage = language;
value.baseValue = localized;
}
else
{
if(value.baseValue != localized)
logMod->warn("Duplicate registered string '%s' found! Old value: '%s', new value: '%s'", UID.get(), value.baseValue, localized);
}
value.baseLanguage = language;
value.baseValue = localized;
}
else
{
StringState result;
result.baseLanguage = language;
result.baseValue = localized;
result.modContext = modContext;
StringState value;
value.baseLanguage = language;
value.baseValue = localized;
value.modContext = modContext;
stringsLocalizations[UID.get()] = result;
stringsLocalizations[UID.get()] = value;
}
}

View File

@ -277,8 +277,8 @@ void Inspector::updateProperties(CGHeroInstance * o)
delegate->options = {{"MALE", QVariant::fromValue(int(EHeroGender::MALE))}, {"FEMALE", QVariant::fromValue(int(EHeroGender::FEMALE))}};
addProperty<std::string>("Gender", (o->gender == EHeroGender::FEMALE ? "FEMALE" : "MALE"), delegate , false);
}
addProperty("Name", o->nameCustomTextId, false);
addProperty("Biography", o->biographyCustomTextId, new MessageDelegate, false);
addProperty("Name", o->getNameTranslated(), false);
addProperty("Biography", o->getBiographyTranslated(), new MessageDelegate, false);
addProperty("Portrait", o->portrait, false);
auto * delegate = new HeroSkillsDelegate(*o);
@ -531,7 +531,7 @@ void Inspector::setProperty(CGPandoraBox * o, const QString & key, const QVarian
if(!o) return;
if(key == "Message")
o->message.appendRawString(value.toString().toStdString());
o->message.appendTextID(mapWriteStringId(TextIdentifier("guards", o->instanceName, "message"), value.toString().toStdString()));
}
void Inspector::setProperty(CGEvent * o, const QString & key, const QVariant & value)
@ -553,7 +553,7 @@ void Inspector::setProperty(CGTownInstance * o, const QString & key, const QVari
if(!o) return;
if(key == "Town name")
o->setNameTextId(value.toString().toStdString());
o->setNameTextId(mapWriteStringId(TextIdentifier("town", o->instanceName, "name"), value.toString().toStdString()));
}
void Inspector::setProperty(CGSignBottle * o, const QString & key, const QVariant & value)
@ -561,7 +561,7 @@ void Inspector::setProperty(CGSignBottle * o, const QString & key, const QVarian
if(!o) return;
if(key == "Message")
o->message.appendRawString(value.toString().toStdString());
o->message.appendTextID(mapWriteStringId(TextIdentifier("sign", o->instanceName, "message"), value.toString().toStdString()));
}
void Inspector::setProperty(CGMine * o, const QString & key, const QVariant & value)
@ -577,7 +577,7 @@ void Inspector::setProperty(CGArtifact * o, const QString & key, const QVariant
if(!o) return;
if(key == "Message")
o->message.appendRawString(value.toString().toStdString());
o->message.appendTextID(mapWriteStringId(TextIdentifier("guards", o->instanceName, "message"), value.toString().toStdString()));
if(o->storedArtifact && key == "Spell")
{
@ -606,7 +606,10 @@ void Inspector::setProperty(CGHeroInstance * o, const QString & key, const QVari
o->gender = EHeroGender(value.toInt());
if(key == "Name")
o->nameCustomTextId = value.toString().toStdString();
o->nameCustomTextId = mapWriteStringId(TextIdentifier("hero", o->instanceName, "name"), value.toString().toStdString());
if(key == "Biography")
o->biographyCustomTextId = mapWriteStringId(TextIdentifier("hero", o->instanceName, "biography"), value.toString().toStdString());
if(key == "Experience")
o->exp = value.toString().toInt();
@ -643,7 +646,7 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant
if(!o) return;
if(key == "Message")
o->message.appendRawString(value.toString().toStdString());
o->message.appendTextID(mapWriteStringId(TextIdentifier("monster", o->instanceName, "message"), value.toString().toStdString()));
if(key == "Character")
o->character = CGCreature::Character(value.toInt());
if(key == "Never flees")
@ -661,11 +664,11 @@ void Inspector::setProperty(CGSeerHut * o, const QString & key, const QVariant &
if(key == "Mission type")
o->quest->missionType = CQuest::Emission(value.toInt());
if(key == "First visit text")
o->quest->firstVisitText.appendRawString(value.toString().toStdString());
o->quest->firstVisitText.appendTextID(mapWriteStringId(TextIdentifier("quest", o->instanceName, "firstVisit"), value.toString().toStdString()));
if(key == "Next visit text")
o->quest->nextVisitText.appendRawString(value.toString().toStdString());
o->quest->nextVisitText.appendTextID(mapWriteStringId(TextIdentifier("quest", o->instanceName, "nextVisit"), value.toString().toStdString()));
if(key == "Completed text")
o->quest->completedText.appendRawString(value.toString().toStdString());
o->quest->completedText.appendTextID(mapWriteStringId(TextIdentifier("quest", o->instanceName, "completed"), value.toString().toStdString()));
}
@ -713,6 +716,11 @@ QTableWidgetItem * Inspector::addProperty(const std::string & value)
return addProperty(QString::fromStdString(value));
}
QTableWidgetItem * Inspector::addProperty(const TextIdentifier & value)
{
return addProperty(VLC->generaltexth->translate(value.get()));
}
QTableWidgetItem * Inspector::addProperty(const MetaString & value)
{
return addProperty(value.toString());
@ -797,6 +805,12 @@ Inspector::Inspector(CMap * m, CGObjectInstance * o, QTableWidget * t): obj(o),
{
}
std::string Inspector::mapWriteStringId(const TextIdentifier & stringIdentifier, const std::string & localized)
{
map->registerString("map", stringIdentifier, localized);
return stringIdentifier.get();
}
/*
* Delegates
*/

View File

@ -18,6 +18,7 @@
#include "../lib/mapObjects/CGCreature.h"
#include "../lib/mapObjects/MapObjects.h"
#include "../lib/mapObjects/CRewardableObject.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/ResourceSet.h"
#include "../lib/MetaString.h"
@ -85,6 +86,7 @@ protected:
QTableWidgetItem * addProperty(unsigned int value);
QTableWidgetItem * addProperty(int value);
QTableWidgetItem * addProperty(const MetaString & value);
QTableWidgetItem * addProperty(const TextIdentifier & value);
QTableWidgetItem * addProperty(const std::string & value);
QTableWidgetItem * addProperty(const QString & value);
QTableWidgetItem * addProperty(const int3 & value);
@ -146,6 +148,8 @@ protected:
{
addProperty<T>(key, value, nullptr, restricted);
}
std::string mapWriteStringId(const TextIdentifier & stringIdentifier, const std::string & localized);
protected:
int row = 0;