diff --git a/source/glest_game/facilities/logger.cpp b/source/glest_game/facilities/logger.cpp index 352fe0d9..15fbf6ef 100644 --- a/source/glest_game/facilities/logger.cpp +++ b/source/glest_game/facilities/logger.cpp @@ -241,17 +241,30 @@ void Logger::renderLoadingScreen() { 56 * metrics.getVirtualH() / 100, false); } } - if(gameHintToShow!=""){ + + if(gameHintToShow != "") { + Lang &lang= Lang::getInstance(); + string hintText = lang.get("Hint"); + char szBuf[8096]=""; + sprintf(szBuf,hintText.c_str(),gameHintToShow.c_str()); + hintText = szBuf; + if(Renderer::renderText3DEnabled) { + int xLocationHint = (metrics.getVirtualW() / 2) - (coreData.getMenuFontBig3D()->getMetrics()->getTextWidth(hintText) / 2); + renderer.renderText3D( - "Hint:\n"+gameHintToShow, coreData.getMenuFontBig3D(), Vec3f(1.f), - xLocation*1.5f, - 90 * metrics.getVirtualH() / 100, false); + hintText, coreData.getMenuFontBig3D(), Vec3f(1.f), + //xLocation*1.5f, + xLocationHint, + 90 * metrics.getVirtualH() / 100, false); } else { + int xLocationHint = (metrics.getVirtualW() / 2) - (coreData.getMenuFontBig()->getMetrics()->getTextWidth(hintText) / 2); + renderer.renderText( - "Hint:\n"+gameHintToShow, coreData.getMenuFontBig(), Vec3f(1.f), - xLocation*1.5f, + hintText, coreData.getMenuFontBig(), Vec3f(1.f), + //xLocation*1.5f, + xLocationHint, 90 * metrics.getVirtualH() / 100, false); } diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index f6ff3780..53ffd8ff 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -120,24 +120,34 @@ Text * FontMetrics::getTextHandler() { } float FontMetrics::getTextWidth(const string &str) { + string longestLine = ""; + vector lineTokens; + Tokenize(str,lineTokens,"\n"); + for(unsigned int i = 0; i < lineTokens.size(); ++i) { + string currentStr = lineTokens[i]; + if(currentStr.length() > longestLine.length()) { + longestLine = currentStr; + } + } + if(textHandler != NULL) { //printf("str [%s] textHandler->Advance = %f Font::scaleFontValue = %f\n",str.c_str(),textHandler->Advance(str.c_str()),Font::scaleFontValue); - return (textHandler->Advance(str.c_str()) * Font::scaleFontValue); + return (textHandler->Advance(longestLine.c_str()) * Font::scaleFontValue); //return (textHandler->Advance(str.c_str())); } else { float width= 0.f; - for(unsigned int i=0; i< str.size() && (int)i < Font::charCount; ++i){ - if(str[i] >= Font::charCount) { - string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i); + for(unsigned int i=0; i< longestLine.size() && (int)i < Font::charCount; ++i){ + if(longestLine[i] >= Font::charCount) { + string sError = "str[i] >= Font::charCount, [" + longestLine + "] i = " + intToStr(i); throw megaglest_runtime_error(sError); } //Treat 2 byte characters as spaces - if(str[i] < 0) { + if(longestLine[i] < 0) { width+= (widths[97]); // This is the letter a which is a normal wide character and good to use for spacing } else { - width+= widths[str[i]]; + width+= widths[longestLine[i]]; } } return width;