浏览代码

Names for terrains now pass through translator

Ivan Savenko 2 年之前
父节点
当前提交
009705e794
共有 3 个文件被更改,包括 17 次插入16 次删除
  1. 1 2
      client/mapHandler.cpp
  2. 14 14
      lib/Terrain.cpp
  3. 2 0
      lib/Terrain.h

+ 1 - 2
client/mapHandler.cpp

@@ -1390,7 +1390,7 @@ void CMapHandler::getTerrainDescr(const int3 & pos, std::string & out, bool isRM
 	}
 
 	if(!isTile2Terrain || out.empty())
-		out = t.terType->getName();
+		out = t.terType->getNameTranslated();
 
 	if(t.getDiggingStatus(false) == EDiggingStatus::CAN_DIG)
 	{
@@ -1486,4 +1486,3 @@ TerrainTileObject::TerrainTileObject(const CGObjectInstance * obj_, SDL_Rect rec
 TerrainTileObject::~TerrainTileObject()
 {
 }
-

+ 14 - 14
lib/Terrain.cpp

@@ -20,25 +20,13 @@ VCMI_LIB_NAMESPACE_BEGIN
 //("allowedTerrain"\s*:\s*\[.*)9(.*\],\n)
 //\1"rock"\2
 
-/*
-TerrainTypeHandler::TerrainTypeHandler()
-{
-	auto allConfigs = VLC->modh->getActiveMods();
-	allConfigs.insert(allConfigs.begin(), CModHandler::scopeBuiltin());
-
-	initRivers(allConfigs);
-	recreateRiverMaps();
-	initRoads(allConfigs);
-	recreateRoadMaps();
-	initTerrains(allConfigs); //maps will be populated inside
-}*/
-
 TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
 {
 	TerrainType * info = new TerrainType;
 
 	info->id = TerrainId(index);
 	info->identifier = identifier;
+	info->modScope = scope;
 
 	info->moveCost = static_cast<int>(json["moveCost"].Integer());
 	info->musicFilename = json["music"].String();
@@ -47,7 +35,8 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
 	info->horseSoundPenalty = json["horseSoundPenalty"].String();
 	info->transitionRequired = json["transitionRequired"].Bool();
 	info->terrainViewPatterns = json["terrainViewPatterns"].String();
-	//info->nameTranslated = json["nameTranslated"].String();
+
+	VLC->generaltexth->registerString(info->getNameTextID(), json["text"].String());
 
 	const JsonVector & unblockedVec = json["minimapUnblocked"].Vector();
 	info->minimapUnblocked =
@@ -266,6 +255,17 @@ bool TerrainType::isTransitionRequired() const
 	return transitionRequired;
 }
 
+std::string TerrainType::getNameTextID() const
+{
+	TextIdentifier id{ "terrain", modScope, identifier,  "name" };
+	return id.get();
+}
+
+std::string TerrainType::getNameTranslated() const
+{
+	return VLC->generaltexth->translate(getNameTextID());
+}
+
 TerrainType::TerrainType()
 {}
 

+ 2 - 0
lib/Terrain.h

@@ -22,6 +22,7 @@ VCMI_LIB_NAMESPACE_BEGIN
 class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
 {
 	friend class TerrainTypeHandler;
+	std::string modScope;
 	std::string identifier;
 	TerrainId id;
 	ui8 passabilityType;
@@ -79,6 +80,7 @@ public:
 		h & prohibitTransitions;
 		h & minimapBlocked;
 		h & minimapUnblocked;
+		h & modScope;
 		h & identifier;
 		h & musicFilename;
 		h & tilesFilename;