diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index c5d3fe21..7f2db2b2 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -287,6 +287,54 @@ void Lang::loadTechTreeStrings(string techTree) { } } +void Lang::loadTilesetStrings(string tileset) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tileset = [%s]\n",__FILE__,__FUNCTION__,__LINE__,tileset.c_str()); + + string currentPath = ""; + Config &config = Config::getInstance(); + vector tilesetPaths = config.getPathListForType(ptTilesets); + for(int idx = 0; idx < tilesetPaths.size(); idx++) { + string &tilesetPath = tilesetPaths[idx]; + endPathWithSlash(tilesetPath); + + //printf("tilesetPath [%s]\n",tilesetPath.c_str()); + + if(folderExists(tilesetPath + tileset) == true) { + currentPath = tilesetPath; + endPathWithSlash(currentPath); + break; + } + } + + string tilesetFolder = currentPath + tileset + "/"; + string path = tilesetFolder + "lang/" + tileset + "_" + language + ".lng"; + string pathDefault = tilesetFolder + "lang/" + tileset + "_default.lng"; + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] pathDefault = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),pathDefault.c_str()); + + tilesetStrings.clear(); + tilesetStringsDefault.clear(); + + //try to load the current language first + if(fileExists(path)) { + tilesetStrings.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 = tilesetFolder + "lang/" + tileset + "_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)) { + tilesetStrings.load(path); + } + } + + if(fileExists(pathDefault)) { + tilesetStringsDefault.load(pathDefault); + } +} + bool Lang::hasString(const string &s, string uselanguage, bool fallbackToDefault) { bool result = false; try { @@ -411,6 +459,35 @@ string Lang::getTechTreeString(const string &s,const char *defaultValue) { } } +string Lang::getTilesetString(const string &s,const char *defaultValue) { + try{ + string result = ""; + + if(tilesetStrings.hasString(s) == true || defaultValue == NULL) { + if(tilesetStrings.hasString(s) == false && tilesetStringsDefault.hasString(s) == true) { + result = tilesetStringsDefault.getString(s); + } + else { + result = tilesetStrings.getString(s); + } + } + else if(tilesetStringsDefault.hasString(s) == true) { + result = tilesetStringsDefault.getString(s); + } + else if(defaultValue != NULL) { + result = defaultValue; + } + replaceAll(result, "\\n", "\n"); + return result; + } + catch(exception &ex) { + if(tilesetStrings.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; diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index da0a489d..9515eeff 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -39,6 +39,8 @@ private: Properties scenarioStrings; Properties techTreeStrings; Properties techTreeStringsDefault; + Properties tilesetStrings; + Properties tilesetStringsDefault; std::map otherLanguageStrings; @@ -57,11 +59,13 @@ public: void loadStrings(string uselanguage, bool loadFonts=true, bool fallbackToDefault=false); void loadScenarioStrings(string scenarioDir, string scenarioName); void loadTechTreeStrings(string techTree); + void loadTilesetStrings(string tileset); 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 getTilesetString(const string &s, const char *defaultValue=NULL); string getLanguage() const { return language; } bool isLanguageLocal(string compareLanguage) const; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 2244567c..b70f36ea 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -581,20 +581,31 @@ string SkillType::skillClassToStr(SkillClass skillClass) { string SkillType::fieldToStr(Field field) { Lang &lang= Lang::getInstance(); + string fieldName = ""; switch(field) { - case fLand: - if(lang.hasString("FieldLand") == true) { - return lang.get("FieldLand"); - } - return "Land"; - case fAir: - if(lang.hasString("FieldAir") == true) { - return lang.get("FieldAir"); - } - return "Air"; - default: - assert(false); - return ""; + case fLand: + if(lang.hasString("FieldLand") == true) { + fieldName = lang.get("FieldLand"); + } + else { + fieldName = "Land"; + } + //return "Land"; + return lang.getTilesetString("FieldLandName",fieldName.c_str()); + + case fAir: + if(lang.hasString("FieldAir") == true) { + fieldName = lang.get("FieldAir"); + } + else { + fieldName = "Air"; + } + + //return "Air"; + return lang.getTilesetString("FieldAirName",fieldName.c_str()); + default: + assert(false); + return ""; }; } diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index b16ced30..52b64673 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -361,6 +361,9 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); throw megaglest_runtime_error("Error: " + path + "\n" + e.what()); } + + Lang &lang = Lang::getInstance(); + lang.loadTilesetStrings(name); } Tileset::~Tileset() {