- hint text now centered on screen when game is loading

This commit is contained in:
Mark Vejvoda 2012-07-20 19:00:49 +00:00
parent 378b2e0a33
commit 5cb761e5a6
2 changed files with 35 additions and 12 deletions

View File

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

View File

@ -120,24 +120,34 @@ Text * FontMetrics::getTextHandler() {
}
float FontMetrics::getTextWidth(const string &str) {
string longestLine = "";
vector<string> 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;