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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "econ_sample_rootui.h"
#include "vgui/IInput.h"
#include <vgui/ILocalize.h>
#include "ienginevgui.h"
#include "econ_item_inventory.h"
#include "backpack_panel.h"
#include "item_pickup_panel.h"
#include "store/store_panel.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
static vgui::DHANDLE<CEconSampleRootUI> g_EconSampleRootUIPanel;
#if !defined (TF_CLIENT_DLL)
IEconRootUI *EconUI( void )
{
if (!g_EconSampleRootUIPanel.Get())
{
g_EconSampleRootUIPanel = vgui::SETUP_PANEL( new CEconSampleRootUI( NULL ) );
g_EconSampleRootUIPanel->InvalidateLayout( false, true );
}
return g_EconSampleRootUIPanel;
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Basic help dialog
//-----------------------------------------------------------------------------
CEconSampleRootUI::CEconSampleRootUI( vgui::Panel *parent ) : vgui::Frame(parent, "econ_sample_rootui")
{
// Econ UI is parented to the game UI panel (not the client DLL panel).
vgui::VPANEL gameuiPanel = enginevgui->GetPanel( PANEL_GAMEUIDLL );
SetParent( gameuiPanel );
// We don't want the gameui to delete us, or things get messy
SetAutoDelete( false );
SetMoveable( false );
SetSizeable( false );
SetCloseButtonVisible( false );
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme");
SetScheme(scheme);
SetProportional( true );
ListenForGameEvent( "gameui_hidden" );
// Create our subpanels
m_pBackpackPanel = new CBackpackPanel( this, "backpack_panel" );
// Start with just the base UI visible
m_nVisiblePanel = ECONUI_BASEUI;
UpdateSubPanelVisibility();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CEconSampleRootUI::~CEconSampleRootUI()
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
LoadControlSettings( "Resource/UI/Econ/RootUI.res" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::PerformLayout( void )
{
if ( GetVParent() )
{
int w,h;
vgui::ipanel()->GetSize( GetVParent(), w, h );
SetBounds(0,0,w,h);
}
BaseClass::PerformLayout();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::ShowPanel(bool bShow)
{
m_bPreventClosure = false;
SetVisible( bShow );
if ( bShow )
{
MoveToFront();
m_nVisiblePanel = ECONUI_BASEUI;
UpdateSubPanelVisibility();
InventoryManager()->ShowItemsPickedUp( true, false );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::FireGameEvent( IGameEvent *event )
{
const char * type = event->GetName();
if ( Q_strcmp(type, "gameui_hidden") == 0 )
{
if ( m_bPreventClosure )
{
engine->ClientCmd_Unrestricted( "gameui_activate" );
}
else
{
ShowPanel( false );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::OnCommand( const char *command )
{
if ( !Q_stricmp( command, "close" ) )
{
ShowPanel( false );
// If we're connected to a game server, we also close the game UI.
if ( engine->IsInGame() )
{
bool bClose = true;
if ( m_bCheckForRoomOnExit )
{
// Check to make sure the player has room for all his items. If not, bring up the discard panel. Otherwise, go away.
// We need to do this to catch players who used the "Change Loadout" button in the pickup panel, and may be out of room.
bClose = !InventoryManager()->CheckForRoomAndForceDiscard();
}
if ( bClose )
{
engine->ClientCmd_Unrestricted( "gameui_hide" );
}
}
}
else if ( !Q_stricmp( command, "back" ) )
{
ShowPanel( true );
}
else if ( !Q_stricmp( command, "loadout" ) )
{
// Ignore selection while we don't have a steam connection
if ( !InventoryManager()->GetLocalInventory()->RetrievedInventoryFromSteam() )
return;
OpenSubPanel( ECONUI_LOADOUT );
}
else if ( !Q_strnicmp( command, "backpack", 8 ) )
{
OpenSubPanel( ECONUI_BACKPACK );
}
else if ( !Q_strnicmp( command, "crafting", 8 ) )
{
OpenSubPanel( ECONUI_CRAFTING );
}
else if ( !Q_strnicmp( command, "armory", 6 ) )
{
OpenSubPanel( ECONUI_ARMORY );
}
else if ( !Q_strnicmp( command, "store", 5 ) )
{
EconUI()->OpenStorePanel( 0, false );
}
else if ( !Q_strnicmp( command, "trading", 7 ) )
{
// if ( IsFreeTrialAccount() )
// {
// ShowMessageBox( "#TF_Trial_CannotTrade_Title", "#TF_Trial_CannotTrade_Text", "#GameUI_OK" );
// return;
// }
OpenTradingStartDialog();
}
else
{
engine->ClientCmd( const_cast<char *>( command ) );
}
BaseClass::OnCommand( command );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::OnKeyCodeTyped(vgui::KeyCode code)
{
if ( code == KEY_ESCAPE )
{
if ( !m_bPreventClosure )
{
ShowPanel( false );
}
}
else
{
BaseClass::OnKeyCodeTyped( code );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
IEconRootUI *CEconSampleRootUI::OpenEconUI( int iDirectToPage, bool bCheckForInventorySpaceOnExit )
{
engine->ClientCmd_Unrestricted( "gameui_activate" );
ShowPanel( true );
if ( iDirectToPage == ECONUI_BACKPACK )
{
}
else if ( iDirectToPage == ECONUI_CRAFTING )
{
}
else if ( iDirectToPage == ECONUI_ARMORY )
{
}
SetCheckForRoomOnExit( bCheckForInventorySpaceOnExit );
return this;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::CloseEconUI( void )
{
if ( IsVisible() )
{
ShowPanel( false );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CEconSampleRootUI::IsUIPanelVisible( EconBaseUIPanels_t iPanel )
{
if ( !IsVisible() )
return false;
switch ( iPanel )
{
case ECONUI_BASEUI:
return true;
case ECONUI_BACKPACK:
return (GetBackpackPanel() && GetBackpackPanel()->IsVisible());
case ECONUI_CRAFTING:
//return (GetCraftingPanel() && GetCraftingPanel()->IsVisible());
break;
case ECONUI_ARMORY:
break;
case ECONUI_TRADING:
break;
case ECONUI_LOADOUT:
break;
default:
Assert(0);
break;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::OpenSubPanel( EconBaseUIPanels_t nPanel )
{
m_nVisiblePanel = nPanel;
UpdateSubPanelVisibility();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::OpenTradingStartDialog( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::UpdateSubPanelVisibility( void )
{
bool bBackpackVisible = (m_nVisiblePanel == ECONUI_BACKPACK);
if ( m_pBackpackPanel->IsVisible() != bBackpackVisible )
{
m_pBackpackPanel->ShowPanel( false, bBackpackVisible );
}
//m_pClassLoadoutPanel->SetVisible( false );
//m_pArmoryPanel->SetVisible( false );
//m_pCraftingPanel->ShowPanel( m_iCurrentClassIndex, true, (m_iPrevShowingPanel == CHAP_ARMORY) );
}
static vgui::DHANDLE<CItemPickupPanel> g_ItemPickupPanel;
static vgui::DHANDLE<CItemDiscardPanel> g_ItemDiscardPanel;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CItemPickupPanel *CEconSampleRootUI::OpenItemPickupPanel( void )
{
if (!g_ItemPickupPanel.Get())
{
g_ItemPickupPanel = vgui::SETUP_PANEL( new CItemPickupPanel( NULL ) );
g_ItemPickupPanel->InvalidateLayout( false, true );
}
engine->ClientCmd_Unrestricted( "gameui_activate" );
g_ItemPickupPanel->ShowPanel( true );
return g_ItemPickupPanel;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CItemDiscardPanel *CEconSampleRootUI::OpenItemDiscardPanel( void )
{
if (!g_ItemDiscardPanel.Get())
{
g_ItemDiscardPanel = vgui::SETUP_PANEL( new CItemDiscardPanel( NULL ) );
g_ItemDiscardPanel->InvalidateLayout( false, true );
}
engine->ClientCmd_Unrestricted( "gameui_activate" );
g_ItemDiscardPanel->ShowPanel( true );
return g_ItemDiscardPanel;
}
static vgui::DHANDLE<CStorePanel> g_StorePanel;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconSampleRootUI::CreateStorePanel( void )
{
// Clean up previous store panel?
if ( g_StorePanel.Get() != NULL )
{
g_StorePanel->MarkForDeletion();
}
// Create the store panel
g_StorePanel = vgui::SETUP_PANEL( new CStorePanel( NULL ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CStorePanel *CEconSampleRootUI::OpenStorePanel( int iItemDef, bool bAddToCart )
{
// Make sure we've got the appropriate connections to Steam
if ( !steamapicontext || !steamapicontext->SteamUtils() )
{
OpenStoreStatusDialog( NULL, "#StoreUpdate_SteamRequired", true, false );
return NULL;
}
if ( !steamapicontext->SteamUtils()->IsOverlayEnabled() )
{
OpenStoreStatusDialog( NULL, "#StoreUpdate_OverlayRequired", true, false );
return NULL;
}
if ( !CStorePanel::IsPricesheetLoaded() )
{
OpenStoreStatusDialog( NULL, "#StoreUpdate_Loading", false, false );
CStorePanel::SetShouldShowWarnings( true );
CStorePanel::RequestPricesheet();
return NULL;
}
if ( !g_StorePanel )
return NULL;
engine->ClientCmd_Unrestricted( "gameui_activate" );
if ( iItemDef )
{
g_StorePanel->StartAtItemDef( iItemDef, bAddToCart );
}
g_StorePanel->ShowPanel( true );
return g_StorePanel;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CStorePanel *CEconSampleRootUI::GetStorePanel( void )
{
return g_StorePanel;
}
#ifdef _DEBUG
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void Open_EconUI( const CCommand &args )
{
EconUI()->OpenEconUI();
}
ConCommand open_econui( "open_econui", Open_EconUI );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void Open_EconUIBackpack( const CCommand &args )
{
EconUI()->OpenEconUI( ECONUI_BACKPACK );
}
ConCommand open_econui_backpack( "open_econui_backpack", Open_EconUIBackpack, "Open the backpack.", FCVAR_NONE );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void Open_EconUICrafting( const CCommand &args )
{
EconUI()->OpenEconUI( ECONUI_CRAFTING );
}
ConCommand open_econui_crafting( "open_econui_crafting", Open_EconUICrafting, "Open the crafting screen.", FCVAR_NONE );
#endif // _DEBUG
|