summaryrefslogtreecommitdiff
path: root/game/client/tf/vgui/tf_matchmaking_dashboard.h
blob: 57a54e11ac75c4f5e584ec6826f5ee35decfb117 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef TF_MATCHMAKING_DASHBOARD_H
#define TF_MATCHMAKING_DASHBOARD_H
#ifdef _WIN32
#pragma once
#endif

#include "tf_match_join_handlers.h"
#include <vgui_controls/EditablePanel.h>
#include "tf_controls.h"
#include <vgui_controls/PHandle.h>
#include "local_steam_shared_object_listener.h"

CUtlVector< class CTFMatchmakingPopup* >& CreateMMPopupPanels( bool bRecreate = false );
class CTFMatchmakingDashboard* GetMMDashboard();
class CMMDashboardParentManager* GetMMDashboardParentManager();

bool BInEndOfMatch();

//-----------------------------------------------------------------------------
// Purpose: Popup that goes underneath the dashboard and displays anything
//			important the user needs to know about
//-----------------------------------------------------------------------------
class CTFMatchmakingPopup : public CExpandablePanel
						  , public CGameEventListener
						  , public IMatchJoiningHandler
{
	friend class CTFMatchmakingPopupState;
	friend class CTFMatchmakingDashboard;
	DECLARE_CLASS_SIMPLE( CTFMatchmakingPopup, CExpandablePanel );
public:

	CTFMatchmakingPopup( const char* pszName, const char* pszResFile );
	virtual ~CTFMatchmakingPopup();

	virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) OVERRIDE;
	virtual void OnThink() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;
	virtual void OnTick() OVERRIDE;

	virtual void OnEnter();
	virtual void OnUpdate();
	virtual void OnExit();
	virtual void Update();

	virtual void FireGameEvent( IGameEvent *pEvent ) OVERRIDE;

private:

	virtual void MatchFound() {} // We dont need to do anything special
	virtual bool ShouldBeActve() const = 0;
	void UpdateRematchtime();
	void UpdateAutoJoinTime();

	bool m_bActive;
	const char* m_pszResFile;
};

//-----------------------------------------------------------------------------
// Purpose: Matchmaking panel that contains controls for matchmaking
//-----------------------------------------------------------------------------
class CTFMatchmakingDashboard : public CExpandablePanel
{
public:
	DECLARE_CLASS_SIMPLE( CTFMatchmakingDashboard, CExpandablePanel );
	CTFMatchmakingDashboard();
	virtual ~CTFMatchmakingDashboard();

	virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;
	virtual void OnTick() OVERRIDE;
};

//-----------------------------------------------------------------------------
// CMMDashboardParentManager
// Purpose: This guy keeps the MM dashboard as the top-most panel but does so
//			*without making it a popup*.  This is important because popups look
//			awful whenever they overlap and transparency is involved.  This class
//			does its dirty work by keeping track of the top-most fullscreen popup
//			and setting that panel as the MM dashboard's parent.  When that popup
//			goes away, we set the parent to the next popup on the stack, or to
//			the GameUI if none are active.  If we're in-game, then we parent to
//			the our special popup container.  Why not always just parent to that
//			single popup container?  Because we want the MINIMUM mouse focus area
//			possible because the dashboard is not a rectangle (it grows/shrinks).
//			
//			
//			If anything draws on top of the MM dashboard and you dont want it to
//			have that panel add itself to this class using PushModalFullscreenPopup
//			when it goes visible and PopModalFullscreenPopup when it hides itself
//-----------------------------------------------------------------------------
class CMMDashboardParentManager : public CGameEventListener
{
public:
	friend class CTFMatchmakingDashboard;
	friend class CTFMatchmakingPopup;

	CMMDashboardParentManager();

	virtual void FireGameEvent( IGameEvent *event ) OVERRIDE;

	void PushModalFullscreenPopup( vgui::Panel* pPanel );
	void PopModalFullscreenPopup( vgui::Panel* pPanel );
	void UpdateParenting();
private:

	void AddPanel( CExpandablePanel* pPanel );
	void RemovePanel( CExpandablePanel* pPanel );

	void AttachToGameUI();
	void AttachToTopMostPopup();

	bool m_bAttachedToGameUI;

	class CUtlSortVectorPanelZPos
	{
	public:
		bool Less( const vgui::Panel* lhs, const vgui::Panel* rhs, void * )
		{
			return lhs->GetZPos() < rhs->GetZPos();
		}
	};

	CUtlSortVector< CExpandablePanel*, CUtlSortVectorPanelZPos > m_vecPanels;
	CUtlVector< vgui::Panel* > m_vecFullscreenPopups;

	vgui::PHandle m_pHUDPopup;
};

class IMMPopupFactory
{
public:
	virtual CTFMatchmakingPopup* Create() const = 0;
	static CUtlVector< IMMPopupFactory* > s_vecPopupFactories;
};

template< typename Type >
class CMMPopupFactoryImplementation : public IMMPopupFactory
{
public:
	CMMPopupFactoryImplementation( const char* pszName, const char* pszResFile ) : m_pszName( pszName ), m_pszResFile( pszResFile )
	{ s_vecPopupFactories.AddToTail( this ); }

	virtual CTFMatchmakingPopup* Create() const OVERRIDE { return new Type( m_pszName, m_pszResFile ); }
private:
	const char* m_pszName;
	const char* m_pszResFile;
};

#define REG_MM_POPUP_FACTORY( type, name, resfile )	 CMMPopupFactoryImplementation< type > g_##type##Factory( name, resfile );

#endif // TF_MATCHMAKING_DASHBOARD_H