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:
//
//=============================================================================//
#include "sessionlobbydialog.h"
#include "engine/imatchmaking.h"
#include "GameUI_Interface.h"
#include "EngineInterface.h"
#include "vgui/ISurface.h"
#include "vgui_controls/ImagePanel.h"
#include "vgui/ILocalize.h"
#include "BasePanel.h"
#include "matchmakingbasepanel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
CSessionLobbyDialog *g_pLobbyDialog;
//--------------------------------
// CSessionLobbyDialog
//--------------------------------
CSessionLobbyDialog::CSessionLobbyDialog( vgui::Panel *pParent ) : BaseClass( pParent, "SessionLobbyDialog" )
{
m_Menus[0].SetParent( this );
m_Menus[0].SetName( "BluePlayers" );
m_Menus[1].SetParent( this );
m_Menus[1].SetName( "RedPlayers" );
m_iLocalTeam = -1;
m_iActiveMenu = -1;
m_nHostId = 0;
m_bHostLobby = false;
m_bCenterOnScreen = true;
m_pLobbyStateBg = new vgui::Panel( this, "LobbyStateBg" );
m_pLobbyStateLabel = new CPropertyLabel( this, "LobbyStateLabel", "" );
m_pLobbyStateIcon = new CPropertyLabel( this, "LobbyStateIcon", "" );
m_pHostLabel = new CPropertyLabel( this, "HostLabel", "" );
m_pHostOptionsPanel = new vgui::EditablePanel( this, "HostOptions" );
m_pScenarioInfo = new CScenarioInfoPanel( this, "GameScenario" );
m_pTeamInfos[BLUE_TEAM_LOBBY] = new CScenarioInfoPanel( this, "BlueTeamDescription" );
m_pTeamInfos[RED_TEAM_LOBBY] = new CScenarioInfoPanel( this, "RedTeamDescription" );
m_pDialogKeys = NULL;
g_pLobbyDialog = this;
m_bStartingGame = false;
m_nLastPlayersNeeded = 0;
m_nMinInfoHeight[BLUE_TEAM_LOBBY] = 0;
m_nMinInfoHeight[RED_TEAM_LOBBY] = 0;
}
CSessionLobbyDialog::~CSessionLobbyDialog()
{
delete m_pLobbyStateBg;
delete m_pLobbyStateLabel;
delete m_pLobbyStateIcon;
delete m_pHostLabel;
delete m_pHostOptionsPanel;
delete m_pScenarioInfo;
for ( int i = 0; i < TOTAL_LOBBY_TEAMS; ++i )
{
delete m_pTeamInfos[i];
}
}
//---------------------------------------------------------------------
// Purpose: Dialog keys contain session contexts and properties
//---------------------------------------------------------------------
void CSessionLobbyDialog::SetDialogKeys( KeyValues *pKeys )
{
m_pDialogKeys = pKeys;
InvalidateLayout();
}
//---------------------------------------------------------------------
// Purpose: Helper to set label text from keyvalues
//---------------------------------------------------------------------
void CSessionLobbyDialog::SetTextFromKeyvalues( CPropertyLabel *pLabel )
{
KeyValues *pKey = m_pDialogKeys->FindKey( pLabel->m_szPropertyString );
if ( pKey )
{
const char *pString = pKey->GetString( "displaystring", NULL );
if ( pString )
{
pLabel->SetText( pString );
}
}
}
//---------------------------------------------------------------------
// Purpose: Center the dialog on the screen
//---------------------------------------------------------------------
void CSessionLobbyDialog::PerformLayout()
{
BaseClass::PerformLayout();
if ( !m_pDialogKeys )
return;
// Set the label strings according to the keyvalues passed in
SetTextFromKeyvalues( m_pScenarioInfo->m_pTitle );
SetTextFromKeyvalues( m_pScenarioInfo->m_pDescOne );
SetTextFromKeyvalues( m_pScenarioInfo->m_pDescTwo );
SetTextFromKeyvalues( m_pScenarioInfo->m_pDescThree );
SetTextFromKeyvalues( m_pScenarioInfo->m_pValueTwo );
SetTextFromKeyvalues( m_pScenarioInfo->m_pValueThree );
const char *pDiskName = "unknown";
KeyValues *pName = m_pDialogKeys->FindKey( "MapDiskNames" );
if ( pName )
{
KeyValues *pScenario = m_pDialogKeys->FindKey( "CONTEXT_SCENARIO" );
if ( pScenario )
{
pDiskName = pName->GetString( pScenario->GetString( "displaystring" ), "unknown" );
}
}
// find the scenario type
KeyValues *pType = m_pDialogKeys->FindKey( "ScenarioTypes" );
if ( pType )
{
const char *pString = pType->GetString( pDiskName, NULL );
if ( pString )
{
m_pScenarioInfo->m_pSubtitle->SetText( pString );
}
}
// Set the team goals
KeyValues *pGoals = m_pDialogKeys->FindKey( "TeamGoals" );
if ( pGoals )
{
KeyValues *pTeam = pGoals->FindKey( "Blue" );
if ( pTeam )
{
m_pTeamInfos[BLUE_TEAM_LOBBY]->m_pDescOne->SetText( pTeam->GetString( pDiskName, "" ) );
}
pTeam = pGoals->FindKey( "Red" );
if ( pTeam )
{
m_pTeamInfos[RED_TEAM_LOBBY]->m_pDescOne->SetText( pTeam->GetString( pDiskName, "" ) );
}
}
for ( int i = 0; i < TOTAL_LOBBY_TEAMS; ++i )
{
UpdatePlayerCountDisplay( i );
}
if ( m_bCenterOnScreen )
{
MoveToCenterOfScreen();
}
// Don't allow player reviews in system link games
CMatchmakingBasePanel *pBase = dynamic_cast< CMatchmakingBasePanel* >( m_pParent );
if ( pBase )
{
pBase->SetFooterButtonVisible( "#GameUI_PlayerReview", pBase->GetGameType() != GAMETYPE_SYSTEMLINK_MATCH );
// hide the settings changing if we're in a ranked game
if ( m_pHostOptionsPanel )
{
bool bVisible = pBase->GetGameType() != GAMETYPE_RANKED_MATCH;
vgui::Label *pSettingsLabel = (vgui::Label *)m_pHostOptionsPanel->FindChildByName("ChangeSettingsButton",true);
if ( pSettingsLabel )
{
pSettingsLabel->SetVisible( bVisible );
}
pSettingsLabel = (vgui::Label *)m_pHostOptionsPanel->FindChildByName("ChangeSettingsText",true);
if ( pSettingsLabel )
{
pSettingsLabel->SetVisible( bVisible );
}
}
}
}
//---------------------------------------------------------------------
// Purpose: Parse session properties and contexts from the resource file
//---------------------------------------------------------------------
void CSessionLobbyDialog::ApplySettings( KeyValues *pResourceData )
{
BaseClass::ApplySettings( pResourceData );
m_nImageBorderWidth = pResourceData->GetInt( "imageborderwidth", 15 );
m_nTeamspacing = pResourceData->GetInt( "teamspacing", 0 );
m_bHostLobby = pResourceData->GetInt( "hostlobby", 0 ) != 0;
m_bCenterOnScreen = pResourceData->GetInt( "center", 1 ) == 1;
Q_strncpy( m_szCommand, pResourceData->GetString( "commandstring", "NULL" ), sizeof( m_szCommand ) );
}
//---------------------------------------------------------------------
// Purpose: Set up colors and other such stuff
//---------------------------------------------------------------------
void CSessionLobbyDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
Color cLabelColor = pScheme->GetColor( "MatchmakingDialogTitleColor", Color( 0, 0, 0, 255 ) );
m_pLobbyStateLabel->SetFgColor( cLabelColor );
m_pHostLabel->SetFgColor( cLabelColor );
m_pLobbyStateBg->SetBgColor( pScheme->GetColor( "TanDarker", Color( 0, 0, 0, 255 ) ) );
m_pLobbyStateBg->SetPaintBackgroundType( 2 );
m_pHostOptionsPanel->SetBgColor( pScheme->GetColor( "TanDarker", Color( 0, 0, 0, 255 ) ) );
m_pHostOptionsPanel->SetPaintBackgroundType( 2 );
m_pScenarioInfo->SetBgColor( pScheme->GetColor( "TanDarker", Color( 0, 0, 0, 255 ) ) );
m_pTeamInfos[BLUE_TEAM_LOBBY]->SetBgColor( pScheme->GetColor( "HudBlueTeam", Color( 0, 0, 0, 255 ) ) );
m_pTeamInfos[RED_TEAM_LOBBY]->SetBgColor( pScheme->GetColor( "HudRedTeam", Color( 0, 0, 0, 255 ) ) );
// Cache of these heights so we never go below them when resizing
m_nMinInfoHeight[BLUE_TEAM_LOBBY] = m_pTeamInfos[BLUE_TEAM_LOBBY]->GetTall();
m_nMinInfoHeight[RED_TEAM_LOBBY] = m_pTeamInfos[RED_TEAM_LOBBY]->GetTall();
//Lets set all the labels this panel owns to be the right fgcolor. hooray vgui!
int iChildren = m_pHostOptionsPanel->GetChildCount();
for ( int i=0;i<iChildren;i++ )
{
vgui::Label *pLabel = dynamic_cast< vgui::Label * >( m_pHostOptionsPanel->GetChild(i) );
if ( pLabel )
{
SETUP_PANEL( pLabel );
pLabel->SetFgColor( cLabelColor );
}
}
vgui::Label *pPlayerReviewLabel = (vgui::Label *)FindChildByName("PlayerReviewLabel" );
if ( pPlayerReviewLabel )
{
SETUP_PANEL( pPlayerReviewLabel );
pPlayerReviewLabel->SetFgColor( cLabelColor );
}
SetLobbyReadyState( m_nLastPlayersNeeded );
}
void CSessionLobbyDialog::PositionTeamInfos()
{
// Line up the team info panels and menus
int x, y;
int menux, menuy;
m_pTeamInfos[0]->GetPos( x, y );
m_Menus[0].GetPos( menux, menuy );
for ( int i = 1; i < TOTAL_LOBBY_TEAMS; ++i )
{
y += m_pTeamInfos[i - 1]->GetTall() + m_nTeamspacing;
m_pTeamInfos[i]->SetPos( x, y );
m_Menus[i].SetPos( menux, y );
}
}
void CSessionLobbyDialog::ActivateNextMenu()
{
int startIndex = m_iActiveMenu;
m_Menus[m_iActiveMenu].SetFocus( -1 );
do
{
m_iActiveMenu = (m_iActiveMenu + 1) % TOTAL_LOBBY_TEAMS;
} while ( m_Menus[m_iActiveMenu].GetItemCount() == 0 && m_iActiveMenu != startIndex );
m_Menus[m_iActiveMenu].SetFocus( 0 );
}
void CSessionLobbyDialog::ActivatePreviousMenu()
{
int startIndex = m_iActiveMenu;
m_Menus[m_iActiveMenu].SetFocus( -1 );
do
{
m_iActiveMenu = m_iActiveMenu ? m_iActiveMenu - 1 : TOTAL_LOBBY_TEAMS - 1;
} while ( m_Menus[m_iActiveMenu].GetItemCount() == 0 && m_iActiveMenu != startIndex );
m_Menus[m_iActiveMenu].SetFocus( m_Menus[m_iActiveMenu].GetItemCount() - 1 );
}
void CSessionLobbyDialog::UpdatePlayerCountDisplay( int iTeam )
{
int ct = m_Menus[iTeam].GetItemCount();
wchar_t wszString[32];
wchar_t *wzPlayersFmt = g_pVGuiLocalize->Find( ct != 1 ? "#TF_ScoreBoard_Players" : "#TF_ScoreBoard_Player" );
wchar_t wzPlayerCt[8];
V_snwprintf( wzPlayerCt, ARRAYSIZE( wzPlayerCt ), L"%d", ct );
g_pVGuiLocalize->ConstructString( wszString, sizeof( wszString ), wzPlayersFmt, 1, wzPlayerCt );
m_pTeamInfos[iTeam]->m_pSubtitle->SetText( wszString );
if ( m_nMinInfoHeight[iTeam] == 0 )
{
m_nMinInfoHeight[iTeam] = m_pTeamInfos[iTeam]->GetTall();
}
int height = max( m_nMinInfoHeight[iTeam], m_Menus[iTeam].GetTall() );
m_pTeamInfos[iTeam]->SetTall( height );
PositionTeamInfos();
}
void CSessionLobbyDialog::UpdatePlayerInfo( uint64 nPlayerId, const char *pName, int iTeam, byte cVoiceState, int nPlayersNeeded, bool bHost )
{
if ( m_iLocalTeam == -1 )
{
m_iLocalTeam = iTeam;
}
bool bReady = ( nPlayersNeeded == 0 );
// Look for the player
int iFoundTeam = -1;
int iFoundItem = -1;
CPlayerItem *pFound = NULL;
for ( int iMenu = 0; iMenu < TOTAL_LOBBY_TEAMS && !pFound; ++iMenu )
{
CDialogMenu &menu = m_Menus[iMenu];
if ( menu.GetItemCount() == 0 )
continue;
for ( int idx = 0; idx < menu.GetItemCount(); ++idx )
{
CPlayerItem *pPlayerItem = dynamic_cast< CPlayerItem* >( menu.GetItem( idx ) );
if ( pPlayerItem && pPlayerItem->m_nId == nPlayerId )
{
pFound = pPlayerItem;
iFoundTeam = iMenu;
iFoundItem = idx;
break;
}
}
}
// Update menu and item focus if the player changed teams
if ( iFoundTeam != iTeam )
{
if ( pFound )
{
// Remove the player from the current team
m_Menus[iFoundTeam].RemovePlayerItem( iFoundItem );
UpdatePlayerCountDisplay( iFoundTeam );
}
if ( 0 <= iTeam && iTeam < TOTAL_LOBBY_TEAMS )
{
// Add the player to the new team
m_Menus[iTeam].AddPlayerItem( pName, nPlayerId, cVoiceState, bReady );
UpdatePlayerCountDisplay( iTeam );
}
// if the player joined an empty lobby, set the active team
if ( m_iActiveMenu == -1 )
{
m_iActiveMenu = iTeam;
m_Menus[m_iActiveMenu].SetFocus( 0 );
}
// update the highlight position
if ( iFoundTeam == m_iActiveMenu )
{
CDialogMenu &activeMenu = m_Menus[m_iActiveMenu];
int iActive = activeMenu.GetActiveItemIndex();
if ( iActive == iFoundItem )
{
// The changed player was also the highlighted player
if ( iTeam >= 0 )
{
// Move the highlight to the player's new position
activeMenu.SetFocus( -1 );
m_iActiveMenu = iTeam;
m_Menus[m_iActiveMenu].SetFocus( m_Menus[m_iActiveMenu].GetItemCount() - 1 );
}
else
{
// player left the game, move the highlight to the next filled slot
if ( iActive >= activeMenu.GetItemCount() )
{
ActivateNextMenu();
}
}
}
else if ( iActive > iFoundItem )
{
// Need to drop the highlighted index one slot
m_Menus[m_iActiveMenu].SetFocus( iActive - 1 );
}
}
}
else
{
if ( pFound )
{
if ( pFound->m_bVoice != cVoiceState )
{
pFound->m_bVoice = cVoiceState;
pFound->InvalidateLayout();
}
}
}
if ( bHost )
{
wchar_t wszString[MAX_PATH];
wchar_t wszHostname[MAX_PATH];
wchar_t *wzHostFmt = g_pVGuiLocalize->Find( "#TF_Lobby_Host" );
g_pVGuiLocalize->ConvertANSIToUnicode( pName, wszHostname, sizeof( wszHostname ) );
V_snwprintf( wszString, ARRAYSIZE(wszString), L"%s\n%s", wzHostFmt, wszHostname );
m_pHostLabel->SetText( wszString );
m_nHostId = nPlayerId;
}
int iPlayersNeeded = ( bReady ) ? 0 : nPlayersNeeded;
SetLobbyReadyState( iPlayersNeeded );
m_nLastPlayersNeeded = iPlayersNeeded;
InvalidateLayout( true, false );
}
void CSessionLobbyDialog::SetLobbyReadyState( int nPlayersNeeded )
{
// check if the host is allowed to start the game
if ( nPlayersNeeded <= 0 )
{
if ( m_bHostLobby )
{
m_pLobbyStateLabel->SetText( "#TF_PressStart" );
m_pLobbyStateIcon->SetText( "#GameUI_Icons_START" );
}
else
{
m_pLobbyStateLabel->SetText( "#TF_WaitingForHost" );
m_pLobbyStateIcon->SetText( "#TF_Icon_Alert" );
m_bStartingGame = false; // client guesses that they can change teams
}
}
else
{
wchar_t wszWaiting[64];
wchar_t *wzWaitingFmt;
if ( nPlayersNeeded == 1 )
{
wzWaitingFmt = g_pVGuiLocalize->Find( "#TF_WaitingForPlayerFmt" );
}
else
{
wzWaitingFmt = g_pVGuiLocalize->Find( "#TF_WaitingForPlayersFmt" );
}
wchar_t wzPlayers[8];
V_snwprintf( wzPlayers, ARRAYSIZE( wzPlayers ), L"%d", nPlayersNeeded );
g_pVGuiLocalize->ConstructString( wszWaiting, sizeof( wszWaiting ), wzWaitingFmt, 1, wzPlayers );
m_pLobbyStateLabel->SetText( wszWaiting );
m_pLobbyStateIcon->SetText( "#TF_Icon_Alert" );
// If we were starting and dropped below min players, cancel
SetStartGame( false );
}
}
void CSessionLobbyDialog::UpdateCountdown( int seconds )
{
if ( seconds == -1 )
{
// countdown was canceled
SetLobbyReadyState( 0 );
return;
}
// Set the text in the countdown label
wchar_t wszCountdown[MAX_PATH];
wchar_t wszSeconds[MAX_PATH];
wchar_t *wzCountdownFmt;
if ( seconds != 1 )
{
wzCountdownFmt = g_pVGuiLocalize->Find( "#TF_StartingInSecs" );
}
else
{
wzCountdownFmt = g_pVGuiLocalize->Find( "#TF_StartingInSec" );
}
V_snwprintf( wszSeconds, ARRAYSIZE( wszSeconds ), L"%d", seconds );
g_pVGuiLocalize->ConstructString( wszCountdown, sizeof( wszCountdown ), wzCountdownFmt, 1, wszSeconds );
m_pLobbyStateLabel->SetText( wszCountdown );
if ( !m_bHostLobby )
{
m_bStartingGame = true; // client guesses that they can't change teams
}
}
//-----------------------------------------------------------------
// Purpose: Send key presses to the dialog's menu
//-----------------------------------------------------------------
void CSessionLobbyDialog::OnKeyCodePressed( vgui::KeyCode code )
{
CDialogMenu *pMenu = &m_Menus[m_iActiveMenu];
if ( !pMenu )
return;
int idx = pMenu->GetActiveItemIndex();
int itemCt = pMenu->GetItemCount();
CPlayerItem *pItem = dynamic_cast< CPlayerItem* >( pMenu->GetItem( idx ) );
if ( !pItem )
return;
SetDeleteSelfOnClose( true );
switch( code )
{
case KEY_XBUTTON_DOWN:
case KEY_XSTICK1_DOWN:
case STEAMCONTROLLER_DPAD_DOWN:
if ( idx >= itemCt - 1 )
{
ActivateNextMenu();
}
else
{
pMenu->HandleKeyCode( code );
}
break;
case KEY_XBUTTON_UP:
case KEY_XSTICK1_UP:
case STEAMCONTROLLER_DPAD_UP:
if ( idx <= 0 )
{
ActivatePreviousMenu();
}
else
{
pMenu->HandleKeyCode( code );
}
break;
case KEY_XBUTTON_A:
case STEAMCONTROLLER_A:
#ifdef _X360
XShowGamerCardUI( XBX_GetPrimaryUserId(), pItem->m_nId );
#endif
break;
case KEY_XBUTTON_RIGHT_SHOULDER:
#ifdef _X360
{
// Don't allow player reviews in system link games
CMatchmakingBasePanel *pBase = dynamic_cast< CMatchmakingBasePanel* >( m_pParent );
if ( pBase && pBase->GetGameType() == GAMETYPE_SYSTEMLINK_MATCH )
break;
}
XShowPlayerReviewUI( XBX_GetPrimaryUserId(), pItem->m_nId );
#endif
break;
case KEY_XBUTTON_LEFT_SHOULDER:
{
// Don't kick ourselves
if ( m_bHostLobby )
{
if ( pItem && ((CPlayerItem*)pItem)->m_nId != m_nHostId )
{
GameUI().ShowMessageDialog( MD_KICK_CONFIRMATION, this );
}
else
{
vgui::surface()->PlaySound( "player/suit_denydevice.wav" );
}
}
}
break;
case KEY_XBUTTON_B:
case STEAMCONTROLLER_B:
GameUI().ShowMessageDialog( MD_EXIT_SESSION_CONFIRMATION, this );
if ( m_bHostLobby )
{
SetStartGame( false );
}
break;
case KEY_XBUTTON_X:
case STEAMCONTROLLER_X:
if ( m_bStartingGame )
{
// We think we're loading the game, so play deny sound
vgui::surface()->PlaySound( "player/suit_denydevice.wav" );
}
else
{
matchmaking->ChangeTeam( NULL );
}
break;
case KEY_XBUTTON_Y:
case STEAMCONTROLLER_Y:
if ( m_bHostLobby )
{
// Don't allow settings changes in ranked games
CMatchmakingBasePanel *pBase = dynamic_cast< CMatchmakingBasePanel* >( m_pParent );
if ( pBase && pBase->GetGameType() == GAMETYPE_RANKED_MATCH )
break;
SetDeleteSelfOnClose( false );
OnCommand( "SessionOptions_Modify" );
SetStartGame( false );
}
break;
case KEY_XBUTTON_START:
SetStartGame( !m_bStartingGame );
break;
default:
pMenu->HandleKeyCode( code );
break;
}
}
//---------------------------------------------------------------------
// Purpose: start and stop the countdown
//---------------------------------------------------------------------
void CSessionLobbyDialog::SetStartGame( bool bStartGame )
{
if ( !m_bHostLobby )
return;
bool bCanStart = true;
if ( m_bStartingGame != bStartGame )
{
if ( bStartGame )
{
m_bStartingGame = matchmaking->StartGame();
bCanStart = m_bStartingGame;
}
else
{
if ( matchmaking->CancelStartGame() )
{
m_bStartingGame = false;
}
}
// If we can start the game but haven't started yet, show the "Start Game" label
bool bShowStartGame = bCanStart && !m_bStartingGame;
// show/hide the "start game" and countdown hint label based on state
vgui::Label *pStartGame = (vgui::Label *)m_pHostOptionsPanel->FindChildByName("StartGameText" );
if ( pStartGame )
{
pStartGame->SetVisible( m_bStartingGame == false );
}
vgui::Label *pCancelCountdown = (vgui::Label *)m_pHostOptionsPanel->FindChildByName("CancelGameText" );
if ( pCancelCountdown )
{
pCancelCountdown->SetVisible( m_bStartingGame == true );
}
if ( bShowStartGame )
{
m_pLobbyStateLabel->SetText( "#TF_PressStart" );
m_pLobbyStateIcon->SetText( "#GameUI_Icons_START" );
}
}
}
//---------------------------------------------------------------------
// Purpose: Handle menu commands
//---------------------------------------------------------------------
void CSessionLobbyDialog::OnCommand( const char *pCommand )
{
if ( !Q_stricmp( pCommand, "ReturnToMainMenu" ) )
{
matchmaking->KickPlayerFromSession( 0 );
}
else if ( !Q_stricmp( pCommand, "KickPlayer" ) )
{
CDialogMenu *pMenu = &m_Menus[m_iActiveMenu];
CPlayerItem *pItem = (CPlayerItem*)pMenu->GetItem( pMenu->GetActiveItemIndex() );
if ( pItem )
{
matchmaking->KickPlayerFromSession( pItem->m_nId );
}
}
GetParent()->OnCommand( pCommand );
}
static int pnum = 1;
CON_COMMAND( mm_add_player, "Add a player" )
{
if ( args.ArgC() >= 5 )
{
int team = atoi( args[1] );
const char *pName = args[2];
uint32 id = atoi( args[3] );
byte cVoiceState = atoi( args[4] ) != 0;
int nPlayersNeeded = atoi( args[5] );
g_pLobbyDialog->UpdatePlayerInfo( id, pName, team, cVoiceState, nPlayersNeeded, false );
}
else if ( args.ArgC() >= 1 )
{
char name[ 32 ];
int team = pnum & 0x1;
int id = pnum++;
if ( args.ArgC() >= 2 )
{
team = atoi( args[ 1 ] );
if ( args.ArgC() >= 3 )
{
id = atoi( args[2] );
}
}
Q_snprintf( name, sizeof( name ), "Player%d", pnum );
g_pLobbyDialog->UpdatePlayerInfo( id, name, team, true, 0, false );
}
}
|