Skip to content

Commit bd6dbf4

Browse files
authored
Merge pull request #282 from rtxa/fix-ag-hud-string-utf8
Fix AG HUD texts not displaying UTF-8 characters
2 parents 50b15cf + 73ed574 commit bd6dbf4

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/game/client/hud.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ class CHud
165165
int DrawHudString(int x, int y, int iMaxX, char *szString, int r, int g, int b);
166166
int DrawHudStringReverse(int xpos, int ypos, int iMinX, char *szString, int r, int g, int b);
167167
int DrawHudStringColorCodes(int x, int y, int iMaxX, char *string, int _r, int _g, int _b);
168+
int DrawHudStringColorCodesCentered(int x, int y, int iMaxX, char *string, int _r, int _g, int _b);
168169
int DrawHudStringReverseColorCodes(int x, int y, int iMaxX, char *string, int _r, int _g, int _b);
169170
int DrawHudNumberString(int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b);
170171
int GetNumWidth(int iNumber, int iFlags);
171172
int GetHudCharWidth(int c);
173+
int GetHudStringWidthColorCodes(char *string);
172174
int CalculateCharWidth(int c);
173175

174176
//! @returns The font height for string render functions.

src/game/client/hud/ag/ag_countdown.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void AgHudCountdown::Draw(float fTime)
4848
{
4949
// Write arena text.
5050
sprintf(szText, "%s vs %s", m_szPlayer1, m_szPlayer2);
51-
AgDrawHudStringCentered(ScreenWidth / 2, gHUD.m_scrinfo.iCharHeight * 7, ScreenWidth, szText, r, g, b);
51+
gHUD.DrawHudStringColorCodesCentered(ScreenWidth / 2, gHUD.m_scrinfo.iCharHeight * 7, ScreenWidth, szText, r, g, b);
5252
}
5353
else
5454
{
@@ -62,7 +62,7 @@ void AgHudCountdown::Draw(float fTime)
6262
if (strlen(m_szPlayer1) != 0)
6363
{
6464
sprintf(szText, "Last round won by %s", m_szPlayer1);
65-
AgDrawHudStringCentered(ScreenWidth / 2, gHUD.m_scrinfo.iCharHeight * 7, ScreenWidth, szText, r, g, b);
65+
gHUD.DrawHudStringColorCodesCentered(ScreenWidth / 2, gHUD.m_scrinfo.iCharHeight * 7, ScreenWidth, szText, r, g, b);
6666
}
6767
else
6868
{

src/game/client/hud/ag/ag_vote.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void AgHudVote::Draw(float fTime)
5454
sprintf(szText, "Vote: %s %s", m_szVote, m_szValue);
5555
gHUD.DrawHudString(ScreenWidth / 20, ScreenHeight / 8, 0, szText, r, g, b);
5656
sprintf(szText, "Called by: %s", m_szCalled);
57-
AgDrawHudString(ScreenWidth / 20, ScreenHeight / 8 + gHUD.m_scrinfo.iCharHeight, ScreenWidth, szText, r, g, b);
57+
gHUD.DrawHudStringColorCodes(ScreenWidth / 20, ScreenHeight / 8 + gHUD.m_scrinfo.iCharHeight, ScreenWidth, szText, r, g, b);
5858
if (VoteStatus::Called == m_iVoteStatus)
5959
{
6060
sprintf(szText, "For: %d", m_iFor);

src/game/client/hud_redraw.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ int CHud::DrawHudStringReverse(int xpos, int ypos, int iMinX, char *szString, in
247247
return xpos - gEngfuncs.pfnDrawStringReverse(xpos, ypos, szString, r, g, b);
248248
}
249249

250+
int CHud::DrawHudStringColorCodesCentered(int x, int y, int iMaxX, char *string, int _r, int _g, int _b)
251+
{
252+
auto width = GetHudStringWidthColorCodes(string);
253+
return DrawHudStringColorCodes(x - width / 2, y, iMaxX, string, _r, _g, _b);
254+
}
255+
256+
int CHud::GetHudStringWidthColorCodes(char *string)
257+
{
258+
static char buffer[1024];
259+
RemoveColorCodes(string, buffer, sizeof(buffer));
260+
return DrawHudStringColorCodes(0, 0, 0, buffer, 0, 0, 0);
261+
}
262+
250263
int CHud::DrawHudStringColorCodes(int x, int y, int iMaxX, char *string, int _r, int _g, int _b)
251264
{
252265
// How colorcodes work in DrawHudStringColorCodes

0 commit comments

Comments
 (0)