From c04a73017c2dec380a7b499fd7d5ba8e5d3a1fe2 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 29 Oct 2013 21:13:44 +0000 Subject: [PATCH] allow language toggle to switch faction names in menus --- .../menu/menu_state_custom_game.cpp | 2 ++ source/glest_game/types/faction_type.cpp | 2 +- source/glest_game/types/tech_tree.cpp | 35 +++++++++++++------ source/glest_game/types/tech_tree.h | 4 ++- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 8382beba..df824441 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -819,6 +819,8 @@ void MenuStateCustomGame::reloadUI() { labelScenario.setText(lang.getString("Scenario")); + reloadFactions(true,(checkBoxScenario.getValue() == true ? scenarioFiles[listBoxScenario.getSelectedItemIndex()] : "")); + // write hint to console: Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index cfae53ff..02627039 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -43,7 +43,7 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string techTreePath = techTree->getPath(); - string techTreeName=techTree->getName(); + string techTreeName=techTree->getNameUntranslated(); string currentPath = ""; //open xml file diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index dd485f5e..967851b5 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -45,17 +45,26 @@ TechTree::TechTree(const vector pathList) { attackTypes.clear(); translatedTechNames.clear(); translatedTechFactionNames.clear(); + languageUsedForCache = ""; } -string TechTree::getName(bool translatedValue) const { - if(translatedValue == false) return name; +string TechTree::getNameUntranslated() const { + return name; +} + +string TechTree::getName(bool translatedValue) { + if(translatedValue == false) { + return getNameUntranslated(); + } Lang &lang = Lang::getInstance(); - if(lang.getTechNameLoaded() != name) { + if(lang.getTechNameLoaded() != name || + lang.getLanguage() != languageUsedForCache) { //printf("Line: %d Tech [%s]\n",__LINE__,name.c_str()); - lang.loadTechTreeStrings(name,false); - //translatedTechFactionNames.erase(name); + lang.loadTechTreeStrings(name,lang.getLanguage() != languageUsedForCache); + languageUsedForCache = lang.getLanguage(); + translatedTechFactionNames.erase(name); } return lang.getTechTreeString("TechTreeName",name.c_str()); @@ -66,8 +75,10 @@ string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTe //printf("Line: %d Tech [%s] forceLoad = %d forceTechtreeActiveFile = %d\n",__LINE__,techName.c_str(),forceLoad,forceTechtreeActiveFile); + Lang &lang = Lang::getInstance(); if(forceTechtreeActiveFile == false && - translatedTechNames.find(techName) != translatedTechNames.end()) { + translatedTechNames.find(techName) != translatedTechNames.end() && + lang.getLanguage() != languageUsedForCache) { result = translatedTechNames[techName]; } else { @@ -79,8 +90,8 @@ string TechTree::getTranslatedName(string techName, bool forceLoad, bool forceTe treePath = currentPath; name= lastDir(currentPath); - Lang &lang = Lang::getInstance(); - lang.loadTechTreeStrings(name,forceLoad); + lang.loadTechTreeStrings(name,lang.getLanguage() != languageUsedForCache); + languageUsedForCache = lang.getLanguage(); translatedTechFactionNames.erase(name); @@ -97,10 +108,13 @@ 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) { + if(lang.getTechNameLoaded() != techName || + lang.getLanguage() != languageUsedForCache) { //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); + lang.loadTechTreeStrings(techName,lang.getLanguage() != languageUsedForCache); + languageUsedForCache = lang.getLanguage(); + translatedTechFactionNames.erase(techName); } @@ -172,6 +186,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum Lang &lang = Lang::getInstance(); lang.loadTechTreeStrings(name, true); + languageUsedForCache = lang.getLanguage(); char szBuf[8096]=""; snprintf(szBuf,8096,Lang::getInstance().getString("LogScreenGameLoadingTechtree","",true).c_str(),formatString(getName(true)).c_str()); diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index 2bd7d403..c2fa1b18 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -53,6 +53,7 @@ private: DamageMultiplierTable damageMultiplierTable; Checksum checksumValue; + string languageUsedForCache; std::map translatedTechNames; std::map > translatedTechFactionNames; @@ -73,7 +74,8 @@ public: int getTypeCount() const {return factionTypes.size();} const FactionType *getType(int i) const {return &factionTypes[i];} const ResourceType *getResourceType(int i) const {return &resourceTypes[i];} - string getName(bool translatedValue=false) const; + string getName(bool translatedValue=false); + string getNameUntranslated() const; string getTranslatedName(string techName, bool forceLoad=false, bool forceTechtreeActiveFile=false); string getTranslatedFactionName(string techName, string factionName);