diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index 8262a63f..34c01c88 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -276,6 +276,8 @@ void Lang::loadScenarioStrings(string scenarioDir, string scenarioName, bool isT void Lang::loadTechTreeStrings(string techTree,bool forceLoad) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] techTree = [%s]\n",__FILE__,__FUNCTION__,__LINE__,techTree.c_str()); + //printf("Line: %d techTree = %s forceLoad = %d\n",__LINE__,techTree.c_str(),forceLoad); + if(forceLoad == false && techTree == techNameLoaded) { return; } @@ -302,13 +304,22 @@ void Lang::loadTechTreeStrings(string techTree,bool forceLoad) { //techTreeStrings.clear(); //techTreeStringsDefault.clear(); + //printf("Line: %d techTree = %s this->language = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),this->language.c_str(),forceLoad,path.c_str()); + //try to load the current language first if(fileExists(path)) { if(forceLoad == true || path != techTreeStringsAllLanguages[techTree][this->language].getpath()) { + + //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); + techTreeStringsAllLanguages[techTree][this->language].load(path); techNameLoaded = techTree; } + else if(path == techTreeStringsAllLanguages[techTree][this->language].getpath() && + techTree != techNameLoaded) { + techNameLoaded = techTree; + } } 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()); @@ -318,22 +329,39 @@ void Lang::loadTechTreeStrings(string techTree,bool forceLoad) { path = techTreeFolder + "lang/" + techTree + "_" + default_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()); + //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); + if(fileExists(path)) { if(forceLoad == true || path != techTreeStringsAllLanguages[techTree][default_language].getpath()) { + //printf("Line: %d techTree = %s forceLoad = %d path = %s\n",__LINE__,techTree.c_str(),forceLoad,path.c_str()); + techTreeStringsAllLanguages[techTree][default_language].load(path); techNameLoaded = techTree; } + else if(path == techTreeStringsAllLanguages[techTree][default_language].getpath() && + techTree != techNameLoaded) { + techNameLoaded = techTree; + } } } if(fileExists(pathDefault)) { string default_language = "default"; + + //printf("Line: %d techTree = %s forceLoad = %d default_language = %s\n",__LINE__,techTree.c_str(),forceLoad,default_language.c_str()); + if(forceLoad == true || pathDefault != techTreeStringsAllLanguages[techTree][default_language].getpath()) { + //printf("Line: %d techTree = %s forceLoad = %d pathDefault = %s\n",__LINE__,techTree.c_str(),forceLoad,pathDefault.c_str()); + techTreeStringsAllLanguages[techTree][default_language].load(pathDefault); techNameLoaded = techTree; } + else if(pathDefault == techTreeStringsAllLanguages[techTree][default_language].getpath() && + techTree != techNameLoaded) { + techNameLoaded = techTree; + } } } @@ -504,19 +532,30 @@ string Lang::getTechTreeString(const string &s,const char *defaultValue) { string default_language = "default"; string result = ""; + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + if(allowNativeLanguageTechtree == true && (techTreeStringsAllLanguages[techNameLoaded][this->language].hasString(s) == true || defaultValue == NULL)) { if(techTreeStringsAllLanguages[techNameLoaded][this->language].hasString(s) == false && techTreeStringsAllLanguages[techNameLoaded][default_language].hasString(s) == true) { + + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + result = techTreeStringsAllLanguages[techNameLoaded][default_language].getString(s); } else { + + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + result = techTreeStringsAllLanguages[techNameLoaded][this->language].getString(s); } } else if(allowNativeLanguageTechtree == true && techTreeStringsAllLanguages[techNameLoaded][default_language].hasString(s) == true) { + + //printf("Line: %d techNameLoaded = %s s = %s this->language = %s\n",__LINE__,techNameLoaded.c_str(),s.c_str(),this->language.c_str()); + result = techTreeStringsAllLanguages[techNameLoaded][default_language].getString(s); } else if(defaultValue != NULL) { diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index 099c1307..e30362df 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -57,6 +57,7 @@ private: public: static Lang &getInstance(); + string getTechNameLoaded() const { return techNameLoaded; } bool getAllowNativeLanguageTechtree() const { return allowNativeLanguageTechtree; } void setAllowNativeLanguageTechtree(bool value) { allowNativeLanguageTechtree = value; } diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 74156e03..dd485f5e 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -51,12 +51,21 @@ string TechTree::getName(bool translatedValue) const { if(translatedValue == false) return name; Lang &lang = Lang::getInstance(); + if(lang.getTechNameLoaded() != name) { + //printf("Line: %d Tech [%s]\n",__LINE__,name.c_str()); + + lang.loadTechTreeStrings(name,false); + //translatedTechFactionNames.erase(name); + } + return lang.getTechTreeString("TechTreeName",name.c_str()); } string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTechtreeActiveFile) { string result = techName; + //printf("Line: %d Tech [%s] forceLoad = %d forceTechtreeActiveFile = %d\n",__LINE__,techName.c_str(),forceLoad,forceTechtreeActiveFile); + if(forceTechtreeActiveFile == false && translatedTechNames.find(techName) != translatedTechNames.end()) { result = translatedTechNames[techName]; @@ -73,6 +82,8 @@ string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTe Lang &lang = Lang::getInstance(); lang.loadTechTreeStrings(name,forceLoad); + translatedTechFactionNames.erase(name); + result = getName(true); translatedTechNames[techName] = result; @@ -83,19 +94,33 @@ string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTe } string TechTree::getTranslatedFactionName(string techName, string factionName) { + //printf("Line: %d Tech [%s] name [%s] factionName [%s]\n",__LINE__,techName.c_str(),name.c_str(),factionName.c_str()); + + Lang &lang = Lang::getInstance(); + if(lang.getTechNameLoaded() != techName) { + //printf("Line: %d Tech [%s] name [%s] lang.getTechNameLoaded() [%s] factionName [%s]\n",__LINE__,techName.c_str(),name.c_str(),lang.getTechNameLoaded().c_str(),factionName.c_str()); + + lang.loadTechTreeStrings(techName,false); + translatedTechFactionNames.erase(techName); + } + std::map >::iterator iterMap = translatedTechFactionNames.find(techName); if(iterMap != translatedTechFactionNames.end()) { if(iterMap->second.find(factionName) != iterMap->second.end()) { + //printf("Line: %d Tech [%s] factionName [%s]\n",__LINE__,techName.c_str(),factionName.c_str()); + return iterMap->second.find(factionName)->second; } } + //printf("Line: %d Tech [%s] factionName [%s]\n",__LINE__,techName.c_str(),factionName.c_str()); + getTranslatedName(techName,false,true); - Lang &lang = Lang::getInstance(); + string result = lang.getTechTreeString("FactionName_" + factionName,factionName.c_str()); translatedTechFactionNames[techName][factionName] = result; - //printf("Translated faction for Tech [%s] faction [%s] result [%s]\n",techName.c_str(),factionName.c_str(),result.c_str()); + //printf("Line: %d Translated faction for Tech [%s] faction [%s] result [%s]\n",__LINE__,techName.c_str(),factionName.c_str(),result.c_str()); return result; }