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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "base_loadout_panel.h"
#include "item_confirm_delete_dialog.h"
#include "vgui/ISurface.h"
#include "gamestringpool.h"
#include "iclientmode.h"
#include "econ_item_inventory.h"
#include "ienginevgui.h"
#include <vgui/ILocalize.h>
#include "vgui_controls/TextImage.h"
#include "vgui_controls/CheckButton.h"
#include "vgui_controls/ComboBox.h"
#include "vgui/IInput.h"
#include "econ_ui.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
#ifdef STAGING_ONLY
ConVar tf_use_card_tooltips( "tf_use_card_tooltips", "0", FCVAR_ARCHIVE );
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseLoadoutPanel::CBaseLoadoutPanel( vgui::Panel *parent, const char *panelName ) : EditablePanel(parent, panelName )
{
SetParent( parent );
// Use the client scheme
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme");
SetScheme(scheme);
SetProportional( true );
m_pItemModelPanelKVs = NULL;
m_pMouseOverItemPanel = vgui::SETUP_PANEL( new CItemModelPanel( this, "mouseoveritempanel" ) );
m_pMouseOverTooltip = new CItemModelPanelToolTip( this );
m_pMouseOverTooltip->SetupPanels( this, m_pMouseOverItemPanel );
#ifdef STAGING_ONLY
m_pMouseOverCardPanel = vgui::SETUP_PANEL( new CTFItemCardPanel( this, "mouseovercardpanel" ) );
m_pMouseOverCardTooltip = new CItemCardPanelToolTip( this );
m_pMouseOverCardTooltip->SetupPanels( this, m_pMouseOverCardPanel );
#endif
m_pItemPanelBeingMousedOver = NULL;
m_pCaratLabel = NULL;
m_pClassLabel = NULL;
m_nCurrentPage = 0;
m_bTooltipKeyPressed = false;
SetMouseInputEnabled( true );
SetKeyBoardInputEnabled( true );
ListenForGameEvent( "inventory_updated" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseLoadoutPanel::~CBaseLoadoutPanel()
{
if ( m_pItemModelPanelKVs )
{
m_pItemModelPanelKVs->deleteThis();
m_pItemModelPanelKVs = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
m_pCaratLabel = dynamic_cast<vgui::Label*>( FindChildByName("CaratLabel") );
m_pClassLabel = dynamic_cast<vgui::Label*>( FindChildByName("ClassLabel") );
m_bReapplyItemKVs = true;
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
SetBorderForItem( m_pItemModelPanels[i], false );
}
m_pMouseOverItemPanel->SetBorder( pScheme->GetBorder("LoadoutItemPopupBorder") );
CreateItemPanels();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::ApplySettings( KeyValues *inResourceData )
{
BaseClass::ApplySettings( inResourceData );
KeyValues *pItemKV = inResourceData->FindKey( "modelpanels_kv" );
if ( pItemKV )
{
if ( m_pItemModelPanelKVs )
{
m_pItemModelPanelKVs->deleteThis();
}
m_pItemModelPanelKVs = new KeyValues("modelpanels_kv");
pItemKV->CopySubkeys( m_pItemModelPanelKVs );
}
}
extern const char *g_szItemBorders[AE_MAX_TYPES][5];
extern ConVar cl_showbackpackrarities;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::SetBorderForItem( CItemModelPanel *pItemPanel, bool bMouseOver )
{
if ( !pItemPanel )
return;
const char *pszBorder = NULL;
if ( pItemPanel->IsGreyedOut() )
{
if( pItemPanel->IsSelected() )
{
pszBorder = "BackpackItemGrayedOut_Selected";
}
else
{
pszBorder = "BackpackItemGrayedOut";
}
}
else
{
int iRarity = 0;
if ( pItemPanel->HasItem() && cl_showbackpackrarities.GetBool() )
{
iRarity = pItemPanel->GetItem()->GetItemQuality() ;
uint8 nRarity = pItemPanel->GetItem()->GetItemDefinition()->GetRarity();
if ( ( nRarity != k_unItemRarity_Any ) && ( iRarity != AE_SELFMADE ) )
{
// translate this quality to rarity
iRarity = nRarity + AE_RARITY_DEFAULT;
}
}
if ( pItemPanel->IsSelected() )
{
pszBorder = g_szItemBorders[iRarity][2];
}
if ( bMouseOver )
{
pszBorder = g_szItemBorders[iRarity][1];
}
else
{
pszBorder = g_szItemBorders[iRarity][0];
}
}
vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
pItemPanel->SetBorder( pScheme->GetBorder( pszBorder ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::ApplyKVsToItemPanels( void )
{
if ( m_pItemModelPanelKVs )
{
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
m_pItemModelPanels[i]->ApplySettings( m_pItemModelPanelKVs );
SetBorderForItem( m_pItemModelPanels[i], false );
m_pItemModelPanels[i]->InvalidateLayout();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::PerformLayout( void )
{
if ( m_bReapplyItemKVs )
{
m_bReapplyItemKVs = false;
ApplyKVsToItemPanels();
}
BaseClass::PerformLayout();
// If we're items only, we hide various elements
if ( m_pCaratLabel )
{
m_pCaratLabel->SetVisible( !m_bItemsOnly );
}
if ( m_pClassLabel )
{
m_pClassLabel->SetVisible( !m_bItemsOnly );
}
if ( m_pMouseOverItemPanel->IsVisible() )
{
// The mouseover panel was visible. Fake a panel entry into the original panel to get it to show up again properly.
if ( m_pItemPanelBeingMousedOver )
{
OnItemPanelEntered( m_pItemPanelBeingMousedOver );
}
else
{
HideMouseOverPanel();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::AddNewItemPanel( int iPanelIndex )
{
CItemModelPanel *pPanel = vgui::SETUP_PANEL( new CItemModelPanel( this, VarArgs("modelpanel%d", iPanelIndex) ) );
pPanel->SetActAsButton( true, true );
m_pItemModelPanels.AddToTail( pPanel );
#ifdef STAGING_ONLY
if ( tf_use_card_tooltips.GetBool() )
{
pPanel->SetTooltip( m_pMouseOverCardTooltip, "" );
}
else
#endif
pPanel->SetTooltip( m_pMouseOverTooltip, "" );
Assert( iPanelIndex == (m_pItemModelPanels.Count()-1) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::CreateItemPanels( void )
{
int iNumPanels = GetNumItemPanels();
if ( m_pItemModelPanels.Count() < iNumPanels )
{
for ( int i = m_pItemModelPanels.Count(); i < iNumPanels; i++ )
{
AddNewItemPanel(i);
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::ShowPanel( int iClass, bool bBackpack, bool bReturningFromArmory )
{
bool bShow = (iClass != 0 || bBackpack);
OnShowPanel( bShow, bReturningFromArmory );
SetVisible( bShow );
if ( bShow )
{
HideMouseOverPanel();
CreateItemPanels();
UpdateModelPanels();
// make the first slot be selected so controller input will work
static ConVarRef joystick( "joystick" );
if( joystick.IsValid() && joystick.GetBool() && m_pItemModelPanels.Count() && m_pItemModelPanels[0] )
{
m_pItemModelPanels[0]->SetSelected( true );
m_pItemModelPanels[0]->RequestFocus();
}
}
else
{
// clear items from panels to make sure that items get invalidate on show panel
FOR_EACH_VEC( m_pItemModelPanels, i )
{
m_pItemModelPanels[i]->SetItem( NULL );
}
}
if ( !bReturningFromArmory )
{
PostShowPanel( bShow );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::OnCommand( const char *command )
{
engine->ClientCmd( const_cast<char *>( command ) );
BaseClass::OnCommand( command );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::FireGameEvent( IGameEvent *event )
{
// If we're not visible, ignore all events
if ( !IsVisible() )
return;
const char *type = event->GetName();
if ( Q_strcmp( "inventory_updated", type ) == 0 )
{
// We need to refresh our model panels, because the items may have changed.
UpdateModelPanels();
}
}
CItemModelPanel *CBaseLoadoutPanel::FindBestPanelNavigationForDirection( const CItemModelPanel *pCurrentPanel, const Vector2D &vPos, const Vector2D &vDirection )
{
CItemModelPanel *pBestPanel = NULL;
// Start with the worst allowable score
float flDistance = GetWide() + GetTall();
float flDot = -1.0f;
float flClosenessScore = flDistance * ( 1.5f - flDot );
for ( int j = 0; j < m_pItemModelPanels.Count(); j++ )
{
CItemModelPanel *pTempPanel = m_pItemModelPanels[ j ];
if ( !pTempPanel || pTempPanel == pCurrentPanel )
continue;
// Get temp center position
int nX, nY;
pTempPanel->GetPos( nX, nY );
nX += pTempPanel->GetWide() / 2;
nY += pTempPanel->GetTall() / 2;
Vector2D vTempPos( nX, nY );
// Get distance and dot
Vector2D vDiff = vTempPos - vPos;
float flTempDistance = Vector2DNormalize( vDiff );
float flTempDot = vDiff.Dot( vDirection );
// Must be somewhat in the correct direction
if ( flTempDot <= 0.0f )
continue;
float flTempScore = flTempDistance * ( 1.5f - flTempDot );
if ( flClosenessScore > flTempScore )
{
flClosenessScore = flTempScore;
flDistance = flTempDistance;
flDot = flTempDot;
pBestPanel = pTempPanel;
}
}
return pBestPanel;
}
void CBaseLoadoutPanel::LinkModelPanelControllerNavigation( bool bForceRelink )
{
if ( m_pItemModelPanels.Count() < 2 )
return;
// first unlink everything
if( bForceRelink )
{
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
CItemModelPanel *pCurrentPanel = m_pItemModelPanels[ i ];
if ( !pCurrentPanel )
continue;
pCurrentPanel->SetNavUp( (vgui::Panel*)NULL );
pCurrentPanel->SetNavDown( (vgui::Panel*)NULL );
pCurrentPanel->SetNavLeft( (vgui::Panel*)NULL );
pCurrentPanel->SetNavRight( (vgui::Panel*)NULL );
}
}
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
CItemModelPanel *pCurrentPanel = m_pItemModelPanels[ i ];
if ( !pCurrentPanel )
continue;
// Get center position
int nX, nY;
pCurrentPanel->GetPos( nX, nY );
nX += pCurrentPanel->GetWide() / 2;
nY += pCurrentPanel->GetTall() / 2;
Vector2D vPos( nX, nY );
if ( !pCurrentPanel->GetNavUpName() || pCurrentPanel->GetNavUpName()[ 0 ] == '\0' )
{
CItemModelPanel *pBestPanel = FindBestPanelNavigationForDirection( pCurrentPanel, vPos, Vector2D( 0, -1 ) );
if ( pBestPanel )
{
pCurrentPanel->SetNavUp( pBestPanel->GetName() );
pBestPanel->SetNavDown( pCurrentPanel->GetName() );
}
}
if ( !pCurrentPanel->GetNavDownName() || pCurrentPanel->GetNavDownName()[ 0 ] == '\0' )
{
CItemModelPanel *pBestPanel = FindBestPanelNavigationForDirection( pCurrentPanel, vPos, Vector2D( 0, 1 ) );
if ( pBestPanel )
{
pCurrentPanel->SetNavDown( pBestPanel->GetName() );
pBestPanel->SetNavUp( pCurrentPanel->GetName() );
}
}
if ( !pCurrentPanel->GetNavLeftName() || pCurrentPanel->GetNavLeftName()[ 0 ] == '\0' )
{
CItemModelPanel *pBestPanel = FindBestPanelNavigationForDirection( pCurrentPanel, vPos, Vector2D( -1, 0 ) );
if ( pBestPanel )
{
pCurrentPanel->SetNavLeft( pBestPanel->GetName() );
pBestPanel->SetNavRight( pCurrentPanel->GetName() );
}
}
if ( !pCurrentPanel->GetNavRightName() || pCurrentPanel->GetNavRightName()[ 0 ] == '\0' )
{
CItemModelPanel *pBestPanel = FindBestPanelNavigationForDirection( pCurrentPanel, vPos, Vector2D( 1, 0 ) );
if ( pBestPanel )
{
pCurrentPanel->SetNavRight( pBestPanel->GetName() );
pBestPanel->SetNavLeft( pCurrentPanel->GetName() );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::OnItemPanelEntered( vgui::Panel *panel )
{
CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
if ( pItemPanel && IsVisible() )
{
CEconItemView *pItem = pItemPanel->GetItem();
if ( pItem && !IsIgnoringItemPanelEnters() && !pItemPanel->IsGreyedOut() )
{
m_pItemPanelBeingMousedOver = pItemPanel;
}
if ( !pItemPanel->IsSelected() )
{
SetBorderForItem( pItemPanel, true );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::OnItemPanelExited( vgui::Panel *panel )
{
CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
if ( pItemPanel && IsVisible() )
{
if ( !pItemPanel->IsSelected() )
{
SetBorderForItem( pItemPanel, false );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::HideMouseOverPanel( void )
{
if ( m_pMouseOverItemPanel->IsVisible() )
{
m_pMouseOverItemPanel->SetVisible( false );
m_pItemPanelBeingMousedOver = NULL;
}
#ifdef STAGING_ONLY
if ( m_pMouseOverCardPanel->IsVisible() )
{
m_pMouseOverCardPanel->SetVisible( false );
m_pItemPanelBeingMousedOver = NULL;
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Returns the index of the first selected item.
//-----------------------------------------------------------------------------
int CBaseLoadoutPanel::GetFirstSelectedItemIndex( bool bIncludeEmptySlots )
{
for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
{
if ( m_pItemModelPanels[i]->IsSelected() && ( bIncludeEmptySlots || m_pItemModelPanels[i]->HasItem() ) )
{
return i;
}
}
return -1;
}
//-----------------------------------------------------------------------------
// Purpose: Returns the first selected item model panel or NULL if there is no
// such panel.
//-----------------------------------------------------------------------------
CItemModelPanel *CBaseLoadoutPanel::GetFirstSelectedItemModelPanel (bool bIncludeEmptySlots )
{
int i = GetFirstSelectedItemIndex( bIncludeEmptySlots );
if( i == -1 )
return NULL;
else
return m_pItemModelPanels[ i ];
}
//-----------------------------------------------------------------------------
// Purpose: Returns the first selected econ item view or NULL if there is no
// selected item
//-----------------------------------------------------------------------------
CEconItemView *CBaseLoadoutPanel::GetFirstSelectedItem()
{
CItemModelPanel *pItemModelPanel = GetFirstSelectedItemModelPanel( false );
if( pItemModelPanel )
return pItemModelPanel->GetItem();
else
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Returns the next item in the specified direction, possibly switching
// pages to get there
//-----------------------------------------------------------------------------
bool CBaseLoadoutPanel::GetAdjacentItemIndex( int nIndex, int nPage, int *pnNewIndex, int *pnNewPage, int dx, int dy )
{
// if we don't have a valid index the right answer is always the first item on the first page
if( nIndex == -1 )
{
*pnNewIndex = 0;
*pnNewPage = nPage;
return true;
}
int nRow = nIndex / GetNumColumns() + dy;
int nColumn = nIndex % GetNumColumns() + dx;
// just limit us to the top and bottom edges
if( nRow < 0 || nRow >= GetNumRows() )
return false;
// for columns, try to switch pages
int nNewPage = nPage;
while( nColumn < 0 )
{
if( nNewPage == 0 )
break;
nNewPage--;
nColumn += GetNumColumns();
}
while( nColumn >= GetNumColumns() )
{
if( nNewPage == GetNumPages() - 1 )
break;
nNewPage++;
nColumn -= GetNumColumns();
}
if( nColumn < 0 )
{
if( nNewPage != nPage )
{
nColumn = 0;
}
else
{
return false;
}
}
else if( nColumn >= GetNumColumns() )
{
if( nNewPage != nPage )
{
nColumn = GetNumColumns() - 1;
}
else
{
return false;
}
}
// never change to an invisible panel
int nNewIndex = nRow * GetNumColumns() + nColumn;
if( nNewIndex >= m_pItemModelPanels.Count() || !m_pItemModelPanels[ nNewIndex ]->IsVisible() )
{
// try to find a model panel that's still valid so we find the last one on the last valid row
while( nNewIndex >= 0 && !m_pItemModelPanels[ nNewIndex ]->IsVisible() )
nNewIndex--;
if( nNewIndex < 0 || nNewIndex == nIndex )
return false;
}
*pnNewPage = nNewPage;
*pnNewIndex = nNewIndex;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: selects the next item in the specified direction, possibly switching
// pages to get there
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::SelectAdjacentItem( int dx, int dy )
{
int nSelected = GetFirstSelectedItemIndex( true );
int nNewPage, nNewSelected;
bool bFoundNext = GetAdjacentItemIndex( nSelected, m_nCurrentPage, &nNewSelected, &nNewPage, dx, dy );
if( !bFoundNext )
{
vgui::surface()->PlaySound( "player/suit_denydevice.wav" );
return;
}
// change pages
if( nNewPage != m_nCurrentPage )
{
Assert( nNewPage >= 0 && nNewPage < GetNumPages() );
SetCurrentPage( nNewPage );
UpdateModelPanels();
}
// select the new model
if( nSelected != nNewSelected )
{
if( nSelected != -1 && m_pItemModelPanels[ nSelected ]->IsSelected() )
{
m_pItemModelPanels[ nSelected ]->SetSelected( false );
SetBorderForItem( m_pItemModelPanels[ nSelected ], false );
}
if( nNewSelected != -1 && !m_pItemModelPanels[ nNewSelected ]->IsSelected() )
{
m_pItemModelPanels[ nNewSelected ]->SetSelected( true );
SetBorderForItem( m_pItemModelPanels[ nNewSelected ], false );
if( m_bTooltipKeyPressed )
{
if( m_pItemModelPanels[ nNewSelected ]->HasItem() )
{
m_pMouseOverTooltip->ShowTooltip( m_pItemModelPanels[ nNewSelected ] );
}
else
{
m_pMouseOverTooltip->HideTooltip();
}
}
}
}
OnItemSelectionChanged();
}
//-----------------------------------------------------------------------------
// Purpose: Processes up/down/left/right keys for selecting items in the panel
//-----------------------------------------------------------------------------
bool CBaseLoadoutPanel::HandleItemSelectionKeyPressed( vgui::KeyCode code )
{
ButtonCode_t nButtonCode = GetBaseButtonCode( code );
if ( nButtonCode == KEY_XBUTTON_UP ||
nButtonCode == KEY_XSTICK1_UP ||
nButtonCode == KEY_XSTICK2_UP ||
nButtonCode == KEY_UP )
{
SelectAdjacentItem( 0, -1 );
return true;
}
else if ( nButtonCode == KEY_XBUTTON_DOWN ||
nButtonCode == KEY_XSTICK1_DOWN ||
nButtonCode == KEY_XSTICK2_DOWN ||
nButtonCode == STEAMCONTROLLER_DPAD_DOWN ||
nButtonCode == KEY_DOWN )
{
SelectAdjacentItem( 0, 1 );
return true;
}
else if ( nButtonCode == KEY_XBUTTON_RIGHT ||
nButtonCode == KEY_XSTICK1_RIGHT ||
nButtonCode == KEY_XSTICK2_RIGHT ||
nButtonCode == STEAMCONTROLLER_DPAD_RIGHT ||
nButtonCode == KEY_RIGHT )
{
SelectAdjacentItem( 1, 0 );
return true;
}
else if ( nButtonCode == KEY_XBUTTON_LEFT ||
nButtonCode == KEY_XSTICK1_LEFT ||
nButtonCode == KEY_XSTICK2_LEFT ||
nButtonCode == STEAMCONTROLLER_DPAD_LEFT ||
nButtonCode == KEY_LEFT )
{
SelectAdjacentItem( -1, 0 );
return true;
}
else if ( code == KEY_PAGEDOWN ||
nButtonCode == KEY_XBUTTON_RIGHT_SHOULDER )
{
if( m_nCurrentPage < GetNumPages() - 1 )
{
SetCurrentPage( m_nCurrentPage + 1 );
UpdateModelPanels();
}
return true;
}
else if ( code == KEY_PAGEUP ||
nButtonCode == KEY_XBUTTON_LEFT_SHOULDER )
{
if( m_nCurrentPage > 0 )
{
SetCurrentPage( m_nCurrentPage - 1 );
UpdateModelPanels();
}
return true;
}
else if ( nButtonCode == KEY_XBUTTON_Y )
{
m_bTooltipKeyPressed = true;
CItemModelPanel *pSelection = GetFirstSelectedItemModelPanel( false );
if( pSelection )
{
m_pMouseOverTooltip->ResetDelay();
m_pMouseOverTooltip->ShowTooltip( pSelection );
}
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
// Purpose: Processes up/down/left/right keys for selecting items in the panel
//-----------------------------------------------------------------------------
bool CBaseLoadoutPanel::HandleItemSelectionKeyReleased( vgui::KeyCode code )
{
ButtonCode_t nButtonCode = GetBaseButtonCode( code );
if( nButtonCode == KEY_XBUTTON_Y )
{
m_bTooltipKeyPressed = false;
m_pMouseOverTooltip->HideTooltip();
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseLoadoutPanel::SetCurrentPage( int nNewPage )
{
if( nNewPage < 0 || nNewPage >= GetNumPages() )
return;
m_nCurrentPage = nNewPage;
}
|