|
43 | 43 | // |
44 | 44 | // #include <vgui/ILocalize.h> |
45 | 45 |
|
| 46 | +#include "utlstring.h" |
| 47 | + |
46 | 48 | #include "triangleapi.h" |
47 | 49 | #include "draw_util.h" |
48 | 50 |
|
@@ -95,9 +97,8 @@ void CVoiceLabel::SetLocation( const char *location ) |
95 | 97 | if ( !m_locationString ) |
96 | 98 | { |
97 | 99 | // 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 ); |
101 | 102 | RebuildLabelText(); |
102 | 103 | } |
103 | 104 | } |
@@ -156,16 +157,42 @@ void CVoiceLabel::RebuildLabelText() |
156 | 157 | // localize()->ConvertANSIToUnicode( m_playerName, wsPlayer, sizeof( wsPlayer ) ); |
157 | 158 |
|
158 | 159 | // const wchar_t *formatStr = L"%ls "; |
159 | | - const char *formatStr = "%s "; |
| 160 | + const char *locStr = Localize( "#Voice_Location" ); |
| 161 | + |
160 | 162 | if ( m_locationString ) |
161 | 163 | { |
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 ); |
166 | 194 | } |
167 | 195 | // _snwprintf( buf, BufLen, formatStr, wsPlayer, m_locationString ); |
168 | | - snprintf( buf, BufLen, formatStr, m_playerName, m_locationString ); |
169 | 196 | } |
170 | 197 | // /m_pLabel->SetText( buf ); |
171 | 198 | strncpy( m_buf, buf, sizeof( m_buf ) ); |
|
0 commit comments