summaryrefslogtreecommitdiff
path: root/game/client/tf/vgui/tf_matchmaking_dashboard_next_map_winner.cpp
blob: 1658fb030f37c9a1c98fa6b28b5489dea10f9bfc (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//


#include "cbase.h"
#include "tf_matchmaking_dashboard.h"
#include "tf_gamerules.h"
#include "tf_gc_client.h"
#include <vgui/ISurface.h>

using namespace vgui;
using namespace GCSDK;

#ifdef STAGING_ONLY 
extern ConVar tf_mm_popup_state_override;
#endif

class CNextMapWinnerDashboardState : public CTFMatchmakingPopup
{
public:

	CNextMapWinnerDashboardState( const char* pszName, const char* pszResFile )
		: CTFMatchmakingPopup( pszName, pszResFile )
	{
	}

	virtual bool ShouldBeActve() const OVERRIDE
	{
#ifdef STAGING_ONLY
		if ( FStrEq( const_cast<CNextMapWinnerDashboardState*>(this)->GetName(), tf_mm_popup_state_override.GetString() ) ) 
			return true;
#endif

		int nVotes[ CTFGameRules::EUserNextMapVote::NUM_VOTE_STATES ];
		CTFGameRules::EUserNextMapVote eWinningVote = TFGameRules()->GetWinningVote( nVotes );

		if ( BInEndOfMatch() &&
			 TFGameRules() &&
			 TFGameRules()->GetCurrentNextMapVotingState() == CTFGameRules::NEXT_MAP_VOTE_STATE_MAP_CHOSEN_PAUSE &&
			 eWinningVote != CTFGameRules::USER_NEXT_MAP_VOTE_UNDECIDED && 
			 GTFGCClientSystem()->BConnectedToMatchServer( false ) )
		{
			return true;
		}

		return false;
	}

private:

	virtual void OnEnter() OVERRIDE
	{
		CTFMatchmakingPopup::OnEnter();

		MapDefIndex_t nWinningDefIndex;
		if ( TFGameRules() )
		{
			int nVotes[ CTFGameRules::EUserNextMapVote::NUM_VOTE_STATES ];
			CTFGameRules::EUserNextMapVote eWinningVote = TFGameRules()->GetWinningVote( nVotes );
			nWinningDefIndex = TFGameRules()->GetNextMapVoteOption( eWinningVote );
		}
		else
		{
			Assert( false );
			nWinningDefIndex = RandomInt( 1, GetItemSchema()->GetMapCount() - 1 );
		}

		// Sound effect for success
		surface()->PlaySound( UTIL_GetRandomSoundFromEntry( "Vote.Passed" ) );
		
		const MapDef_t *pMapDef = GetItemSchema()->GetMasterMapDefByIndex( nWinningDefIndex );
		if ( pMapDef )
		{
			Label* pMapNameLabel = FindControl< Label >( "NameLabel", true );
			if ( pMapNameLabel )
			{
				pMapNameLabel->SetText( g_pVGuiLocalize->Find( pMapDef->pszMapNameLocKey ) );
			}

			ScalableImagePanel* pMapImage = FindControl< ScalableImagePanel >( "MapImage", true );
			if ( pMapImage )
			{
				char imagename[ 512 ];
				Q_snprintf( imagename, sizeof( imagename ), "..\\vgui\\maps\\menu_thumb_%s", pMapDef->pszMapName );
				pMapImage->SetImage( imagename );
			}
		}
	}
};

REG_MM_POPUP_FACTORY( CNextMapWinnerDashboardState, "NextMapWinner", "resource/UI/MatchMakingDashboardPopup_NextMapWinner.res" )