Skip to content

Commit aac0ae7

Browse files
committed
client: small cleanup
1 parent 5a51b72 commit aac0ae7

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

cl_dll/hud/scoreboard.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,24 +321,13 @@ int CHudScoreboard :: DrawTeams( float list_slot )
321321
sprintf( numPlayers, "%d", team_info->players );
322322

323323
char fmtString[32];
324-
strncpy( fmtString, Localize( team_info->players == 1 ? "#Cstrike_ScoreBoard_Player" : "#Cstrike_ScoreBoard_Players" ), sizeof( fmtString ) );
324+
const char *fmtStringName = team_info->players == 1 ? "#Cstrike_ScoreBoard_Player" : "#Cstrike_ScoreBoard_Players";
325+
strncpy( fmtString, Localize( fmtStringName ), sizeof( fmtString ) );
325326

326-
if ( !strcmp( fmtString, team_info->players == 1 ? "Cstrike_ScoreBoard_Player" : "Cstrike_ScoreBoard_Players" ) )
327+
if ( !strcmp( fmtString, fmtStringName ) )
327328
strncpy( fmtString, team_info->players == 1 ? "%s - %s player" : "%s - %s players", sizeof( fmtString ) );
328329
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-
}
330+
Localize_StripIndices( fmtString );
342331

343332
GetTeamColor( r, g, b, team_info->teamnumber );
344333
switch ( team_info->teamnumber )

cl_dll/include/vgui_parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ void Localize_Free( );
3737

3838
const char* Localize( const char* string );
3939
void StripEndNewlineFromString( char *str );
40+
41+
void Localize_StripIndices( char *s );
4042
#endif

cl_dll/text_message.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,7 @@ int CHudTextMessage::MsgFunc_TextMsg( const char *pszName, int iSize, void *pbuf
206206

207207
// Remove numbers after %s.
208208
// VALVEWHY?
209-
if( strlen(msg_text) >= 3 )
210-
{
211-
for( size_t i = 0; i < strlen(msg_text) - 2; i++)
212-
{
213-
if( msg_text[i] == '%' && msg_text[i + 1] == 's' && isdigit(msg_text[i + 2]))
214-
{
215-
char *first = &msg_text[i + 2];
216-
char *second = &msg_text[i + 3];
217-
218-
size_t len = strlen( second );
219-
220-
memmove( first, second, strlen( second ));
221-
first[len] = '\0'; // one character has been removed and string moved, set null terminator
222-
}
223-
}
224-
}
225-
209+
Localize_StripIndices( msg_text );
226210

227211
switch ( msg_dest )
228212
{

cl_dll/vgui_parser.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ const char *Localize( const char *szStr )
6363
{
6464
if( szStr )
6565
{
66-
if( *szStr == '#' )
67-
szStr++;
68-
6966
char *str = strdup( szStr );
67+
7068
StripEndNewlineFromString( str );
7169

70+
if( *str == '#' )
71+
str++;
72+
7273
int i = hashed_cmds.Find( str );
7374

7475
free( str );
@@ -277,3 +278,23 @@ void Localize_Free( void )
277278

278279
hashed_cmds.Purge();
279280
}
281+
282+
void Localize_StripIndices( char *s )
283+
{
284+
if ( strlen( s ) >= 3 )
285+
{
286+
for ( size_t i = 0; i < strlen( s ) - 2; i++ )
287+
{
288+
if ( s[i] == '%' && s[i + 1] == 's' && isdigit( s[i + 2] ) )
289+
{
290+
char *first = &s[i + 2];
291+
char *second = &s[i + 3];
292+
293+
size_t len = strlen( second );
294+
295+
memmove( first, second, strlen( second ) );
296+
first[len] = '\0'; // one character has been removed and string moved, set null terminator
297+
}
298+
}
299+
}
300+
}

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 ( strcmp( newLocation, location + 1 ) != 0 )
86+
if ( strcmp( newLocation, location ) != 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 ( !strcmp( formatStr, "Voice_Location") )
164+
if ( !strcmp( formatStr, "#Voice_Location") )
165165
formatStr = "%ls/%ls ";
166166
}
167167
// _snwprintf( buf, BufLen, formatStr, wsPlayer, m_locationString );

0 commit comments

Comments
 (0)