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.

268 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BACKPACK_PANEL_H
  8. #define BACKPACK_PANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "base_loadout_panel.h"
  13. #include "tf_item_inspection_panel.h"
  14. #define BACKPACK_SLOTS_PER_PAGE 50
  15. #define BACKPACK_ROWS 5
  16. #define BACKPACK_COLUMNS (BACKPACK_SLOTS_PER_PAGE / BACKPACK_ROWS)
  17. #define BACKPACK_MAX_PAGES (MAX_NUM_BACKPACK_SLOTS / BACKPACK_SLOTS_PER_PAGE)
  18. class CDynamicRecipePanel;
  19. class CItemSlotPanel;
  20. class CStrangeCountTransferPanel;
  21. class CCollectionCraftingPanel;
  22. class CHalloweenOfferingPanel;
  23. class CCraftCommonStatClockPanel;
  24. class CTFStorePreviewItemPanel2;
  25. //-----------------------------------------------------------------------------
  26. // An inventory screen that handles displaying the backpack
  27. //-----------------------------------------------------------------------------
  28. class CBackpackPanel : public CBaseLoadoutPanel
  29. {
  30. DECLARE_CLASS_SIMPLE( CBackpackPanel, CBaseLoadoutPanel );
  31. public:
  32. CBackpackPanel( vgui::Panel *parent, const char *panelName );
  33. virtual ~CBackpackPanel();
  34. virtual const char *GetResFile( void ) { return "Resource/UI/econ/BackpackPanel.res"; }
  35. virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) OVERRIDE;
  36. virtual void ApplySettings( KeyValues *inResourceData ) OVERRIDE;
  37. virtual void PerformLayout( void ) OVERRIDE;
  38. virtual void FireGameEvent( IGameEvent *event ) OVERRIDE;
  39. virtual void UpdateModelPanels( void );
  40. virtual int GetNumItemPanels( void ) { return BACKPACK_SLOTS_PER_PAGE; };
  41. virtual void OnShowPanel( bool bVisible, bool bReturningFromArmory );
  42. virtual void PostShowPanel( bool bVisible );
  43. virtual bool UsesRarityControls( void ) { return true; }
  44. virtual bool AllowSelection( void ) { return true; }
  45. virtual bool AllowDragging( CItemModelPanel *panel ) { return true; }
  46. virtual int GetNumSlotsPerPage( void ) OVERRIDE { return BACKPACK_SLOTS_PER_PAGE; }
  47. virtual int GetNumColumns( void ) OVERRIDE { return BACKPACK_COLUMNS; }
  48. virtual int GetNumRows( void ) OVERRIDE { return BACKPACK_ROWS; }
  49. virtual int GetNumPages( void ) OVERRIDE;
  50. virtual void SetCurrentPage( int nNewPage ) OVERRIDE;
  51. virtual void AssignItemToPanel( CItemModelPanel *pPanel, int iIndex );
  52. virtual void OnItemPanelEntered( vgui::Panel *panel ) OVERRIDE;
  53. virtual void OpenContextMenu();
  54. MESSAGE_FUNC_PTR( OnItemPanelMousePressed, "ItemPanelMousePressed", panel );
  55. MESSAGE_FUNC_PTR( OnItemPanelMouseReleased, "ItemPanelMouseReleased", panel );
  56. MESSAGE_FUNC_PTR( OnItemPanelMouseRightRelease, "ItemPanelMouseRightRelease", panel );
  57. MESSAGE_FUNC_INT_INT( OnCursorMoved, "OnCursorMoved", x, y );
  58. MESSAGE_FUNC_INT_INT( OnItemPanelCursorMoved, "ItemPanelCursorMoved", x, y );
  59. MESSAGE_FUNC_PARAMS( OnConfirmDelete, "ConfirmDlgResult", data );
  60. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );
  61. MESSAGE_FUNC_PARAMS( OnButtonChecked, "CheckButtonChecked", pData );
  62. MESSAGE_FUNC( OnCancelSelection, "CancelSelection" );
  63. MESSAGE_FUNC( DoTradeToPlayer, "DoTradeToPlayer" );
  64. MESSAGE_FUNC( DoSellMarketplace, "DoSellMarketplace" );
  65. MESSAGE_FUNC( DoDescription, "DoDescription" );
  66. MESSAGE_FUNC( DoRename, "DoRename" );
  67. MESSAGE_FUNC( DoDelete, "DoDelete" );
  68. MESSAGE_FUNC( DoApplyOnItem, "Context_ApplyOnItem" );
  69. MESSAGE_FUNC( DoUseConsumableItem, "Context_UseConsumableItem" );
  70. MESSAGE_FUNC( DoUnwrapItem, "Context_UnwrapItem" );
  71. MESSAGE_FUNC( DoDeliverItem, "Context_DeliverItem" );
  72. MESSAGE_FUNC( DoApplyByItem, "Context_ApplyByItem" );
  73. MESSAGE_FUNC( DoShuffle, "Context_Shuffle" );
  74. MESSAGE_FUNC( DoEditSlot, "Context_EditSlot" );
  75. MESSAGE_FUNC( DoRefurbishItem, "Context_RefurbishItem" );
  76. MESSAGE_FUNC( DoGetItemFromStore, "Context_GetItemFromStore" );
  77. MESSAGE_FUNC( DoOpenDuckLeaderboards, "Context_OpenDuckLeaderboards" );
  78. MESSAGE_FUNC( DoInspectModel, "Context_InspectModel" );
  79. MESSAGE_FUNC( DoBuyKeyAndOpenCrate, "Context_BuyKeyAndOpenCrate" );
  80. MESSAGE_FUNC( DoOpenCrateWithKey, "Context_OpenCrateWithKey" );
  81. MESSAGE_FUNC( DoStrangeCountTransfer, "Context_OpenStrangeCountTransfer" );
  82. MESSAGE_FUNC( DoCraftUpCollection, "Context_CraftUpCollection" );
  83. MESSAGE_FUNC( DoHalloweenOffering, "Context_HalloweenOffering" );
  84. MESSAGE_FUNC( DoCraftCommonStatClock, "Context_CraftCommonStatClock" );
  85. void DoEquipForClass( int nClass );
  86. void DoPaint( int nPaintItemIndex, bool bUseStore, bool bUseMarket );
  87. void DoStrangePart( int nStrangePartIndex, bool bUseMarket );
  88. enum ESelection
  89. {
  90. SELECT_FIRST,
  91. SELECT_ALL
  92. };
  93. bool AttemptToUseItem( item_definition_index_t iItemDefIndex );
  94. void AttemptToShowItemInStore( item_definition_index_t iItemDefIndex );
  95. void AttemptToShowItemInMarket( item_definition_index_t iItemDefIndex );
  96. void GetSelectedPanels( ESelection eSelection, CUtlVector< CItemModelPanel* >& m_vecSelected ) const;
  97. virtual void OnCommand( const char *command );
  98. virtual void OnTick( void );
  99. virtual void OnThink( void );
  100. virtual void OnKeyCodePressed( vgui::KeyCode code ) OVERRIDE;
  101. virtual void OnKeyCodeReleased( vgui::KeyCode code ) OVERRIDE;
  102. virtual void OnKeyCodeTyped(vgui::KeyCode code) OVERRIDE;
  103. virtual void OnMouseReleased(vgui::MouseCode code) OVERRIDE;
  104. virtual void OnMouseMismatchedRelease( vgui::MouseCode code, Panel* pPressedPanel ) OVERRIDE;
  105. virtual void OnMouseCaptureLost() OVERRIDE;
  106. void OnItemContentsChanged( CEconItemView *pEconItemView );
  107. virtual void OpenArmory( CEconItemView* item );
  108. void ToggleSelectBackpackItemPanel( CItemModelPanel *pPanel );
  109. void DeSelectAllBackpackItemPanels( void );
  110. CEconItemView* GetComboBoxOverlayUISeletionItem() { return &m_ComboBoxOverlaySelectionItem; }
  111. void SetComboBoxOverlaySelectionItem( const CEconItemView *pEconItemView ) { m_ComboBoxOverlaySelectionItem = *pEconItemView; }
  112. void SetCurrentTransactionID( uint64 nTxnID );
  113. void CheckForQuickOpenKey();
  114. void MarkItemIDDirty( itemid_t itemID );
  115. void OpenInspectModelPanelAndCopyItem( CEconItemView *pItemView );
  116. CCollectionCraftingPanel *GetCollectionCraftPanel();
  117. protected:
  118. virtual void StartDrag( int x, int y );
  119. virtual void StopDrag( bool bSucceeded );
  120. virtual bool CanDragTo( CItemModelPanel *pItemPanel, int iPanelIndex ) { return true; }
  121. virtual void HandleDragTo( CItemModelPanel *pItemPanel, int iPanelIndex );
  122. virtual int GetBackpackPosForPanelIndex( int iPanelIndex ) { return iPanelIndex + 1 + (GetCurrentPage() * GetNumSlotsPerPage()); }
  123. virtual bool NeedsDerivedTickSignal( void ) { return false; }
  124. int GetBackpackPositionForPanel( CItemModelPanel *pItemPanel );
  125. virtual const char *GetGreyOutItemPanelReason( CItemModelPanel *pItemPanel );
  126. virtual void SetBorderForItem( CItemModelPanel *pItemPanel, bool bMouseOver );
  127. virtual bool IsIgnoringItemPanelEnters( void ) { return m_bDragging; }
  128. virtual void AddNewItemPanel( int iPanelIndex );
  129. virtual CItemModelPanel *GetItemPanelAtPos( int x, int y );
  130. virtual void PositionItemPanel( CItemModelPanel *pPanel, int iIndex );
  131. void CancelToolSelection( void );
  132. void SetShowBaseItems( bool bShow );
  133. virtual ConVar *GetExplanationConVar( void );
  134. bool ShouldShowExplanations( void ) { return (!m_bItemsOnly && !InToolSelectionMode()); }
  135. bool InToolSelectionMode() const { return m_eSelectionMode != StandardSelection; }
  136. void SetupToolSelectionItem();
  137. void HandleToolItemSelection( CEconItemView *pItem );
  138. void ClearNameFilter( bool bUpdateModelPanels );
  139. bool HasNameFilter() const { return m_wNameFilter.Count() > 0; }
  140. const wchar_t* GetNameFilter() const { return HasNameFilter() ? m_wNameFilter.Base() : NULL; }
  141. void UpdateFilteringItems();
  142. int GetItemQualityForBorder( CItemModelPanel* pItemPanel ) const;
  143. int GetNumMaxPages() const { return BACKPACK_MAX_PAGES; }
  144. int GetPageButtonIndexAtPos( int x, int y );
  145. void SetPageButtonTextColorBasedOnContents();
  146. void AddPaintToContextMenu( Menu *pPaintSubMenu, item_definition_index_t iPaintDef, bool bAddCommerce );
  147. void AddCommerceToContextMenu( Menu *pMenu, const char* pszActionFmt, item_definition_index_t iItemDefIndex, bool bAddMarket, bool bAddStore );
  148. void AddCommerceSubmenus( Menu *pSubMenu, item_definition_index_t iItemDef, const char* pszActionFmt );
  149. void DoGiftToPlayer( );
  150. protected:
  151. vgui::TextEntry *m_pNameFilterTextEntry;
  152. CUtlVector<wchar_t> m_wNameFilter;
  153. float m_flFilterItemTime;
  154. CUtlMap< int, CEconItemView*, int > m_mapFilteringItems;
  155. CUtlMap< itemid_t, char > m_mapSeenItems;
  156. bool m_bInitializedSeenItems;
  157. CUtlVector< itemid_t > m_vecDirtyItems;
  158. CExButton *m_pNextPageButton;
  159. CExButton *m_pPrevPageButton;
  160. CExButton *m_pShowExplanationsButton;
  161. vgui::Label *m_pCurPageLabel;
  162. vgui::ComboBox *m_pSortByComboBox;
  163. vgui::ComboBox *m_pShowRarityComboBox;
  164. vgui::CheckButton *m_pShowBaseItemsCheckbox;
  165. CExButton *m_pDragToNextPageButton;
  166. CExButton *m_pDragToPrevPageButton;
  167. float m_flPreventDragPageSwitchUntil;
  168. float m_flStartExplanationsAt;
  169. // Dragging support
  170. float m_flMouseDownTime;
  171. int m_iMouseDownX;
  172. int m_iMouseDownY;
  173. CItemModelPanel *m_pItemDraggedFromPanel;
  174. int m_iDraggedFromPage;
  175. bool m_bMouseDownOnItemPanel;
  176. bool m_bDragging;
  177. CItemModelPanel *m_pMouseDragItemPanel;
  178. int m_iDragOffsetX;
  179. int m_iDragOffsetY;
  180. CItemModelPanel *m_pPrevDragOverItemPanel;
  181. // Deletion
  182. vgui::EditablePanel *m_pConfirmDeleteDialog;
  183. // Tool support
  184. enum SelectionMode_t
  185. {
  186. StandardSelection,
  187. ToolSelection,
  188. };
  189. SelectionMode_t m_eSelectionMode;
  190. int m_nLastToolPage;
  191. CEconItemView m_ToolSelectionItem;
  192. CExButton *m_pCancelToolButton;
  193. vgui::ScalableImagePanel *m_pToolIcon;
  194. CEconItemView m_ComboBoxOverlaySelectionItem;
  195. CExButton *m_pCraftButton;
  196. // base items or backpack items
  197. bool m_bShowBaseItems;
  198. // positions of all our item panels, so we can handle drag & drop
  199. struct backpackitempos_t
  200. {
  201. int x,y;
  202. };
  203. CUtlVector<backpackitempos_t> m_ItemModelPanelPos;
  204. KeyValues *m_pPageButtonKVs;
  205. int m_nNumActivePages;
  206. CUtlVector< EditablePanel* > m_Pages;
  207. CUtlVector<backpackitempos_t> m_PageButtonPos;
  208. CDynamicRecipePanel* m_pDynamicRecipePanel;
  209. CItemSlotPanel* m_pItemSlotPanel;
  210. CUtlVector< item_definition_index_t > m_vecPaintCans;
  211. CUtlVector< item_definition_index_t > m_vecStrangeParts;
  212. DHANDLE<CStrangeCountTransferPanel> m_pStrangeToolPanel;
  213. DHANDLE<CCollectionCraftingPanel> m_pCollectionCraftPanel;
  214. DHANDLE<CHalloweenOfferingPanel> m_pHalloweenOfferingPanel;
  215. DHANDLE<CCraftCommonStatClockPanel> m_pMannCoTradePanel; // Make this Panel Generic
  216. CTFItemInspectionPanel *m_pInspectPanel;
  217. CTFStorePreviewItemPanel2 *m_pInspectCosmeticPanel;
  218. vgui::Menu *m_pContextMenu;
  219. CEconItemViewHandle m_hQuickOpenCrate;
  220. uint64 m_nQuickOpenTxn;
  221. CPanelAnimationVarAliasType( int, m_iPageButtonYPos, "page_button_y", "0", "proportional_int" );
  222. CPanelAnimationVarAliasType( int, m_iPageButtonXDelta, "page_button_x_delta", "0", "proportional_int" );
  223. CPanelAnimationVarAliasType( int, m_iPageButtonYDelta, "page_button_y_delta", "0", "proportional_int" );
  224. CPanelAnimationVarAliasType( int, m_iPageButtonPerRow, "page_button_per_row", "20", "int" );
  225. CPanelAnimationVarAliasType( int, m_iPageButtonHeight, "page_button_height", "0", "proportional_int" );
  226. };
  227. #endif // BACKPACK_PANEL_H