Counter Strike : Global Offensive Source Code
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.

245 lines
7.0 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. //
  3. //
  4. //
  5. //==================================================================================================
  6. #ifndef BASEASSETPICKER_H
  7. #define BASEASSETPICKER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/EditablePanel.h"
  12. #include "vgui_controls/Frame.h"
  13. #include "tier1/utlstring.h"
  14. #include "tier1/utllinkedlist.h"
  15. #include "filesystem.h"
  16. #include "assetpickerdefs.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class CAssetTreeView;
  21. namespace vgui
  22. {
  23. class Panel;
  24. }
  25. FORWARD_DECLARE_HANDLE( AssetList_t );
  26. typedef unsigned short DirHandle_t;
  27. struct CachedAssetInfo_t
  28. {
  29. CUtlString m_AssetName;
  30. int m_nModIndex;
  31. int m_nTimesUsed;
  32. };
  33. struct CacheModInfo_t
  34. {
  35. CUtlString m_ModName;
  36. CUtlString m_Path;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Base class for choosing raw assets
  40. //-----------------------------------------------------------------------------
  41. class CBaseAssetPicker : public vgui::EditablePanel
  42. {
  43. DECLARE_CLASS_SIMPLE( CBaseAssetPicker, vgui::EditablePanel );
  44. public:
  45. CBaseAssetPicker( vgui::Panel *pParent, const char *pAssetType,
  46. const char *pExt, const char *pSubDir, const char *pTextType, const char *pSearchPath = "GAME" );
  47. ~CBaseAssetPicker();
  48. // overridden frame functions
  49. virtual void OnTick();
  50. virtual bool HasUserConfigSettings();
  51. virtual void ApplyUserConfigSettings( KeyValues *pUserConfig );
  52. virtual void GetUserConfigSettings( KeyValues *pUserConfig );
  53. virtual void OnCommand( const char *pCommand );
  54. // Purpose:
  55. virtual void OnKeyCodeTyped( vgui::KeyCode code );
  56. // Returns the selected asset name
  57. int GetSelectedAssetCount();
  58. const char *GetSelectedAsset( int nSelectionIndex = -1 );
  59. int GetSelectedAssetIndex( int nSelectionIndex );
  60. // Is multiselect enabled?
  61. bool IsMultiselectEnabled() const;
  62. void SetAllowMultiselect( bool bAllowMultiselect );
  63. // Sets the selected asset
  64. void SetSelection( const char *pAssetName, bool bInitialSelection = false );
  65. void SetInitialSelection( const char *pAssetName );
  66. void SetUsedAssetList( CUtlVector<AssetUsageInfo_t> &usedAssets );
  67. // Set/get the filter
  68. void SetFilter( const char *pFilter );
  69. const char *GetFilter();
  70. // Purpose: refreshes the file tree
  71. void RefreshFileTree();
  72. virtual void Activate();
  73. void CloseModal();
  74. virtual void CustomizeSelectionMessage( KeyValues *pKeyValues ) {}
  75. // asset cache interface
  76. virtual int GetAssetCount();
  77. virtual const char *GetAssetName( int nAssetIndex );
  78. virtual const CachedAssetInfo_t& GetCachedAsset( int nAssetIndex );
  79. virtual int GetCachedAssetCount();
  80. virtual bool IncrementalCacheAssets( float flTimeAllowed ); // return true if finished
  81. virtual bool BeginCacheAssets( bool bForceRecache ); // return true if finished
  82. virtual CUtlString GetSelectedAssetFullPath( int nIndex );
  83. int ModCount() const;
  84. const CacheModInfo_t& ModInfo( int nIndex ) const;
  85. protected:
  86. // Creates standard controls. Allows the derived class to
  87. // add these controls to various splitter windows
  88. void CreateStandardControls( vgui::Panel *pParent, bool bAllowMultiselect = false );
  89. void AutoLayoutStandardControls( );
  90. // Allows the picker to browse multiple asset types
  91. void AddExtension( const char *pExtension );
  92. // Derived classes have this called when the previewed asset changes
  93. virtual void OnSelectedAssetPicked( const char *pAssetName ) {}
  94. // Derived classes have this called when the next selected asset is selected by default
  95. virtual void OnNextSelectionIsDefault() {}
  96. // Derived classes have this called when the filtered list changes
  97. virtual void OnAssetListChanged( ) {}
  98. // Request focus of the filter box
  99. void RequestFilterFocus();
  100. // Rescan assets
  101. void RescanAssets();
  102. bool DoIncrementalCache( );
  103. // Is a particular asset visible?
  104. bool IsAssetVisible( int nAssetIndex );
  105. const char *GetModPath( int nModIndex );
  106. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
  107. MESSAGE_FUNC_PARAMS( OnItemSelected, "ItemSelected", kv );
  108. MESSAGE_FUNC_PARAMS( OnItemDeselected, "ItemDeselected", kv );
  109. MESSAGE_FUNC_PARAMS( OnCheckButtonChecked, "CheckButtonChecked", kv );
  110. MESSAGE_FUNC( OnFileSelected, "TreeViewItemSelected" );
  111. protected:
  112. struct AssetInfo_t
  113. {
  114. int m_nAssetIndex;
  115. int m_nItemId;
  116. };
  117. void BuildAssetNameList();
  118. void RefreshAssetList( );
  119. int GetSelectedAssetModIndex( );
  120. // Recursively add all files matching the wildcard under this directory
  121. void AddAssetToList( int nAssetIndex );
  122. // Update column headers
  123. void UpdateAssetColumnHeader( );
  124. vgui::Splitter *m_pAssetSplitter;
  125. CAssetTreeView* m_pFileTree;
  126. vgui::CheckButton* m_pSubDirCheck;
  127. vgui::TextEntry *m_pFilter;
  128. vgui::ListPanel *m_pAssetBrowser;
  129. vgui::TextEntry *m_pFullPath;
  130. vgui::ComboBox *m_pModSelector;
  131. vgui::Button *m_pRescanButton;
  132. vgui::Button *m_pFindAssetButton;
  133. KeyValues *m_pInsertHelper;
  134. vgui::CheckButton *m_pOnlyUsedCheck;
  135. AssetList_t m_hAssetList;
  136. CUtlString m_FolderFilter;
  137. CUtlString m_Filter;
  138. CUtlString m_SelectedAsset;
  139. CUtlVector< AssetInfo_t > m_AssetList;
  140. const char *m_pAssetType;
  141. const char *m_pAssetTextType;
  142. const char *m_pAssetExt;
  143. const char *m_pAssetSubDir;
  144. const char *m_pAssetSearchPath;
  145. CUtlVector< const char * > m_ExtraAssetExt;
  146. bool m_bBuiltAssetList : 1;
  147. bool m_bFirstAssetScan : 1;
  148. bool m_bFinishedAssetListScan : 1;
  149. bool m_bSubDirCheck : 1;
  150. bool m_bOnlyUsedAssetsCheck : 1;
  151. int m_nCurrentModFilter;
  152. int m_nMatchingAssets;
  153. CUtlVector<AssetUsageInfo_t> m_usedAssets;
  154. friend class CBaseAssetPickerFrame;
  155. };
  156. //-----------------------------------------------------------------------------
  157. // Purpose: Modal dialog for asset picker
  158. //-----------------------------------------------------------------------------
  159. class CBaseAssetPickerFrame : public vgui::Frame
  160. {
  161. DECLARE_CLASS_SIMPLE( CBaseAssetPickerFrame, vgui::Frame );
  162. public:
  163. CBaseAssetPickerFrame( vgui::Panel *pParent );
  164. ~CBaseAssetPickerFrame();
  165. // Inherited from Frame
  166. virtual void OnCommand( const char *pCommand );
  167. // Purpose: Activate the dialog
  168. // The message "AssetSelected" will be sent if an asset is picked
  169. // Pass in optional keyvalues to add to the message
  170. void DoModal( KeyValues *pContextKeyValues = NULL );
  171. // Sets the initial selected asset
  172. void SetInitialSelection( const char *pAssetName );
  173. // Set/get the filter
  174. void SetFilter( const char *pFilter );
  175. const char *GetFilter();
  176. void SetAllowMultiselect( bool bAllowMultiselect );
  177. protected:
  178. // Allows the derived class to create the picker
  179. void SetAssetPicker( CBaseAssetPicker* pPicker );
  180. CBaseAssetPicker* GetAssetPicker() { return m_pPicker; }
  181. // Posts a message (passing the key values)
  182. void PostMessageAndClose( KeyValues *pKeyValues );
  183. virtual void CloseModal();
  184. private:
  185. void CleanUpMessage();
  186. CBaseAssetPicker *m_pPicker;
  187. vgui::Button *m_pOpenButton;
  188. vgui::Button *m_pCancelButton;
  189. KeyValues *m_pContextKeyValues;
  190. };
  191. #endif // BASEASSETPICKER_H