mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-17 20:58:07 +02:00
Implemented translation support for random map descriptions
This commit is contained in:
parent
1826b5bbdf
commit
c43844706e
@ -60,6 +60,16 @@
|
||||
"vcmi.radialWheel.moveUp" : "Move up",
|
||||
"vcmi.radialWheel.moveDown" : "Move down",
|
||||
"vcmi.radialWheel.moveBottom" : "Move to bottom",
|
||||
|
||||
"vcmi.randomMap.description" : "Map created by the Random Map Generator.\nTemplate was %s, size %dx%d, levels %d, players %d, computers %d, water %s, monster %s, VCMI map",
|
||||
"vcmi.randomMap.description.isHuman" : ", %s is human",
|
||||
"vcmi.randomMap.description.townChoice" : ", %s town choice is %s",
|
||||
"vcmi.randomMap.description.water.none" : "none",
|
||||
"vcmi.randomMap.description.water.normal" : "normal",
|
||||
"vcmi.randomMap.description.water.islands" : "islands",
|
||||
"vcmi.randomMap.description.monster.weak" : "weak",
|
||||
"vcmi.randomMap.description.monster.normal" : "normal",
|
||||
"vcmi.randomMap.description.monster.strong" : "strong",
|
||||
|
||||
"vcmi.spellBook.search" : "search...",
|
||||
|
||||
|
@ -152,41 +152,55 @@ std::unique_ptr<CMap> CMapGenerator::generate()
|
||||
return std::move(map->mapInstance);
|
||||
}
|
||||
|
||||
std::string CMapGenerator::getMapDescription() const
|
||||
MetaString CMapGenerator::getMapDescription() const
|
||||
{
|
||||
assert(map);
|
||||
const TextIdentifier mainPattern("vcmi", "randomMap", "description");
|
||||
const TextIdentifier isHuman("vcmi", "randomMap", "description", "isHuman");
|
||||
const TextIdentifier townChoiceIs("vcmi", "randomMap", "description", "townChoice");
|
||||
const std::array waterContent = {
|
||||
TextIdentifier("vcmi", "randomMap", "description", "water", "none"),
|
||||
TextIdentifier("vcmi", "randomMap", "description", "water", "normal"),
|
||||
TextIdentifier("vcmi", "randomMap", "description", "water", "islands")
|
||||
};
|
||||
const std::array monsterStrength = {
|
||||
TextIdentifier("vcmi", "randomMap", "description", "monster", "weak"),
|
||||
TextIdentifier("vcmi", "randomMap", "description", "monster", "normal"),
|
||||
TextIdentifier("vcmi", "randomMap", "description", "monster", "strong")
|
||||
};
|
||||
|
||||
const std::string waterContentStr[3] = { "none", "normal", "islands" };
|
||||
const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" };
|
||||
|
||||
int monsterStrengthIndex = mapGenOptions.getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0
|
||||
const auto * mapTemplate = mapGenOptions.getMapTemplate();
|
||||
int monsterStrengthIndex = mapGenOptions.getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0
|
||||
|
||||
if(!mapTemplate)
|
||||
throw rmgException("Map template for Random Map Generator is not found. Could not start the game.");
|
||||
MetaString result = MetaString::createFromTextID(mainPattern.get());
|
||||
|
||||
std::stringstream ss;
|
||||
ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, size %dx%d") +
|
||||
", levels %d, players %d, computers %d, water %s, monster %s, VCMI map") % mapTemplate->getName() %
|
||||
map->width() % map->height() % static_cast<int>(map->levels()) % static_cast<int>(mapGenOptions.getHumanOrCpuPlayerCount()) %
|
||||
static_cast<int>(mapGenOptions.getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions.getWaterContent()] %
|
||||
monsterStrengthStr[monsterStrengthIndex]);
|
||||
result.replaceRawString(mapTemplate->getName());
|
||||
result.replaceNumber(map->width());
|
||||
result.replaceNumber(map->height());
|
||||
result.replaceNumber(map->levels());
|
||||
result.replaceNumber(mapGenOptions.getHumanOrCpuPlayerCount());
|
||||
result.replaceNumber(mapGenOptions.getCompOnlyPlayerCount());
|
||||
result.replaceTextID(waterContent.at(mapGenOptions.getWaterContent()).get());
|
||||
result.replaceTextID(monsterStrength.at(monsterStrengthIndex).get());
|
||||
|
||||
for(const auto & pair : mapGenOptions.getPlayersSettings())
|
||||
{
|
||||
const auto & pSettings = pair.second;
|
||||
|
||||
if(pSettings.getPlayerType() == EPlayerType::HUMAN)
|
||||
{
|
||||
ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()] << " is human";
|
||||
result.appendTextID(isHuman.get());
|
||||
result.replaceName(pSettings.getColor());
|
||||
}
|
||||
|
||||
if(pSettings.getStartingTown() != FactionID::RANDOM)
|
||||
{
|
||||
ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()]
|
||||
<< " town choice is " << (*VLC->townh)[pSettings.getStartingTown()]->getNameTranslated();
|
||||
result.appendTextID(townChoiceIs.get());
|
||||
result.replaceName(pSettings.getColor());
|
||||
result.replaceName(pSettings.getStartingTown());
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
void CMapGenerator::addPlayerInfo()
|
||||
@ -451,7 +465,7 @@ void CMapGenerator::addHeaderInfo()
|
||||
m.height = mapGenOptions.getHeight();
|
||||
m.twoLevel = mapGenOptions.getHasTwoLevels();
|
||||
m.name.appendLocalString(EMetaText::GENERAL_TXT, 740);
|
||||
m.description.appendRawString(getMapDescription());
|
||||
m.description = getMapDescription();
|
||||
m.difficulty = EMapDifficulty::NORMAL;
|
||||
addPlayerInfo();
|
||||
m.waterMap = (mapGenOptions.getWaterContent() != EWaterContent::EWaterContent::NONE);
|
||||
|
@ -10,14 +10,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../GameConstants.h"
|
||||
#include "CMapGenOptions.h"
|
||||
#include "../int3.h"
|
||||
#include "CRmgTemplate.h"
|
||||
#include "../LoadProgress.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class MetaString;
|
||||
class CRmgTemplate;
|
||||
class CMapGenOptions;
|
||||
class JsonNode;
|
||||
@ -93,7 +91,7 @@ private:
|
||||
/// Generation methods
|
||||
void loadConfig();
|
||||
|
||||
std::string getMapDescription() const;
|
||||
MetaString getMapDescription() const;
|
||||
|
||||
void initPrisonsRemaining();
|
||||
void initQuestArtsRemaining();
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "CArtHandler.h"
|
||||
#include "CCreatureHandler.h"
|
||||
#include "CCreatureSet.h"
|
||||
#include "entities/faction/CFaction.h"
|
||||
#include "texts/CGeneralTextHandler.h"
|
||||
#include "CSkillHandler.h"
|
||||
#include "GameConstants.h"
|
||||
@ -387,6 +388,11 @@ void MetaString::replaceName(const ArtifactID & id)
|
||||
replaceTextID(id.toEntity(VLC)->getNameTextID());
|
||||
}
|
||||
|
||||
void MetaString::replaceName(const FactionID & id)
|
||||
{
|
||||
replaceTextID(id.toEntity(VLC)->getNameTextID());
|
||||
}
|
||||
|
||||
void MetaString::replaceName(const MapObjectID& id)
|
||||
{
|
||||
replaceTextID(VLC->objtypeh->getObjectName(id, 0));
|
||||
|
@ -21,6 +21,7 @@ class MapObjectSubID;
|
||||
class PlayerColor;
|
||||
class SecondarySkill;
|
||||
class SpellID;
|
||||
class FactionID;
|
||||
class GameResID;
|
||||
using TQuantity = si32;
|
||||
|
||||
@ -97,6 +98,7 @@ public:
|
||||
void replacePositiveNumber(int64_t txt);
|
||||
|
||||
void replaceName(const ArtifactID & id);
|
||||
void replaceName(const FactionID& id);
|
||||
void replaceName(const MapObjectID& id);
|
||||
void replaceName(const PlayerColor& id);
|
||||
void replaceName(const SecondarySkill& id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user