mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Add string IDs in map editor
This commit is contained in:
parent
60df49236f
commit
98fde9ab1d
@ -168,4 +168,16 @@ void CMapHeader::registerMapStrings()
|
||||
registerString("map", TextIdentifier(s.first), s.second.String(), language);
|
||||
}
|
||||
|
||||
std::string mapRegisterLocalizedString(CMapHeader & mapHeader, const TextIdentifier & UID, const std::string & localized)
|
||||
{
|
||||
return mapRegisterLocalizedString(mapHeader, UID, localized, VLC->generaltexth->getPreferredLanguage());
|
||||
}
|
||||
|
||||
std::string mapRegisterLocalizedString(CMapHeader & mapHeader, const TextIdentifier & UID, const std::string & localized, const std::string & language)
|
||||
{
|
||||
mapHeader.registerString("map", UID, localized, language);
|
||||
mapHeader.translations.Struct()[language].Struct()[UID.get()].String() = localized;
|
||||
return UID.get();
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -280,4 +280,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// wrapper functions to register string into the map and stores its translation
|
||||
std::string DLL_LINKAGE mapRegisterLocalizedString(CMapHeader & mapHeader, const TextIdentifier & UID, const std::string & localized);
|
||||
std::string DLL_LINKAGE mapRegisterLocalizedString(CMapHeader & mapHeader, const TextIdentifier & UID, const std::string & localized, const std::string & language);
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -319,8 +319,10 @@ TModID CModHandler::findResourceOrigin(const ResourcePath & name)
|
||||
|
||||
std::string CModHandler::getModLanguage(const TModID& modId) const
|
||||
{
|
||||
if ( modId == "core")
|
||||
if(modId == "core")
|
||||
return VLC->generaltexth->getInstalledLanguage();
|
||||
if(modId == "map")
|
||||
return VLC->generaltexth->getPreferredLanguage();
|
||||
return allMods.at(modId).baseLanguage;
|
||||
}
|
||||
|
||||
|
@ -531,7 +531,7 @@ void Inspector::setProperty(CGPandoraBox * o, const QString & key, const QVarian
|
||||
if(!o) return;
|
||||
|
||||
if(key == "Message")
|
||||
o->message.appendTextID(mapWriteStringId(TextIdentifier("guards", o->instanceName, "message"), value.toString().toStdString()));
|
||||
o->message.appendTextID(mapRegisterLocalizedString(*map, 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(mapWriteStringId(TextIdentifier("town", o->instanceName, "name"), value.toString().toStdString()));
|
||||
o->setNameTextId(mapRegisterLocalizedString(*map, 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.appendTextID(mapWriteStringId(TextIdentifier("sign", o->instanceName, "message"), value.toString().toStdString()));
|
||||
o->message.appendTextID(mapRegisterLocalizedString(*map, 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.appendTextID(mapWriteStringId(TextIdentifier("guards", o->instanceName, "message"), value.toString().toStdString()));
|
||||
o->message.appendTextID(mapRegisterLocalizedString(*map, TextIdentifier("guards", o->instanceName, "message"), value.toString().toStdString()));
|
||||
|
||||
if(o->storedArtifact && key == "Spell")
|
||||
{
|
||||
@ -606,10 +606,10 @@ void Inspector::setProperty(CGHeroInstance * o, const QString & key, const QVari
|
||||
o->gender = EHeroGender(value.toInt());
|
||||
|
||||
if(key == "Name")
|
||||
o->nameCustomTextId = mapWriteStringId(TextIdentifier("hero", o->instanceName, "name"), value.toString().toStdString());
|
||||
o->nameCustomTextId = mapRegisterLocalizedString(*map, TextIdentifier("hero", o->instanceName, "name"), value.toString().toStdString());
|
||||
|
||||
if(key == "Biography")
|
||||
o->biographyCustomTextId = mapWriteStringId(TextIdentifier("hero", o->instanceName, "biography"), value.toString().toStdString());
|
||||
o->biographyCustomTextId = mapRegisterLocalizedString(*map, TextIdentifier("hero", o->instanceName, "biography"), value.toString().toStdString());
|
||||
|
||||
if(key == "Experience")
|
||||
o->exp = value.toString().toInt();
|
||||
@ -646,7 +646,7 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant
|
||||
if(!o) return;
|
||||
|
||||
if(key == "Message")
|
||||
o->message.appendTextID(mapWriteStringId(TextIdentifier("monster", o->instanceName, "message"), value.toString().toStdString()));
|
||||
o->message.appendTextID(mapRegisterLocalizedString(*map, TextIdentifier("monster", o->instanceName, "message"), value.toString().toStdString()));
|
||||
if(key == "Character")
|
||||
o->character = CGCreature::Character(value.toInt());
|
||||
if(key == "Never flees")
|
||||
@ -664,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.appendTextID(mapWriteStringId(TextIdentifier("quest", o->instanceName, "firstVisit"), value.toString().toStdString()));
|
||||
o->quest->firstVisitText.appendTextID(mapRegisterLocalizedString(*map, TextIdentifier("quest", o->instanceName, "firstVisit"), value.toString().toStdString()));
|
||||
if(key == "Next visit text")
|
||||
o->quest->nextVisitText.appendTextID(mapWriteStringId(TextIdentifier("quest", o->instanceName, "nextVisit"), value.toString().toStdString()));
|
||||
o->quest->nextVisitText.appendTextID(mapRegisterLocalizedString(*map, TextIdentifier("quest", o->instanceName, "nextVisit"), value.toString().toStdString()));
|
||||
if(key == "Completed text")
|
||||
o->quest->completedText.appendTextID(mapWriteStringId(TextIdentifier("quest", o->instanceName, "completed"), value.toString().toStdString()));
|
||||
o->quest->completedText.appendTextID(mapRegisterLocalizedString(*map, TextIdentifier("quest", o->instanceName, "completed"), value.toString().toStdString()));
|
||||
}
|
||||
|
||||
|
||||
@ -805,12 +805,6 @@ 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
|
||||
*/
|
||||
|
@ -149,8 +149,6 @@ protected:
|
||||
addProperty<T>(key, value, nullptr, restricted);
|
||||
}
|
||||
|
||||
std::string mapWriteStringId(const TextIdentifier & stringIdentifier, const std::string & localized);
|
||||
|
||||
protected:
|
||||
int row = 0;
|
||||
QTableWidget * table;
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "../lib/mapObjects/CGPandoraBox.h"
|
||||
#include "../lib/mapObjects/CQuest.h"
|
||||
|
||||
RewardsWidget::RewardsWidget(const CMap & m, CRewardableObject & p, QWidget *parent) :
|
||||
RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
map(m),
|
||||
object(p),
|
||||
@ -211,7 +211,7 @@ bool RewardsWidget::commitChanges()
|
||||
if(ui->onSelectText->text().isEmpty())
|
||||
object.configuration.onSelect.clear();
|
||||
else
|
||||
object.configuration.onSelect = MetaString::createFromRawString(ui->onSelectText->text().toStdString());
|
||||
object.configuration.onSelect = MetaString::createFromTextID(mapRegisterLocalizedString(map, TextIdentifier("reward", object.instanceName, "onSelect"), ui->onSelectText->text().toStdString()));
|
||||
object.configuration.canRefuse = ui->canRefuse->isChecked();
|
||||
|
||||
//reset parameters
|
||||
@ -232,7 +232,7 @@ void RewardsWidget::saveCurrentVisitInfo(int index)
|
||||
if(ui->rewardMessage->text().isEmpty())
|
||||
vinfo.message.clear();
|
||||
else
|
||||
vinfo.message = MetaString::createFromRawString(ui->rewardMessage->text().toStdString());
|
||||
vinfo.message = MetaString::createFromTextID(mapRegisterLocalizedString(map, TextIdentifier("reward", object.instanceName, "info", index, "message"), ui->rewardMessage->text().toStdString()));
|
||||
|
||||
vinfo.reward.heroLevel = ui->rHeroLevel->value();
|
||||
vinfo.reward.heroExperience = ui->rHeroExperience->value();
|
||||
@ -649,7 +649,7 @@ void RewardsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c
|
||||
}
|
||||
}
|
||||
|
||||
RewardsDelegate::RewardsDelegate(const CMap & m, CRewardableObject & t): map(m), object(t)
|
||||
RewardsDelegate::RewardsDelegate(CMap & m, CRewardableObject & t): map(m), object(t)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ class RewardsWidget : public QDialog
|
||||
|
||||
public:
|
||||
|
||||
explicit RewardsWidget(const CMap &, CRewardableObject &, QWidget *parent = nullptr);
|
||||
explicit RewardsWidget(CMap &, CRewardableObject &, QWidget *parent = nullptr);
|
||||
~RewardsWidget();
|
||||
|
||||
void obtainData();
|
||||
@ -64,14 +64,14 @@ private:
|
||||
|
||||
Ui::RewardsWidget *ui;
|
||||
CRewardableObject & object;
|
||||
const CMap & map;
|
||||
CMap & map;
|
||||
};
|
||||
|
||||
class RewardsDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RewardsDelegate(const CMap &, CRewardableObject &);
|
||||
RewardsDelegate(CMap &, CRewardableObject &);
|
||||
|
||||
using QStyledItemDelegate::QStyledItemDelegate;
|
||||
|
||||
@ -82,5 +82,5 @@ public:
|
||||
|
||||
private:
|
||||
CRewardableObject & object;
|
||||
const CMap & map;
|
||||
CMap & map;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user