Skip to content

Commit 5a51b72

Browse files
committed
client: scoreboard localization and potential crash fix
1 parent ff06dc2 commit 5a51b72

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

cl_dll/hud/scoreboard.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <string.h>
2929
#include <stdio.h>
3030
#include "draw_util.h"
31+
#include "vgui_parser.h"
32+
#include <ctype.h>
3133

3234
hud_player_info_t g_PlayerInfoList[MAX_PLAYERS+1]; // player info from the engine
3335
extra_player_info_t g_PlayerExtraInfo[MAX_PLAYERS+1]; // additional player info sent directly to the client dll
@@ -180,16 +182,17 @@ int CHudScoreboard :: DrawScoreboard( float fTime )
180182
int ypos = ystart + (list_slot * ROW_GAP) + 5;
181183

182184
if( gHUD.m_szServerName[0] )
183-
snprintf( ServerName, 80, "%s SERVER: %s", (char*)(gHUD.m_Teamplay ? "TEAMS" : "PLAYERS"), gHUD.m_szServerName );
185+
// snprintf( ServerName, 80, "%s", (char*)(gHUD.m_Teamplay ? "TEAMS" : "PLAYERS"), gHUD.m_szServerName );
186+
strncpy( ServerName, gHUD.m_szServerName, 80 );
184187
else
185188
strncpy( ServerName, gHUD.m_Teamplay ? "TEAMS" : "PLAYERS", 80 );
186189

187190
DrawUtils::DrawHudString( NAME_POS_START(), ypos, NAME_POS_END(), ServerName, 255, 140, 0 );
188-
DrawUtils::DrawHudStringReverse( HP_POS_END(), ypos, 0, "HP", 255, 140, 0 );
189-
DrawUtils::DrawHudString( MONEY_POS_START(), ypos, MONEY_POS_END(), "MONEY", 255, 140, 0 );
190-
DrawUtils::DrawHudStringReverse( KILLS_POS_END(), ypos, KILLS_POS_START(), "KILLS", 255, 140, 0 );
191-
DrawUtils::DrawHudString( DEATHS_POS_START(), ypos, DEATHS_POS_END(), "DEATHS", 255, 140, 0 );
192-
DrawUtils::DrawHudStringReverse( PING_POS_END(), ypos, PING_POS_START(), "PING", 255, 140, 0 );
191+
DrawUtils::DrawHudStringReverse( HP_POS_END(), ypos, 0, Localize( "#Cstrike_HEALTH" ), 255, 140, 0 );
192+
DrawUtils::DrawHudString( MONEY_POS_START(), ypos, MONEY_POS_END(), Localize( "#Cstrike_ACCOUNT" ), 255, 140, 0 );
193+
DrawUtils::DrawHudStringReverse( KILLS_POS_END(), ypos, KILLS_POS_START(), Localize( "#PlayerScore" ), 255, 140, 0 );
194+
DrawUtils::DrawHudString( DEATHS_POS_START(), ypos, DEATHS_POS_END(), Localize( "#PlayerDeath" ), 255, 140, 0 );
195+
DrawUtils::DrawHudStringReverse( PING_POS_END(), ypos, PING_POS_START(), Localize( "#PlayerPing" ), 255, 140, 0 );
193196

194197
list_slot += 2;
195198
ypos = ystart + (list_slot * ROW_GAP);
@@ -314,20 +317,43 @@ int CHudScoreboard :: DrawTeams( float list_slot )
314317
int r, g, b;
315318
char teamName[64];
316319

320+
char numPlayers[16];
321+
sprintf( numPlayers, "%d", team_info->players );
322+
323+
char fmtString[32];
324+
strncpy( fmtString, Localize( team_info->players == 1 ? "#Cstrike_ScoreBoard_Player" : "#Cstrike_ScoreBoard_Players" ), sizeof( fmtString ) );
325+
326+
if ( !strcmp( fmtString, team_info->players == 1 ? "Cstrike_ScoreBoard_Player" : "Cstrike_ScoreBoard_Players" ) )
327+
strncpy( fmtString, team_info->players == 1 ? "%s - %s player" : "%s - %s players", sizeof( fmtString ) );
328+
else
329+
for ( size_t i = 0; i < strlen( fmtString ) - 2; i++ )
330+
{
331+
if ( fmtString[i] == '%' && fmtString[i + 1] == 's' && isdigit( fmtString[i + 2] ) )
332+
{
333+
char *first = &fmtString[i + 2];
334+
char *second = &fmtString[i + 3];
335+
336+
size_t len = strlen( second );
337+
338+
memmove( first, second, strlen( second ) );
339+
first[len] = '\0';
340+
}
341+
}
342+
317343
GetTeamColor( r, g, b, team_info->teamnumber );
318-
switch( team_info->teamnumber )
344+
switch ( team_info->teamnumber )
319345
{
320346
case TEAM_TERRORIST:
321-
snprintf(teamName, sizeof(teamName), "Terrorists - %i players", team_info->players);
322-
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b );
347+
snprintf( teamName, sizeof( teamName ), fmtString, Localize( "#Cstrike_ScoreBoard_Ter" ), numPlayers );
348+
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b );
323349
break;
324350
case TEAM_CT:
325-
snprintf(teamName, sizeof(teamName), "Counter-Terrorists - %i players", team_info->players);
326-
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b );
351+
snprintf( teamName, sizeof( teamName ), fmtString, Localize( "#Cstrike_ScoreBoard_CT" ), numPlayers );
352+
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b );
327353
break;
328354
case TEAM_SPECTATOR:
329355
case TEAM_UNASSIGNED:
330-
strncpy( teamName, "Spectators", sizeof(teamName) );
356+
strncpy( teamName, Localize( "#Spectators" ), sizeof( teamName ) );
331357
break;
332358
}
333359

@@ -410,11 +436,13 @@ int CHudScoreboard :: DrawPlayers( float list_slot, int nameoffset, const char *
410436
{
411437
// draw bomb( if player have the bomb )
412438
if( g_PlayerExtraInfo[best_player].dead )
413-
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "Dead", r, g, b );
439+
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), Localize( "#Cstrike_DEAD" ), r, g, b );
414440
else if( g_PlayerExtraInfo[best_player].has_c4 )
415-
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "Bomb", r, g, b );
441+
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), Localize( "#Cstrike_BOMB" ), r, g, b );
416442
else if( g_PlayerExtraInfo[best_player].vip )
417-
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "VIP", r, g, b );
443+
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), Localize( "#Cstrike_VIP" ), r, g, b );
444+
else if (g_PlayerExtraInfo[best_player].has_defuse_kit )
445+
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), Localize( "#Cstrike_DEFUSE_KIT" ), r, g, b );
418446
}
419447
}
420448
else

game_shared/voice_status_hud.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void CVoiceLabel::SetLocation( const char *location )
8383
// const wchar_t *newLocation = vgui::localize()->Find( location );
8484
const char *newLocation = Localize( location );
8585

86-
if ( newLocation )
86+
if ( strcmp( newLocation, location + 1 ) != 0 )
8787
{
8888
// localized version
8989
if ( m_locationString && strcmp( newLocation, m_locationString ) )
@@ -161,7 +161,7 @@ void CVoiceLabel::RebuildLabelText()
161161
{
162162
// formatStr = localize()->Find( "#Voice_Location" );
163163
formatStr = Localize( "#Voice_Location" );
164-
if ( !formatStr )
164+
if ( !strcmp( formatStr, "Voice_Location") )
165165
formatStr = "%ls/%ls ";
166166
}
167167
// _snwprintf( buf, BufLen, formatStr, wsPlayer, m_locationString );

0 commit comments

Comments
 (0)