- added the beginning work to support translatable techtrees
This commit is contained in:
parent
5c0db25c86
commit
897346d1f5
|
@ -63,7 +63,7 @@ ProduceTask::ProduceTask(const ResourceType *resourceType) : Task() {
|
|||
string ProduceTask::toString() const{
|
||||
string str= "Produce ";
|
||||
if(unitType!=NULL){
|
||||
str+= unitType->getName();
|
||||
str+= unitType->getName(true);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ BuildTask::BuildTask(const UnitType *unitType, const Vec2i &pos){
|
|||
string BuildTask::toString() const{
|
||||
string str= "Build ";
|
||||
if(unitType!=NULL){
|
||||
str+= unitType->getName();
|
||||
str+= unitType->getName(true);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -17,10 +17,13 @@
|
|||
#include <algorithm>
|
||||
#include "xml_parser.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
//#include "util.h"
|
||||
#include "platform_common.h"
|
||||
#include "conversion.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::PlatformCommon;
|
||||
using Shared::Xml::XmlNode;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "core_data.h"
|
||||
#include "renderer.h"
|
||||
#include <algorithm>
|
||||
#include "config.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -238,6 +239,48 @@ void Lang::loadScenarioStrings(string scenarioDir, string scenarioName){
|
|||
}
|
||||
}
|
||||
|
||||
void Lang::loadTechTreeStrings(string techTree) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] techTree = [%s]\n",__FILE__,__FUNCTION__,__LINE__,techTree.c_str());
|
||||
|
||||
string currentPath = "";
|
||||
Config &config = Config::getInstance();
|
||||
vector<string> techPaths = config.getPathListForType(ptTechs);
|
||||
for(int idx = 0; idx < techPaths.size(); idx++) {
|
||||
string &techPath = techPaths[idx];
|
||||
endPathWithSlash(techPath);
|
||||
|
||||
//printf("techPath [%s]\n",techPath.c_str());
|
||||
|
||||
if(folderExists(techPath + techTree) == true) {
|
||||
currentPath = techPath;
|
||||
endPathWithSlash(currentPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string techTreeFolder = currentPath + techTree + "/";
|
||||
string path = techTreeFolder + "lang/" + techTree + "_" + language + ".lng";
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
|
||||
techTreeStrings.clear();
|
||||
|
||||
//try to load the current language first
|
||||
if(fileExists(path)) {
|
||||
techTreeStrings.load(path);
|
||||
}
|
||||
else {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path not found [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
|
||||
//try english otherwise
|
||||
path = techTreeFolder + "lang/" + techTree + "_english.lng";
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
|
||||
if(fileExists(path)) {
|
||||
techTreeStrings.load(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Lang::hasString(const string &s, string uselanguage, bool fallbackToDefault) {
|
||||
bool result = false;
|
||||
try {
|
||||
|
@ -333,6 +376,27 @@ string Lang::getScenarioString(const string &s) {
|
|||
}
|
||||
}
|
||||
|
||||
string Lang::getTechTreeString(const string &s,const char *defaultValue) {
|
||||
try{
|
||||
string result = "";
|
||||
|
||||
if(techTreeStrings.hasString(s) == true || defaultValue == NULL) {
|
||||
result = techTreeStrings.getString(s);
|
||||
}
|
||||
else if(defaultValue != NULL) {
|
||||
result = defaultValue;
|
||||
}
|
||||
replaceAll(result, "\\n", "\n");
|
||||
return result;
|
||||
}
|
||||
catch(exception &ex) {
|
||||
if(techTreeStrings.getpath() != "") {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
}
|
||||
return "???" + s + "???";
|
||||
}
|
||||
}
|
||||
|
||||
bool Lang::fileMatchesISO630Code(string uselanguage, string testLanguageFile) {
|
||||
bool result = false;
|
||||
Properties stringsTest;
|
||||
|
|
|
@ -37,6 +37,7 @@ private:
|
|||
|
||||
Properties strings;
|
||||
Properties scenarioStrings;
|
||||
Properties techTreeStrings;
|
||||
|
||||
std::map<string,Properties> otherLanguageStrings;
|
||||
|
||||
|
@ -54,10 +55,12 @@ public:
|
|||
|
||||
void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false);
|
||||
void loadScenarioStrings(string scenarioDir, string scenarioName);
|
||||
void loadTechTreeStrings(string techTree);
|
||||
|
||||
string get(const string &s,string uselanguage="", bool fallbackToDefault=false);
|
||||
bool hasString(const string &s, string uselanguage="", bool fallbackToDefault=false);
|
||||
string getScenarioString(const string &s);
|
||||
string getTechTreeString(const string &s, const char *defaultValue=NULL);
|
||||
|
||||
string getLanguage() const { return language; }
|
||||
bool isLanguageLocal(string compareLanguage) const;
|
||||
|
|
|
@ -769,7 +769,7 @@ void Gui::computeDisplay(){
|
|||
const Object *selectedResourceObject =getSelectedResourceObject();
|
||||
if(selection.isEmpty() && selectedResourceObject != NULL) {
|
||||
Resource *r = selectedResourceObject->getResource();
|
||||
display.setTitle(r->getType()->getName());
|
||||
display.setTitle(r->getType()->getName(true));
|
||||
display.setText(lang.get("Amount")+ ": "+intToStr(r->getAmount())+" / "+intToStr(r->getType()->getDefResPerPatch()));
|
||||
//display.setProgressBar(r->);
|
||||
display.setUpImage(0, r->getType()->getImage());
|
||||
|
|
|
@ -60,7 +60,7 @@ void Resource::init(const ResourceType *rt, const Vec2i &pos) {
|
|||
string Resource::getDescription() const {
|
||||
string str;
|
||||
|
||||
str+= type->getName();
|
||||
str+= type->getName(true);
|
||||
str+="\n";
|
||||
str+= intToStr(amount);
|
||||
str+="/";
|
||||
|
|
|
@ -798,7 +798,7 @@ string Unit::getFullName() const{
|
|||
if(type == NULL) {
|
||||
throw megaglest_runtime_error("type == NULL in Unit::getFullName()!");
|
||||
}
|
||||
str += type->getName();
|
||||
str += type->getName(true);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -2501,7 +2501,7 @@ string Unit::getDescExtension() const{
|
|||
if(i == 0){
|
||||
str+= "\n" + lang.get("OrdersOnQueue") + ": ";
|
||||
}
|
||||
str+= "\n#" + intToStr(i + 1) + " " + ct->getName();
|
||||
str+= "\n#" + intToStr(i + 1) + " " + ct->getName(true);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
@ -2572,7 +2572,7 @@ string Unit::getDesc() const {
|
|||
|
||||
//load
|
||||
if(loadCount!=0){
|
||||
str+= "\n" + lang.get("Load")+ ": " + intToStr(loadCount) +" " + loadType->getName();
|
||||
str+= "\n" + lang.get("Load")+ ": " + intToStr(loadCount) +" " + loadType->getName(true);
|
||||
}
|
||||
|
||||
//consumable production
|
||||
|
@ -2581,13 +2581,13 @@ string Unit::getDesc() const {
|
|||
if(r->getType()->getClass() == rcConsumable) {
|
||||
str+= "\n";
|
||||
str+= r->getAmount() < 0 ? lang.get("Produce")+": ": lang.get("Consume")+": ";
|
||||
str+= intToStr(abs(r->getAmount())) + " " + r->getType()->getName();
|
||||
str+= intToStr(abs(r->getAmount())) + " " + r->getType()->getName(true);
|
||||
}
|
||||
}
|
||||
|
||||
//command info
|
||||
if(commands.empty() == false) {
|
||||
str+= "\n" + commands.front()->getCommandType()->getName();
|
||||
str+= "\n" + commands.front()->getCommandType()->getName(true);
|
||||
if(commands.size() > 1) {
|
||||
str+= "\n" + lang.get("OrdersOnQueue") + ": " + intToStr(commands.size());
|
||||
}
|
||||
|
@ -2598,7 +2598,7 @@ string Unit::getDesc() const {
|
|||
for(int i = 0; i < getType()->getStoredResourceCount(); ++i) {
|
||||
const Resource *r= getType()->getStoredResource(i);
|
||||
str+= "\n" + lang.get("Store") + ": ";
|
||||
str+= intToStr(r->getAmount()) + " " + r->getType()->getName();
|
||||
str+= intToStr(r->getAmount()) + " " + r->getType()->getName(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -527,7 +527,7 @@ string HarvestCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
|
|||
}
|
||||
str+=lang.get("Resources")+":\n";
|
||||
for(int i=0; i<getHarvestedResourceCount(); ++i){
|
||||
str+= getHarvestedResource(i)->getName()+"\n";
|
||||
str+= getHarvestedResource(i)->getName(true)+"\n";
|
||||
}
|
||||
str+=harvestSkillType->getBoostDesc();
|
||||
return str;
|
||||
|
@ -601,7 +601,7 @@ string RepairCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
|
|||
}
|
||||
str+="\n"+lang.get("CanRepair")+":\n";
|
||||
for(int i=0; i<repairableUnits.size(); ++i){
|
||||
str+= (static_cast<const UnitType*>(repairableUnits[i]))->getName()+"\n";
|
||||
str+= (static_cast<const UnitType*>(repairableUnits[i]))->getName(true)+"\n";
|
||||
}
|
||||
str+=repairSkillType->getBoostDesc();
|
||||
return str;
|
||||
|
|
|
@ -54,7 +54,7 @@ string RequirableType::getReqDesc() const{
|
|||
if(getUnitReq(i) == NULL) {
|
||||
throw megaglest_runtime_error("getUnitReq(i) == NULL");
|
||||
}
|
||||
reqString+= getUnitReq(i)->getName();
|
||||
reqString+= getUnitReq(i)->getName(true);
|
||||
reqString+= "\n";
|
||||
anyReqs= true;
|
||||
}
|
||||
|
@ -64,12 +64,12 @@ string RequirableType::getReqDesc() const{
|
|||
throw megaglest_runtime_error("getUpgradeReq(i) == NULL");
|
||||
}
|
||||
|
||||
reqString+= getUpgradeReq(i)->getName();
|
||||
reqString+= getUpgradeReq(i)->getName(true);
|
||||
reqString+= "\n";
|
||||
anyReqs= true;
|
||||
}
|
||||
|
||||
string str= getName();
|
||||
string str= getName(true);
|
||||
if(anyReqs){
|
||||
return str + " " + Lang::getInstance().get("Reqs") + ":\n" + reqString;
|
||||
}
|
||||
|
@ -125,11 +125,11 @@ string ProducibleType::getReqDesc() const {
|
|||
return getReqDesc(false);
|
||||
}
|
||||
string ProducibleType::getReqDesc(bool ignoreResourceRequirements) const {
|
||||
string str= getName()+" "+Lang::getInstance().get("Reqs")+":\n";
|
||||
string str= getName(true) + " " + Lang::getInstance().get("Reqs") + ":\n";
|
||||
if(ignoreResourceRequirements == false) {
|
||||
for(int i=0; i<getCostCount(); ++i){
|
||||
if(getCost(i)->getAmount()!=0){
|
||||
str+= getCost(i)->getType()->getName();
|
||||
str+= getCost(i)->getType()->getName(true);
|
||||
str+= ": "+ intToStr(getCost(i)->getAmount());
|
||||
str+= "\n";
|
||||
}
|
||||
|
@ -137,12 +137,12 @@ string ProducibleType::getReqDesc(bool ignoreResourceRequirements) const {
|
|||
}
|
||||
|
||||
for(int i=0; i<getUnitReqCount(); ++i){
|
||||
str+= getUnitReq(i)->getName();
|
||||
str+= getUnitReq(i)->getName(true);
|
||||
str+= "\n";
|
||||
}
|
||||
|
||||
for(int i=0; i<getUpgradeReqCount(); ++i){
|
||||
str+= getUpgradeReq(i)->getName();
|
||||
str+= getUpgradeReq(i)->getName(true);
|
||||
str+= "\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ public:
|
|||
virtual ~DisplayableType(){};
|
||||
|
||||
//get
|
||||
string getName() const {return name;}
|
||||
const Texture2D *getImage() const {return image;}
|
||||
virtual string getName(bool translatedValue=false) const { return name; }
|
||||
virtual const Texture2D *getImage() const { return image; }
|
||||
|
||||
//virtual void saveGame(XmlNode *rootNode) const;
|
||||
};
|
||||
|
|
|
@ -185,6 +185,13 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
|
|||
}
|
||||
}
|
||||
|
||||
string ResourceType::getName(bool translatedValue) const {
|
||||
if(translatedValue == false) return name;
|
||||
|
||||
Lang &lang = Lang::getInstance();
|
||||
return lang.getTechTreeString("ResourceTypeName_" + name,name.c_str());
|
||||
}
|
||||
|
||||
// ==================== misc ====================
|
||||
|
||||
ResourceClass ResourceType::strToRc(const string &s){
|
||||
|
|
|
@ -63,6 +63,7 @@ public:
|
|||
std::map<string,vector<pair<string, string> > > &loadedFileList,
|
||||
string techtreePath);
|
||||
|
||||
virtual string getName(bool translatedValue=false) const;
|
||||
//get
|
||||
int getClass() const {return resourceClass;}
|
||||
int getTilesetObject() const {return tilesetObject;}
|
||||
|
|
|
@ -191,7 +191,7 @@ string AttackBoost::getDesc() const{
|
|||
|
||||
if(boostUnitList.empty() == false) {
|
||||
for(int i=0; i<boostUnitList.size(); ++i){
|
||||
str+= " "+boostUnitList[i]->getName()+"\n";
|
||||
str+= " "+boostUnitList[i]->getName(true)+"\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -225,6 +225,9 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||
*techtreeChecksum = checksumValue;
|
||||
}
|
||||
|
||||
Lang &lang = Lang::getInstance();
|
||||
lang.loadTechTreeStrings(name);
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
|
|
|
@ -487,7 +487,7 @@ string UpgradeType::getReqDesc() const{
|
|||
if(getEffectCount()>0){
|
||||
str+= lang.get("AffectedUnits")+"\n";
|
||||
for(int i=0; i<getEffectCount(); ++i){
|
||||
str+= indent+getEffect(i)->getName()+"\n";
|
||||
str+= indent+getEffect(i)->getName(true)+"\n";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
|
|
|
@ -168,6 +168,9 @@ public:
|
|||
// =====================================================
|
||||
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
|
||||
bool isdir(const char *path);
|
||||
bool fileExists(const string &path);
|
||||
inline bool folderExists(const string &path) { return isdir(path.c_str()); }
|
||||
|
||||
void findDirs(string path, vector<string> &results, bool errorOnNotFound,bool keepDuplicates);
|
||||
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false,bool keepDuplicates=false);
|
||||
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false);
|
||||
|
|
|
@ -79,6 +79,8 @@ public:
|
|||
void setFloat(const string &key, float value);
|
||||
void setString(const string &key, const string &value);
|
||||
|
||||
bool hasString(const string &key) const;
|
||||
|
||||
static bool applyTagsToValue(string &value, std::map<string,string> *mapTagReplacementValues=NULL);
|
||||
static std::map<string,string> getTagReplacementValues(std::map<string,string> *mapExtraTagReplacementValues=NULL);
|
||||
|
||||
|
|
|
@ -203,7 +203,6 @@ float saturate(float value);
|
|||
int round(float f);
|
||||
|
||||
//misc
|
||||
bool fileExists(const string &path);
|
||||
bool checkVersionComptability(string clientVersionString, string serverVersionString);
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -421,6 +421,28 @@ bool isdir(const char *path)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool fileExists(const string &path) {
|
||||
#ifdef WIN32
|
||||
wstring wstr = utf8_decode(path);
|
||||
FILE* file= _wfopen(wstr.c_str(), L"rb");
|
||||
#else
|
||||
FILE* file= fopen(path.c_str(), "rb");
|
||||
#endif
|
||||
if(file != NULL) {
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
//int fileErrno = errno;
|
||||
#ifdef WIN32
|
||||
int fileErrno = errno;
|
||||
DWORD error = GetLastError();
|
||||
string strError = "[#6] Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " " + strerror(fileErrno) + " [" + path + "]";
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void removeFolder(const string path) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
|
||||
|
||||
|
|
|
@ -416,6 +416,15 @@ const string Properties::getString(const string &key, const char *defaultValueIf
|
|||
}
|
||||
}
|
||||
|
||||
bool Properties::hasString(const string &key) const {
|
||||
PropertyMap::const_iterator it;
|
||||
it= propertyMap.find(key);
|
||||
if(it == propertyMap.end()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Properties::setInt(const string &key, int value){
|
||||
setString(key, intToStr(value));
|
||||
}
|
||||
|
|
|
@ -736,28 +736,6 @@ int round(float f){
|
|||
|
||||
// ==================== misc ====================
|
||||
|
||||
bool fileExists(const string &path) {
|
||||
#ifdef WIN32
|
||||
wstring wstr = utf8_decode(path);
|
||||
FILE* file= _wfopen(wstr.c_str(), L"rb");
|
||||
#else
|
||||
FILE* file= fopen(path.c_str(), "rb");
|
||||
#endif
|
||||
if(file != NULL) {
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
//int fileErrno = errno;
|
||||
#ifdef WIN32
|
||||
int fileErrno = errno;
|
||||
DWORD error = GetLastError();
|
||||
string strError = "[#6] Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " " + strerror(fileErrno) + " [" + path + "]";
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkVersionComptability(string clientVersionString, string serverVersionString) {
|
||||
bool compatible = (clientVersionString == serverVersionString);
|
||||
if(compatible == false) {
|
||||
|
|
Loading…
Reference in New Issue