Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
8.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ITEM_SELECTION_PANEL_H
  8. #define ITEM_SELECTION_PANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui_controls/EditablePanel.h"
  13. #include "econ_controls.h"
  14. #include "vgui_controls/ScrollableEditablePanel.h"
  15. #include "backpack_panel.h"
  16. #include "base_loadout_panel.h"
  17. class CItemModelPanel;
  18. #define SELECTION_DISPLAY_SLOTS_PER_PAGE 18
  19. #define SELECTION_DISPLAY_ROWS 3
  20. #define SELECTION_DISPLAY_COLUMNS (SELECTION_DISPLAY_SLOTS_PER_PAGE / SELECTION_DISPLAY_ROWS)
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. struct item_stack_type_t
  25. {
  26. item_stack_type_t() : m_nDefIndex( INVALID_ITEM_DEF_INDEX ), m_nQuality( (uint8)-1 ) { }
  27. item_stack_type_t( item_definition_index_t nDefIndex, uint8 nQuality ) : m_nDefIndex( nDefIndex ), m_nQuality( nQuality ) { }
  28. bool operator<( const item_stack_type_t& other ) const { return m_nDefIndex < other.m_nDefIndex || m_nQuality < other.m_nQuality; }
  29. bool operator==( const item_stack_type_t& other ) const { return m_nDefIndex == other.m_nDefIndex && m_nQuality == other.m_nQuality; }
  30. item_definition_index_t m_nDefIndex;
  31. uint8 m_nQuality;
  32. };
  33. class CItemSelectionPanel : public CBaseLoadoutPanel
  34. {
  35. DECLARE_CLASS_SIMPLE( CItemSelectionPanel, CBaseLoadoutPanel );
  36. public:
  37. CItemSelectionPanel(Panel *parent);
  38. virtual ~CItemSelectionPanel();
  39. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  40. virtual void ApplySettings( KeyValues *inResourceData );
  41. virtual void PerformLayout( void );
  42. virtual void OnThink( void );
  43. virtual void OnCommand( const char *command );
  44. virtual void OnClose( void );
  45. virtual void SetVisible( bool bState );
  46. virtual bool ShouldDeleteOnClose( void ) { return true; }
  47. virtual void OnKeyCodePressed( vgui::KeyCode code ) OVERRIDE;
  48. virtual void OnKeyCodeReleased( vgui::KeyCode code ) OVERRIDE;
  49. virtual void OnKeyCodeTyped( vgui::KeyCode code) OVERRIDE;
  50. MESSAGE_FUNC_PARAMS( OnButtonChecked, "CheckButtonChecked", pData );
  51. virtual int GetNumItemPanels( void ) { return m_bShowingEntireBackpack ? BACKPACK_SLOTS_PER_PAGE : SELECTION_DISPLAY_SLOTS_PER_PAGE; };
  52. virtual void PositionItemPanel( CItemModelPanel *pPanel, int iIndex );
  53. virtual bool AllowSelection( void ) { return true; }
  54. virtual bool AllowDragging( CItemModelPanel *panel ) { return false; }
  55. virtual int GetNumSlotsPerPage( void ) OVERRIDE { return m_bShowingEntireBackpack ? BACKPACK_SLOTS_PER_PAGE : SELECTION_DISPLAY_SLOTS_PER_PAGE; }
  56. virtual int GetNumColumns( void ) OVERRIDE { return m_bShowingEntireBackpack ? BACKPACK_COLUMNS : SELECTION_DISPLAY_COLUMNS; }
  57. virtual int GetNumRows( void ) OVERRIDE { return m_bShowingEntireBackpack ? BACKPACK_ROWS : SELECTION_DISPLAY_ROWS; }
  58. virtual int GetNumPages( void ) OVERRIDE;
  59. virtual void SetCurrentPage( int nNewPage ) OVERRIDE;
  60. void UpdateModelPanels( void );
  61. virtual void ApplyKVsToItemPanels( void );
  62. virtual void CreateItemPanels( void );
  63. void ShowDuplicateCounts( bool bShow ) { m_bShowDuplicates = bShow; }
  64. void UpdateDuplicateCounts( void );
  65. MESSAGE_FUNC_PTR( OnItemPanelMousePressed, "ItemPanelMousePressed", panel );
  66. MESSAGE_FUNC_PTR( OnItemPanelMouseReleased, "ItemPanelMouseReleased", panel );
  67. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );
  68. // Derived panels need to override these with the custom selection behavior
  69. virtual const char *GetSchemeFile( void ) = 0;
  70. virtual bool ShouldItemPanelBeVisible( CItemModelPanel *pPanel, int iPanelIndex ) = 0;
  71. virtual void UpdateModelPanelsForSelection( void ) = 0;
  72. virtual const char *GetItemNotSelectableReason( const CEconItemView *pItem ) const = 0;
  73. virtual bool DisableItemSelectionFromGrayedOutPanels( void ) const { return false; }
  74. void NotifySelectionReturned( CItemModelPanel *pItemPanel );
  75. void SetCaller( Panel* pCaller ) { m_pCaller = pCaller; }
  76. virtual bool DisplayOnlyAllowUniqueQualityCheckbox() const { return false; }
  77. protected:
  78. void PostMessageSelectionReturned( itemid_t ulItemID );
  79. bool m_bShowingEntireBackpack;
  80. KeyValues *m_pSelectionItemModelPanelKVs;
  81. KeyValues *m_pDuplicateLabelKVs;
  82. vgui::CheckButton *m_pOnlyAllowUniqueQuality;
  83. CExButton *m_pShowBackpack;
  84. CExButton *m_pShowSelection;
  85. bool m_bForceBackpack;
  86. CExButton *m_pNextPageButton;
  87. CExButton *m_pPrevPageButton;
  88. vgui::Label *m_pCurPageLabel;
  89. vgui::Label *m_pNoItemsInSelectionLabel;
  90. int m_iItemsInSelection;
  91. bool m_bShowDuplicates;
  92. CUtlVector<CExLabel*> m_pDuplicateCountLabels;
  93. typedef CUtlMap< item_stack_type_t, int > DuplicateCountsMap_t;
  94. DuplicateCountsMap_t m_DuplicateCounts; // A map of item def indices to item counts. Derived classes should fill this out.
  95. bool m_bGotMousePressed;
  96. Panel *m_pCaller;
  97. vgui::TextEntry *m_pNameFilterTextEntry;
  98. CUtlVector<wchar_t> m_wNameFilter;
  99. float m_flFilterItemTime;
  100. };
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. class CEquipSlotItemSelectionPanel : public CItemSelectionPanel
  105. {
  106. public:
  107. DECLARE_CLASS_SIMPLE( CEquipSlotItemSelectionPanel, CItemSelectionPanel );
  108. public:
  109. CEquipSlotItemSelectionPanel(Panel *parent, int iClass, int iSlot);
  110. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  111. virtual void PerformLayout( void );
  112. virtual const char *GetSchemeFile( void ) { return "Resource/UI/ItemSelectionPanel.res"; }
  113. virtual bool ShouldItemPanelBeVisible( CItemModelPanel *pPanel, int iPanelIndex );
  114. virtual void UpdateModelPanelsForSelection( void );
  115. virtual const char *GetItemNotSelectableReason( const CEconItemView *pItem ) const;
  116. virtual bool DisableItemSelectionFromGrayedOutPanels( void ) const { return true; }
  117. void OnBackPressed();
  118. protected:
  119. int m_iClass; // Class of the player we're selecting an item for
  120. int m_iSlot; // Slot on the player that we're selecting an item for
  121. itemid_t m_iCurrentItemID;
  122. vgui::Label *m_pWeaponLabel;
  123. };
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Selection panel that uses an Item Criteria block to do selection
  126. //-----------------------------------------------------------------------------
  127. class CItemCriteriaSelectionPanel : public CItemSelectionPanel
  128. {
  129. DECLARE_CLASS_SIMPLE( CItemCriteriaSelectionPanel, CItemSelectionPanel );
  130. public:
  131. CItemCriteriaSelectionPanel(Panel *parent, const CItemSelectionCriteria *pCriteria, itemid_t pExceptions[] = NULL, int iNumExceptions = 0 );
  132. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  133. void UpdateExceptions( itemid_t pExceptions[], int iNumExceptions );
  134. virtual const char *GetSchemeFile( void ) { return "Resource/UI/ItemSelectionPanel.res"; }
  135. virtual bool ShouldItemPanelBeVisible( CItemModelPanel *pPanel, int iPanelIndex );
  136. virtual void UpdateModelPanelsForSelection( void );
  137. virtual const char *GetItemNotSelectableReason( const CEconItemView *pItem ) const;
  138. protected:
  139. const CItemSelectionCriteria *m_pCriteria;
  140. CUtlVector<itemid_t> m_Exceptions;
  141. };
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Selection panel for crafting
  144. //-----------------------------------------------------------------------------
  145. class CCraftingItemSelectionPanel : public CItemCriteriaSelectionPanel
  146. {
  147. DECLARE_CLASS_SIMPLE( CCraftingItemSelectionPanel, CItemCriteriaSelectionPanel );
  148. public:
  149. CCraftingItemSelectionPanel(Panel *parent );
  150. virtual const char *GetItemNotSelectableReason( const CEconItemView *pItem ) const;
  151. virtual bool ShouldDeleteOnClose( void ) { return false; }
  152. void UpdateOnShow( const CItemSelectionCriteria *pCriteria, bool bForceBackpack, itemid_t pExceptions[] = NULL, int iNumExceptions = 0 );
  153. virtual bool DisplayOnlyAllowUniqueQualityCheckbox() const { return true; }
  154. };
  155. //-----------------------------------------------------------------------------
  156. // Purpose:
  157. //-----------------------------------------------------------------------------
  158. class CAccountSlotItemSelectionPanel : public CEquipSlotItemSelectionPanel
  159. {
  160. DECLARE_CLASS_SIMPLE( CAccountSlotItemSelectionPanel, CEquipSlotItemSelectionPanel );
  161. public:
  162. CAccountSlotItemSelectionPanel( Panel *pParent, int iSlot, const char *pszTitleToken );
  163. virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) OVERRIDE;
  164. virtual const char *GetItemNotSelectableReason( const CEconItemView *pItem ) const OVERRIDE;
  165. protected:
  166. const char * m_pszTitleToken;
  167. };
  168. #endif // ITEM_SELECTION_PANEL_H