diff --git a/src/g_shared/sbarinfo_commands.cpp b/src/g_shared/sbarinfo_commands.cpp index 91e7aa06c0..65be83f7d2 100644 --- a/src/g_shared/sbarinfo_commands.cpp +++ b/src/g_shared/sbarinfo_commands.cpp @@ -582,7 +582,7 @@ class CommandDrawString : public SBarInfoCommand str = sc.String; } sc.MustGetToken(','); - GetCoordinates(sc, fullScreenOffsets, x, y); + GetCoordinates(sc, fullScreenOffsets, startX, y); if(sc.CheckToken(',')) //spacing { sc.MustGetToken(TK_IntConst); @@ -590,10 +590,7 @@ class CommandDrawString : public SBarInfoCommand } sc.MustGetToken(';'); - if(script->spacingCharacter == '\0') - x -= static_cast (font->StringWidth(str)+(spacing * str.Len())); - else //monospaced, so just multiplay the character size - x -= static_cast ((font->GetCharWidth((int) script->spacingCharacter) + spacing) * str.Len()); + RealignString(); } void Reset() { @@ -619,6 +616,7 @@ class CommandDrawString : public SBarInfoCommand { cache = level.lumpnum; str = level.LevelName; + RealignString(); } break; case LEVELLUMP: @@ -626,6 +624,7 @@ class CommandDrawString : public SBarInfoCommand { cache = level.lumpnum; str = level.mapname; + RealignString(); } break; case SKILLNAME: @@ -633,6 +632,7 @@ class CommandDrawString : public SBarInfoCommand { cache = level.lumpnum; str = G_SkillName(); + RealignString(); } break; case PLAYERCLASS: @@ -640,6 +640,7 @@ class CommandDrawString : public SBarInfoCommand { cache = statusBar->CPlayer->userinfo.PlayerClass; str = statusBar->CPlayer->cls->Meta.GetMetaString(APMETA_DisplayName); + RealignString(); } break; case AMMO1TAG: @@ -658,12 +659,14 @@ class CommandDrawString : public SBarInfoCommand // Can't think of a good way to detect changes to this, so // I guess copying it every tick will have to do. str = statusBar->CPlayer->userinfo.netname; + RealignString(); break; case GLOBALVAR: if(ACS_GlobalVars[valueArgument] != cache) { cache = ACS_GlobalVars[valueArgument]; str = FBehavior::StaticLookupString(ACS_GlobalVars[valueArgument]); + RealignString(); } break; case GLOBALARRAY: @@ -671,6 +674,7 @@ class CommandDrawString : public SBarInfoCommand { cache = ACS_GlobalArrays[valueArgument][consoleplayer]; str = FBehavior::StaticLookupString(ACS_GlobalArrays[valueArgument][consoleplayer]); + RealignString(); } break; default: @@ -678,6 +682,15 @@ class CommandDrawString : public SBarInfoCommand } } protected: + void RealignString() + { + x = startX; + if(script->spacingCharacter == '\0') + x -= static_cast (font->StringWidth(str)+(spacing * str.Len())); + else //monospaced, so just multiplay the character size + x -= static_cast ((font->GetCharWidth((int) script->spacingCharacter) + spacing) * str.Len()); + } + enum StringValueType { LEVELNAME, @@ -701,6 +714,7 @@ class CommandDrawString : public SBarInfoCommand int spacing; FFont *font; EColorRange translation; + SBarInfoCoordinate startX; SBarInfoCoordinate x; SBarInfoCoordinate y; int cache; /// General purpose cache. @@ -717,6 +731,7 @@ class CommandDrawString : public SBarInfoCommand { cache = actor->GetClass()->ClassIndex; str = actor->GetTag(); + RealignString(); } } else @@ -1061,9 +1076,7 @@ class CommandDrawNumber : public CommandDrawString translation = lowTranslation; else if(highValue != -1 && drawValue >= highValue) //high translation = highTranslation; - - x = startX; - + // 10^9 is a largest we can hold in a 32-bit int. So if we go any larger we have to toss out the positions limit. int maxval = length <= 9 ? (int) ceil(pow(10., length))-1 : INT_MAX; if(!fillZeros || length == 1) @@ -1083,10 +1096,8 @@ class CommandDrawNumber : public CommandDrawString str.Insert(0, "0"); } } - if(script->spacingCharacter == '\0') - x -= static_cast (font->StringWidth(str)+(spacing * str.Len())); - else //monospaced, so just multiplay the character size - x -= static_cast ((font->GetCharWidth((int) script->spacingCharacter) + spacing) * str.Len()); + + RealignString(); } protected: enum ValueType @@ -1131,8 +1142,6 @@ class CommandDrawNumber : public CommandDrawString ValueType value; const PClass *inventoryItem; - SBarInfoCoordinate startX; - friend class CommandDrawInventoryBar; };