forked from XutaxKamay/css_enhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuimanager.cpp
244 lines (195 loc) · 7.04 KB
/
uimanager.cpp
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: The main manager of the UI
//
// $Revision: $
// $NoKeywords: $
//===========================================================================//
#include "uimanager.h"
#include "legion.h"
#include "appframework/vguimatsysapp.h"
#include "vgui/IVGui.h"
#include "vgui/ISurface.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "vgui_controls/controls.h"
#include "vgui/ILocalize.h"
#include "vgui_controls/EditablePanel.h"
#include "vgui_controls/AnimationController.h"
#include "filesystem.h"
#include "tier3/tier3.h"
#include "vgui_controls/consoledialog.h"
#include "inputmanager.h"
//-----------------------------------------------------------------------------
// Console dialog for use in legion
//-----------------------------------------------------------------------------
class CLegionConsoleDialog : public vgui::CConsoleDialog
{
DECLARE_CLASS_SIMPLE( CLegionConsoleDialog, vgui::CConsoleDialog );
public:
CLegionConsoleDialog( vgui::Panel *pParent, const char *pName );
virtual ~CLegionConsoleDialog();
virtual void OnClose();
MESSAGE_FUNC_CHARPTR( OnCommandSubmitted, "CommandSubmitted", command );
};
CLegionConsoleDialog::CLegionConsoleDialog( vgui::Panel *pParent, const char *pName ) : BaseClass ( pParent, pName )
{
AddActionSignalTarget( this );
}
CLegionConsoleDialog::~CLegionConsoleDialog()
{
g_pUIManager->HideConsole( );
}
//-----------------------------------------------------------------------------
// A command was sent by the console
//-----------------------------------------------------------------------------
void CLegionConsoleDialog::OnCommandSubmitted( const char *pCommand )
{
g_pInputManager->AddCommand( pCommand );
}
//-----------------------------------------------------------------------------
// Deals with close
//-----------------------------------------------------------------------------
void CLegionConsoleDialog::OnClose()
{
g_pUIManager->HideConsole( );
}
//-----------------------------------------------------------------------------
// Singleton accessor
//-----------------------------------------------------------------------------
static CUIManager s_UIManager;
extern CUIManager *g_pUIManager = &s_UIManager;
static const char *s_pRootPanelNames[UI_ROOT_PANEL_COUNT] =
{
"RootGamePanel",
"RootMenuPanel",
"RootToolsPanel",
};
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CUIManager::CUIManager()
{
}
//-----------------------------------------------------------------------------
// Init, shutdown
//-----------------------------------------------------------------------------
bool CUIManager::Init()
{
COMPILE_TIME_ASSERT( sizeof(s_pRootPanelNames) / sizeof(const char*) == UI_ROOT_PANEL_COUNT );
// load the base localization file
if (! vgui::scheme()->LoadSchemeFromFile("resource/legion.res", "Legion" ) )
return false;
vgui::filesystem()->AddSearchPath( "platform", "PLATFORM" );
vgui::localize()->AddFile( vgui::filesystem(), "Resource/vgui_%language%.txt" );
// start vgui
g_pVGui->Start();
// Run a frame to get the embedded panel to be the right size
g_pVGui->RunFrame();
int w, h;
m_hEmbeddedPanel = g_pVGuiSurface->GetEmbeddedPanel();
vgui::ipanel()->GetSize( m_hEmbeddedPanel, w, h );
// add our root panels
for ( int i = 0; i < UI_ROOT_PANEL_COUNT; ++i )
{
m_pRootPanels[i] = new vgui::EditablePanel( NULL, s_pRootPanelNames[i] );
m_pRootPanels[i]->SetParent( m_hEmbeddedPanel );
m_pRootPanels[i]->SetZPos( i );
m_pRootPanels[i]->SetBounds( 0, 0, w, h );
m_pRootPanels[i]->SetPaintBorderEnabled( false );
m_pRootPanels[i]->SetPaintBackgroundEnabled( false );
m_pRootPanels[i]->SetPaintEnabled( false );
m_pRootPanels[i]->SetKeyBoardInputEnabled( i != UI_ROOT_GAME );
m_pRootPanels[i]->SetMouseInputEnabled( i != UI_ROOT_GAME );
m_pRootPanels[i]->SetVisible( false );
m_pRootPanels[i]->SetCursor( vgui::dc_crosshair );
m_pRootPanels[i]->SetAutoResize( vgui::Panel::PIN_TOPLEFT, vgui::Panel::AUTORESIZE_DOWNANDRIGHT, 0, 0, 0, 0 );
}
m_hConsole = NULL;
vgui::surface()->Invalidate( m_hEmbeddedPanel );
return true;
}
void CUIManager::Shutdown()
{
g_pVGui->Stop();
}
//-----------------------------------------------------------------------------
// Sets particular root panels to be visible
//-----------------------------------------------------------------------------
void CUIManager::EnablePanel( UIRootPanel_t id, bool bEnable )
{
m_pRootPanels[id]->SetVisible( bEnable );
}
//-----------------------------------------------------------------------------
// Toggles the console
//-----------------------------------------------------------------------------
void CUIManager::ToggleConsole( const CCommand &args )
{
if ( !m_hConsole.Get() )
{
m_hConsole = new CLegionConsoleDialog( m_pRootPanels[UI_ROOT_TOOLS], "Console" );
// set the console to taking up most of the right-half of the screen
int swide, stall;
vgui::surface()->GetScreenSize(swide, stall);
int offset = vgui::scheme()->GetProportionalScaledValue(16);
m_hConsole->SetBounds(
swide / 2 - (offset * 4),
offset,
(swide / 2) + (offset * 3),
stall - (offset * 8));
m_hConsole->SetVisible( false );
}
bool bMakeVisible = !m_hConsole->IsVisible();
EnablePanel( UI_ROOT_TOOLS, bMakeVisible );
if ( bMakeVisible )
{
m_hConsole->Activate();
}
else
{
m_hConsole->Hide();
}
}
//-----------------------------------------------------------------------------
// Hides the console
//-----------------------------------------------------------------------------
void CUIManager::HideConsole()
{
EnablePanel( UI_ROOT_TOOLS, false );
if ( m_hConsole.Get() )
{
m_hConsole->SetVisible( false );
}
}
//-----------------------------------------------------------------------------
// Per-frame update
//-----------------------------------------------------------------------------
void CUIManager::Update( )
{
vgui::GetAnimationController()->UpdateAnimations( IGameManager::CurrentTime() );
g_pVGui->RunFrame();
if ( !g_pVGui->IsRunning() )
{
IGameManager::Stop();
}
}
//-----------------------------------------------------------------------------
// Attempt to process an input event, return true if it sholdn't be chained to the rest of the game
//-----------------------------------------------------------------------------
bool CUIManager::ProcessInputEvent( const InputEvent_t& event )
{
return g_pMatSystemSurface->HandleInputEvent( event );
}
//-----------------------------------------------------------------------------
// Draws the UI
//-----------------------------------------------------------------------------
void CUIManager::DrawUI()
{
g_pVGuiSurface->PaintTraverseEx( m_hEmbeddedPanel, true );
}
//-----------------------------------------------------------------------------
// Push, pop menus
//-----------------------------------------------------------------------------
vgui::Panel *CUIManager::GetRootPanel( UIRootPanel_t id )
{
return m_pRootPanels[id];
}