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.

202 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CRAFTING_PANEL_H
  8. #define CRAFTING_PANEL_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. class CImageButton;
  20. // Crafting slots on crafting page
  21. #define CRAFTING_SLOTS_INPUT_ROWS 3
  22. #define CRAFTING_SLOTS_INPUT_COLUMNS 4
  23. #define CRAFTING_SLOTS_INPUTPANELS (CRAFTING_SLOTS_INPUT_ROWS * CRAFTING_SLOTS_INPUT_COLUMNS)
  24. #define CRAFTING_SLOTS_OUTPUT_ROWS 1
  25. #define CRAFTING_SLOTS_OUTPUT_COLUMNS 4
  26. #define CRAFTING_SLOTS_COUNT (CRAFTING_SLOTS_INPUTPANELS + (CRAFTING_SLOTS_OUTPUT_ROWS * CRAFTING_SLOTS_OUTPUT_COLUMNS))
  27. #define RECIPE_CUSTOM -2
  28. //-----------------------------------------------------------------------------
  29. // Purpose:
  30. //-----------------------------------------------------------------------------
  31. class CRecipeButton : public CExButton
  32. {
  33. private:
  34. DECLARE_CLASS_SIMPLE( CRecipeButton, CExButton );
  35. public:
  36. CRecipeButton( vgui::Panel *parent, const char *name, const char *text, vgui::Panel *pActionSignalTarget = NULL, const char *cmd = NULL )
  37. : CExButton( parent, name, text, pActionSignalTarget, cmd )
  38. {
  39. }
  40. virtual void ApplySettings( KeyValues *inResourceData )
  41. {
  42. BaseClass::ApplySettings( inResourceData );
  43. SetEnabled( m_iRecipeDefIndex != -1 );
  44. }
  45. void SetDefIndex( int iIndex )
  46. {
  47. m_iRecipeDefIndex = iIndex;
  48. SetEnabled( m_iRecipeDefIndex != -1 );
  49. }
  50. void OnCursorEntered( void )
  51. {
  52. PostActionSignal( new KeyValues("RecipePanelEntered") );
  53. BaseClass::OnCursorEntered();
  54. }
  55. void OnCursorExited( void )
  56. {
  57. PostActionSignal( new KeyValues("RecipePanelExited") );
  58. BaseClass::OnCursorExited();
  59. }
  60. public:
  61. int m_iRecipeDefIndex;
  62. };
  63. //-----------------------------------------------------------------------------
  64. // An inventory screen that handles displaying the crafting screen
  65. //-----------------------------------------------------------------------------
  66. class CCraftingPanel : public CBaseLoadoutPanel
  67. {
  68. DECLARE_CLASS_SIMPLE( CCraftingPanel, CBaseLoadoutPanel );
  69. public:
  70. CCraftingPanel( vgui::Panel *parent, const char *panelName );
  71. ~CCraftingPanel( void );
  72. virtual const char *GetResFile( void ) { return "Resource/UI/CraftingPanel.res"; }
  73. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  74. virtual void ApplySettings( KeyValues *inResourceData );
  75. virtual void PerformLayout( void );
  76. virtual void OnShowPanel( bool bVisible, bool bReturningFromArmory );
  77. virtual void OnCommand( const char *command );
  78. void CreateRecipeFilterButtons( void );
  79. void UpdateRecipeFilter( void );
  80. virtual int GetNumItemPanels( void ) { return CRAFTING_SLOTS_COUNT; };
  81. bool IsInputItemPanel( int iSlot ) { return (iSlot < CRAFTING_SLOTS_INPUTPANELS); }
  82. virtual void PositionItemPanel( CItemModelPanel *pPanel, int iIndex );
  83. int GetItemPanelIndex( CItemModelPanel *pItemPanel );
  84. void UpdateSelectedRecipe( bool bClearInputItems );
  85. void UpdateRecipeItems( bool bClearInputItems );
  86. void UpdateCraftButton( void );
  87. const char *GetItemTextForCriteria( const CItemSelectionCriteria *pCriteria );
  88. CEconItemDefinition *GetItemDefFromCriteria( const CItemSelectionCriteria *pCriteria );
  89. virtual void AddNewItemPanel( int iPanelIndex );
  90. virtual void UpdateModelPanels( void );
  91. void SetButtonToRecipe( int iButton, int iDefIndex, wchar_t *pszText );
  92. bool CheckForUntradableItems( void );
  93. void Craft( void );
  94. void OnCraftResponse( EGCMsgResponse eResponse, CUtlVector<uint64> *vecCraftedIndices, int iRecipeUsed );
  95. void ShowCraftFinish( void );
  96. virtual void OnTick( void );
  97. void CleanupPostCraft( bool bClearInputItems );
  98. MESSAGE_FUNC_PTR( OnItemPanelMousePressed, "ItemPanelMousePressed", panel );
  99. MESSAGE_FUNC_PTR( OnRecipePanelEntered, "RecipePanelEntered", panel );
  100. MESSAGE_FUNC_PTR( OnRecipePanelExited, "RecipePanelExited", panel );
  101. MESSAGE_FUNC( OnCancelSelection, "CancelSelection" );
  102. MESSAGE_FUNC_PARAMS( OnSelectionReturned, "SelectionReturned", data );
  103. MESSAGE_FUNC( OnClosing, "Closing" );
  104. virtual ConVar *GetExplanationConVar( void );
  105. private:
  106. // Items in the input model panels
  107. itemid_t m_InputItems[CRAFTING_SLOTS_INPUTPANELS];
  108. const CItemSelectionCriteria *m_ItemPanelCriteria[CRAFTING_SLOTS_INPUTPANELS];
  109. CExButton *m_pCraftButton;
  110. CExButton *m_pUpgradeButton;
  111. CExLabel *m_pFreeAccountLabel;
  112. vgui::EditablePanel *m_pRecipeListContainer;
  113. vgui::ScrollableEditablePanel *m_pRecipeListContainerScroller;
  114. vgui::EditablePanel *m_pSelectedRecipeContainer;
  115. KeyValues *m_pRecipeButtonsKV;
  116. CUtlVector<CRecipeButton*> m_pRecipeButtons;
  117. KeyValues *m_pRecipeFilterButtonsKV;
  118. CUtlVector<CImageButton*> m_pRecipeFilterButtons;
  119. int m_iCurrentlySelectedRecipe;
  120. int m_iCurrentRecipeTotalInputs;
  121. int m_iCurrentRecipeTotalOutputs;
  122. recipecategories_t m_iRecipeCategoryFilter;
  123. CUtlVector<itemid_t> m_vecNewlyCraftedItems;
  124. double m_flAbortCraftingAt;
  125. bool m_bWaitingForCraftItems;
  126. int m_iRecipeIndexTried;
  127. int m_iNewRecipeIndex;
  128. bool m_bEventLogging;
  129. int m_iCraftingAttempts;
  130. CTFTextToolTip *m_pToolTip;
  131. vgui::EditablePanel *m_pToolTipEmbeddedPanel;
  132. CCraftingItemSelectionPanel *m_pSelectionPanel;
  133. int m_iSelectingForSlot;
  134. CPanelAnimationVarAliasType( int, m_iItemCraftingOffcenterX, "item_crafting_offcenter_x", "0", "proportional_int" );
  135. CPanelAnimationVarAliasType( int, m_iFilterOffcenterX, "filter_xoffset", "0", "proportional_int" );
  136. CPanelAnimationVarAliasType( int, m_iFilterYPos, "filter_ypos", "0", "proportional_int" );
  137. CPanelAnimationVarAliasType( int, m_iFilterDeltaX, "filter_xdelta", "0", "proportional_int" );
  138. CPanelAnimationVarAliasType( int, m_iFilterDeltaY, "filter_ydelta", "0", "proportional_int" );
  139. CPanelAnimationVarAliasType( int, m_iOutputItemYPos, "output_item_ypos", "0", "proportional_int" );
  140. };
  141. //-----------------------------------------------------------------------------
  142. // Purpose: A dialog used to show the current state of a crafting request.
  143. //-----------------------------------------------------------------------------
  144. class CCraftingStatusDialog : public vgui::EditablePanel
  145. {
  146. DECLARE_CLASS_SIMPLE( CCraftingStatusDialog, vgui::EditablePanel );
  147. public:
  148. CCraftingStatusDialog( vgui::Panel *pParent, const char *pElementName );
  149. virtual void ApplySchemeSettings( vgui::IScheme *scheme );
  150. virtual void OnCommand( const char *command );
  151. virtual void OnTick( void );
  152. void UpdateSchemeForVersion( bool bRecipe );
  153. void ShowStatusUpdate( bool bAnimateEllipses, bool bAllowed, bool bShowOnExit );
  154. private:
  155. bool m_bShowOnExit;
  156. bool m_bAnimateEllipses;
  157. int m_iNumEllipses;
  158. bool m_bShowNewRecipe;
  159. CItemModelPanel *m_pRecipePanel;
  160. };
  161. CCraftingStatusDialog *OpenCraftingStatusDialog( vgui::Panel *pParent, const char *pszText, bool bAnimateEllipses, bool bAllowClose, bool bShowOnExit );
  162. CCraftingStatusDialog *OpenNewRecipeFoundDialog( vgui::Panel *pParent, const CEconCraftingRecipeDefinition *pRecipeDef );
  163. void CloseCraftingStatusDialog( void );
  164. #endif // CRAFTING_PANEL_H