summaryrefslogtreecommitdiff
path: root/game/client/tf/vgui/tf_lobbypanel_mvm.cpp
blob: 2132da3e305b3074806010b765a3750cbc066229 (plain) (blame)
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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//

#include "cbase.h"
#include "tf_gc_client.h"
#include "tf_party.h"

#include "vgui_controls/PropertySheet.h"
#include "vgui_controls/SectionedListPanel.h"
#include "vgui_bitmapimage.h"
#include "vgui_avatarimage.h"
#include "store/store_panel.h"
#include <VGuiMatSurface/IMatSystemSurface.h>
#include <vgui_controls/ImageList.h>

#include "tf_lobbypanel_mvm.h"
#include "tf_lobby_container_frame_mvm.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

extern ConVar tf_matchmaking_join_in_progress;
ConVar tf_matchmaking_ticket_help( "tf_matchmaking_ticket_help", "0", FCVAR_CLIENTDLL | FCVAR_DONTRECORD | FCVAR_ARCHIVE | FCVAR_HIDDEN, "Saved if the player has see the ticket help screen." );

const int k_iPopIndex_Any = -1000;
const int k_iPopIndex_OnlyNotYetCompleted = -1001;
const int k_iPopIndex_AnyNormal = -1002;
const int k_iPopIndex_AnyIntermediate = -1003;
const int k_iPopIndex_AnyAdvanced = -1004;
const int k_iPopIndex_AnyExpert = -1005;
const int k_iPopIndex_AnyHaunted = -1006;

static void GetMvmChallengeSet( int idxChallenge, CMvMMissionSet &result )
{
	result.Clear();

	if ( idxChallenge >= 0 )
	{
		result.SetMissionBySchemaIndex( idxChallenge, true );
		return;
	}

	bool bMannUP = GTFGCClientSystem()->GetSearchPlayForBraggingRights();
#ifdef USE_MVM_TOUR
	int idxTour = GTFGCClientSystem()->GetSearchMannUpTourIndex();
	Assert( bMannUP || idxTour < 0 );
#endif // USE_MVM_TOUR

#ifdef USE_MVM_TOUR
	uint32 nNotCompletedChallenges = ~0U;
	CTFParty *pParty = GTFGCClientSystem()->GetParty();
	if ( pParty )
	{
		for ( int i = 0 ; i < pParty->GetNumMembers() ; ++i )
		{
			nNotCompletedChallenges &= ~pParty->Obj().members( i ).completed_missions();
		}
	}
	else
	{
		if ( idxTour >= 0 )
		{
			uint32 nTours = 0, nCompletedChallenge = 0;
			GTFGCClientSystem()->BGetLocalPlayerBadgeInfoForTour( idxTour, &nTours, &nCompletedChallenge );

			nNotCompletedChallenges = ~nCompletedChallenge;
		}
	}
#endif // USE_MVM_TOUR

	for ( int i = 0 ; i < GetItemSchema()->GetMvmMissions().Count() ; ++i )
	{
		const MvMMission_t &chal = GetItemSchema()->GetMvmMissions()[ i ];

		// Cannot select non-MannUp missions in mann up mode
#ifdef USE_MVM_TOUR
		int iBadgeSlot = (idxTour < 0) ? -1 : GetItemSchema()->GetMvmMissionBadgeSlotForTour( idxTour, i );
		if ( bMannUP && iBadgeSlot < 0 )
			continue;
#else // new mm
		bool bIsChallengeInMannUp = chal.m_unMannUpPoints > 0;
		if ( bMannUP && !bIsChallengeInMannUp )
			continue;
#endif // USE_MVM_TOUR

		// Does this challenge fit the search criteria?
		bool bSelect = false;
		switch ( idxChallenge )
		{
			case k_iPopIndex_Any:
					bSelect = true;
				break;
			case k_iPopIndex_OnlyNotYetCompleted:
#ifdef USE_MVM_TOUR
				if ( iBadgeSlot >= 0 )
				{
					int iChallengeBit = ( 1 << iBadgeSlot );
					if ( nNotCompletedChallenges & iChallengeBit )
					{
						bSelect = true;
					}
				}
#endif // USE_MVM_TOUR
				break;

			case k_iPopIndex_AnyNormal:
				bSelect = ( chal.m_eDifficulty == k_EMvMChallengeDifficulty_Normal );
				break;

			case k_iPopIndex_AnyIntermediate:
				bSelect = ( chal.m_eDifficulty == k_EMvMChallengeDifficulty_Intermediate );
				break;

			case k_iPopIndex_AnyAdvanced:
				bSelect = ( chal.m_eDifficulty == k_EMvMChallengeDifficulty_Advanced );
				break;

			case k_iPopIndex_AnyExpert:
				bSelect = ( chal.m_eDifficulty == k_EMvMChallengeDifficulty_Expert );
				break;

			case k_iPopIndex_AnyHaunted:
				bSelect = ( chal.m_eDifficulty == k_EMvMChallengeDifficulty_Haunted );
				break;

			default:
				Assert( false );
		}
		result.SetMissionBySchemaIndex( i, bSelect );
	}
}

extern Color s_colorBannedPlayerListItem;
extern Color s_colorPlayerListItem;
extern Color s_colorChatRemovedFromQueue;
extern Color s_colorChatAddedToQueue;
extern Color s_colorChatPlayerJoinedParty;
extern Color s_colorChatPlayerJoinedPartyName;
extern Color s_colorChatPlayerLeftParty;
extern Color s_colorChatPlayerLeftPartyName;
extern Color s_colorChatPlayerChatName;
extern Color s_colorChatPlayerChatText;
extern Color s_colorChatDefault;
extern Color s_colorChallengeForegroundEnabled;
extern Color s_colorChallengeForegroundHaunted;
extern Color s_colorChallengeForegroundDisabled;
extern Color s_colorChallengeHeader;


static void GetPlayerNameForSteamID( wchar_t *wCharPlayerName, int nBufSizeBytes, const CSteamID &steamID )
{
	const char *pszName = steamapicontext->SteamFriends()->GetFriendPersonaName( steamID );
	V_UTF8ToUnicode( pszName, wCharPlayerName, nBufSizeBytes );
}

CLobbyPanel_MvM::CLobbyPanel_MvM( vgui::Panel *pParent, CBaseLobbyContainerFrame* pLobbyContainer ) 
	: CBaseLobbyPanel( pParent, pLobbyContainer )
{
	m_pMvMMannVsMachineGroupPanel = NULL;
	m_pMvMMannUpGroupPanel = NULL;
	m_pMvMPracticeGroupPanel = NULL;
	m_pMvMTourOfDutyGroupPanel = NULL;
	m_pMvMTourOfDutyListGroupBox = NULL;
	m_pTourList = NULL;

	m_MvMEconItemsGroupBox = NULL;
	m_pSquadSurplusCheckButton = NULL;
	m_pOpenStoreButton = NULL;
	m_pOpenStoreButton2 = NULL;
	m_pOpenHelpButton = NULL;
	m_pMannUpNowButton = NULL;
	m_pMannUpTourLootDescriptionBox = NULL;
	m_pMannUpTourLootImage = NULL;
	//m_pMannUpTourLootDetailLabel = NULL;
	m_pTourDifficultyWarning = NULL;
	
	m_MvMPracticeGroupPanel = NULL;

	m_pMvMSelectChallengeGroupPanel = NULL;
	m_pMVMChallengeListGroupBox = NULL;

	// MvM
	m_pMvMMannVsMachineGroupPanel = new vgui::EditablePanel( this, "MannVsMachineGroupBox" );
	m_pMvMMannUpGroupPanel = new vgui::EditablePanel( this, "MannUpGroupBox" );
	m_pMvMPracticeGroupPanel = new vgui::EditablePanel( this, "PracticeGroupBox" );
	m_pMvMTourOfDutyGroupPanel = new vgui::EditablePanel( this, "MvMTourOfDutyGroupBox" );

	m_MvMEconItemsGroupBox = new vgui::EditablePanel( this, "MvMEconItemsGroupBox" );
	m_pMannUpTicketImage = new vgui::ImagePanel( m_MvMEconItemsGroupBox, "MannUpTicketImage" );
	m_pSquadSurplusImage = new vgui::ImagePanel( m_MvMEconItemsGroupBox, "SquadSurplusImage" );

	m_pMannUpTourLootDescriptionBox = new vgui::EditablePanel( this, "MannUpTourLootDescriptionBox" );
	m_pMannUpTourLootImage = new vgui::ImagePanel( m_pMannUpTourLootDescriptionBox, "TourLootImage" );
	//m_pMannUpTourLootDetailLabel = new vgui::Label( m_pMannUpTourLootDescriptionBox, "TourLootDetailLabel", " );

	m_MvMPracticeGroupPanel = new vgui::EditablePanel( this, "MvMPracticeGroupBox" );

	m_pMvMSelectChallengeGroupPanel = new vgui::EditablePanel( this, "MvMSelectChallengeGroupBox" );
	m_pMVMChallengeListGroupBox = new vgui::EditablePanel( m_pMvMSelectChallengeGroupPanel, "ChallengeListGroupBox" );
	m_pChallengeList = new ChallengeList( this, m_pMVMChallengeListGroupBox, "ChallengeList" );

	m_pMvMTourOfDutyListGroupBox = new vgui::EditablePanel( m_pMvMTourOfDutyGroupPanel, "TourlistGroupBox" );
	m_pTourList = new vgui::SectionedListPanel( m_pMvMTourOfDutyListGroupBox, "TourList" );

	m_pTourDifficultyWarning = new vgui::Label( m_pMvMTourOfDutyGroupPanel, "TourDifficultyWarning", "" );

	m_fontChallengeListHeader = 0;
	m_fontChallengeListItem = 0;
}

CLobbyPanel_MvM::~CLobbyPanel_MvM()
{}

//-----------------------------------------------------------------------------
void CLobbyPanel_MvM::FireGameEvent( IGameEvent *event )
{
	BaseClass::FireGameEvent( event );

	const char *pszEventName = event->GetName();

	if ( !Q_stricmp( pszEventName, "mm_lobby_member_join" ) )
	{
#ifdef USE_MVM_TOUR
		WriteTourList();
#endif // USE_MVM_TOUR
		WriteChallengeList();

		return;
	}
	else if ( !Q_stricmp( pszEventName, "mm_lobby_member_leave" ) )
	{
#ifdef USE_MVM_TOUR
		WriteTourList();
#endif // USE_MVM_TOUR
		WriteChallengeList();

		return;
	}
}

void CLobbyPanel_MvM::OnCommand( const char *command )
{
	if ( FStrEq( command, "open_store_ticket" ) )
	{
		// Open the store, and show the upgrade advice
		EconUI()->CloseEconUI();

		CSchemaItemDefHandle hItemDef( CTFItemSchema::k_rchMvMTicketItemDefName );
		EconUI()->GetStorePanel()->AddToCartAndCheckoutImmediately( hItemDef->GetDefinitionIndex() );
		return;
	}
	else if ( FStrEq( command, "open_store_voucher" ) )
	{
		// Open the store, and show the upgrade advice
		EconUI()->CloseEconUI();

		CSchemaItemDefHandle hItemDef( CTFItemSchema::k_rchMvMSquadSurplusVoucherItemDefName );
		EconUI()->GetStorePanel()->AddToCartAndCheckoutImmediately( hItemDef->GetDefinitionIndex() );
		return;
	}
	else if ( FStrEq( command, "open_help" ) )
	{
		CExplanationPopup *pPopup = dynamic_cast< CExplanationPopup* >( GetParent()->FindChildByName("StartExplanation") );
		if ( pPopup )
		{
			pPopup->Popup();
		}
		return;
	}
	else if ( FStrEq( command, "mann_up_now" ) )
	{
		GTFGCClientSystem()->SetSearchChallenges( CMvMMissionSet() );
		m_pContainer->OnCommand( "back" );
		m_pContainer->OnCommand( "mannup" );
		return;
	}

	BaseClass::OnCommand( command );
}

void CLobbyPanel_MvM::SetMannUpTicketCount( int nCount )
{
	m_pMannUpTicketImage->SetImage( nCount > 0 ? "pve/mvm_ticket_active" : "pve/mvm_ticket_inactive" );

	char szCount[ 5 ];
	V_snprintf( szCount, sizeof( szCount ), "%i", nCount );

	m_MvMEconItemsGroupBox->SetDialogVariable( "ticket_count", szCount );
}

void CLobbyPanel_MvM::SetSquadSurplusCount( int nCount )
{
	char szCount[ 5 ];
	V_snprintf( szCount, sizeof( szCount ), "%i", nCount );

	m_MvMEconItemsGroupBox->SetDialogVariable( "voucher_count", szCount );
}

EMatchGroup CLobbyPanel_MvM::GetMatchGroup( void ) const
{
	return GTFGCClientSystem()->GetSearchPlayForBraggingRights() ? k_nMatchGroup_MvM_MannUp : k_nMatchGroup_MvM_Practice;
}

void CLobbyPanel_MvM::OnCheckButtonChecked( vgui::Panel *panel )
{
	if ( m_iWritingPanel > 0 )
		return;

	if ( panel == m_pSquadSurplusCheckButton )
	{
		if ( BIsPartyInUIState() && GTFGCClientSystem()->GetSearchPlayForBraggingRights() )
		{
			if ( m_pSquadSurplusCheckButton->IsSelected() )
			{
				if ( GTFGCClientSystem()->BLocalPlayerInventoryHasSquadSurplusVoucher() )
				{
					GTFGCClientSystem()->SetLocalPlayerSquadSurplus( true );
					m_pSquadSurplusImage->SetImage( "pve/mvm_voucher_active" );
				}
				else
				{
					m_pSquadSurplusCheckButton->SetSilentMode( true );
					m_pSquadSurplusCheckButton->SetSelected( false );
					m_pSquadSurplusCheckButton->SetSilentMode( false );
					ShowEconRequirementDialog( "#TF_MvM_RequiresSquadSurplusVoucher_Title", "#TF_MvM_RequiresSquadSurplusVoucher", CTFItemSchema::k_rchMvMSquadSurplusVoucherItemDefName );
				}
			}
			else
			{
				GTFGCClientSystem()->SetLocalPlayerSquadSurplus( false );

				m_pSquadSurplusImage->SetImage( "pve/mvm_voucher_inactive" );
			}
		}
		else
		{
			WriteGameSettingsControls();
		}

		return;
	}

	BaseClass::OnCheckButtonChecked( panel );
}


void CLobbyPanel_MvM::OnItemLeftClick( vgui::Panel* panel )
{
	if ( m_iWritingPanel > 0 )
		return;

#ifdef USE_MVM_TOUR
	if ( panel == m_pTourList )
	{
		OnClickedOnTour();
	}
#endif // USE_MVM_TOUR
	else if ( panel == m_pChallengeList )
	{
		OnClickedOnChallenge();
	}
	
	BaseClass::OnItemLeftClick( panel );
}

void CLobbyPanel_MvM::ApplyChatUserSettings( const LobbyPlayerInfo& player, KeyValues* pSettings ) const
{
	if ( GTFGCClientSystem()->GetSearchPlayForBraggingRights() )
	{
		pSettings->SetInt( "has_ticket", player.m_bHasTicket ? m_iImageHasTicket : m_iImageNoTicket );
		pSettings->SetInt( "squad_surplus", player.m_bSquadSurplus ? m_iImageSquadSurplus : m_iImageNoSquadSurplus );
	}
}

#ifdef USE_MVM_TOUR
void CLobbyPanel_MvM::OnClickedOnTour()
{
	int iSelected = m_pTourList->GetSelectedItem();
	m_pTourList->SetSelectedItem( -1 );
	if ( iSelected < 0 )
		return;
	if ( BIsPartyLeader() && BIsPartyInUIState() )
	{
		int iTourIndex = m_pTourList->GetItemData( iSelected )->GetInt( "tour_index", -1 );
		Assert( iTourIndex >= 0 );
		GTFGCClientSystem()->SetSearchMannUpTourIndex( iTourIndex );
	}
	else
	{
		WriteChallengeList();
	}
}
#endif // USE_MVM_TOUR

void CLobbyPanel_MvM::WriteGameSettingsControls()
{
	BaseClass::WriteGameSettingsControls();

	// Make sure we want to be in matchmaking.  (If we don't, the frame should hide us pretty quickly.)
	// We might get an event or something right at the transition point occasionally when the UI should
	// not be visible
	if ( GTFGCClientSystem()->GetMatchmakingUIState() == eMatchmakingUIState_Inactive )
	{
		return;
	}

	++m_iWritingPanel;

	bool bLeader = BIsPartyLeader();
	bool bInUIState = BIsPartyInUIState();

	TF_Matchmaking_WizardStep eWizardStep = GTFGCClientSystem()->GetWizardStep();

	// MVM
	m_pMvMMannVsMachineGroupPanel->SetVisible( eWizardStep == TF_Matchmaking_WizardStep_MVM_PLAY_FOR_BRAGGING_RIGHTS );
	m_pMvMMannUpGroupPanel->SetVisible( eWizardStep == TF_Matchmaking_WizardStep_MVM_PLAY_FOR_BRAGGING_RIGHTS );
	m_pMvMPracticeGroupPanel->SetVisible( eWizardStep == TF_Matchmaking_WizardStep_MVM_PLAY_FOR_BRAGGING_RIGHTS );
	m_pMannUpTourLootDescriptionBox->SetVisible( eWizardStep == TF_Matchmaking_WizardStep_MVM_TOUR_OF_DUTY );
	m_pMvMTourOfDutyGroupPanel->SetVisible( eWizardStep == TF_Matchmaking_WizardStep_MVM_TOUR_OF_DUTY );
	m_pMvMSelectChallengeGroupPanel->SetVisible( eWizardStep == TF_Matchmaking_WizardStep_MVM_CHALLENGE );

	bool bShowBottomPanel = ( eWizardStep == TF_Matchmaking_WizardStep_MVM_CHALLENGE );

	if ( !tf_matchmaking_ticket_help.GetBool() && bShowBottomPanel && GTFGCClientSystem()->GetSearchPlayForBraggingRights() )
	{
		OnCommand( "open_help" );
		tf_matchmaking_ticket_help.SetValue( 1 );
	}

	m_MvMEconItemsGroupBox->SetVisible( bShowBottomPanel && GTFGCClientSystem()->GetSearchPlayForBraggingRights() );
	m_MvMPracticeGroupPanel->SetVisible( bShowBottomPanel && !GTFGCClientSystem()->GetSearchPlayForBraggingRights() );

	if ( m_pMvMTourOfDutyGroupPanel->IsVisible() )
	{
		SetNavToRelay( m_pMvMTourOfDutyGroupPanel->GetName() );
	}
	else if ( m_pMvMSelectChallengeGroupPanel->IsVisible() )
	if ( m_pMvMSelectChallengeGroupPanel->IsVisible() )
	{
		SetNavToRelay( m_pMvMSelectChallengeGroupPanel->GetName() );
	}

	if ( m_MvMPracticeGroupPanel->IsVisible() )
	{
		SetNavToRelay( m_MvMPracticeGroupPanel->GetName() );
	}
	else if ( m_MvMEconItemsGroupBox->IsVisible() )
	{
		SetNavToRelay( m_MvMEconItemsGroupBox->GetName() );
	}

	m_pContainer->SetNextButtonEnabled( true );


#ifdef USE_MVM_TOUR
	WriteTourList();
#endif // USE_MVM_TOUR
	WriteChallengeList();

	FOR_EACH_VEC( m_vecSearchCriteriaLabels, i )
	{
		m_vecSearchCriteriaLabels[i]->SetEnabled( bInUIState );
	}

	m_pMVMChallengeListGroupBox->SetControlVisible( "GreyOutPanel", !( bLeader && bInUIState ) );
#ifdef USE_MVM_TOUR
	m_pMvMTourOfDutyListGroupBox->SetControlVisible( "GreyOutPanel", !( bLeader && bInUIState ) );
#endif // USE_MVM_TOUR
	bool bPlayForBraggingRights = GTFGCClientSystem()->GetSearchPlayForBraggingRights();
	m_pSquadSurplusCheckButton->SetEnabled( bInUIState && bPlayForBraggingRights );
	m_pSquadSurplusCheckButton->SetSilentMode( true );
	m_pSquadSurplusCheckButton->SetSelected( GTFGCClientSystem()->GetLocalPlayerSquadSurplus() );
	m_pSquadSurplusCheckButton->SetSilentMode( false );

	m_pSquadSurplusImage->SetImage( GTFGCClientSystem()->GetLocalPlayerSquadSurplus() ? "pve/mvm_voucher_active" : "pve/mvm_voucher_inactive" );

	--m_iWritingPanel;
}

bool CLobbyPanel_MvM::ShouldShowLateJoin() const
{
	TF_Matchmaking_WizardStep eWizardStep = GTFGCClientSystem()->GetWizardStep();
	return 
#ifdef USE_MVM_TOUR
		( eWizardStep == TF_Matchmaking_WizardStep_MVM_TOUR_OF_DUTY ) ||
#endif // USE_MVM_TOUR
		( eWizardStep == TF_Matchmaking_WizardStep_MVM_CHALLENGE ) ||
		( ( eWizardStep == TF_Matchmaking_WizardStep_SEARCHING ) && ( GTFGCClientSystem()->GetSearchMode() == TF_Matchmaking_MVM ) );
}

#ifdef USE_MVM_TOUR
void CLobbyPanel_MvM::WriteTourList()
{
	if ( !GTFGCClientSystem()->GetSearchPlayForBraggingRights() )
		return;

	++m_iWritingPanel;

	bool bLeader = BIsPartyLeader();
	bool bInUIState = BIsPartyInUIState();
	int idxSelectedTour = GTFGCClientSystem()->GetSearchMannUpTourIndex();

	m_pTourList->RemoveAll();
	m_pTourList->RemoveAllSections();

	m_pTourList->SetClickable( bLeader && bInUIState );
	m_pTourList->AddSection( 0, "Tour name" );
	m_pTourList->SetSectionAlwaysVisible( 0, false );
	m_pTourList->SetSectionFgColor( 0, s_colorChallengeHeader );
	m_pTourList->SetSectionDividerColor( 0, Color(0,0,0,0) );
	m_pTourList->AddColumnToSection( 0, "new","", vgui::SectionedListPanel::COLUMN_IMAGE, m_iNewWidth );
	m_pTourList->AddColumnToSection( 0, "check_box", "", vgui::SectionedListPanel::COLUMN_IMAGE, m_iChallengeCheckBoxWidth );
	m_pTourList->AddColumnToSection( 0, "spacer", "", 0, m_iChallengeSpacer );
 	m_pTourList->AddColumnToSection( 0, "display_name", "Tour", 0, m_iTourNameWidth );
 	m_pTourList->AddColumnToSection( 0, "skill", "Difficulty", 0, m_iTourSkillWidth );
 	m_pTourList->AddColumnToSection( 0, "progress", "Progress", 0, m_iTourProgressWidth );
 	m_pTourList->AddColumnToSection( 0, "badge_level", "Tours Completed", 0, m_iTourNumberWidth );
	m_pTourList->SetFontSection( 0, m_fontChallengeListHeader );

	bool bCompletedOneAdvancedTour = false;
	uint32 unBadgeLevel = 0, unCompletedChallengeMask = 0;
	const char *pszWarningString = "#TF_MVM_Tour_ExpertDifficulty_Warning";
	
	// Local player has completed at least one Advanced tour?
	FOR_EACH_VEC( GetItemSchema()->GetMvmTours(), idxTour )
	{
		GTFGCClientSystem()->BGetLocalPlayerBadgeInfoForTour( idxTour, &unBadgeLevel, &unCompletedChallengeMask );
		
		const MvMTour_t &tourInfo = GetItemSchema()->GetMvmTours()[idxTour];
		if ( tourInfo.m_eDifficulty >= k_EMvMChallengeDifficulty_Advanced && unBadgeLevel > 0 )
		{
			bCompletedOneAdvancedTour = true;
			break;
		}
	}

	// Add a row for each tour
	FOR_EACH_VEC( GetItemSchema()->GetMvmTours(), idxTour )
	{
		const MvMTour_t &tour = GetItemSchema()->GetMvmTours()[ idxTour ];

		KeyValues *kvItem = new KeyValues("item");

		GTFGCClientSystem()->BGetLocalPlayerBadgeInfoForTour( idxTour, &unBadgeLevel, &unCompletedChallengeMask );

		int nCompletedChallengeCount = 0;
		for ( int i = 0 ; i < tour.m_vecMissions.Count() ; ++i )
		{
			if ( unCompletedChallengeMask & ( 1 << tour.m_vecMissions[i].m_iBadgeSlot ) )
			{
				++nCompletedChallengeCount;
			}
		}

		char cchTemp[256];
		V_sprintf_safe( cchTemp, "%d / %d", nCompletedChallengeCount, tour.m_vecMissions.Count() );
		kvItem->SetString( "progress", cchTemp );

		uint32 iTourNumber = Max( 1U, unBadgeLevel );
		V_sprintf_safe( cchTemp, "%d", iTourNumber );
		kvItem->SetString( "badge_level", cchTemp );

		if ( tour.m_bIsNew )
		{
			kvItem->SetInt( "new", m_iImageNew );
		}

		kvItem->SetInt( "check_box", idxSelectedTour == idxTour ? m_iImageRadioButtonYes : m_iImageRadioButtonNo );
		kvItem->SetString( "display_name", tour.m_sTourNameLocalizationToken.Get() );
		kvItem->SetString( "skill", GetMvMChallengeDifficultyLocName( tour.m_eDifficulty ) );
		kvItem->SetInt( "tour_index", idxTour );
		int itemID = m_pTourList->AddItem( 0, kvItem );
		m_pTourList->SetItemFont( itemID, m_fontChallengeListItem );
		
		if ( tour.m_eDifficulty >= k_EMvMChallengeDifficulty_Expert && !bCompletedOneAdvancedTour )
		{
			m_pTourList->SetItemFgColor( itemID, s_colorBannedPlayerListItem );
			pszWarningString = "#TF_MVM_Tour_ExpertDifficulty_Denied";
		}
		else
		{
			m_pTourList->SetItemFgColor( itemID, s_colorChallengeForegroundEnabled );
		}
	}
	m_pTourList->SetSelectedItem( idxSelectedTour );

	const char *pszSelectedTourLocToken = "TF_MvM_Tour_NoSelection";
	const char *pszLootImage = "pve/mvm_loot_image";
	bool bShowDifficultyWarning = false;
	if ( idxSelectedTour >= 0 )
	{
		const MvMTour_t &tour = GetItemSchema()->GetMvmTours()[ idxSelectedTour ];
		pszLootImage = tour.m_sLootImageName.Get();
		pszSelectedTourLocToken = tour.m_sTourNameLocalizationToken.Get();

		// Check if we should show the difficulty warning
		if ( tour.m_eDifficulty >= k_EMvMChallengeDifficulty_Expert )
		{
			// Deny expert mode if they haven't completed at least one Advanced tour
			if (  !bCompletedOneAdvancedTour )
			{
				m_pContainer->SetNextButtonEnabled( false );
			}

			// Local player hasn't completed one mission?
			if ( !GTFGCClientSystem()->BGetLocalPlayerBadgeInfoForTour( idxSelectedTour, &unBadgeLevel, &unCompletedChallengeMask )
				|| unBadgeLevel == 0 )
			{
				bShowDifficultyWarning = true;
			}

			// Anybody in the party hasn't completed a mission?
			CTFParty *pParty = GTFGCClientSystem()->GetParty();
			if ( pParty != NULL )
			{
				for ( int i = 0 ; !bShowDifficultyWarning && i < pParty->GetNumMembers() ; ++i )
				{
					if ( pParty->Obj().members( i ).badge_level() == 0 )
					{
						bShowDifficultyWarning = true;
					}
				}
			}
		}
	}

	char archTemp[ 256 ];
	V_sprintf_safe( archTemp, "%s_LootDescription", pszSelectedTourLocToken );
	m_pMannUpTourLootDescriptionBox->SetDialogVariable( "tour_loot_detail", g_pVGuiLocalize->Find( archTemp ) );

	m_pMannUpTourLootImage->SetImage( pszLootImage );

	wchar_t wszLocalized[512];
	g_pVGuiLocalize->ConstructString_safe( wszLocalized, g_pVGuiLocalize->Find( pszWarningString ), 0 );
	m_pTourDifficultyWarning->SetText( wszLocalized );
	m_pTourDifficultyWarning->SetVisible( bShowDifficultyWarning );

	--m_iWritingPanel;
}
#endif // USE_MVM_TOUR

void CLobbyPanel_MvM::WriteChallengeList()
{
	++m_iWritingPanel;

	bool bLeader = BIsPartyLeader();
	bool bInUIState = BIsPartyInUIState();
	bool bForBraggingRights = GTFGCClientSystem()->GetSearchPlayForBraggingRights();
	
#ifdef USE_MVM_TOUR
	int idxTour = GTFGCClientSystem()->GetSearchMannUpTourIndex();

	char szTours[ 8 ] = "";
	if ( idxTour >= 0 )
	{
		uint32 nTours, nCompletedChallenge;
		GTFGCClientSystem()->BGetLocalPlayerBadgeInfoForTour( idxTour, &nTours, &nCompletedChallenge );
		if ( nTours < 1 ) // if we don't have a badge, show "1"
			nTours = 1;
		V_snprintf( szTours, sizeof( szTours ), "%u", nTours );
	}

	m_pChallengeList->SetClickable( bLeader && bInUIState );
	if ( idxTour < 0 )
	{
		m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "tour_name", g_pVGuiLocalize->Find( "#TF_MvM_Missions" ) );
	}
	else
	{
		m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "tour_name", g_pVGuiLocalize->Find( GetItemSchema()->GetMvmTours()[ idxTour ].m_sTourNameLocalizationToken.Get() ) );
	}
	m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "complete_heading", g_pVGuiLocalize->Find( bForBraggingRights ? "#TF_MvM_Complete" : "#TF_MvM_Difficulty" ) );
	m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "tour_level", szTours );
	m_pMvMSelectChallengeGroupPanel->SetControlVisible( "TourLevelImage", idxTour >= 0 );
#else // new mm
	char szTours[ 8 ] = "";

	m_pChallengeList->SetClickable( bLeader && bInUIState );
	m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "tour_name", g_pVGuiLocalize->Find( "#TF_MvM_Missions" ) );
	m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "complete_heading", g_pVGuiLocalize->Find( "#TF_MvM_Difficulty" ) );
	m_pMvMSelectChallengeGroupPanel->SetDialogVariable( "tour_level", szTours );
	m_pMvMSelectChallengeGroupPanel->SetControlVisible( "TourLevelImage", false );
#endif // USE_MVM_TOUR

	CMvMMissionSet searchChallenges;
	GTFGCClientSystem()->GetSearchChallenges( searchChallenges );

	m_pChallengeList->RemoveAll();
	m_pChallengeList->RemoveAllSections();
//	int iSelectChallengeItem = -1;

	int nCurrentSection = -1;
	KeyValues *kvItem = NULL;
	int itemID = 0;

	//
	// Top section is for special multi-select checkboxes
	//

	++nCurrentSection;

	m_pChallengeList->AddSection( nCurrentSection, "dummy_any_section" );
	m_pChallengeList->SetSectionAlwaysVisible( nCurrentSection, true );
	m_pChallengeList->SetSectionDividerColor( nCurrentSection, Color(0,0,0,0) );
	//m_pChallengeList->SetSectionFgColor( nCurrentSection, Color( 255, 255, 255, 255 ) );
	m_pChallengeList->AddColumnToSection( nCurrentSection, "check_box", "", vgui::SectionedListPanel::COLUMN_IMAGE, m_iChallengeCheckBoxWidth );
	m_pChallengeList->AddColumnToSection( nCurrentSection, "spacer", "", 0, m_iChallengeSpacer );
	m_pChallengeList->AddColumnToSection( nCurrentSection, "display_name", "", 0, m_iChallengeNameWidth );
	//m_pChallengeList->AddColumnToSection( nCurrentSection, "completed", "", 0, m_iChallengeCompletedWidth );
	//m_pChallengeList->SetFontSection( nCurrentSection, m_fontChallengeListHeader );
	//m_pChallengeList->SetSectionMinimumContentHeight( nCurrentSection, m_iMapImageHeight );

	m_pChallengeList->m_vecMapImages.Purge();

	// List of special multi-select options
	struct MissionMultiSelect_t
	{
		int m_idxChallenge;
		const char *m_pszDisplayName;
		bool m_bMannUp;
		bool m_bBootCamp;
	};
	static const MissionMultiSelect_t arMultiSelect[] =
	{
#ifdef USE_MVM_TOUR
		{ k_iPopIndex_Any, "#TF_MvM_AnyChallenge", true, false },
//		{ k_iPopIndex_AnyHaunted, "#TF_MvM_AnyHauntedChallenge", false, true },
		{ k_iPopIndex_AnyNormal, "#TF_MvM_AnyNormalChallenge", false, true },
		{ k_iPopIndex_AnyIntermediate, "#TF_MvM_AnyIntermediateChallenge", false, true },
		{ k_iPopIndex_AnyAdvanced, "#TF_MvM_AnyAdvancedChallenge", false, true },
		{ k_iPopIndex_AnyExpert, "#TF_MvM_AnyExpertChallenge", false, true },
		{ k_iPopIndex_OnlyNotYetCompleted, "#TF_MvM_OnlyChallengeNotYetCompleted", true, false }
#else // new mm
		{ k_iPopIndex_Any, "#TF_MvM_AnyChallenge", true, true },
//		{ k_iPopIndex_AnyHaunted, "#TF_MvM_AnyHauntedChallenge", false, true },
		{ k_iPopIndex_AnyNormal, "#TF_MvM_AnyNormalChallenge", true, true },
		{ k_iPopIndex_AnyIntermediate, "#TF_MvM_AnyIntermediateChallenge", true, true },
		{ k_iPopIndex_AnyAdvanced, "#TF_MvM_AnyAdvancedChallenge", true, true },
		{ k_iPopIndex_AnyExpert, "#TF_MvM_AnyExpertChallenge", true, true },
		{ k_iPopIndex_OnlyNotYetCompleted, "#TF_MvM_OnlyChallengeNotYetCompleted", false, false }
#endif // USE_MVM_TOUR
	};

	// Scan each potential multi-select option
	for ( int i = 0 ; i < Q_ARRAYSIZE( arMultiSelect ) ; ++i )
	{
		const MissionMultiSelect_t &ms = arMultiSelect[i];

		// Check if entry is applicable for this mode
		if ( bForBraggingRights ? !ms.m_bMannUp : !ms.m_bBootCamp )
			continue;

		// Gather list of all missions that fit this mode
		CMvMMissionSet msChallenges;
		GetMvmChallengeSet( ms.m_idxChallenge, msChallenges );

		// Any missions actually met the criteria for this multi-select?
		// (e.g. we might not have any intermediate missions active right now).
		int iCheckImage;
		if ( msChallenges.IsEmpty() )
		{
			if ( ms.m_idxChallenge != k_iPopIndex_OnlyNotYetCompleted )
				continue;
			iCheckImage = m_iImageCheckBoxDisabled;
		}
		else
		{

			// Determine checkbox status.  "Only not yet completed" is special
			if ( ms.m_idxChallenge == k_iPopIndex_OnlyNotYetCompleted )
			{
				if ( searchChallenges == msChallenges )
					iCheckImage = m_iImageCheckBoxYes; // all items currently selected
				else 
					iCheckImage = m_iImageCheckBoxNo; // does not exactly match, show as a "no"
			}
			else
			{
				// Get set of checked challenges that fall under this category
				CMvMMissionSet checked( searchChallenges );
				checked.Intersect( msChallenges );

				if ( checked == msChallenges )
					iCheckImage = m_iImageCheckBoxYes; // all items currently selected
				//else if ( !checked.IsEmpty() ) // Nope, don't ever show "mixed" state
				//	iCheckImage = m_iImageCheckBoxMixed; // some items currently selected
				else
					iCheckImage = m_iImageCheckBoxNo; // no items currently selected
			}

		}

		kvItem = new KeyValues("item");
		kvItem->SetInt( "check_box", iCheckImage );
		kvItem->SetString( "display_name", ms.m_pszDisplayName );
		kvItem->SetInt( "pop_index", ms.m_idxChallenge );
		itemID = m_pChallengeList->AddItem( nCurrentSection, kvItem );
		m_pChallengeList->SetItemFont( itemID, m_fontChallengeListItem );

		Color color = s_colorChallengeForegroundEnabled;
		if ( ms.m_idxChallenge == k_iPopIndex_AnyHaunted )
			color = s_colorChallengeForegroundHaunted;
		if ( iCheckImage == m_iImageCheckBoxDisabled )
			color = s_colorChallengeForegroundDisabled;
		m_pChallengeList->SetItemFgColor( itemID, color );
	}


	//
	// Now add a section for each map
	//

	int nCurrentMap = -1;
	FOR_EACH_VEC( GetItemSchema()->GetMvmMissions(), iMissionIndex )
	{
		const MvMMission_t &mission = GetItemSchema()->GetMvmMissions()[ iMissionIndex ];

#ifdef USE_MVM_TOUR
		if ( bForBraggingRights && GetItemSchema()->FindMvmMissionInTour( idxTour, iMissionIndex) < 0 ) // !KLUDGE! This is sort of crappy, we probably should iterate the tour's mission list rather than iterating the larger list with filtering
#else // new mm
		if ( bForBraggingRights && !searchChallenges.GetMissionBySchemaIndex( iMissionIndex ) )
#endif // USE_MVM_TOUR
			continue;

		kvItem = new KeyValues("item");

		const MvMMap_t &map = GetItemSchema()->GetMvmMaps()[ mission.m_iDisplayMapIndex ];

		if ( mission.m_iDisplayMapIndex != nCurrentMap )
		{
			++nCurrentSection;
			
			m_pChallengeList->AddSection( nCurrentSection, map.m_sDisplayName.Get() );
			m_pChallengeList->SetSectionAlwaysVisible( nCurrentSection, true );
			m_pChallengeList->SetSectionFgColor( nCurrentSection, s_colorChallengeHeader );
			m_pChallengeList->SetSectionDividerColor( nCurrentSection, Color(0,0,0,0) );
#ifdef USE_MVM_TOUR
			m_pChallengeList->AddColumnToSection( nCurrentSection, "check_box", "", vgui::SectionedListPanel::COLUMN_IMAGE, m_iChallengeCheckBoxWidth );
#else // new mm
			// for mannup, don't show check box
			if ( bForBraggingRights )
			{
				m_pChallengeList->AddColumnToSection( nCurrentSection, "spacer", "", 0, m_iChallengeCheckBoxWidth );
			}
			else
			{
				m_pChallengeList->AddColumnToSection( nCurrentSection, "check_box", "", vgui::SectionedListPanel::COLUMN_IMAGE, m_iChallengeCheckBoxWidth );
			}
#endif // USE_MVM_TOUR
			m_pChallengeList->AddColumnToSection( nCurrentSection, "spacer", "", 0, m_iChallengeSpacer );
			m_pChallengeList->AddColumnToSection( nCurrentSection, "display_name", map.m_sDisplayName.Get(), 0, m_iChallengeNameWidth );
			m_pChallengeList->AddColumnToSection( nCurrentSection, "skill", "", 0, m_iChallengeSkillWidth );
			m_pChallengeList->SetFontSection( nCurrentSection, m_fontChallengeListHeader );
			m_pChallengeList->SetSectionMinimumHeight( nCurrentSection, m_iMapImageHeight );

			BitmapImage &img = m_pChallengeList->m_vecMapImages[ m_pChallengeList->m_vecMapImages.AddToTail() ];
			CFmtStr sImageName("vgui/maps/menu_thumb_%s", map.m_sMap.Get() );
			img.SetImageFile( sImageName );

			nCurrentMap = mission.m_iDisplayMapIndex;
		}

		//wchar_t wszChallengeName[ 256 ];
		//g_pVGuiLocalize->ConstructString_safe( wszChallengeName, L"%s1 (%s2)", 2, 
		//								  g_pVGuiLocalize->Find( mission.m_sDisplayName.Get() ), g_pVGuiLocalize->Find( mission.m_sMode.Get() ) );
		//kvItem->SetWString( "display_name", wszChallengeName );
		kvItem->SetString( "display_name", mission.m_sDisplayName.Get() );

		bool bSelected = searchChallenges.GetMissionBySchemaIndex( iMissionIndex );

		kvItem->SetInt( "check_box", bSelected ? m_iImageCheckBoxYes : m_iImageCheckBoxNo );
		const char *pszDifficulty = "";
#ifdef USE_MVM_TOUR
		if ( !bForBraggingRights )
#endif // USE_MVM_TOUR
		{
			pszDifficulty = GetMvMChallengeDifficultyLocName( mission.m_eDifficulty );
		}
		kvItem->SetString( "skill", pszDifficulty );
		kvItem->SetInt( "pop_index", iMissionIndex );
		itemID = m_pChallengeList->AddItem( nCurrentSection, kvItem );
		m_pChallengeList->SetItemFont( itemID, m_fontChallengeListItem );

		Color color = s_colorChallengeForegroundEnabled;
		if ( mission.m_eDifficulty == k_EMvMChallengeDifficulty_Haunted )
			color = s_colorChallengeForegroundHaunted;
		m_pChallengeList->SetItemFgColor( itemID, color );

		kvItem->deleteThis();
	}

	--m_iWritingPanel;
}


//-----------------------------------------------------------------------------
void CLobbyPanel_MvM::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );

	m_pOpenStoreButton = dynamic_cast<vgui::Button *>(FindChildByName( "OpenStoreButton", true )); Assert( m_pOpenStoreButton );
	m_pOpenStoreButton2 = dynamic_cast<vgui::Button *>(FindChildByName( "OpenStoreButton2", true )); Assert( m_pOpenStoreButton2 );
	m_pOpenHelpButton = dynamic_cast<vgui::Button *>(FindChildByName( "OpenHelpButton", true )); Assert( m_pOpenHelpButton );
	m_pSquadSurplusCheckButton = dynamic_cast<vgui::CheckButton *>(FindChildByName( "SquadSurplusCheckButton", true )); Assert( m_pSquadSurplusCheckButton );
	m_pMannUpNowButton = dynamic_cast<vgui::Button *>(FindChildByName( "MannUpNowButton", true )); Assert( m_pMannUpNowButton );

	m_iImageHasTicket = m_pImageList->AddImage( vgui::scheme()->GetImage( "pve/mvm_ticket_small", true ) );
		m_pImageList->GetImage( m_iImageHasTicket )->SetSize( m_iHasTicketWidth, m_iHasTicketWidth );
	m_iImageNoTicket = m_pImageList->AddImage( vgui::scheme()->GetImage( "pve/mvm_no_ticket_small", true ) );
		m_pImageList->GetImage( m_iImageNoTicket )->SetSize( m_iHasTicketWidth, m_iHasTicketWidth );
	m_iImageSquadSurplus = m_pImageList->AddImage( vgui::scheme()->GetImage( "pve/mvm_squad_surplus_small", true ) );
		m_pImageList->GetImage( m_iImageSquadSurplus )->SetSize( m_iSquadSurplusWidth, m_iSquadSurplusWidth );
	m_iImageNoSquadSurplus = m_pImageList->AddImage( vgui::scheme()->GetImage( "pve/mvm_no_squad_surplus_small", true ) );
		m_pImageList->GetImage( m_iImageNoSquadSurplus )->SetSize( m_iSquadSurplusWidth, m_iSquadSurplusWidth );

	m_pChatPlayerList->SetImageList( m_pImageList, false );
	m_pChatPlayerList->SetVisible( true );
	m_pChallengeList->SetImageList( m_pImageList, false );
#ifdef USE_MVM_TOUR
	m_pTourList->SetImageList( m_pImageList, false );
#endif // USE_MVM_TOUR

	//
	// Populate the challenge list
	//

	m_pChallengeList->AddActionSignalTarget( this );
#ifdef USE_MVM_TOUR
	m_pTourList->AddActionSignalTarget( this );
#endif // USE_MVM_TOUR
	m_pSquadSurplusCheckButton->AddActionSignalTarget( this );
	m_pChatPlayerList->AddActionSignalTarget( this );
	m_pOpenStoreButton->AddActionSignalTarget( this );
	m_pOpenStoreButton2->AddActionSignalTarget( this );
	m_pOpenHelpButton->AddActionSignalTarget( this );
	m_pMannUpNowButton->AddActionSignalTarget( this );

	m_pChallengeList->SetVerticalScrollbar( true );
	m_pChallengeList->RemoveAll();
	m_pChallengeList->RemoveAllSections();
	m_pChallengeList->SetDrawHeaders( true );
	m_pChallengeList->SetClickable( true );
	m_pChallengeList->SetBgColor( Color( 0, 0, 0, 0 ) );
	m_pChallengeList->SetBorder( NULL );

#ifdef USE_MVM_TOUR
	m_pTourList->SetDrawHeaders( false );
#endif // USE_MVM_TOUR

	m_fontChallengeListHeader = pScheme->GetFont( "HudFontSmallestBold", true );
	m_fontChallengeListItem = pScheme->GetFont( "HudFontSmallest", true );

	//
	// Populate the player list
	//
	int nAvatarWidth = ( ( m_iAvatarWidth * 5 / 4 ) + 1 );
	int nExtraWidth = m_pChatPlayerList->GetWide() - nAvatarWidth - m_iPlayerNameWidth - m_iBannedWidth - m_iHasTicketWidth - m_iSquadSurplusWidth - m_iBadgeLevelWidth;

	m_pChatPlayerList->AddColumnToSection( 0, "avatar", "#TF_Players", vgui::SectionedListPanel::COLUMN_IMAGE, nAvatarWidth );
	m_pChatPlayerList->AddColumnToSection( 0, "name", "", 0, m_iPlayerNameWidth + nExtraWidth );
	m_pChatPlayerList->AddColumnToSection( 0, "is_banned", "", vgui::SectionedListPanel::COLUMN_IMAGE | vgui::SectionedListPanel::COLUMN_CENTER, m_iBannedWidth );
	m_pChatPlayerList->AddColumnToSection( 0, "has_ticket", "", vgui::SectionedListPanel::COLUMN_IMAGE | vgui::SectionedListPanel::COLUMN_CENTER, m_iHasTicketWidth );
	m_pChatPlayerList->AddColumnToSection( 0, "squad_surplus", "", vgui::SectionedListPanel::COLUMN_IMAGE | vgui::SectionedListPanel::COLUMN_CENTER, m_iSquadSurplusWidth );
	m_pChatPlayerList->AddColumnToSection( 0, "badge_level", "#TF_MvM_Tours", vgui::SectionedListPanel::COLUMN_CENTER, m_iBadgeLevelWidth );
}

void CLobbyPanel_MvM::PerformLayout()
{
#ifdef USE_MVM_TOUR
	WriteTourList();
#endif // USE_MVM_TOUR
	WriteChallengeList();

	BaseClass::PerformLayout();
}

void CLobbyPanel_MvM::OnClickedOnChallenge()
{
	int iSelected = m_pChallengeList->GetSelectedItem();
	m_pChallengeList->SetSelectedItem( -1 );
	if ( iSelected < 0 )
		return;
	if ( BIsPartyLeader() && BIsPartyInUIState() )
	{
		int iChallengeIndex = m_pChallengeList->GetItemData( iSelected )->GetInt( "pop_index", -1 );

#ifndef USE_MVM_TOUR
		// disallow player to select individual challenge in mannup
		if ( iChallengeIndex >= 0 && GTFGCClientSystem()->GetSearchPlayForBraggingRights() )
			return;
#endif // !USE_MVM_TOUR

		CMvMMissionSet searchChallenges;

		// Fetch current selection.  Except when clicking the "only uncompleted" checkbox, which is special
		if ( iChallengeIndex != k_iPopIndex_OnlyNotYetCompleted )
			GTFGCClientSystem()->GetSearchChallenges( searchChallenges );

		CMvMMissionSet setChallenges;
		GetMvmChallengeSet( iChallengeIndex, setChallenges );
		bool bSelect = ( m_pChallengeList->GetItemData( iSelected )->GetInt( "check_box" ) != m_iImageCheckBoxYes );
		for ( int i = 0 ; i < GetItemSchema()->GetMvmMissions().Count() ; ++i )
		{
			if ( setChallenges.GetMissionBySchemaIndex( i ) )
			{
				searchChallenges.SetMissionBySchemaIndex( i, bSelect );
			}
		}

		GTFGCClientSystem()->SetSearchChallenges( searchChallenges );
	}
	else
	{
		WriteChallengeList();
	}
}


void CLobbyPanel_MvM::ChallengeList::Paint()
{
	vgui::SectionedListPanel::Paint();

	FOR_EACH_VEC( m_vecMapImages, i )
	{
		int x, y, w, h;
		if ( !GetSectionHeaderBounds( i + 1, x, y, w, h ) )
		{
			Assert( "MvM map mismatch" );
			continue;
		}

		// Dear god.  Why is VGUI such a piece of crap?
		// And why is it such excruciating pain to do
		// anything at all?

		// Select subrectangle within image to draw
		w = m_pLobbyPanel->m_iMapImageWidth;
		h = m_pLobbyPanel->m_iMapImageHeight;
		m_vecMapImages[i].SetViewport( true, 0.0, 0.0, 1.0, (float)h / (float)w );

		// Compute horiziontal position of icon
		int gutter = vgui::scheme()->GetProportionalScaledValue( 5 );
		x -= gutter + m_pLobbyPanel->m_iMapImageWidth;

		// Save clipping rectangle.  We want to be able to draw off to the left,
		// outside of our bounding box, but we need to keep the vertical clipping
		int left, top, right, bottom;
		bool bDisabled;
		g_pMatSystemSurface->GetClippingRect( left, top, right, bottom, bDisabled );

		// Adjust clipping rectangle
		int sx = x;
		int sy = y;
		LocalToScreen(sx, sy);
		g_pMatSystemSurface->SetClippingRect( sx, top, right, bottom );

		m_vecMapImages[i].DoPaint( x, y, w, h );

		// Restore clipping rectangle
		g_pMatSystemSurface->SetClippingRect( left, top, right, bottom );
		g_pMatSystemSurface->DisableClipping( bDisabled );
	}

#ifdef USE_MVM_TOUR
	// We can only do checkmarks if we know what tour they are working towards
	int idxTour = GTFGCClientSystem()->GetSearchMannUpTourIndex();
	if ( idxTour >= 0 )
	{
		int nCheckSize = m_pLobbyPanel->m_iChallengeCompletedSize;
		int nCompletedX0 = m_pLobbyPanel->m_iChallengeCheckBoxWidth + m_pLobbyPanel->m_iChallengeNameWidth + m_pLobbyPanel->m_iChallengeSkillWidth / 4;

		uint32 nTours, nCompletedChallenge;
		bool bFoundPlayerCompletedChallenges = GTFGCClientSystem()->BGetLocalPlayerBadgeInfoForTour( idxTour, &nTours, &nCompletedChallenge );

		for ( int i = 0 ; i < GetItemCount() ; ++i )
		{
			// Get The Pop File Name for this item
			KeyValues *pkv = GetItemData( GetItemIDFromRow( i ) );
			int iMissionIndexInSchema = pkv->GetInt( "pop_index", -1 );
			if ( iMissionIndexInSchema < 0 ) // special multi-select entry
				continue;

			int iBadgeSlot = GetItemSchema()->GetMvmMissionBadgeSlotForTour( idxTour, iMissionIndexInSchema );
			if ( iBadgeSlot < 0 )
				continue;

			int x, y, w, h;
			GetItemBounds( i, x, y, w, h );

			if ( bFoundPlayerCompletedChallenges )
			{
				if ( nCompletedChallenge & (1 << iBadgeSlot) )
				{
					m_imageChallengeCompleted.SetColor( Color(255,255,255,255) );
				}
				else if ( GetSelectedItem() == i )
				{
					m_imageChallengeCompleted.SetColor( Color(0,0,0,255) );
				}
				else
				{
					m_imageChallengeCompleted.SetColor( Color(0,0,0,70) );
				}
				int checkX0 = nCompletedX0;
				int checkY0 = y + ( h - nCheckSize ) / 2;
				m_imageChallengeCompleted.DoPaint( checkX0, checkY0, nCheckSize, nCheckSize );
			}
		}
	}
#endif // USE_MVM_TOUR
}