blob: e3096cdf9ba4c33592f2e66c037438e61956ae3b (
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: The manager that deals with menus
//
// $Revision: $
// $NoKeywords: $
//===========================================================================//
#ifndef MENUMANAGER_H
#define MENUMANAGER_H
#ifdef _WIN32
#pragma once
#endif
#include "gamemanager.h"
#include "tier1/utldict.h"
#include "tier1/utlstack.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
namespace vgui
{
class Panel;
}
//-----------------------------------------------------------------------------
// Interface used to create menus
//-----------------------------------------------------------------------------
abstract_class IMenuFactory
{
public:
// Returns the name of the menu it will create
virtual const char *GetMenuName() = 0;
// Creates the menu
virtual vgui::Panel *CreateMenu( vgui::Panel *pParent ) = 0;
// Used to build a list during construction
virtual IMenuFactory *GetNextFactory( ) = 0;
protected:
virtual ~IMenuFactory() {}
};
//-----------------------------------------------------------------------------
// Menu managemer
//-----------------------------------------------------------------------------
class CMenuManager : public CGameManager<>
{
public:
typedef vgui::Panel* (*MenuFactory_t)( vgui::Panel *pParent );
// Inherited from IGameManager
virtual bool Init();
virtual void Update( );
virtual void Shutdown();
// Push, pop menus
void PushMenu( const char *pMenuName );
void PopMenu( );
void PopAllMenus( );
// Pop the top menu, push specified menu
void SwitchToMenu( const char *pMenuName );
// Returns the name of the topmost panel
const char *GetTopmostPanelName();
// Call to register methods which can construct menus w/ particular ids
// NOTE: This method is not expected to be called directly. Use the REGISTER_MENU macro instead
// It returns the previous head of the list of factories
static IMenuFactory* RegisterMenu( IMenuFactory *pMenuFactory );
private:
void CleanUpAllMenus();
typedef unsigned char MenuFactoryIndex_t;
CUtlDict< IMenuFactory *, MenuFactoryIndex_t > m_MenuFactories;
CUtlStack< vgui::Panel * > m_nActiveMenu;
bool m_bPopRequested;
bool m_bPopAllRequested;
IMenuFactory *m_pPushRequested;
static IMenuFactory *m_pFirstFactory;
};
//-----------------------------------------------------------------------------
// Singleton accessor
//-----------------------------------------------------------------------------
extern CMenuManager *g_pMenuManager;
//-----------------------------------------------------------------------------
// Macro used to register menus with the menu manager
// For example, add the line REGISTER_MENU( "MainMenu", CMainMenu );
// into the class defining the main menu
//-----------------------------------------------------------------------------
template < class T >
class CMenuFactory : public IMenuFactory
{
public:
CMenuFactory( const char *pMenuName ) : m_pMenuName( pMenuName )
{
m_pNextFactory = CMenuManager::RegisterMenu( this );
}
// Returns the name of the menu it will create
virtual const char *GetMenuName()
{
return m_pMenuName;
}
// Creates the menu
virtual vgui::Panel *CreateMenu( vgui::Panel *pParent )
{
return new T( pParent, m_pMenuName );
}
// Used to build a list during construction
virtual IMenuFactory *GetNextFactory( )
{
return m_pNextFactory;
}
private:
const char* m_pMenuName;
IMenuFactory *m_pNextFactory;
};
#define REGISTER_MENU( _name, _className ) \
static CMenuFactory< _className > s_Factory ## _className( _name )
#endif // MENUMANAGER_H
|