diff --git a/source/glest_game/facilities/logger.cpp b/source/glest_game/facilities/logger.cpp index d3e31cb3..538388eb 100644 --- a/source/glest_game/facilities/logger.cpp +++ b/source/glest_game/facilities/logger.cpp @@ -115,21 +115,50 @@ void Logger::loadLoadingScreen(string filepath) { } } -void Logger::loadGameHints(string filepath) { +void Logger::loadGameHints(string filePathEnglish,string filePathTranslation,bool clearList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(filepath == "") { + if((filePathEnglish == "") || (filePathTranslation == "")) { return; } else { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filepath = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filepath.c_str()); - gameHints.load(filepath,false); - gameHintToShow=gameHints.getRandomString(true); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filePathEnglish = [%s]\n filePathTranslation = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filePathEnglish.c_str(),filePathTranslation.c_str()); + gameHints.load(filePathEnglish,clearList); + gameHintsTranslation.load(filePathTranslation,clearList); + string key=gameHints.getRandomKey(true); + string tmpString=gameHintsTranslation.getString(key,""); + if(tmpString!=""){ + gameHintToShow=tmpString; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] key [%s] not found for [%s] hint translation\n",__FILE__,__FUNCTION__,__LINE__,key.c_str(),Lang::getInstance().getLanguage().c_str()); + tmpString=gameHints.getString(key,""); + if(tmpString!=""){ + gameHintToShow=tmpString; + } + else { + gameHintToShow="Problems to resolve hint key '"+key+"'"; + } + } replaceAll(gameHintToShow, "\\n", "\n"); + + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + + vector > mergedKeySettings = configKeys.getMergedProperties(); + for(unsigned int j = 0; j < mergedKeySettings.size(); ++j) { + pair &property = mergedKeySettings[j]; + replaceAll(gameHintToShow, "#"+property.first+"#", property.second); + } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } } +void Logger::clearHints() { + gameHintToShow=""; + gameHints.clear(); + gameHintsTranslation.clear(); +} + void Logger::handleMouseClick(int x, int y) { if(buttonCancel.getEnabled() == true) { if(buttonCancel.mouseClick(x, y)) { diff --git a/source/glest_game/facilities/logger.h b/source/glest_game/facilities/logger.h index 53dfe22f..c52bb560 100644 --- a/source/glest_game/facilities/logger.h +++ b/source/glest_game/facilities/logger.h @@ -52,6 +52,7 @@ private: string current; Texture2D *loadingTexture; Properties gameHints; + Properties gameHintsTranslation; string gameHintToShow; int progress; bool showProgressBar; @@ -81,13 +82,14 @@ public: void add(const string str, bool renderScreen= false, const string statusText=""); void loadLoadingScreen(string filepath); - void loadGameHints(string filepath); + void loadGameHints(string filePathEnglish,string filePathTranslation,bool clearList); void renderLoadingScreen(); void setCancelLoadingEnabled(bool value); bool getCancelLoading() const { return cancelSelected; } void setCancelLoading(bool value) { cancelSelected = value; } void handleMouseClick(int x, int y); + void clearHints(); void clear(); diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 6442ecc5..8fb47a0b 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -264,6 +264,7 @@ void Game::endGame() { Logger &logger= Logger::getInstance(); Renderer &renderer= Renderer::getInstance(); + logger.clearHints(); logger.loadLoadingScreen(""); logger.setState(Lang::getInstance().get("Deleting")); //logger.add("Game", true); @@ -739,7 +740,19 @@ void Game::load(int loadTypes) { if(data_path != ""){ endPathWithSlash(data_path); } - logger.loadGameHints(getGameCustomCoreDataPath(data_path, "data/core/hint/hint_english.lng")); + string englishFile=getGameCustomCoreDataPath(data_path, "data/core/hint/hint_"+Lang::getInstance().getDefaultLanguage()+".lng"); + string languageFile=getGameCustomCoreDataPath(data_path, "data/core/hint/hint_"+ Lang::getInstance().getLanguage() +".lng"); + if(fileExists(languageFile) == false){ + // if there is no language specific file use english instead + languageFile=englishFile; + } + if(fileExists(englishFile) == false){ + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] file [%s] not found\n",__FILE__,__FUNCTION__,__LINE__,englishFile.c_str()); + } else { + logger.loadGameHints(englishFile,languageFile,true); + } + + if((loadTypes & lgt_FactionPreview) == lgt_FactionPreview) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/util/properties.h b/source/shared_lib/include/util/properties.h index e4f2b64f..d7442d86 100644 --- a/source/shared_lib/include/util/properties.h +++ b/source/shared_lib/include/util/properties.h @@ -73,7 +73,7 @@ public: bool getBool(const char *key,const char *defaultValueIfNotFound=NULL) const; float getFloat(const char *key,const char *defaultValueIfNotFound=NULL) const; const string getString(const char *key,const char *defaultValueIfNotFound=NULL) const; - const string getRandomString(const bool realrandom) const; + const string getRandomKey(const bool realrandom) const; void setInt(const string &key, int value); void setBool(const string &key, bool value); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index df8849a3..bbbcab44 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -417,7 +417,7 @@ const string Properties::getString(const string &key, const char *defaultValueIf } } -const string Properties::getRandomString(const bool realrandom) const{ +const string Properties::getRandomKey(const bool realrandom) const{ PropertyMap::const_iterator it; int max=getPropertyCount(); int randomIndex=-1; @@ -428,7 +428,7 @@ const string Properties::getRandomString(const bool realrandom) const{ RandomGen randgen; randomIndex=randgen.randRange(0,max); } - string s=getString(randomIndex); + string s=getKey(randomIndex); return (s != "" ? s : "nothing found"); }