hints while loading with language support and keycode replacement.

This commit is contained in:
Titus Tscharntke 2012-06-19 00:32:39 +00:00
parent 6d6f2c362a
commit a9049ac887
5 changed files with 54 additions and 10 deletions

View File

@ -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<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
vector<pair<string,string> > mergedKeySettings = configKeys.getMergedProperties();
for(unsigned int j = 0; j < mergedKeySettings.size(); ++j) {
pair<string,string> &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)) {

View File

@ -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();

View File

@ -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__);

View File

@ -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);

View File

@ -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");
}