1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "tf_hud_escort.h"
#include <vgui/IVGui.h>
#include "tf_hud_freezepanel.h"
#include "teamplayroundbased_gamerules.h"
#include "iclientmode.h"
#include "tf_gamerules.h"
#include "tf_hud_training.h"
#include <vgui/ILocalize.h>
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: Localize text for training messages. Used in annotations and in the training hud. Assumes the output string size is greater than or equal to MAX_TRAINING_MSG_LENGTH
//-----------------------------------------------------------------------------
bool CTFHudTraining::FormatTrainingText(const char* inputString, wchar_t* outputString)
{
static wchar_t szBuf[MAX_TRAINING_MSG_LENGTH];
static wchar_t *pszBuf;
if ( !inputString || !inputString[0] )
{
return false;
}
// init buffers & pointers
outputString[0] = 0;
szBuf[0] = 0;
pszBuf = szBuf;
// try to localize
pszBuf = g_pVGuiLocalize->Find( inputString );
if ( !pszBuf )
{
// use plain ASCII string
g_pVGuiLocalize->ConvertANSIToUnicode( inputString, szBuf, sizeof(szBuf) );
pszBuf = szBuf;
}
// Replace bindings with the keys
// parse out the text into a label set
wchar_t *ws = pszBuf;
while ( *ws )
{
wchar_t token[MAX_TRAINING_MSG_LENGTH];
bool isVar = false;
// check for variables
if ( *ws == '%' )
{
isVar = true;
++ws;
}
// parse out the string
wchar_t *end = wcschr( ws, '%' );
if ( end )
{
wcsncpy( token, ws, end - ws );
token[end - ws] = 0;
}
else
{
V_wcscpy_safe( token, ws );
}
ws += wcslen( token );
if ( isVar )
{
// move over the end of the variable
++ws;
}
// modify the label if necessary
if ( isVar )
{
// lookup key names
char binding[64];
g_pVGuiLocalize->ConvertUnicodeToANSI( token, binding, sizeof(binding) );
//!! change some key names into better names
char friendlyName[64];
const char *key = engine->Key_LookupBinding( *binding == '+' ? binding + 1 : binding );
if ( !key )
{
key = "< not bound >";
}
Q_snprintf( friendlyName, sizeof(friendlyName), "#%s", key );
Q_strupr( friendlyName );
// set the variable text - key may need to be localized (button images for example)
wchar_t *locName = g_pVGuiLocalize->Find( friendlyName );
if ( !locName || wcslen(locName) <= 0)
{
wchar_t wszFriendly[64];
g_pVGuiLocalize->ConvertANSIToUnicode( friendlyName+1, wszFriendly, sizeof( wszFriendly ) );
V_wcsncat( outputString, wszFriendly, MAX_TRAINING_MSG_LENGTH );
}
else
{
V_wcsncat( outputString, locName, MAX_TRAINING_MSG_LENGTH );
}
}
else
{
V_wcsncat( outputString, token, MAX_TRAINING_MSG_LENGTH );
}
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFHudTraining::CTFHudTraining( Panel *parent, const char *name ) : EditablePanel( parent, name )
{
m_pMsgLabel = NULL;
m_pPressSpacebarToContinueLabel = NULL;
ivgui()->AddTickSignal( GetVPanel(), 10 );
ListenForGameEvent( "teamplay_round_start" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFHudTraining::~CTFHudTraining()
{
ivgui()->RemoveTickSignal( GetVPanel() );
}
//-----------------------------------------------------------------------------
// Purpose: Hide when we take a freeze cam shot
//-----------------------------------------------------------------------------
bool CTFHudTraining::IsVisible( void )
{
if( IsTakingAFreezecamScreenshot() )
return false;
if ( IsInFreezeCam() )
return false;
return BaseClass::IsVisible();
}
void CTFHudTraining::Reset( void )
{
const char *emptyText = "";
SetDialogVariable( "goal", emptyText );
if (m_pMsgLabel) m_pMsgLabel->SetText(emptyText);
if (m_pPressSpacebarToContinueLabel) m_pPressSpacebarToContinueLabel->SetVisible( false );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFHudTraining::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
// load control settings...
LoadControlSettings( "resource/UI/HudTraining.res" );
m_pMsgLabel = dynamic_cast<CExRichText *>( FindChildByName("MsgLabel") );
m_pPressSpacebarToContinueLabel = dynamic_cast<CExLabel *>( FindChildByName("PressSpacebarToContinue") );
}
void CTFHudTraining::SetTrainingObjective(char *szRawString)
{
wchar_t wszText[MAX_TRAINING_MSG_LENGTH];
if (!FormatTrainingText(szRawString, wszText))
{
SetDialogVariable( "goal", "" );
return;
}
SetDialogVariable( "goal", wszText );
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( pLocalPlayer )
{
pLocalPlayer->EmitSound( "Hud.TrainingMsgUpdate" );
}
}
void CTFHudTraining::SetTrainingText(char *szRawString)
{
static wchar_t wszText[MAX_TRAINING_MSG_LENGTH];
InvalidateLayout( false, true );
if ( !m_pMsgLabel )
return;
if (!FormatTrainingText(szRawString, wszText))
{
m_pMsgLabel->SetText( "" );
return;
}
// clear the text first
m_pMsgLabel->SetText("");
enum
{
COLOR_NORMAL = 1,
COLOR_HINT = 2,
};
static wchar_t wszInsertedText[MAX_TRAINING_MSG_LENGTH];
Color color = m_pMsgLabel->GetFgColor();
Color newColor = color;
int startIdx = 0;
int endIdx = 0;
bool bContinue = true;
while ( bContinue )
{
bool bSetText = false;
switch ( wszText[endIdx] )
{
case 0:
bContinue = false;
bSetText = true;
break;
case COLOR_NORMAL:
newColor = m_pMsgLabel->GetFgColor();
bSetText = true;
break;
case COLOR_HINT:
newColor = m_pMsgLabel->GetSchemeColor( "HudTrainingHint", Color(255, 255, 255, 255), scheme()->GetIScheme( m_pMsgLabel->GetScheme() ) );
bSetText = true;
break;
}
if ( bSetText )
{
if ( startIdx != endIdx )
{
int len = endIdx - startIdx + 1;
wcsncpy( wszInsertedText, wszText + startIdx, len );
wszInsertedText[len-1] = 0;
m_pMsgLabel->InsertColorChange( color );
m_pMsgLabel->InsertString( wszInsertedText );
// skip past the color change character
startIdx = endIdx + 1;
}
color = newColor;
}
++endIdx;
}
//m_pMessageFlashEndTime = gpGlobals->curtime + MESSAGE_FLASH_TIME;
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "TrainingHudBounce");
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( pLocalPlayer )
{
pLocalPlayer->EmitSound( "Hud.TrainingMsgUpdate" );
}
}
//-----------------------------------------------------------------------------
// Purpose: Receive messages about changes in state
//-----------------------------------------------------------------------------
void CTFHudTraining::FireGameEvent( IGameEvent *event )
{
const char *eventName = event->GetName();
if ( FStrEq( "teamplay_round_start", eventName ) )
{
InvalidateLayout( false, true );
}
}
void CTFHudTraining::OnTick( )
{
bool bShouldBeVisible = TFGameRules() && TFGameRules()->IsWaitingForTrainingContinue();
if ( m_pPressSpacebarToContinueLabel && bShouldBeVisible != m_pPressSpacebarToContinueLabel->IsVisible() )
{
m_pPressSpacebarToContinueLabel->SetVisible( bShouldBeVisible );
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( bShouldBeVisible ? "TrainingPressSpacebarBlink" : "TrainingPressSpacebarBlinkStop" );
}
}
|