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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_hud_winpanel.h"
#include "tf_hud_statpanel.h"
#include "tf_spectatorgui.h"
#include "vgui_controls/AnimationController.h"
#include "iclientmode.h"
#include "engine/IEngineSound.h"
#include "c_tf_playerresource.h"
#include "c_team.h"
#include "tf_clientscoreboard.h"
#include <vgui_controls/Label.h>
#include <vgui_controls/ImagePanel.h>
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include "vgui_avatarimage.h"
#include "fmtstr.h"
#include "teamplayroundbased_gamerules.h"
#include "tf_gamerules.h"
#include "tf_logic_halloween_2014.h"
#include "c_tf_team.h"
#include "tf_badge_panel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
DECLARE_HUDELEMENT_DEPTH( CTFWinPanel, 1 );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CTFWinPanel::CTFWinPanel( const char *pElementName ) : EditablePanel( NULL, "WinPanel" ), CHudElement( pElementName )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
m_bShouldBeVisible = false;
SetAlpha( 0 );
SetScheme( "ClientScheme" );
m_pTeamScorePanel = new EditablePanel( this, "TeamScoresPanel" );
m_pRedTeamName = new CExLabel( m_pTeamScorePanel, "RedTeamLabel", "" );
m_pBlueTeamName = new CExLabel( m_pTeamScorePanel, "BlueTeamLabel", "" );
m_pRedLeaderAvatarImage = new CAvatarImagePanel( m_pTeamScorePanel, "RedLeaderAvatar" );
m_pBlueLeaderAvatarImage = new CAvatarImagePanel( m_pTeamScorePanel, "BlueLeaderAvatar" );
m_pRedLeaderAvatarBG = new EditablePanel( m_pTeamScorePanel, "RedLeaderAvatarBG" );
m_pBlueLeaderAvatarBG = new EditablePanel( m_pTeamScorePanel, "BlueLeaderAvatarBG" );
m_flTimeUpdateTeamScore = 0;
m_iBlueTeamScore = 0;
m_iRedTeamScore = 0;
RegisterForRenderGroup( "mid" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFWinPanel::ApplySettings( KeyValues *inResourceData )
{
BaseClass::ApplySettings( inResourceData );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFWinPanel::Reset()
{
m_bShouldBeVisible = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFWinPanel::Init()
{
// listen for events
ListenForGameEvent( "teamplay_win_panel" );
ListenForGameEvent( "teamplay_round_start" );
ListenForGameEvent( "teamplay_game_over" );
ListenForGameEvent( "tf_game_over" );
ListenForGameEvent( "training_complete" );
ListenForGameEvent( "show_match_summary" );
m_bShouldBeVisible = false;
CHudElement::Init();
}
void CTFWinPanel::SetVisible( bool state )
{
if ( state == IsVisible() )
return;
if ( state )
{
HideLowerPriorityHudElementsInGroup( "mid" );
}
else
{
UnhideLowerPriorityHudElementsInGroup( "mid" );
}
BaseClass::SetVisible( state );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFWinPanel::FireGameEvent( IGameEvent * event )
{
const char *pEventName = event->GetName();
if ( FStrEq( "teamplay_round_start", pEventName ) ||
FStrEq( "teamplay_game_over", pEventName ) ||
FStrEq( "tf_game_over", pEventName ) ||
FStrEq( "training_complete", pEventName ) ||
FStrEq( "show_match_summary", pEventName ) )
{
m_bShouldBeVisible = false;
}
else if ( Q_strcmp( "teamplay_win_panel", pEventName ) == 0 )
{
if ( !g_PR )
return;
vgui::IScheme* pScheme = scheme()->GetIScheme( GetScheme() );
int iWinningTeam = event->GetInt( "winning_team" );
int iWinReason = event->GetInt( "winreason" );
int iFlagCapLimit = event->GetInt( "flagcaplimit" );
bool bRoundComplete = (bool) event->GetInt( "round_complete" );
int iRoundsRemaining = event->GetInt( "rounds_remaining" );
bool bGameOver = event->GetBool( "game_over", false );
bool bUseMoreOpaqueBorder = false;
if ( TFGameRules() && bGameOver )
{
if ( TFGameRules()->IsMatchTypeCompetitive() )
{
bUseMoreOpaqueBorder = true;
}
}
// non-final rounds of stopwatch mode should say something different
CTeamRoundTimer *pTimer = NULL;
if ( TFGameRules() && TFGameRules()->IsInTournamentMode() && TFGameRules()->IsInStopWatch() )
{
int iActiveTimer = ObjectiveResource()->GetStopWatchTimer();
pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( iActiveTimer ) );
if ( pTimer )
{
if ( pTimer->IsWatchingTimeStamps() )
{
iWinningTeam = TEAM_INVALID;
iWinReason = bRoundComplete ? WINREASON_STOPWATCH_WATCHING_FINAL_ROUND : WINREASON_STOPWATCH_WATCHING_ROUNDS;
}
else
{
if ( !TFGameRules()->HaveStopWatchWinner() && !bRoundComplete )
{
iWinningTeam = TEAM_INVALID;
iWinReason = WINREASON_STOPWATCH_PLAYING_ROUNDS;
}
}
}
}
LoadControlSettings( "resource/UI/WinPanel.res" );
InvalidateLayout( false, true );
SetDialogVariable( "WinningTeamLabel", "" );
SetDialogVariable( "AdvancingTeamLabel", "" );
SetDialogVariable( "WinReasonLabel", "" );
SetDialogVariable( "DetailsLabel", "" );
EditablePanel *pBGPanel = dynamic_cast<EditablePanel *>( FindChildByName("WinPanelBGBorder") );
Assert( pBGPanel );
if ( !pBGPanel )
return;
EditablePanel *pBlueBGPanel = FindControl< EditablePanel >( "BlueScoreBG", true );
Assert( pBlueBGPanel );
EditablePanel *pRedBGPanel = FindControl< EditablePanel >( "RedScoreBG", true );
Assert( pRedBGPanel );
if( !pBlueBGPanel || !pRedBGPanel )
return;
pBlueBGPanel->SetBorder( pScheme->GetBorder( bUseMoreOpaqueBorder ? "TFFatLineBorderBlueBGMoreOpaque" : "TFFatLineBorderBlueBG" ) );
pRedBGPanel->SetBorder( pScheme->GetBorder( bUseMoreOpaqueBorder ? "TFFatLineBorderRedBGMoreOpaque" : "TFFatLineBorderRedBG" ) ) ;
// we want to suppress the winreason for sd_doomsday_event and plr_hightower_event
if ( TFGameRules() )
{
if ( ( TFGameRules()->IsHalloweenScenario( CTFGameRules::HALLOWEEN_SCENARIO_DOOMSDAY ) && CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() ) ||
( TFGameRules()->IsHalloweenScenario( CTFGameRules::HALLOWEEN_SCENARIO_HIGHTOWER ) ) )
{
iWinReason = WINREASON_NONE;
}
}
// this is an area defense, but not a round win, if this was a successful defend until time limit but not a complete round
bool bIsAreaDefense = ( ( WINREASON_DEFEND_UNTIL_TIME_LIMIT == iWinReason ) && !bRoundComplete );
// set the appropriate background image and label text
const wchar_t *pTeamLabel = L"";
const wchar_t *pTopPlayersLabel = L"";
const wchar_t *pLocalizedTeamName = L"";
const char *pWinTeamLabel = ( bRoundComplete ? "#Winpanel_TeamWins" : ( bIsAreaDefense ? "#Winpanel_TeamDefends" : "#Winpanel_TeamAdvances" ) );
C_TFTeam *pBlueTeam = GetGlobalTFTeam( TF_TEAM_BLUE );
const wchar_t *pBlueTeamName = pBlueTeam ? pBlueTeam->Get_Localized_Name() : L"BLU";
C_TFTeam *pRedTeam = GetGlobalTFTeam( TF_TEAM_RED );
const wchar_t *pRedTeamName = pRedTeam ? pRedTeam->Get_Localized_Name() : L"RED";
if ( TFGameRules() && TFGameRules()->IsInTournamentMode() )
{
pWinTeamLabel = ( bRoundComplete ? "#Winpanel_TournamentTeamWins" : ( bIsAreaDefense ? "#Winpanel_TournamentTeamDefends" : "#Winpanel_TournamentTeamAdvances" ) );
}
wchar_t wzTeamWin[256] = L"";
switch ( iWinningTeam )
{
case TF_TEAM_BLUE:
pBGPanel->SetBorder( pScheme->GetBorder( bUseMoreOpaqueBorder ? "TFFatLineBorderBlueBGMoreOpaque" : "TFFatLineBorderBlueBG" ) );
pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_BlueMVPs" );
pLocalizedTeamName = pBlueTeamName;
g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( pWinTeamLabel ), 2, pLocalizedTeamName, g_pVGuiLocalize->Find( "#Winpanel_Team1" ) );
pTeamLabel = wzTeamWin;
break;
case TF_TEAM_RED:
pBGPanel->SetBorder( pScheme->GetBorder( bUseMoreOpaqueBorder ? "TFFatLineBorderRedBGMoreOpaque" : "TFFatLineBorderRedBG" ) );
pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_RedMVPs" );
pLocalizedTeamName = pRedTeamName;
break;
case TEAM_UNASSIGNED: // stalemate
pBGPanel->SetBorder( pScheme->GetBorder( "TFFatLineBorder" ) );
pTeamLabel = g_pVGuiLocalize->Find( "#Winpanel_Stalemate" );
pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_TopPlayers" );
break;
case TEAM_INVALID: // used for stopwatch mode when it's not the final victory yet
pBGPanel->SetBorder( pScheme->GetBorder( "TFFatLineBorder" ) );
pTopPlayersLabel = g_pVGuiLocalize->Find( "#Winpanel_TopPlayers" );
pTeamLabel = L"";
if ( pBlueTeam && pBlueTeamName && pRedTeamName )
{
if ( bRoundComplete )
{
pTeamLabel = g_pVGuiLocalize->Find( "#WinPanel_StopWatch_Watching_RoundFinal" );
}
else
{
bool bBlueAttackers = ( pBlueTeam->GetRole() == TEAM_ROLE_ATTACKERS );
g_pVGuiLocalize->ConstructString_safe( wzTeamWin,
g_pVGuiLocalize->Find( "#WinPanel_StopWatch_Round_Complete" ),
1,
bBlueAttackers ? pBlueTeamName : pRedTeamName );
pTeamLabel = wzTeamWin;
}
}
break;
default:
Assert( false );
break;
}
SetDialogVariable( "TopPlayersLabel", pTopPlayersLabel );
if ( TFGameRules() && TFGameRules()->IsInTournamentMode() && !TFGameRules()->IsInStopWatch() )
{
g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( pWinTeamLabel ), 1, pLocalizedTeamName );
wchar_t wzTeamMPVs[256];
g_pVGuiLocalize->ConstructString_safe( wzTeamMPVs, g_pVGuiLocalize->Find( "#Winpanel_TournamentMVPs" ), 1, pLocalizedTeamName );
if ( iWinningTeam != TEAM_UNASSIGNED )
{
SetDialogVariable( "TopPlayersLabel", wzTeamMPVs );
}
}
else if ( ( iWinningTeam != TEAM_UNASSIGNED ) && ( iWinningTeam != TEAM_INVALID ) )
{
g_pVGuiLocalize->ConstructString_safe( wzTeamWin, g_pVGuiLocalize->Find( pWinTeamLabel ), 2, pLocalizedTeamName, g_pVGuiLocalize->Find( "#Winpanel_Team1" ) );
}
if ( ( iWinningTeam != TEAM_UNASSIGNED ) && ( iWinningTeam != TEAM_INVALID ) )
{
pTeamLabel = wzTeamWin;
}
SetDialogVariable( bRoundComplete ? "WinningTeamLabel" : "AdvancingTeamLabel", pTeamLabel );
wchar_t wzWinReason[256] = L"";
switch ( iWinReason )
{
case WINREASON_ALL_POINTS_CAPTURED:
{
if ( TFGameRules() && ( TFGameRules()->GetGameType() == TF_GAMETYPE_ESCORT ) && ( TFGameRules()->HasMultipleTrains() == true ) && ( iRoundsRemaining == 0 ) )
{
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_PayloadRace" ), 1, pLocalizedTeamName );
}
else
{
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_AllPointsCaptured" ), 1, pLocalizedTeamName );
}
}
break;
case WINREASON_FLAG_CAPTURE_LIMIT:
{
wchar_t wzFlagCaptureLimit[16];
_snwprintf( wzFlagCaptureLimit, ARRAYSIZE( wzFlagCaptureLimit), L"%i", iFlagCapLimit );
const wchar_t *wpszFormatString = NULL;
if ( iFlagCapLimit == 1 )
{
wpszFormatString = g_pVGuiLocalize->Find( "#Winreason_FlagCaptureLimit_One" );
}
if ( !wpszFormatString )
{
wpszFormatString = g_pVGuiLocalize->Find( "#Winreason_FlagCaptureLimit" );
}
g_pVGuiLocalize->ConstructString_safe( wzWinReason, wpszFormatString, 2,
pLocalizedTeamName, wzFlagCaptureLimit );
}
break;
case WINREASON_OPPONENTS_DEAD:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_OpponentsDead" ), 1, pLocalizedTeamName );
break;
case WINREASON_DEFEND_UNTIL_TIME_LIMIT:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_DefendedUntilTimeLimit" ), 1, pLocalizedTeamName );
break;
case WINREASON_STALEMATE:
if ( !TFGameRules() || !TFGameRules()->IsCompetitiveMode() )
{
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_Stalemate" ), 0 );
}
break;
case WINREASON_TIMELIMIT:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_TimeLimit" ), 1, pLocalizedTeamName );
break;
case WINREASON_WINLIMIT:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_WinLimit" ), 1, pLocalizedTeamName );
break;
case WINREASON_WINDIFFLIMIT:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_WinDiffLimit" ), 1, pLocalizedTeamName );
break;
case WINREASON_RD_REACTOR_CAPTURED:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_ReactorCaptured" ), 1, pLocalizedTeamName );
break;
case WINREASON_RD_CORES_COLLECTED:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_CoresCollected" ), 1, pLocalizedTeamName );
break;
case WINREASON_RD_REACTOR_RETURNED:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_ReactorReturned" ), 1, pLocalizedTeamName );
break;
case WINREASON_PD_POINTS:
g_pVGuiLocalize->ConstructString_safe( wzWinReason, g_pVGuiLocalize->Find( "#Winreason_PlayerDestructionPoints" ), 1, pLocalizedTeamName );
break;
case WINREASON_SCORED:
{
wchar_t wzScoreLimit[16];
_snwprintf( wzScoreLimit, ARRAYSIZE( wzScoreLimit ), L"%i", iFlagCapLimit );
const wchar_t *wpszFormatString = NULL;
if ( iFlagCapLimit == 1 )
{
wpszFormatString = g_pVGuiLocalize->Find( "#Winreason_ScoreLimit_One" );
}
if ( !wpszFormatString )
{
wpszFormatString = g_pVGuiLocalize->Find( "#Winreason_ScoreLimit" );
}
g_pVGuiLocalize->ConstructString_safe( wzWinReason, wpszFormatString, 2,
pLocalizedTeamName, wzScoreLimit );
}
break;
case WINREASON_STOPWATCH_WATCHING_ROUNDS:
if ( pBlueTeam && pBlueTeamName && pRedTeamName )
{
bool bBlueAttackers = ( pBlueTeam->GetRole() == TEAM_ROLE_ATTACKERS );
g_pVGuiLocalize->ConstructString_safe( wzWinReason,
g_pVGuiLocalize->Find( "#Winreason_Stopwatch_Watching_Rounds" ),
2,
bBlueAttackers ? pBlueTeamName : pRedTeamName,
bBlueAttackers ? pRedTeamName : pBlueTeamName );
}
break;
case WINREASON_STOPWATCH_WATCHING_FINAL_ROUND:
if ( pBlueTeam && pBlueTeamName && pRedTeamName )
{
bool bBlueAttackers = ( pBlueTeam->GetRole() == TEAM_ROLE_ATTACKERS );
g_pVGuiLocalize->ConstructString_safe( wzWinReason,
g_pVGuiLocalize->Find( "#Winreason_Stopwatch_SwitchSides" ),
2,
bBlueAttackers ? pRedTeamName : pBlueTeamName,
bBlueAttackers ? pBlueTeamName : pRedTeamName );
}
break;
case WINREASON_STOPWATCH_PLAYING_ROUNDS:
if ( pBlueTeam && pBlueTeamName && pRedTeamName )
{
bool bBlueAttackers = ( pBlueTeam->GetRole() == TEAM_ROLE_ATTACKERS );
g_pVGuiLocalize->ConstructString_safe( wzWinReason,
g_pVGuiLocalize->Find( "#Winreason_Stopwatch_Playing_Rounds" ),
2,
bBlueAttackers ? pBlueTeamName : pRedTeamName,
bBlueAttackers ? pRedTeamName : pBlueTeamName );
}
break;
default:
// This happens at the end of the Soldier training mission, FYI
Assert( false );
break;
}
SetDialogVariable( "WinReasonLabel", wzWinReason );
if ( !bRoundComplete && ( WINREASON_STALEMATE != iWinReason ) && ( WINREASON_STOPWATCH_WATCHING_ROUNDS != iWinReason ) && ( WINREASON_STOPWATCH_WATCHING_FINAL_ROUND != iWinReason ) && ( WINREASON_STOPWATCH_PLAYING_ROUNDS != iWinReason ) )
{
// if this was a mini-round, show # of capture points remaining
wchar_t wzNumCapturesRemaining[16];
wchar_t wzCapturesRemainingMsg[256]=L"";
_snwprintf( wzNumCapturesRemaining, ARRAYSIZE( wzNumCapturesRemaining ), L"%i", iRoundsRemaining );
g_pVGuiLocalize->ConstructString_safe( wzCapturesRemainingMsg,
g_pVGuiLocalize->Find( 1 == iRoundsRemaining ? "#Winpanel_CapturePointRemaining" : "Winpanel_CapturePointsRemaining" ),
1, wzNumCapturesRemaining );
SetDialogVariable( "DetailsLabel", wzCapturesRemainingMsg );
}
else if ( ( WINREASON_ALL_POINTS_CAPTURED == iWinReason ) || ( WINREASON_FLAG_CAPTURE_LIMIT == iWinReason ) )
{
// if this was a full round that ended with point capture or flag capture, show the winning cappers
const char *pCappers = event->GetString( "cappers" );
int iCappers = Q_strlen( pCappers );
if ( iCappers > 0 )
{
char szPlayerNames[256]="";
wchar_t wzPlayerNames[256]=L"";
wchar_t wzCapMsg[512]=L"";
for ( int i = 0; i < iCappers; i++ )
{
Q_strncat( szPlayerNames, g_PR->GetPlayerName( (int) pCappers[i] ), ARRAYSIZE( szPlayerNames ) );
if ( i < iCappers - 1 )
{
Q_strncat( szPlayerNames, ", ", ARRAYSIZE( szPlayerNames ) );
}
}
g_pVGuiLocalize->ConvertANSIToUnicode( szPlayerNames, wzPlayerNames, sizeof( wzPlayerNames ) );
g_pVGuiLocalize->ConstructString_safe( wzCapMsg, g_pVGuiLocalize->Find( "#Winpanel_WinningCapture" ), 1, wzPlayerNames );
SetDialogVariable( "DetailsLabel", wzCapMsg );
}
}
// get the current & previous team scores
int iBlueTeamPrevScore = event->GetInt( "blue_score_prev", 0 );
int iRedTeamPrevScore = event->GetInt( "red_score_prev", 0 );
m_iBlueTeamScore = event->GetInt( "blue_score", 0 );
m_iRedTeamScore = event->GetInt( "red_score", 0 );
if ( m_pTeamScorePanel )
{
m_pTeamScorePanel->SetDialogVariable( "blueteamname", pBlueTeamName );
m_pTeamScorePanel->SetDialogVariable( "redteamname", pRedTeamName );
if ( bRoundComplete )
{
// set the previous team scores in scoreboard
m_pTeamScorePanel->SetDialogVariable( "blueteamscore", iBlueTeamPrevScore );
m_pTeamScorePanel->SetDialogVariable( "redteamscore", iRedTeamPrevScore );
if ( ( m_iBlueTeamScore != iBlueTeamPrevScore ) || ( m_iRedTeamScore != iRedTeamPrevScore ) )
{
// if the new scores are different, set ourselves to update the scoreboard to the new values after a short delay, so players
// see the scores tick up
m_flTimeUpdateTeamScore = gpGlobals->curtime + 2.0f;
}
}
// only show team scores if round is complete
m_pTeamScorePanel->SetVisible( bRoundComplete );
}
if ( !g_TF_PR )
return;
// look for the top 3 players sent in the event
for ( int i = 1; i <= 3; i++ )
{
bool bShow = false;
char szPlayerIndexVal[64]="", szPlayerScoreVal[64]="";
// get player index and round points from the event
Q_snprintf( szPlayerIndexVal, ARRAYSIZE( szPlayerIndexVal ), "player_%d", i );
Q_snprintf( szPlayerScoreVal, ARRAYSIZE( szPlayerScoreVal ), "player_%d_points", i );
int iPlayerIndex = event->GetInt( szPlayerIndexVal, 0 );
int iRoundScore = event->GetInt( szPlayerScoreVal, 0 );
// round score of 0 means no player to show for that position (not enough players, or didn't score any points that round)
if ( iRoundScore > 0 )
bShow = true;
CAvatarImagePanel *pPlayerAvatar = dynamic_cast<CAvatarImagePanel *>( FindChildByName( CFmtStr( "Player%dAvatar", i ) ) );
if ( pPlayerAvatar )
{
pPlayerAvatar->SetShouldScaleImage( true );
pPlayerAvatar->SetShouldDrawFriendIcon( false );
if ( bShow )
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex( iPlayerIndex );
pPlayerAvatar->SetPlayer( pPlayer );
}
pPlayerAvatar->SetVisible( bShow );
}
CTFBadgePanel *pBadgePanel = dynamic_cast<CTFBadgePanel *>( FindChildByName( CFmtStr( "Player%dBadge", i ) ) );
if ( pBadgePanel )
{
const IMatchGroupDescription *pMatchDesc = TFGameRules() ? GetMatchGroupDescription( TFGameRules()->GetCurrentMatchGroup() ) : NULL;
const IProgressionDesc *pProgressionDesc = pMatchDesc ? pMatchDesc->m_pProgressionDesc : NULL;
bool bVisible = ( pMatchDesc && pProgressionDesc );
if ( bVisible )
{
if ( !bGameOver && TFGameRules()->IsMatchTypeCompetitive() )
{
bVisible = false;
}
}
if ( bVisible )
{
const CSteamID steamID = GetSteamIDForPlayerIndex( iPlayerIndex );
if ( steamID.IsValid() )
{
pBadgePanel->SetupBadge( pProgressionDesc, steamID );
}
else
{
bVisible = false;
}
}
if ( pBadgePanel->IsVisible() != bVisible )
{
pBadgePanel->SetVisible( bVisible );
}
}
vgui::Label *pPlayerName = dynamic_cast<Label *>( FindChildByName( CFmtStr( "Player%dName", i ) ) );
vgui::Label *pPlayerClass = dynamic_cast<Label *>( FindChildByName( CFmtStr( "Player%dClass", i ) ) );
vgui::Label *pPlayerScore = dynamic_cast<Label *>( FindChildByName( CFmtStr( "Player%dScore", i ) ) );
if ( !pPlayerName || !pPlayerClass || !pPlayerScore )
return;
if ( bShow )
{
// set the player labels to team color
Color clr = g_PR->GetTeamColor( g_PR->GetTeam( iPlayerIndex ) );
pPlayerName->SetFgColor( clr );
pPlayerClass->SetFgColor( clr );
pPlayerScore->SetFgColor( clr );
// set label contents
pPlayerName->SetText( g_PR->GetPlayerName( iPlayerIndex ) );
pPlayerClass->SetText( g_aPlayerClassNames[g_TF_PR->GetPlayerClass( iPlayerIndex )] );
pPlayerScore->SetText( CFmtStr( "%d", iRoundScore ) );
// send an achievement event
IGameEvent *pEvent = gameeventmanager->CreateEvent( "player_mvp" );
if ( pEvent )
{
pEvent->SetInt( "player", iPlayerIndex );
gameeventmanager->FireEventClientSide( pEvent );
}
}
// show or hide labels for this player position
pPlayerName->SetVisible( bShow );
pPlayerClass->SetVisible( bShow );
pPlayerScore->SetVisible( bShow );
}
// Top killstreak
const int nMaxKillStreaks = 1;
for ( int i = 1; i <= nMaxKillStreaks; ++i )
{
char szPlayerIndexVal[64]="", szPlayerScoreVal[64]="";
Q_snprintf( szPlayerIndexVal, ARRAYSIZE( szPlayerIndexVal ), "killstreak_player_%d", i );
Q_snprintf( szPlayerScoreVal, ARRAYSIZE( szPlayerScoreVal ), "killstreak_player_%d_count", i );
int iPlayerIndex = event->GetInt( szPlayerIndexVal, 0 );
int iCount = event->GetInt( szPlayerScoreVal, 0 );
vgui::Label *pKillStreakPlayerName = dynamic_cast<Label *>( FindChildByName( CFmtStr( "KillStreakPlayer%dName", i ) ) );
vgui::Label *pKillStreakPlayerClass = dynamic_cast<Label *>( FindChildByName( CFmtStr( "KillStreakPlayer%dClass", i ) ) );
vgui::Label *pKillStreakPlayerScore = dynamic_cast<Label *>( FindChildByName( CFmtStr( "KillStreakPlayer%dScore", i ) ) );
if ( !pKillStreakPlayerName || !pKillStreakPlayerClass || !pKillStreakPlayerScore )
continue;
bool bShow = iCount > 0;
if ( bShow )
{
CAvatarImagePanel *pPlayerAvatar = dynamic_cast<CAvatarImagePanel *>( FindChildByName( CFmtStr( "KillStreakPlayer%dAvatar", i ) ) );
if ( pPlayerAvatar )
{
pPlayerAvatar->SetShouldScaleImage( true );
pPlayerAvatar->SetShouldDrawFriendIcon( false );
CBasePlayer *pPlayer = UTIL_PlayerByIndex( iPlayerIndex );
pPlayerAvatar->SetPlayer( pPlayer );
pPlayerAvatar->SetVisible( true );
}
// set the player labels to team color
Color clr = g_PR->GetTeamColor( g_PR->GetTeam( iPlayerIndex ) );
pKillStreakPlayerName->SetFgColor( clr );
pKillStreakPlayerClass->SetFgColor( clr );
pKillStreakPlayerScore->SetFgColor( clr );
// set label contents
pKillStreakPlayerName->SetText( g_PR->GetPlayerName( iPlayerIndex ) );
pKillStreakPlayerClass->SetText( g_aPlayerClassNames[g_TF_PR->GetPlayerClass( iPlayerIndex )] );
pKillStreakPlayerScore->SetText( CFmtStr( "%d", iCount ) );
}
CTFBadgePanel *pBadgePanel = dynamic_cast<CTFBadgePanel *>( FindChildByName( CFmtStr( "KillStreakPlayer%dBadge", i ) ) );
if ( pBadgePanel )
{
const IMatchGroupDescription *pMatchDesc = GetMatchGroupDescription( TFGameRules()->GetCurrentMatchGroup() );
const IProgressionDesc *pProgressionDesc = pMatchDesc ? pMatchDesc->m_pProgressionDesc : NULL;
bool bVisible = ( bShow && pMatchDesc && pProgressionDesc );
if ( bVisible )
{
const CSteamID steamID = GetSteamIDForPlayerIndex( iPlayerIndex );
if ( steamID.IsValid() )
{
pBadgePanel->SetupBadge( pProgressionDesc, steamID );
}
else
{
bVisible = false;
}
}
if ( pBadgePanel->IsVisible() != bVisible )
{
pBadgePanel->SetVisible( bVisible );
}
}
// show or hide labels for this player position
pKillStreakPlayerName->SetVisible( bShow );
pKillStreakPlayerClass->SetVisible( bShow );
pKillStreakPlayerScore->SetVisible( bShow );
}
UpdateTeamInfo();
m_bShouldBeVisible = true;
MoveToFront();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFWinPanel::UpdateTeamInfo()
{
bool bShowAvatars = g_TF_PR && g_TF_PR->HasPremadeParties();
if ( bShowAvatars )
{
m_pRedLeaderAvatarImage->SetPlayer( GetSteamIDForPlayerIndex( g_TF_PR->GetPartyLeaderRedTeamIndex() ), k_EAvatarSize64x64 );
m_pRedLeaderAvatarImage->SetShouldDrawFriendIcon( false );
m_pBlueLeaderAvatarImage->SetPlayer( GetSteamIDForPlayerIndex( g_TF_PR->GetPartyLeaderBlueTeamIndex() ), k_EAvatarSize64x64 );
m_pBlueLeaderAvatarImage->SetShouldDrawFriendIcon( false );
}
m_pRedLeaderAvatarImage->SetVisible( bShowAvatars );
m_pRedLeaderAvatarBG->SetVisible( bShowAvatars );
m_pRedTeamName->SetVisible( !bShowAvatars );
m_pBlueLeaderAvatarImage->SetVisible( bShowAvatars );
m_pBlueLeaderAvatarBG->SetVisible( bShowAvatars );
m_pBlueTeamName->SetVisible( !bShowAvatars );
}
//-----------------------------------------------------------------------------
// Purpose: Applies scheme settings
//-----------------------------------------------------------------------------
void CTFWinPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
}
//-----------------------------------------------------------------------------
// Purpose: returns whether panel should be drawn
//-----------------------------------------------------------------------------
bool CTFWinPanel::ShouldDraw()
{
if ( !m_bShouldBeVisible )
return false;
return CHudElement::ShouldDraw();
}
//-----------------------------------------------------------------------------
// Purpose: panel think method
//-----------------------------------------------------------------------------
void CTFWinPanel::OnThink()
{
// if we've scheduled ourselves to update the team scores, handle it now
if ( m_flTimeUpdateTeamScore > 0 && ( gpGlobals->curtime > m_flTimeUpdateTeamScore ) && m_pTeamScorePanel )
{
IGameEvent *event = gameeventmanager->CreateEvent( "winpanel_show_scores" );
if ( event )
{
gameeventmanager->FireEventClientSide( event );
}
// play a sound
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "Hud.EndRoundScored" );
// update the team scores
if ( m_pTeamScorePanel )
{
m_pTeamScorePanel->SetDialogVariable( "blueteamscore", m_iBlueTeamScore );
m_pTeamScorePanel->SetDialogVariable( "redteamscore", m_iRedTeamScore );
}
m_flTimeUpdateTeamScore = 0;
}
}
|