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.

267 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef DYNAMIC_RECIPE_SUBPANEL_H
  8. #define DYNAMIC_RECIPE_SUBPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "backpack_panel.h"
  13. #include "vgui_controls/ScrollableEditablePanel.h"
  14. #include "tf_gcmessages.h"
  15. #include "econ_gcmessages.h"
  16. #include "tf_imagepanel.h"
  17. #include "tf_controls.h"
  18. #include "item_selection_panel.h"
  19. #include "econ_dynamic_recipe.h"
  20. class CImageButton;
  21. #define DYNAMIC_RECIPE_INPUT_ROWS 4
  22. #define DYNAMIC_RECIPE_INPUT_COLS 3
  23. #define DYNAMIC_RECIPE_INPUT_COUNT ( DYNAMIC_RECIPE_INPUT_ROWS * DYNAMIC_RECIPE_INPUT_COLS )
  24. #define DYNAMIC_RECIPE_OUTPUT_ROWS 4
  25. #define DYNAMIC_RECIPE_OUTPUT_COLS 3
  26. #define DYNAMIC_RECIPE_OUTPUT_COUNT ( DYNAMIC_RECIPE_OUTPUT_ROWS * DYNAMIC_RECIPE_OUTPUT_COLS )
  27. #define DYNAMIC_RECIPE_BACKPACK_ROWS 4
  28. #define DYNAMIC_RECIPE_BACKPACK_COLS 4
  29. #define DYNAMIC_RECIPE_PACKPACK_COUNT_PER_PAGE ( DYNAMIC_RECIPE_BACKPACK_ROWS * DYNAMIC_RECIPE_BACKPACK_COLS )
  30. class CRecipeComponentItemModelPanel;
  31. class CRecipeComponentItemModelPanel : public CItemModelPanel
  32. {
  33. public:
  34. DECLARE_CLASS_SIMPLE( CRecipeComponentItemModelPanel, CItemModelPanel );
  35. CRecipeComponentItemModelPanel( vgui::Panel *parent, const char *name );
  36. void AddRecipe( itemid_t nRecipe );
  37. virtual void DeleteRecipes();
  38. virtual void SetItem( const CEconItemView *pItem ) OVERRIDE;
  39. void SetRecipeItem( itemid_t nRecipeItem, int nPageNumber );
  40. void AddDefaultItem( CEconItemView *pItem );
  41. CEconItemView* GetRecipeItem( int nPageNumber ) const;
  42. itemid_t GetRecipeIndex( int nPageNumber ) const;
  43. bool IsSlotAvailable( int nPageNumber );
  44. CEconItemView* GetDefaultItem() const { return m_nPageNumber < m_vecDefaultItems.Count() ? m_vecDefaultItems[ m_nPageNumber ] : NULL; }
  45. void UpdateDisplayItem();
  46. void SetPageNumber( int nPageNumber );
  47. int GetPageNumber() const { return m_nPageNumber; }
  48. protected:
  49. struct RecipeItem_t
  50. {
  51. itemid_t m_nRecipeIndex;
  52. CEconItemView* m_pRecipeItem;
  53. };
  54. void UpdateRecipeItem( RecipeItem_t* pRecipeItem );
  55. virtual void SetBlankState();
  56. CUtlVector< CEconItemView* > m_vecDefaultItems;
  57. CUtlVector< RecipeItem_t > m_vecRecipes;
  58. int m_nPageNumber;
  59. };
  60. class CInputPanelItemModelPanel : public CRecipeComponentItemModelPanel
  61. {
  62. public:
  63. CInputPanelItemModelPanel( vgui::Panel *parent, const char *name, const CEconItemView* pDynamicRecipeItem )
  64. : CRecipeComponentItemModelPanel( parent, name )
  65. , m_pDynamicRecipeItem( pDynamicRecipeItem )
  66. {}
  67. virtual void DeleteRecipes();
  68. void AddComponentInfo( const CEconItemAttributeDefinition *pComponentAttrib );
  69. bool MatchesAttribCriteria( itemid_t itemID ) const;
  70. bool MatchesAttribCriteria( itemid_t itemID, int nPageNumber ) const;
  71. const CEconItemAttributeDefinition * GetAttrib( int nPageNumber ) const;
  72. void SetDynamicRecipeItem( const CEconItemView* pDynamicRecipeItem ) { m_pDynamicRecipeItem = pDynamicRecipeItem; }
  73. protected:
  74. virtual void SetBlankState() OVERRIDE;
  75. private:
  76. CUtlVector< const CEconItemAttributeDefinition* > m_vecAttrDef;
  77. const CEconItemView* m_pDynamicRecipeItem;
  78. };
  79. //-----------------------------------------------------------------------------
  80. // An inventory screen that handles displaying the crafting screen
  81. //-----------------------------------------------------------------------------
  82. class CDynamicRecipePanel : public CBackpackPanel
  83. {
  84. DECLARE_CLASS_SIMPLE( CDynamicRecipePanel, CBackpackPanel );
  85. public:
  86. #ifdef STAGING_ONLY
  87. void Debug_GiveRequiredInputs() const;
  88. CExButton *m_pDevGiveInputsButton;
  89. #endif
  90. CDynamicRecipePanel( vgui::Panel *parent, const char *panelName, CEconItemView* pRecipeItem );
  91. ~CDynamicRecipePanel( void );
  92. void SetNewRecipe( CEconItemView* pNewRecipeItem );
  93. void ConsumeItem( );
  94. void InitItemPanels();
  95. virtual const char *GetResFile( void ) { return "Resource/UI/DynamicRecipePanel.res"; }
  96. virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) OVERRIDE;
  97. virtual void ApplySettings( KeyValues *inResourceData ) OVERRIDE;
  98. virtual void PerformLayout( void ) OVERRIDE;
  99. virtual void OnCommand( const char *command ) OVERRIDE;
  100. virtual void OnKeyCodePressed( vgui::KeyCode code ) OVERRIDE;
  101. void OnButtonChecked( KeyValues *pData ) OVERRIDE;
  102. virtual void OpenContextMenu() OVERRIDE {}
  103. virtual int GetNumItemPanels( void ) OVERRIDE;
  104. virtual void AddNewItemPanel( int iPanelIndex ) OVERRIDE;
  105. void Craft();
  106. virtual void OnTick( void ) OVERRIDE;
  107. virtual void OnShowPanel( bool bVisible, bool bReturningFromArmory ) OVERRIDE;
  108. void OnCraftResponse( itemid_t nNewToolID, EGCMsgResponse eResponse );
  109. private:
  110. bool IsInputPanel( int iPanelIndex ) const;
  111. bool IsOutputPanel( int iPanelIndex) const;
  112. bool IsBackpackPanel( int iPanelIndex) const;
  113. bool IsInvPanelOnThisPage( unsigned nIndex ) const;
  114. int GetNumBackpackPanelsPerPage() const { return DYNAMIC_RECIPE_BACKPACK_ROWS * DYNAMIC_RECIPE_BACKPACK_COLS; }
  115. virtual int GetNumPages() OVERRIDE;
  116. virtual void SetCurrentPage( int nNewPage ) OVERRIDE;
  117. int GetFirstBackpackIndex() const { return DYNAMIC_RECIPE_INPUT_COUNT + DYNAMIC_RECIPE_OUTPUT_COUNT; }
  118. void SetCurrentInputPage( int nNewPage );
  119. int GetNumInputPages() const;
  120. int GetNumInputPanelsPerPage() const { return DYNAMIC_RECIPE_INPUT_COUNT; }
  121. int GetNumOutputPage() const;
  122. int GetNumOutputPanelsPerPage() const { return DYNAMIC_RECIPE_OUTPUT_COUNT; }
  123. class CRecipeComponentAttributeCounter : public CEconItemSpecificAttributeIterator
  124. {
  125. public:
  126. CRecipeComponentAttributeCounter()
  127. : m_nInputCount( 0 )
  128. {}
  129. ~CRecipeComponentAttributeCounter() { Reset(); }
  130. virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_DynamicRecipeComponent& value ) OVERRIDE;
  131. int GetInputCount() const { return m_nInputCount; }
  132. int GetOutputCount() const { return m_vecOutputItems.Count(); }
  133. CEconItemView* GetOutputItem( int i );
  134. CEconItemView* GetInputItem( int i );
  135. const CEconItemAttributeDefinition* GetInputAttrib( int i );
  136. void Reset();
  137. private:
  138. struct InputComponent_t
  139. {
  140. CEconItemView m_ItemView;
  141. const CEconItemAttributeDefinition* m_pAttrib;
  142. };
  143. typedef CUtlVector< CCopyableUtlVector<InputComponent_t> > InputComponentVec;
  144. static int LeastCommonInputSortFunc( const CCopyableUtlVector<InputComponent_t> *p1, const CCopyableUtlVector<InputComponent_t> *p2 );
  145. InputComponent_t* GetInputComponent( int i );
  146. InputComponentVec m_vecInputItems;
  147. CUtlVector< CEconItemView > m_vecOutputItems;
  148. CUtlVector< CEconItem* > m_vecTempEconItems;
  149. int m_nInputCount;
  150. };
  151. class CDynamicRecipeItemMatchFind : public CEconItemSpecificAttributeIterator
  152. {
  153. public:
  154. CDynamicRecipeItemMatchFind( const CEconItemView* pSourceItem, const CEconItemView* pItemTomatch )
  155. : m_bMatchesAny( false )
  156. , m_pSourceItem( pSourceItem )
  157. , m_pItemToMatch( pItemTomatch )
  158. {}
  159. virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_DynamicRecipeComponent& value ) OVERRIDE;
  160. bool MatchesAnyAttributes() const { return m_bMatchesAny; }
  161. private:
  162. const CEconItemView* m_pSourceItem;
  163. const CEconItemView* m_pItemToMatch;
  164. bool m_bMatchesAny;
  165. };
  166. CEconItemView* m_pDynamicRecipeItem;
  167. CRecipeComponentAttributeCounter m_RecipeIterator;
  168. bool AllRecipePanelsFilled( void );
  169. bool CheckForUntradableItems( void );
  170. bool WarnAboutPartialCompletion( void );
  171. void FindPossibleBackpackItems();
  172. virtual void PositionItemPanel( CItemModelPanel *pPanel, int iIndex );
  173. void PopulatePanelsForCurrentPage();
  174. virtual void UpdateModelPanels( void );
  175. virtual void SetBorderForItem( CItemModelPanel *pItemPanel, bool bMouseOver );
  176. void SetRecipeComponentIntoPanel( itemid_t nSrcRecipeIndex, CRecipeComponentItemModelPanel* pSrcPanel, int nSrcPage, CRecipeComponentItemModelPanel* pDstPanel, int nDstPage );
  177. bool InputPanelCanAcceptItem( CItemModelPanel* pPanel, itemid_t nItemID );
  178. CTFTextToolTip *m_pToolTip;
  179. vgui::EditablePanel *m_pToolTipEmbeddedPanel;
  180. CExButton *m_pRecipeCraftButton;
  181. CExLabel *m_pNoMatchesLabel;
  182. CExLabel *m_pUntradableOutputsLabel;
  183. CExLabel *m_pInputsLabel;
  184. CExLabel *m_pOutputsLabel;
  185. vgui::Label *m_pCurInputPageLabel;
  186. CExButton *m_pNextInputPageButton;
  187. CExButton *m_pPrevInputPageButton;
  188. CItemModelPanel *m_pMouseOverItemPanel;
  189. vgui::CheckButton *m_pShowUntradableItemsCheckbox;
  190. CUtlVector<CInputPanelItemModelPanel*> m_vecRecipeInputModelPanels;
  191. CUtlVector<CRecipeComponentItemModelPanel*> m_vecBackpackModelPanels;
  192. CUtlVector<CItemModelPanel*> m_vecRecipeOutputModelPanels;
  193. vgui::EditablePanel *m_pRecipeContainer;
  194. vgui::EditablePanel *m_pInventoryContainer;
  195. unsigned m_nNumRecipeItems;
  196. bool m_bAllRecipePanelsFilled;
  197. bool m_bInputPanelsDirty;
  198. bool m_bShowUntradable;
  199. int m_nInputPage;
  200. int m_nOutputPage;
  201. float m_flAbortCraftingAt;
  202. MESSAGE_FUNC_PTR( OnItemPanelMouseDoublePressed, "ItemPanelMouseDoublePressed", panel );
  203. MESSAGE_FUNC_PTR( OnItemPanelEntered, "ItemPanelEntered", panel );
  204. MESSAGE_FUNC_PTR( OnItemPanelExited, "ItemPanelExited", panel );
  205. MESSAGE_FUNC( OnRecipeCompleted, "RecipeCompleted" );
  206. virtual bool AllowDragging( CItemModelPanel *panel ) OVERRIDE;
  207. virtual void StartDrag( int x, int y ) OVERRIDE;
  208. virtual void StopDrag( bool bSucceeded ) OVERRIDE;
  209. virtual bool CanDragTo( CItemModelPanel *pItemPanel, int iPanelIndex ) OVERRIDE;
  210. virtual void HandleDragTo( CItemModelPanel *pItemPanel, int iPanelIndex ) OVERRIDE;
  211. void ReturnRecipeItemToBackpack( itemid_t nItemID, CRecipeComponentItemModelPanel* pSrcPanel, int nSrcPage );
  212. CPanelAnimationVarAliasType( int, m_iItemCraftingOffcenterX, "item_crafting_offcenter_x", "0", "proportional_int" );
  213. CPanelAnimationVarAliasType( int, m_iOutputItemYPos, "output_item_ypos", "0", "proportional_int" );
  214. CPanelAnimationVarAliasType( int, m_iInventoryXPos, "inventory_xpos", "0", "proportional_int" );
  215. CPanelAnimationVarAliasType( int, m_iInventoryYPos, "inventory_ypos", "0", "proportional_int" );
  216. friend void ConfirmDestroyItems( bool bConfirmed, void* pContext );
  217. };
  218. #endif // DYNAMIC_RECIPE_SUBPANEL_H