diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index 26fa25a8e..f24e3733f 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -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; } diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index c95661fa4..4d3ce3f1e 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -17,10 +17,13 @@ #include #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{ diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index aa239c8ec..e4dca29b4 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -24,6 +24,7 @@ #include "core_data.h" #include "renderer.h" #include +#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 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; diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index f420ae571..4f651de6b 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -37,6 +37,7 @@ private: Properties strings; Properties scenarioStrings; + Properties techTreeStrings; std::map 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; diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 17c2d888d..fb4fe441f 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -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()); diff --git a/source/glest_game/type_instances/resource.cpp b/source/glest_game/type_instances/resource.cpp index 484818a7e..f098e6743 100644 --- a/source/glest_game/type_instances/resource.cpp +++ b/source/glest_game/type_instances/resource.cpp @@ -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+="/"; diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index d5e00702b..88dba8d5b 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -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); } } } diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index 2815aebfa..9e27d7c7b 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -527,7 +527,7 @@ string HarvestCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ } str+=lang.get("Resources")+":\n"; for(int i=0; igetName()+"\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[i]))->getName()+"\n"; + str+= (static_cast(repairableUnits[i]))->getName(true)+"\n"; } str+=repairSkillType->getBoostDesc(); return str; diff --git a/source/glest_game/types/element_type.cpp b/source/glest_game/types/element_type.cpp index 7fad27076..c8d4d383a 100644 --- a/source/glest_game/types/element_type.cpp +++ b/source/glest_game/types/element_type.cpp @@ -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; igetAmount()!=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; igetName(); + str+= getUnitReq(i)->getName(true); str+= "\n"; } for(int i=0; igetName(); + str+= getUpgradeReq(i)->getName(true); str+= "\n"; } diff --git a/source/glest_game/types/element_type.h b/source/glest_game/types/element_type.h index 5e044535f..1653ea922 100644 --- a/source/glest_game/types/element_type.h +++ b/source/glest_game/types/element_type.h @@ -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; }; diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index edc61648e..9a4fcf8e8 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -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){ diff --git a/source/glest_game/types/resource_type.h b/source/glest_game/types/resource_type.h index 11e9ac09c..30f59827f 100644 --- a/source/glest_game/types/resource_type.h +++ b/source/glest_game/types/resource_type.h @@ -63,6 +63,7 @@ public: std::map > > &loadedFileList, string techtreePath); + virtual string getName(bool translatedValue=false) const; //get int getClass() const {return resourceClass;} int getTilesetObject() const {return tilesetObject;} diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 30e62126f..2244567c0 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -191,7 +191,7 @@ string AttackBoost::getDesc() const{ if(boostUnitList.empty() == false) { for(int i=0; igetName()+"\n"; + str+= " "+boostUnitList[i]->getName(true)+"\n"; } } else diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 6d9efba48..a4e142a37 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -225,6 +225,9 @@ void TechTree::load(const string &dir, set &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__); } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 22166b22e..7cfb51c78 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -487,7 +487,7 @@ string UpgradeType::getReqDesc() const{ if(getEffectCount()>0){ str+= lang.get("AffectedUnits")+"\n"; for(int i=0; igetName()+"\n"; + str+= indent+getEffect(i)->getName(true)+"\n"; } } return str; diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index f91df27f1..00b072bc6 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -168,6 +168,9 @@ public: // ===================================================== void Tokenize(const string& str,vector& 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 &results, bool errorOnNotFound,bool keepDuplicates); void findDirs(const vector &paths, vector &results, bool errorOnNotFound=false,bool keepDuplicates=false); void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false); diff --git a/source/shared_lib/include/util/properties.h b/source/shared_lib/include/util/properties.h index a752f2734..150e60510 100644 --- a/source/shared_lib/include/util/properties.h +++ b/source/shared_lib/include/util/properties.h @@ -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 *mapTagReplacementValues=NULL); static std::map getTagReplacementValues(std::map *mapExtraTagReplacementValues=NULL); diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 408e91370..c932c6de7 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -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 diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index ae56fb1e1..2e072bdbb 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -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()); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index f99621d67..8ffbf66b9 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -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)); } diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 9b730e973..9cefaf8a4 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -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) {