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.

195 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  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. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class CAssetTreeView;
  20. namespace vgui
  21. {
  22. class Panel;
  23. }
  24. FORWARD_DECLARE_HANDLE( AssetList_t );
  25. typedef unsigned short DirHandle_t;
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Base class for choosing raw assets
  28. //-----------------------------------------------------------------------------
  29. class CBaseAssetPicker : public vgui::EditablePanel
  30. {
  31. DECLARE_CLASS_SIMPLE( CBaseAssetPicker, vgui::EditablePanel );
  32. public:
  33. CBaseAssetPicker( vgui::Panel *pParent, const char *pAssetType,
  34. const char *pExt, const char *pSubDir, const char *pTextType );
  35. ~CBaseAssetPicker();
  36. // overridden frame functions
  37. virtual void OnTick();
  38. virtual bool HasUserConfigSettings();
  39. virtual void ApplyUserConfigSettings( KeyValues *pUserConfig );
  40. virtual void GetUserConfigSettings( KeyValues *pUserConfig );
  41. virtual void OnCommand( const char *pCommand );
  42. // Purpose:
  43. virtual void OnKeyCodePressed( vgui::KeyCode code );
  44. // Returns the selected asset name
  45. int GetSelectedAssetCount();
  46. const char *GetSelectedAsset( int nAssetIndex = -1 );
  47. // Is multiselect enabled?
  48. bool IsMultiselectEnabled() const;
  49. // Sets the initial selected asset
  50. void SetInitialSelection( const char *pAssetName );
  51. // Set/get the filter
  52. void SetFilter( const char *pFilter );
  53. const char *GetFilter();
  54. // Purpose: refreshes the file tree
  55. void RefreshFileTree();
  56. virtual void Activate();
  57. protected:
  58. // Creates standard controls. Allows the derived class to
  59. // add these controls to various splitter windows
  60. void CreateStandardControls( vgui::Panel *pParent, bool bAllowMultiselect = false );
  61. // Allows the picker to browse multiple asset types
  62. void AddExtension( const char *pExtension );
  63. // Derived classes have this called when the previewed asset changes
  64. virtual void OnSelectedAssetPicked( const char *pAssetName ) {}
  65. // Derived classes have this called when the next selected asset is selected by default
  66. virtual void OnNextSelectionIsDefault() {}
  67. // Request focus of the filter box
  68. void RequestFilterFocus();
  69. // Rescan assets
  70. void RescanAssets();
  71. const char *GetModPath( int nModIndex );
  72. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
  73. MESSAGE_FUNC_PARAMS( OnItemSelected, "ItemSelected", kv );
  74. MESSAGE_FUNC_PARAMS( OnCheckButtonChecked, "CheckButtonChecked", kv );
  75. MESSAGE_FUNC( OnFileSelected, "TreeViewItemSelected" );
  76. protected:
  77. struct AssetInfo_t
  78. {
  79. int m_nAssetIndex;
  80. int m_nItemId;
  81. };
  82. void BuildAssetNameList();
  83. void RefreshAssetList( );
  84. int GetSelectedAssetModIndex( );
  85. // Is a particular asset visible?
  86. bool IsAssetVisible( int nAssetIndex );
  87. // Recursively add all files matching the wildcard under this directory
  88. void AddAssetToList( int nAssetIndex );
  89. // Update column headers
  90. void UpdateAssetColumnHeader( );
  91. vgui::Splitter *m_pAssetSplitter;
  92. CAssetTreeView* m_pFileTree;
  93. vgui::CheckButton* m_pSubDirCheck;
  94. vgui::TextEntry *m_pFilter;
  95. vgui::ListPanel *m_pAssetBrowser;
  96. vgui::TextEntry *m_pFullPath;
  97. vgui::ComboBox *m_pModSelector;
  98. vgui::Button *m_pRescanButton;
  99. AssetList_t m_hAssetList;
  100. CUtlString m_FolderFilter;
  101. CUtlString m_Filter;
  102. CUtlString m_SelectedAsset;
  103. CUtlVector< AssetInfo_t > m_AssetList;
  104. const char *m_pAssetType;
  105. const char *m_pAssetTextType;
  106. const char *m_pAssetExt;
  107. const char *m_pAssetSubDir;
  108. CUtlVector< const char * > m_ExtraAssetExt;
  109. bool m_bBuiltAssetList : 1;
  110. bool m_bFirstAssetScan : 1;
  111. bool m_bFinishedAssetListScan : 1;
  112. int m_nCurrentModFilter;
  113. int m_nMatchingAssets;
  114. bool m_bSubDirCheck;
  115. friend class CBaseAssetPickerFrame;
  116. };
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Modal dialog for asset picker
  119. //-----------------------------------------------------------------------------
  120. class CBaseAssetPickerFrame : public vgui::Frame
  121. {
  122. DECLARE_CLASS_SIMPLE( CBaseAssetPickerFrame, vgui::Frame );
  123. public:
  124. CBaseAssetPickerFrame( vgui::Panel *pParent );
  125. ~CBaseAssetPickerFrame();
  126. // Inherited from Frame
  127. virtual void OnCommand( const char *pCommand );
  128. // Purpose: Activate the dialog
  129. // The message "AssetSelected" will be sent if an asset is picked
  130. // Pass in optional keyvalues to add to the message
  131. void DoModal( KeyValues *pContextKeyValues = NULL );
  132. // Sets the initial selected asset
  133. void SetInitialSelection( const char *pAssetName );
  134. // Set/get the filter
  135. void SetFilter( const char *pFilter );
  136. const char *GetFilter();
  137. protected:
  138. // Allows the derived class to create the picker
  139. void SetAssetPicker( CBaseAssetPicker* pPicker );
  140. CBaseAssetPicker* GetAssetPicker() { return m_pPicker; }
  141. // Posts a message (passing the key values)
  142. void PostMessageAndClose( KeyValues *pKeyValues );
  143. private:
  144. void CleanUpMessage();
  145. CBaseAssetPicker *m_pPicker;
  146. vgui::Button *m_pOpenButton;
  147. vgui::Button *m_pCancelButton;
  148. KeyValues *m_pContextKeyValues;
  149. };
  150. #endif // BASEASSETPICKER_H