IExtContentBrowserSingleton.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "IContentBrowserSingleton.h"
  4. #include "ExtContentBrowser.h"
  5. #include "ExtAssetData.h"
  6. #include "CoreMinimal.h"
  7. #include "SlateFwd.h"
  8. #include "Misc/Attribute.h"
  9. #include "AssetRegistry/AssetData.h"
  10. #include "Developer/AssetTools/Public/AssetTypeCategories.h"
  11. #include "AssetRegistry/ARFilter.h"
  12. #include "ContentBrowserDelegates.h"
  13. #include "Developer/CollectionManager/Public/CollectionManagerTypes.h"
  14. #include "Misc/FilterCollection.h"
  15. #include "Framework/Views/ITypedTableView.h"
  16. #include "AssetThumbnail.h"
  17. class FViewport;
  18. class UFactory;
  19. typedef const FExtAssetData& FExtAssetFilterType;
  20. typedef TFilterCollection<FExtAssetFilterType> FExtAssetFilterCollectionType;
  21. /** A selection of items in the Content Browser */
  22. struct FExtContentBrowserSelection
  23. {
  24. TArray<FExtAssetData> SelectedAssets;
  25. TArray<FString> SelectedFolders;
  26. int32 Num() const
  27. {
  28. return SelectedAssets.Num() + SelectedFolders.Num();
  29. }
  30. void Reset()
  31. {
  32. SelectedAssets.Reset();
  33. SelectedFolders.Reset();
  34. }
  35. void Empty()
  36. {
  37. SelectedAssets.Empty();
  38. SelectedFolders.Empty();
  39. }
  40. };
  41. #if ECB_LEGACY
  42. /** A struct containing details about how the asset picker should behave */
  43. struct FAssetPickerConfig
  44. {
  45. /** The selection mode the picker should use */
  46. ESelectionMode::Type SelectionMode;
  47. /** An array of pointers to existing delegates which the AssetView will register a function which returns the current selection */
  48. TArray<FGetCurrentSelectionDelegate*> GetCurrentSelectionDelegates;
  49. /** An array of pointers to existing delegates which the AssetView will register a function which sync the asset list*/
  50. TArray<FSyncToAssetsDelegate*> SyncToAssetsDelegates;
  51. /** A pointer to an existing delegate that, when executed, will set the filter an the asset picker after it is created. */
  52. TArray<FSetARFilterDelegate*> SetFilterDelegates;
  53. /** A pointer to an existing delegate that, when executed, will refresh the asset view. */
  54. TArray<FRefreshAssetViewDelegate*> RefreshAssetViewDelegates;
  55. /** The asset registry filter to use to cull results */
  56. FARFilter Filter;
  57. /** Custom front end filters to be displayed */
  58. TArray< TSharedRef<class FExtFrontendFilter> > ExtraFrontendFilters;
  59. /** The names of columns to hide by default in the column view */
  60. TArray<FString> HiddenColumnNames;
  61. /** List of custom columns that fill out data with a callback */
  62. TArray<FAssetViewCustomColumn> CustomColumns;
  63. /** The contents of the label on the thumbnail */
  64. EThumbnailLabel::Type ThumbnailLabel;
  65. /** The default scale for thumbnails. [0-1] range */
  66. TAttribute< float > ThumbnailScale;
  67. /** Only display results in these collections */
  68. TArray<FCollectionNameType> Collections;
  69. /** The asset that should be initially selected */
  70. FAssetData InitialAssetSelection;
  71. /** The delegate that fires when an asset was selected */
  72. FOnAssetSelected OnAssetSelected;
  73. /** The delegate that fires when a folder was double clicked */
  74. FOnPathSelected OnFolderEntered;
  75. /** The delegate that fires when an asset is double clicked */
  76. FOnAssetDoubleClicked OnAssetDoubleClicked;
  77. /** The delegate that fires when an asset has enter pressed while selected */
  78. FOnAssetEnterPressed OnAssetEnterPressed;
  79. /** The delegate that fires when any number of assets are activated */
  80. FOnAssetsActivated OnAssetsActivated;
  81. /** The delegate that fires when an asset is right clicked and a context menu is requested */
  82. FOnGetAssetContextMenu OnGetAssetContextMenu;
  83. /** The delegate that fires when a folder is right clicked and a context menu is requested */
  84. FOnGetFolderContextMenu OnGetFolderContextMenu;
  85. /** Called to see if it is valid to get a custom asset tool tip */
  86. FOnIsAssetValidForCustomToolTip OnIsAssetValidForCustomToolTip;
  87. /** Fired when an asset item is constructed and a tooltip is requested. If unbound the item will use the default widget */
  88. FOnGetCustomAssetToolTip OnGetCustomAssetToolTip;
  89. /** Called to add extra asset data to the asset view, to display virtual assets. These get treated similar to Class assets */
  90. FOnGetCustomSourceAssets OnGetCustomSourceAssets;
  91. /** Fired when an asset item is about to show its tool tip */
  92. FOnVisualizeAssetToolTip OnVisualizeAssetToolTip;
  93. /** Fired when an asset item's tooltip is closing */
  94. FOnAssetToolTipClosing OnAssetToolTipClosing;
  95. /** If more detailed filtering is required than simply Filter, this delegate will get fired for every asset to determine if it should be culled. */
  96. FOnShouldFilterAsset OnShouldFilterAsset;
  97. /** This delegate will be called in Details view when a new asset registry searchable tag is encountered, to
  98. determine if it should be displayed or not. If it returns true or isn't bound, the tag will be displayed normally. */
  99. FOnShouldDisplayAssetTag OnAssetTagWantsToBeDisplayed;
  100. /** The default view mode */
  101. EAssetViewType::Type InitialAssetViewType;
  102. /** The text to show when there are no assets to show */
  103. TAttribute< FText > AssetShowWarningText;
  104. /** If set, view settings will be saved and loaded for the asset view using this name in ini files */
  105. FString SaveSettingsName;
  106. /** If true, the search box will gain focus when the asset picker is created */
  107. bool bFocusSearchBoxWhenOpened;
  108. /** If true, a "None" item will always appear at the top of the list */
  109. bool bAllowNullSelection;
  110. /** If true, show the bottom toolbar which shows # of assets selected, view mode buttons, etc... */
  111. bool bShowBottomToolbar;
  112. /** If false, auto-hide the search bar above */
  113. bool bAutohideSearchBar;
  114. /** Whether to allow dragging of items */
  115. bool bAllowDragging;
  116. /** Indicates if the 'Show folders' option should be enabled or disabled */
  117. bool bCanShowFolders;
  118. /** Indicates if the context menu is going to load the assets, and if so to preload before the context menu is shown, and warn about the pending load. */
  119. bool bPreloadAssetsForContextMenu;
  120. /** Indicates that we would like to build the filter UI with the Asset Picker */
  121. bool bAddFilterUI;
  122. /** If true, show path in column view */
  123. bool bShowPathInColumnView;
  124. /** If true, show class in column view */
  125. bool bShowTypeInColumnView;
  126. /** If true, sort by path in column view. Only works if initial view type is Column */
  127. bool bSortByPathInColumnView;
  128. /** Override the default filter context menu layout */
  129. EAssetTypeCategories::Type DefaultFilterMenuExpansion;
  130. FAssetPickerConfig()
  131. : SelectionMode( ESelectionMode::Multi )
  132. , ThumbnailLabel( EThumbnailLabel::ClassName )
  133. , ThumbnailScale(0.1f)
  134. , InitialAssetViewType(EAssetViewType::Tile)
  135. , bFocusSearchBoxWhenOpened(true)
  136. , bAllowNullSelection(false)
  137. , bShowBottomToolbar(true)
  138. , bAutohideSearchBar(false)
  139. , bAllowDragging(true)
  140. , bCanShowFolders(false)
  141. , bPreloadAssetsForContextMenu(true)
  142. , bAddFilterUI(false)
  143. , bShowPathInColumnView(false)
  144. , bShowTypeInColumnView(true)
  145. , bSortByPathInColumnView(false)
  146. , DefaultFilterMenuExpansion(EAssetTypeCategories::Basic)
  147. {}
  148. };
  149. /** A struct containing details about how the path picker should behave */
  150. struct FPathPickerConfig
  151. {
  152. /** The initial path to select. Leave empty to skip initial selection. */
  153. FString DefaultPath;
  154. /** The delegate that fires when a path was selected */
  155. FOnPathSelected OnPathSelected;
  156. /** The delegate that fires when a path is right clicked and a context menu is requested */
  157. FContentBrowserMenuExtender_SelectedPaths OnGetPathContextMenuExtender;
  158. /** The delegate that fires when a folder is right clicked and a context menu is requested */
  159. FOnGetFolderContextMenu OnGetFolderContextMenu;
  160. /** A pointer to an existing delegate that, when executed, will set the paths for the path picker after it is created. */
  161. TArray<FSetPathPickerPathsDelegate*> SetPathsDelegates;
  162. /** If true, the search box will gain focus when the path picker is created */
  163. bool bFocusSearchBoxWhenOpened;
  164. /** If false, the context menu will not open when an item is right clicked */
  165. bool bAllowContextMenu;
  166. /** If true, will allow class folders to be shown in the picker */
  167. bool bAllowClassesFolder;
  168. /** If true, will add the path specified in DefaultPath to the tree if it doesn't exist already */
  169. bool bAddDefaultPath;
  170. FPathPickerConfig()
  171. : bFocusSearchBoxWhenOpened(true)
  172. , bAllowContextMenu(true)
  173. , bAllowClassesFolder(false)
  174. , bAddDefaultPath(false)
  175. {}
  176. };
  177. /** A struct containing details about how the collection picker should behave */
  178. struct FCollectionPickerConfig
  179. {
  180. /** If true, collection buttons will be displayed */
  181. bool AllowCollectionButtons;
  182. /** If true, users will be able to access the right-click menu of a collection */
  183. bool AllowRightClickMenu;
  184. /** Called when a collection was selected */
  185. FOnCollectionSelected OnCollectionSelected;
  186. FCollectionPickerConfig()
  187. : AllowCollectionButtons(true)
  188. , AllowRightClickMenu(true)
  189. , OnCollectionSelected()
  190. {}
  191. };
  192. namespace EAssetDialogType
  193. {
  194. enum Type
  195. {
  196. Open,
  197. Save
  198. };
  199. }
  200. /** A struct containing shared details about how asset dialogs should behave. You should not instanciate this config, but use FOpenAssetDialogConfig or FSaveAssetDialogConfig instead. */
  201. struct FSharedAssetDialogConfig
  202. {
  203. FText DialogTitleOverride;
  204. FString DefaultPath;
  205. TArray<FName> AssetClassNames;
  206. FVector2D WindowSizeOverride;
  207. FOnPathSelected OnPathSelected;
  208. virtual EAssetDialogType::Type GetDialogType() const = 0;
  209. FSharedAssetDialogConfig()
  210. : WindowSizeOverride(ForceInitToZero)
  211. {}
  212. virtual ~FSharedAssetDialogConfig()
  213. {}
  214. };
  215. /** A struct containing details about how the open asset dialog should behave. */
  216. struct FOpenAssetDialogConfig : public FSharedAssetDialogConfig
  217. {
  218. bool bAllowMultipleSelection;
  219. virtual EAssetDialogType::Type GetDialogType() const override { return EAssetDialogType::Open; }
  220. FOpenAssetDialogConfig()
  221. : FSharedAssetDialogConfig()
  222. , bAllowMultipleSelection(false)
  223. {}
  224. };
  225. /** An enum to choose the behavior of the save asset dialog when the user chooses an asset that already exists */
  226. namespace ESaveAssetDialogExistingAssetPolicy
  227. {
  228. enum Type
  229. {
  230. /** Display an error and disallow the save */
  231. Disallow,
  232. /** Allow the save, but warn that the existing file will be overwritten */
  233. AllowButWarn
  234. };
  235. }
  236. /** A struct containing details about how the save asset dialog should behave. */
  237. struct FSaveAssetDialogConfig : public FSharedAssetDialogConfig
  238. {
  239. FString DefaultAssetName;
  240. ESaveAssetDialogExistingAssetPolicy::Type ExistingAssetPolicy;
  241. virtual EAssetDialogType::Type GetDialogType() const override { return EAssetDialogType::Save; }
  242. FSaveAssetDialogConfig()
  243. : FSharedAssetDialogConfig()
  244. , ExistingAssetPolicy(ESaveAssetDialogExistingAssetPolicy::Disallow)
  245. {}
  246. };
  247. #endif
  248. /**
  249. * External Content browser module singleton
  250. */
  251. class IExtContentBrowserSingleton
  252. {
  253. public:
  254. /** Virtual destructor */
  255. virtual ~IExtContentBrowserSingleton() {}
  256. /**
  257. * Generates a content browser. Generally you should not call this function, but instead use CreateAssetPicker().
  258. *
  259. * @param InstanceName Global name of this content browser instance
  260. * @param ContainingTab The tab the browser is contained within or nullptr
  261. * @param ContentBrowserConfig Initial defaults for the new content browser, or nullptr to use saved settings
  262. *
  263. * @return The newly created content browser widget
  264. */
  265. virtual TSharedRef<class SWidget> CreateContentBrowser( const FName InstanceName, TSharedPtr<SDockTab> ContainingTab) = 0;
  266. /** Generates a list of assets that are selected in the primary content browser */
  267. virtual void GetSelectedAssets(TArray<FExtAssetData>& SelectedAssets) = 0;
  268. #if ECB_LEGACY
  269. /**
  270. * Generates an asset picker widget locked to the specified FARFilter.
  271. *
  272. * @param AssetPickerConfig A struct containing details about how the asset picker should behave
  273. * @return The asset picker widget
  274. */
  275. virtual TSharedRef<class SWidget> CreateAssetPicker(const FAssetPickerConfig& AssetPickerConfig) = 0;
  276. /**
  277. * Generates a path picker widget.
  278. *
  279. * @param PathPickerConfig A struct containing details about how the path picker should behave
  280. * @return The path picker widget
  281. */
  282. virtual TSharedRef<class SWidget> CreatePathPicker(const FPathPickerConfig& PathPickerConfig) = 0;
  283. /**
  284. * Generates a collection picker widget.
  285. *
  286. * @param CollectionPickerConfig A struct containing details about how the collection picker should behave
  287. * @return The collection picker widget
  288. */
  289. virtual TSharedRef<class SWidget> CreateCollectionPicker(const FCollectionPickerConfig& CollectionPickerConfig) = 0;
  290. /**
  291. * Opens the Open Asset dialog in a non-modal window
  292. *
  293. * @param OpenAssetConfig A struct containing details about how the open asset dialog should behave
  294. * @param OnAssetsChosenForOpen A delegate that is fired when assets are chosen and the open button is pressed
  295. * @param OnAssetDialogCancelled A delegate that is fired when the asset dialog is closed or cancelled
  296. */
  297. virtual void CreateOpenAssetDialog(const FOpenAssetDialogConfig& OpenAssetConfig, const FOnAssetsChosenForOpen& OnAssetsChosenForOpen, const FOnAssetDialogCancelled& OnAssetDialogCancelled) = 0;
  298. /**
  299. * Opens the Open Asset dialog in a modal window
  300. *
  301. * @param OpenAssetConfig A struct containing details about how the open asset dialog should behave
  302. * @return The assets that were chosen to be opened
  303. */
  304. virtual TArray<FAssetData> CreateModalOpenAssetDialog(const FOpenAssetDialogConfig& InConfig) = 0;
  305. /**
  306. * Opens the Save Asset dialog in a non-modal window
  307. *
  308. * @param SaveAssetConfig A struct containing details about how the save asset dialog should behave
  309. * @param OnAssetNameChosenForSave A delegate that is fired when an object path is chosen and the save button is pressed
  310. * @param OnAssetDialogCancelled A delegate that is fired when the asset dialog is closed or cancelled
  311. */
  312. virtual void CreateSaveAssetDialog(const FSaveAssetDialogConfig& SaveAssetConfig, const FOnObjectPathChosenForSave& OnAssetNameChosenForSave, const FOnAssetDialogCancelled& OnAssetDialogCancelled) = 0;
  313. /**
  314. * Opens the Save Asset dialog in a modal window
  315. *
  316. * @param SaveAssetConfig A struct containing details about how the save asset dialog should behave
  317. * @return The object path that was chosen
  318. */
  319. virtual FString CreateModalSaveAssetDialog(const FSaveAssetDialogConfig& SaveAssetConfig) = 0;
  320. /** Returns true if there is at least one browser open that is eligible to be a primary content browser */
  321. virtual bool HasPrimaryContentBrowser() const = 0;
  322. /** Brings the primary content browser to the front or opens one if it does not exist. */
  323. virtual void FocusPrimaryContentBrowser(bool bFocusSearch) = 0;
  324. /** Sets up an inline-name for the creation of a new asset in the primary content browser using the specified path and the specified class and/or factory */
  325. virtual void CreateNewAsset(const FString& DefaultAssetName, const FString& PackagePath, UClass* AssetClass, UFactory* Factory) = 0;
  326. /**
  327. * Selects the supplied assets in the primary content browser.
  328. *
  329. * @param AssetList An array of AssetDataList structs to sync
  330. * @param bAllowLockedBrowsers When true, even locked browsers may handle the sync. Only set to true if the sync doesn't seem external to the content browser
  331. * @param bFocuSExtContentBrowser When true, brings the ContentBrowser into the foreground.
  332. * @param InstanceName When supplied, will only sync the Content Browser with the matching InstanceName. bAllowLockedBrowsers is ignored.
  333. */
  334. virtual void SyncBrowserToAssets(const TArray<struct FAssetData>& AssetDataList, bool bAllowLockedBrowsers = false, bool bFocuSExtContentBrowser = true, const FName& InstanceName = FName(), bool bNewSpawnBrowser = false) = 0;
  335. /**
  336. * Selects the supplied assets in the primary content browser.
  337. *
  338. * @param AssetList An array of UObject pointers to sync
  339. * @param bAllowLockedBrowsers When true, even locked browsers may handle the sync. Only set to true if the sync doesn't seem external to the content browser
  340. * @param bFocuSExtContentBrowser When true, brings the ContentBrowser into the foreground.
  341. * @param InstanceName When supplied, will only sync the Content Browser with the matching InstanceName. bAllowLockedBrowsers is ignored.
  342. */
  343. virtual void SyncBrowserToAssets(const TArray<UObject*>& AssetList, bool bAllowLockedBrowsers = false, bool bFocuSExtContentBrowser = true, const FName& InstanceName = FName(), bool bNewSpawnBrowser = false) = 0;
  344. /**
  345. * Selects the supplied assets in the primary content browser.
  346. *
  347. * @param AssetList An array of strings represeting folder asset paths to sync
  348. * @param bAllowLockedBrowsers When true, even locked browsers may handle the sync. Only set to true if the sync doesn't seem external to the content browser
  349. * @param bFocuSExtContentBrowser When true, brings the ContentBrowser into the foreground.
  350. * @param InstanceName When supplied, will only sync the Content Browser with the matching InstanceName. bAllowLockedBrowsers is ignored.
  351. * @param bNewSpawnBrowser When supplied, will spawn a new Content Browser instead of selecting the assets in an existing one.
  352. */
  353. virtual void SyncBrowserToFolders(const TArray<FString>& FolderList, bool bAllowLockedBrowsers = false, bool bFocuSExtContentBrowser = true, const FName& InstanceName = FName(), bool bNewSpawnBrowser = false) = 0;
  354. /**
  355. * Selects the supplied assets in the primary content browser.
  356. *
  357. * @param ItemSelection A struct containing AssetData and Folders to sync
  358. * @param bAllowLockedBrowsers When true, even locked browsers may handle the sync. Only set to true if the sync doesn't seem external to the content browser
  359. * @param bFocuSExtContentBrowser When true, brings the ContentBrowser into the foreground.
  360. * @param InstanceName When supplied, will only sync the Content Browser with the matching InstanceName. bAllowLockedBrowsers is ignored.
  361. * @param bNewSpawnBrowser When supplied, will spawn a new Content Browser instead of selecting the assets in an existing one.
  362. */
  363. virtual void SyncBrowserTo(const FExtContentBrowserSelection& ItemSelection, bool bAllowLockedBrowsers = false, bool bFocuSExtContentBrowser = true, const FName& InstanceName = FName(), bool bNewSpawnBrowser = false) = 0;
  364. /** Generates a list of assets that are selected in the primary content browser */
  365. virtual void GetSelectedAssets(TArray<FAssetData>& SelectedAssets) = 0;
  366. /** Generates a list of folders that are selected in the primary content browser */
  367. virtual void GetSelectedFolders(TArray<FString>& SelectedFolders) = 0;
  368. /** Returns the folders that are selected in the path view */
  369. virtual void GetSelectedPathViewFolders(TArray<FString>& SelectedFolders) = 0;
  370. /**
  371. * Capture active viewport to thumbnail and assigns that thumbnail to incoming assets
  372. *
  373. * @param InViewport - viewport to sample from
  374. * @param InAssetsToAssign - assets that should receive the new thumbnail ONLY if they are assets that use GenericThumbnails
  375. */
  376. virtual void CaptureThumbnailFromViewport(FViewport* InViewport, TArray<FAssetData>& SelectedAssets) = 0;
  377. /**
  378. * Sets the content browser to display the selected paths
  379. */
  380. virtual void SetSelectedPaths(const TArray<FString>& FolderPaths, bool bNeedsRefresh = false) = 0;
  381. #endif
  382. };