Skip to content

Commit 0c6711d

Browse files
committed
client: add player location to voice HUD for Condition Zero
1 parent 6e3f8c9 commit 0c6711d

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

cl_dll/hud.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ class CCStrikeVoiceStatusHelper : public IVoiceStatusHelper
9494
{
9595
return !gHUD.m_Scoreboard.m_bForceDraw && !gHUD.m_Scoreboard.m_bShowscoresHeld;
9696
}
97+
98+
const char *GetPlayerLocation( int entindex ) override
99+
{
100+
if ( gHUD.GetGameType() == GAME_CZERO )
101+
{
102+
if ( entindex >= 1 && entindex <= MAX_PLAYERS )
103+
{
104+
return g_PlayerExtraInfo[entindex].location;
105+
}
106+
}
107+
108+
return "";
109+
}
97110
};
98111
static CCStrikeVoiceStatusHelper g_VoiceStatusHelper;
99112

game_shared/voice_status_hud.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
//
4444
// #include <vgui/ILocalize.h>
4545

46+
#include "utlstring.h"
47+
4648
#include "triangleapi.h"
4749
#include "draw_util.h"
4850

@@ -95,9 +97,8 @@ void CVoiceLabel::SetLocation( const char *location )
9597
if ( !m_locationString )
9698
{
9799
// m_locationString = CloneWString( newLocation );
98-
m_locationString = new char[sizeof( newLocation )];
99-
strncpy( m_locationString, newLocation, sizeof( m_locationString ) );
100-
// m_locationString[sizeof( m_locationString ) - 1] = '\0';
100+
m_locationString = new char[strlen( newLocation ) + 1];
101+
strcpy( m_locationString, newLocation );
101102
RebuildLabelText();
102103
}
103104
}
@@ -156,16 +157,42 @@ void CVoiceLabel::RebuildLabelText()
156157
// localize()->ConvertANSIToUnicode( m_playerName, wsPlayer, sizeof( wsPlayer ) );
157158

158159
// const wchar_t *formatStr = L"%ls ";
159-
const char *formatStr = "%s ";
160+
const char *locStr = Localize( "#Voice_Location" );
161+
160162
if ( m_locationString )
161163
{
162-
// formatStr = localize()->Find( "#Voice_Location" );
163-
formatStr = Localize( "#Voice_Location" );
164-
if ( !strcmp( formatStr, "#Voice_Location") )
165-
formatStr = "%ls/%ls ";
164+
if ( !strcmp( locStr, "#Voice_Location" ) )
165+
{
166+
snprintf( buf, BufLen, "%s @ %s ", m_playerName, m_locationString );
167+
}
168+
else
169+
{
170+
const char *tokens[2] = { m_playerName, m_locationString };
171+
int tokenIdx = 0;
172+
173+
CUtlString result;
174+
for ( const char *src = locStr; *src; )
175+
{
176+
if ( src[0] == '%' && src[1] == 'l' && src[2] == 's' && tokenIdx < 2 )
177+
{
178+
result += tokens[tokenIdx++];
179+
src += 3;
180+
}
181+
else
182+
{
183+
result.AppendChar( *src++ );
184+
}
185+
}
186+
187+
strncpy( buf, result.String(), BufLen - 1 );
188+
buf[BufLen - 1] = '\0';
189+
}
190+
}
191+
else
192+
{
193+
snprintf( buf, BufLen, "%s ", m_playerName );
166194
}
167195
// _snwprintf( buf, BufLen, formatStr, wsPlayer, m_locationString );
168-
snprintf( buf, BufLen, formatStr, m_playerName, m_locationString );
169196
}
170197
// /m_pLabel->SetText( buf );
171198
strncpy( m_buf, buf, sizeof( m_buf ) );

game_shared/voice_status_hud.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CVoiceLabel
6363
void GetContentSize( int &wide, int &tall )
6464
{
6565
// m_pLabel->GetContentSize( wide, tall );
66-
wide = DrawUtils::HudStringLen( m_playerName ) + 8;
66+
wide = DrawUtils::HudStringLen( m_buf );
6767

6868
tall = gHUD.GetCharHeight();
6969

0 commit comments

Comments
 (0)