ExtAssetViewWidgets.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "ContentBrowserDelegates.h"
  4. #include "CoreMinimal.h"
  5. #include "SlateFwd.h"
  6. #include "Misc/Attribute.h"
  7. #include "Layout/Geometry.h"
  8. #include "Input/Reply.h"
  9. #include "Layout/Visibility.h"
  10. #include "Widgets/DeclarativeSyntaxSupport.h"
  11. #include "Styling/SlateColor.h"
  12. #include "Widgets/SWidget.h"
  13. #include "Widgets/SCompoundWidget.h"
  14. #include "AssetRegistry/AssetData.h"
  15. #include "AssetThumbnail.h"
  16. #include "Fonts/SlateFontInfo.h"
  17. #include "Widgets/Views/STableViewBase.h"
  18. #include "Types/SlateStructs.h"
  19. #include "Widgets/SBoxPanel.h"
  20. #include "Widgets/Views/STableRow.h"
  21. #include "Widgets/Text/STextBlock.h"
  22. #include "EditorStyleSet.h"
  23. #include "Widgets/Views/SListView.h"
  24. #include "Widgets/Views/STileView.h"
  25. class SLayeredImage;
  26. struct FExtAssetViewItem;
  27. class FExtAssetThumbnail;
  28. template <typename ItemType> class SListView;
  29. DECLARE_DELEGATE_ThreeParams( FOnRenameBegin, const TSharedPtr<FExtAssetViewItem>& /*AssetItem*/, const FString& /*OriginalName*/, const FSlateRect& /*MessageAnchor*/)
  30. DECLARE_DELEGATE_FourParams( FOnRenameCommit, const TSharedPtr<FExtAssetViewItem>& /*AssetItem*/, const FString& /*NewName*/, const FSlateRect& /*MessageAnchor*/, ETextCommit::Type /*CommitType*/ )
  31. DECLARE_DELEGATE_RetVal_FourParams( bool, FOnVerifyRenameCommit, const TSharedPtr<FExtAssetViewItem>& /*AssetItem*/, const FText& /*NewName*/, const FSlateRect& /*MessageAnchor*/, FText& /*OutErrorMessage*/)
  32. DECLARE_DELEGATE_OneParam( FOnItemDestroyed, const TSharedPtr<FExtAssetViewItem>& /*AssetItem*/);
  33. class SExtAssetListItem;
  34. class SExtAssetTileItem;
  35. namespace FAssetViewModeUtils
  36. {
  37. FReply OnViewModeKeyDown( const TSet< TSharedPtr<FExtAssetViewItem> >& SelectedItems, const FKeyEvent& InKeyEvent );
  38. }
  39. struct FExtAssetViewItemHelper
  40. {
  41. public:
  42. static TSharedRef<SWidget> CreateListItemContents(SExtAssetListItem* const InListItem, const TSharedRef<SWidget>& InThumbnail, FName& OutItemShadowBorder);
  43. static TSharedRef<SWidget> CreateTileItemContents(SExtAssetTileItem* const InTileItem, const TSharedRef<SWidget>& InThumbnail, FName& OutItemShadowBorder);
  44. private:
  45. template <typename T>
  46. static TSharedRef<SWidget> CreateListTileItemContents(T* const InTileOrListItem, const TSharedRef<SWidget>& InThumbnail, FName& OutItemShadowBorder);
  47. };
  48. /** The tile view mode of the asset view */
  49. class SExtAssetTileView : public STileView<TSharedPtr<FExtAssetViewItem>>
  50. {
  51. public:
  52. virtual bool SupportsKeyboardFocus() const override { return true; }
  53. virtual FReply OnKeyDown( const FGeometry& InGeometry, const FKeyEvent& InKeyEvent ) override;
  54. virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override;
  55. /** Returns true if a widget is currently generated for a given asset */
  56. bool HasWidgetForAsset(const FName& AssetPathName);
  57. };
  58. /** The list view mode of the asset view */
  59. class SExtAssetListView : public SListView<TSharedPtr<FExtAssetViewItem>>
  60. {
  61. public:
  62. virtual bool SupportsKeyboardFocus() const override { return true; }
  63. virtual FReply OnKeyDown( const FGeometry& InGeometry, const FKeyEvent& InKeyEvent ) override;
  64. virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
  65. /** Returns true if a widget is currently generated for a given asset */
  66. bool HasWidgetForAsset(const FName& AssetPathName);
  67. };
  68. /** The columns view mode of the asset view */
  69. class SExtAssetColumnView : public SListView<TSharedPtr<FExtAssetViewItem>>
  70. {
  71. public:
  72. virtual bool SupportsKeyboardFocus() const override { return true; }
  73. virtual FReply OnKeyDown( const FGeometry& InGeometry, const FKeyEvent& InKeyEvent ) override;
  74. virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
  75. };
  76. /** A base class for all asset view items */
  77. class SExtAssetViewItem : public SCompoundWidget
  78. {
  79. friend class SExtAssetViewItemToolTip;
  80. public:
  81. DECLARE_DELEGATE_ThreeParams( FOnAssetsOrPathsDragDropped, const TArray<FAssetData>& /*AssetList*/, const TArray<FString>& /*AssetPaths*/, const FString& /*DestinationPath*/);
  82. DECLARE_DELEGATE_TwoParams( FOnFilesDragDropped, const TArray<FString>& /*FileNames*/, const FString& /*DestinationPath*/);
  83. SLATE_BEGIN_ARGS( SExtAssetViewItem )
  84. : _ShouldAllowToolTip(true)
  85. , _ThumbnailEditMode(false)
  86. {}
  87. /** Data for the asset this item represents */
  88. SLATE_ARGUMENT( TSharedPtr<FExtAssetViewItem>, AssetItem )
  89. /** Delegate for when an asset name has entered a rename state */
  90. SLATE_EVENT( FOnRenameBegin, OnRenameBegin )
  91. /** Delegate for when an asset name has been entered for an item that is in a rename state */
  92. SLATE_EVENT( FOnRenameCommit, OnRenameCommit )
  93. /** Delegate for when an asset name has been entered for an item to verify the name before commit */
  94. SLATE_EVENT( FOnVerifyRenameCommit, OnVerifyRenameCommit )
  95. /** Called when any asset item is destroyed. Used in thumbnail management */
  96. SLATE_EVENT( FOnItemDestroyed, OnItemDestroyed )
  97. /** If false, the tooltip will not be displayed */
  98. SLATE_ATTRIBUTE( bool, ShouldAllowToolTip )
  99. /** If true, display the thumbnail edit mode UI */
  100. SLATE_ATTRIBUTE( bool, ThumbnailEditMode )
  101. /** The string in the title to highlight (used when searching by string) */
  102. SLATE_ATTRIBUTE(FText, HighlightText)
  103. /** Delegate for when assets or asset paths are dropped on this item, if it is a folder */
  104. SLATE_EVENT( FOnAssetsOrPathsDragDropped, OnAssetsOrPathsDragDropped )
  105. /** Delegate for when a list of files is dropped on this folder (if it is a folder) from an external source */
  106. SLATE_EVENT( FOnFilesDragDropped, OnFilesDragDropped )
  107. /** Delegate to call (if bound) to check if it is valid to get a custom tooltip for this view item */
  108. SLATE_EVENT(FOnIsAssetValidForCustomToolTip, OnIsAssetValidForCustomToolTip)
  109. /** Delegate to call (if bound) to get a custom tooltip for this view item */
  110. SLATE_EVENT( FOnGetCustomAssetToolTip, OnGetCustomAssetToolTip )
  111. /** Delegate for when an item is about to show a tool tip */
  112. SLATE_EVENT( FOnVisualizeAssetToolTip, OnVisualizeAssetToolTip)
  113. /** Delegate for when an item's tooltip is about to close */
  114. SLATE_EVENT( FOnAssetToolTipClosing, OnAssetToolTipClosing )
  115. SLATE_END_ARGS()
  116. /** Virtual destructor */
  117. virtual ~SExtAssetViewItem();
  118. /** Performs common initialization logic for all asset view items */
  119. void Construct( const FArguments& InArgs );
  120. /** NOTE: Any functions overridden from the base widget classes *must* also be overridden by SExtAssetColumnViewRow and forwarded on to its internal item */
  121. virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override;
  122. virtual TSharedPtr<IToolTip> GetToolTip() override;
  123. virtual void OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  124. virtual void OnDragLeave( const FDragDropEvent& DragDropEvent ) override;
  125. virtual FReply OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  126. virtual FReply OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  127. virtual bool OnVisualizeTooltip( const TSharedPtr<SWidget>& TooltipContent ) override;
  128. virtual void OnToolTipClosing() override;
  129. /** Returns the color this item should be tinted with */
  130. virtual FSlateColor GetAssetColor() const;
  131. /** Get the border image to display */
  132. const FSlateBrush* GetBorderImage() const;
  133. /** Get the name text to be displayed for this item */
  134. FText GetNameText() const;
  135. protected:
  136. /** Used by OnDragEnter, OnDragOver, and OnDrop to check and update the validity of the drag operation */
  137. bool ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const;
  138. /** Check to see if the name should be read-only */
  139. bool IsNameReadOnly() const;
  140. /** Handles starting a name change */
  141. virtual void HandleBeginNameChange( const FText& OriginalText );
  142. /** Handles committing a name change */
  143. virtual void HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo );
  144. /** Handles verifying a name change */
  145. virtual bool HandleVerifyNameChanged( const FText& NewText, FText& OutErrorMessage );
  146. /** Handles committing a name change */
  147. virtual void OnAssetDataChanged();
  148. /** Notification for when the dirty flag changes */
  149. virtual void DirtyStateChanged();
  150. /** Gets the name of the class of this asset */
  151. FText GetAssetClassText() const;
  152. /** Gets the brush for the source control indicator image */
  153. const FSlateBrush* GetSCCStateImage() const;
  154. /** Gets the brush for the dirty indicator image */
  155. const FSlateBrush* GetDirtyImage() const;
  156. /** Generates the source control icon widget */
  157. TSharedRef<SWidget> GenerateSourceControlIconWidget();
  158. /** Generate a widget to inject extra external state indicator on the asset. */
  159. TSharedRef<SWidget> GenerateExtraStateIconWidget(TAttribute<float> InMaxExtraStateIconWidth) const;
  160. /** Generate a widget to inject extra external state indicator on the asset tooltip. */
  161. TSharedRef<SWidget> GenerateExtraStateTooltipWidget() const;
  162. /** Gets the visibility for the thumbnail edit mode UI */
  163. EVisibility GetThumbnailEditModeUIVisibility() const;
  164. /** Creates a tooltip widget for this item */
  165. TSharedRef<SWidget> CreateToolTipWidget() const;
  166. /** Helper function for CreateToolTipWidget. Gets the user description for the asset, if it exists. */
  167. FText GetAssetUserDescription() const;
  168. /** Helper function for CreateToolTipWidget. Adds a key value pair to the info box of the tooltip */
  169. void AddToToolTipInfoBox(const TSharedRef<SVerticalBox>& InfoBox, const FText& Key, const FText& Value, bool bImportant) const;
  170. /** Updates the bPackageDirty flag */
  171. void UpdatePackageDirtyState();
  172. /** Returns true if the package that contains the asset that this item represents is dirty. */
  173. bool IsDirty() const;
  174. /** Update the source control state of this item if required */
  175. void UpdateSourceControlState(float InDeltaTime);
  176. /** Cache the package name from the asset we are representing */
  177. void CachePackageName();
  178. /** Cache the display tags for this item */
  179. void CacheDisplayTags();
  180. /** Whether this item is a folder */
  181. bool IsFolder() const;
  182. /** Set mips to be resident while this (loaded) asset is visible */
  183. void SetForceMipLevelsToBeResident(bool bForce) const;
  184. /** Delegate handler for when the source control provider changes */
  185. void HandleSourceControlProviderChanged(class ISourceControlProvider& OldProvider, class ISourceControlProvider& NewProvider);
  186. /** Delegate handler for when source control state changes */
  187. void HandleSourceControlStateChanged();
  188. /** Returns the width at which the name label will wrap the name */
  189. virtual float GetNameTextWrapWidth() const { return 0.0f; }
  190. protected:
  191. /** Data for a cached display tag for this item (used in the tooltip, and also as the display string in column views) */
  192. struct FTagDisplayItem
  193. {
  194. FTagDisplayItem(FName InTagKey, FText InDisplayKey, FText InDisplayValue, const bool InImportant)
  195. : TagKey(InTagKey)
  196. , DisplayKey(MoveTemp(InDisplayKey))
  197. , DisplayValue(MoveTemp(InDisplayValue))
  198. , bImportant(InImportant)
  199. {
  200. }
  201. FName TagKey;
  202. FText DisplayKey;
  203. FText DisplayValue;
  204. bool bImportant;
  205. };
  206. TSharedPtr< SInlineEditableTextBlock > InlineRenameWidget;
  207. /** The data for this item */
  208. TSharedPtr<FExtAssetViewItem> AssetItem;
  209. /** The package containing the asset that this item represents */
  210. TWeakObjectPtr<UPackage> AssetPackage;
  211. /** The asset type actions associated with the asset that this item represents */
  212. TWeakPtr<IAssetTypeActions> AssetTypeActions;
  213. /** The cached name of the package containing the asset that this item represents */
  214. FString CachedPackageName;
  215. /** The cached filename of the package containing the asset that this item represents */
  216. FString CachedPackageFileName;
  217. /** The cached display tags for this item */
  218. TArray<FTagDisplayItem> CachedDisplayTags;
  219. /** Delegate for when an asset name has entered a rename state */
  220. FOnRenameBegin OnRenameBegin;
  221. /** Delegate for when an asset name has been entered for an item that is in a rename state */
  222. FOnRenameCommit OnRenameCommit;
  223. /** Delegate for when an asset name has been entered for an item to verify the name before commit */
  224. FOnVerifyRenameCommit OnVerifyRenameCommit;
  225. /** Called when any asset item is destroyed. Used in thumbnail management */
  226. FOnItemDestroyed OnItemDestroyed;
  227. /** Called to test if it is valid to make a custom tool tip for that asset */
  228. FOnIsAssetValidForCustomToolTip OnIsAssetValidForCustomToolTip;
  229. /** Called if bound to get a custom asset item tooltip */
  230. FOnGetCustomAssetToolTip OnGetCustomAssetToolTip;
  231. /** Called if bound when about to show a tooltip */
  232. FOnVisualizeAssetToolTip OnVisualizeAssetToolTip;
  233. /** Called if bound when a tooltip is closing */
  234. FOnAssetToolTipClosing OnAssetToolTipClosing;
  235. /** The geometry last frame. Used when telling popup messages where to appear. */
  236. FGeometry LastGeometry;
  237. /** If false, the tooltip will not be displayed */
  238. TAttribute<bool> ShouldAllowToolTip;
  239. /** If true, display the thumbnail edit mode UI */
  240. TAttribute<bool> ThumbnailEditMode;
  241. /** The substring to be highlighted in the name and tooltip path */
  242. TAttribute<FText> HighlightText;
  243. /** Cached brushes for the dirty state */
  244. const FSlateBrush* AssetDirtyBrush;
  245. /** Cached flag describing if the package is dirty */
  246. bool bPackageDirty;
  247. /** Flag indicating whether we have requested initial source control state */
  248. bool bSourceControlStateRequested;
  249. /** Delay timer before we request a source control state update, to prevent spam */
  250. float SourceControlStateDelay;
  251. /** Delegate for when a list of assets or asset paths are dropped on this item, if it is a folder */
  252. FOnAssetsOrPathsDragDropped OnAssetsOrPathsDragDropped;
  253. /** Delegate for when a list of files is dropped on this item (if it is a folder) from an external source */
  254. FOnFilesDragDropped OnFilesDragDropped;
  255. /** True when a drag is over this item with a drag operation that we know how to handle. The operation itself may not be valid to drop. */
  256. bool bDraggedOver;
  257. /** Widget for the source control state */
  258. TSharedPtr<SLayeredImage> SCCStateWidget;
  259. /** Delegate handle for the HandleSourceControlStateChanged function callback */
  260. FDelegateHandle SourceControlStateChangedDelegateHandle;
  261. };
  262. /** An item in the asset list view */
  263. class SExtAssetListItem : public SExtAssetViewItem
  264. {
  265. friend struct FExtAssetViewItemHelper;
  266. public:
  267. SLATE_BEGIN_ARGS( SExtAssetListItem )
  268. : _ThumbnailPadding(0)
  269. , _ThumbnailLabel( EThumbnailLabel::ClassName )
  270. , _ThumbnailHintColorAndOpacity( FLinearColor( 0.0f, 0.0f, 0.0f, 0.0f ) )
  271. , _ItemHeight(16)
  272. , _ShouldAllowToolTip(true)
  273. , _ThumbnailEditMode(false)
  274. , _AllowThumbnailHintLabel(false)
  275. {}
  276. /** The handle to the thumbnail this item should render */
  277. SLATE_ARGUMENT( TSharedPtr<FExtAssetThumbnail>, AssetThumbnail)
  278. /** Data for the asset this item represents */
  279. SLATE_ARGUMENT( TSharedPtr<FExtAssetViewItem>, AssetItem )
  280. /** How much padding to allow around the thumbnail */
  281. SLATE_ARGUMENT( float, ThumbnailPadding )
  282. /** The contents of the label displayed on the thumbnail */
  283. SLATE_ARGUMENT( EThumbnailLabel::Type, ThumbnailLabel )
  284. /** */
  285. SLATE_ATTRIBUTE( FLinearColor, ThumbnailHintColorAndOpacity )
  286. /** The height of the list item */
  287. SLATE_ATTRIBUTE( float, ItemHeight )
  288. /** Delegate for when an asset name has entered a rename state */
  289. SLATE_EVENT( FOnRenameBegin, OnRenameBegin )
  290. /** Delegate for when an asset name has been entered for an item that is in a rename state */
  291. SLATE_EVENT( FOnRenameCommit, OnRenameCommit )
  292. /** Delegate for when an asset name has been entered for an item to verify the name before commit */
  293. SLATE_EVENT( FOnVerifyRenameCommit, OnVerifyRenameCommit )
  294. /** Called when any asset item is destroyed. Used in thumbnail management */
  295. SLATE_EVENT( FOnItemDestroyed, OnItemDestroyed )
  296. /** If false, the tooltip will not be displayed */
  297. SLATE_ATTRIBUTE( bool, ShouldAllowToolTip )
  298. /** The string in the title to highlight (used when searching by string) */
  299. SLATE_ATTRIBUTE( FText, HighlightText )
  300. /** If true, the thumbnail in this item can be edited */
  301. SLATE_ATTRIBUTE( bool, ThumbnailEditMode )
  302. /** Whether the thumbnail should ever show it's hint label */
  303. SLATE_ARGUMENT( bool, AllowThumbnailHintLabel )
  304. /** Whether the item is selected in the view */
  305. SLATE_ARGUMENT( FIsSelected, IsSelected )
  306. /** Delegate for when assets or asset paths are dropped on this item, if it is a folder */
  307. SLATE_EVENT( FOnAssetsOrPathsDragDropped, OnAssetsOrPathsDragDropped )
  308. /** Delegate for when a list of files is dropped on this folder (if it is a folder) from an external source */
  309. SLATE_EVENT( FOnFilesDragDropped, OnFilesDragDropped )
  310. /** Delegate to call (if bound) to check if it is valid to get a custom tooltip for this view item */
  311. SLATE_EVENT(FOnIsAssetValidForCustomToolTip, OnIsAssetValidForCustomToolTip)
  312. /** Delegate to request a custom tool tip if necessary */
  313. SLATE_EVENT(FOnGetCustomAssetToolTip, OnGetCustomAssetToolTip)
  314. /* Delegate to signal when the item is about to show a tooltip */
  315. SLATE_EVENT(FOnVisualizeAssetToolTip, OnVisualizeAssetToolTip)
  316. /** Delegate for when an item's tooltip is about to close */
  317. SLATE_EVENT( FOnAssetToolTipClosing, OnAssetToolTipClosing )
  318. SLATE_END_ARGS()
  319. /** Destructor */
  320. ~SExtAssetListItem();
  321. /** Constructs this widget with InArgs */
  322. void Construct( const FArguments& InArgs );
  323. /** Handles committing a name change */
  324. virtual void OnAssetDataChanged() override;
  325. /** Whether the widget should allow primitive tools to be displayed */
  326. bool CanDisplayPrimitiveTools() const { return false; }
  327. private:
  328. /** Get the expected width of an extra state icon. */
  329. float GetExtraStateIconWidth() const;
  330. /** Returns the max width size to be used by extra state icons. */
  331. FOptionalSize GetExtraStateIconMaxWidth() const;
  332. /** Returns the size of the state icon box widget (i.e dirty image, scc)*/
  333. FOptionalSize GetStateIconImageSize() const;
  334. /** Returns the size of the thumbnail widget */
  335. FOptionalSize GetThumbnailBoxSize() const;
  336. private:
  337. /** The handle to the thumbnail that this item is rendering */
  338. TSharedPtr<FExtAssetThumbnail> AssetThumbnail;
  339. /** The height allowed for this item */
  340. TAttribute<float> ItemHeight;
  341. /** The text block containing the class name */
  342. TSharedPtr<STextBlock> ClassText;
  343. };
  344. /** An item in the asset tile view */
  345. class SExtAssetTileItem : public SExtAssetViewItem
  346. {
  347. friend struct FExtAssetViewItemHelper;
  348. public:
  349. SLATE_BEGIN_ARGS( SExtAssetTileItem )
  350. : _ThumbnailPadding(0)
  351. , _ThumbnailLabel( EThumbnailLabel::ClassName )
  352. , _ThumbnailHintColorAndOpacity( FLinearColor( 0.0f, 0.0f, 0.0f, 0.0f ) )
  353. , _AllowThumbnailHintLabel(true)
  354. , _ItemWidth(16)
  355. , _ShouldAllowToolTip(true)
  356. , _ThumbnailEditMode(false)
  357. {}
  358. /** The handle to the thumbnail this item should render */
  359. SLATE_ARGUMENT( TSharedPtr<FExtAssetThumbnail>, AssetThumbnail)
  360. /** Data for the asset this item represents */
  361. SLATE_ARGUMENT( TSharedPtr<FExtAssetViewItem>, AssetItem )
  362. /** How much padding to allow around the thumbnail */
  363. SLATE_ARGUMENT( float, ThumbnailPadding )
  364. /** The contents of the label displayed on the thumbnail */
  365. SLATE_ARGUMENT( EThumbnailLabel::Type, ThumbnailLabel )
  366. /** */
  367. SLATE_ATTRIBUTE( FLinearColor, ThumbnailHintColorAndOpacity )
  368. /** Whether the thumbnail should ever show it's hint label */
  369. SLATE_ARGUMENT( bool, AllowThumbnailHintLabel )
  370. /** The width of the item */
  371. SLATE_ATTRIBUTE( float, ItemWidth )
  372. /** Delegate for when an asset name has entered a rename state */
  373. SLATE_EVENT( FOnRenameBegin, OnRenameBegin )
  374. /** Delegate for when an asset name has been entered for an item that is in a rename state */
  375. SLATE_EVENT( FOnRenameCommit, OnRenameCommit )
  376. /** Delegate for when an asset name has been entered for an item to verify the name before commit */
  377. SLATE_EVENT( FOnVerifyRenameCommit, OnVerifyRenameCommit )
  378. /** Called when any asset item is destroyed. Used in thumbnail management */
  379. SLATE_EVENT( FOnItemDestroyed, OnItemDestroyed )
  380. /** If false, the tooltip will not be displayed */
  381. SLATE_ATTRIBUTE( bool, ShouldAllowToolTip )
  382. /** The string in the title to highlight (used when searching by string) */
  383. SLATE_ATTRIBUTE( FText, HighlightText )
  384. /** If true, the thumbnail in this item can be edited */
  385. SLATE_ATTRIBUTE( bool, ThumbnailEditMode )
  386. /** Whether the item is selected in the view */
  387. SLATE_ARGUMENT( FIsSelected, IsSelected )
  388. /** Delegate for when assets or asset paths are dropped on this item, if it is a folder */
  389. SLATE_EVENT( FOnAssetsOrPathsDragDropped, OnAssetsOrPathsDragDropped )
  390. /** Delegate for when a list of files is dropped on this folder (if it is a folder) from an external source */
  391. SLATE_EVENT( FOnFilesDragDropped, OnFilesDragDropped )
  392. /** Delegate to call (if bound) to check if it is valid to get a custom tooltip for this view item */
  393. SLATE_EVENT(FOnIsAssetValidForCustomToolTip, OnIsAssetValidForCustomToolTip)
  394. /** Delegate to request a custom tool tip if necessary */
  395. SLATE_EVENT(FOnGetCustomAssetToolTip, OnGetCustomAssetToolTip)
  396. /* Delegate to signal when the item is about to show a tooltip */
  397. SLATE_EVENT(FOnVisualizeAssetToolTip, OnVisualizeAssetToolTip)
  398. /** Delegate for when an item's tooltip is about to close */
  399. SLATE_EVENT( FOnAssetToolTipClosing, OnAssetToolTipClosing )
  400. SLATE_END_ARGS()
  401. /** Destructor */
  402. ~SExtAssetTileItem();
  403. /** Constructs this widget with InArgs */
  404. void Construct( const FArguments& InArgs );
  405. /** Handles committing a name change */
  406. virtual void OnAssetDataChanged() override;
  407. /** Whether the widget should allow primitive tools to be displayed */
  408. bool CanDisplayPrimitiveTools() const { return true; }
  409. protected:
  410. /** SExtAssetViewItem interface */
  411. virtual float GetNameTextWrapWidth() const override { return LastGeometry.GetLocalSize().X - 2.f; }
  412. /** Get the expected width of an extra state icon. */
  413. float GetExtraStateIconWidth() const;
  414. /** Returns the max width size to be used by extra state icons. */
  415. FOptionalSize GetExtraStateIconMaxWidth() const;
  416. /** Returns the size of the state icon box widget (i.e dirty image, scc)*/
  417. FOptionalSize GetStateIconImageSize() const;
  418. /** Returns the size of the thumbnail widget */
  419. FOptionalSize GetThumbnailBoxSize() const;
  420. /** Returns the font to use for the thumbnail label */
  421. FSlateFontInfo GetThumbnailFont() const;
  422. private:
  423. /** The handle to the thumbnail that this item is rendering */
  424. TSharedPtr<FExtAssetThumbnail> AssetThumbnail;
  425. /** The width of the item. Used to enforce a square thumbnail. */
  426. TAttribute<float> ItemWidth;
  427. /** The padding allotted for the thumbnail */
  428. float ThumbnailPadding;
  429. };
  430. /** An item in the asset column view */
  431. class SExtAssetColumnItem : public SExtAssetViewItem
  432. {
  433. public:
  434. SLATE_BEGIN_ARGS( SExtAssetColumnItem ) {}
  435. /** Data for the asset this item represents */
  436. SLATE_ARGUMENT( TSharedPtr<FExtAssetViewItem>, AssetItem )
  437. /** Delegate for when an asset name has entered a rename state */
  438. SLATE_EVENT( FOnRenameBegin, OnRenameBegin )
  439. /** Delegate for when an asset name has been entered for an item that is in a rename state */
  440. SLATE_EVENT( FOnRenameCommit, OnRenameCommit )
  441. /** Delegate for when an asset name has been entered for an item to verify the name before commit */
  442. SLATE_EVENT( FOnVerifyRenameCommit, OnVerifyRenameCommit )
  443. /** Called when any asset item is destroyed. Used in thumbnail management, though it may be used for more so It is in column items for consistency. */
  444. SLATE_EVENT( FOnItemDestroyed, OnItemDestroyed )
  445. /** The string in the title to highlight (used when searching by string) */
  446. SLATE_ATTRIBUTE( FText, HighlightText )
  447. /** Delegate for when assets or asset paths are dropped on this item, if it is a folder */
  448. SLATE_EVENT( FOnAssetsOrPathsDragDropped, OnAssetsOrPathsDragDropped )
  449. /** Delegate for when a list of files is dropped on this folder (if it is a folder) from an external source */
  450. SLATE_EVENT( FOnFilesDragDropped, OnFilesDragDropped )
  451. /** Delegate to call (if bound) to check if it is valid to get a custom tooltip for this view item */
  452. SLATE_EVENT(FOnIsAssetValidForCustomToolTip, OnIsAssetValidForCustomToolTip)
  453. /** Delegate to request a custom tool tip if necessary */
  454. SLATE_EVENT( FOnGetCustomAssetToolTip, OnGetCustomAssetToolTip)
  455. /* Delegate to signal when the item is about to show a tooltip */
  456. SLATE_EVENT( FOnVisualizeAssetToolTip, OnVisualizeAssetToolTip)
  457. /** Delegate for when an item's tooltip is about to close */
  458. SLATE_EVENT( FOnAssetToolTipClosing, OnAssetToolTipClosing )
  459. SLATE_END_ARGS()
  460. /** Constructs this widget with InArgs */
  461. void Construct( const FArguments& InArgs );
  462. /** Generates a widget for a particular column */
  463. virtual TSharedRef<SWidget> GenerateWidgetForColumn( const FName& ColumnName, FIsSelected InIsSelected );
  464. /** Handles committing a name change */
  465. virtual void OnAssetDataChanged() override;
  466. private:
  467. /** Gets the tool tip text for the name */
  468. FString GetAssetNameToolTipText() const;
  469. /** Gets the path to this asset */
  470. FText GetAssetPathText() const;
  471. /** Gets the value for the specified tag in this asset */
  472. FText GetAssetTagText(FName Tag) const;
  473. private:
  474. TAttribute<FText> HighlightText;
  475. TSharedPtr<STextBlock> ClassText;
  476. TSharedPtr<STextBlock> PathText;
  477. };
  478. class SExtAssetColumnViewRow : public SMultiColumnTableRow< TSharedPtr<FExtAssetViewItem> >
  479. {
  480. public:
  481. SLATE_BEGIN_ARGS( SExtAssetColumnViewRow )
  482. {}
  483. SLATE_EVENT( FOnDragDetected, OnDragDetected )
  484. SLATE_ARGUMENT( TSharedPtr<SExtAssetColumnItem>, AssetColumnItem )
  485. SLATE_END_ARGS()
  486. /** Constructs this widget with InArgs */
  487. void Construct( const FArguments& InArgs, const TSharedRef<STableViewBase>& InOwnerTableView )
  488. {
  489. this->AssetColumnItem = InArgs._AssetColumnItem;
  490. ensure(this->AssetColumnItem.IsValid());
  491. SMultiColumnTableRow< TSharedPtr<FExtAssetViewItem> >::Construct(
  492. FSuperRowType::FArguments()
  493. .Style(FAppStyle::Get(), "ContentBrowser.AssetListView.TableRow")
  494. .OnDragDetected(InArgs._OnDragDetected),
  495. InOwnerTableView);
  496. Content = this->AssetColumnItem;
  497. }
  498. virtual TSharedRef<SWidget> GenerateWidgetForColumn( const FName& ColumnName ) override
  499. {
  500. if ( this->AssetColumnItem.IsValid() )
  501. {
  502. return this->AssetColumnItem->GenerateWidgetForColumn(ColumnName, FIsSelected::CreateSP( this, &SExtAssetColumnViewRow::IsSelectedExclusively ));
  503. }
  504. else
  505. {
  506. return SNew(STextBlock) .Text( NSLOCTEXT("AssetView", "InvalidColumnId", "Invalid Column Item") );
  507. }
  508. }
  509. virtual FVector2D GetRowSizeForColumn(const FName& InColumnName) const override
  510. {
  511. const TSharedRef<SWidget>* ColumnWidget = GetWidgetFromColumnId(InColumnName);
  512. if (ColumnWidget != nullptr)
  513. {
  514. return (*ColumnWidget)->GetDesiredSize();
  515. }
  516. return FVector2D::ZeroVector;
  517. }
  518. virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override
  519. {
  520. this->AssetColumnItem->Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
  521. }
  522. virtual TSharedPtr<IToolTip> GetToolTip() override
  523. {
  524. return AssetColumnItem->GetToolTip();
  525. }
  526. virtual void OnDragEnter(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override
  527. {
  528. AssetColumnItem->OnDragEnter(MyGeometry, DragDropEvent);
  529. }
  530. virtual void OnDragLeave(const FDragDropEvent& DragDropEvent) override
  531. {
  532. AssetColumnItem->OnDragLeave(DragDropEvent);
  533. }
  534. virtual FReply OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override
  535. {
  536. return AssetColumnItem->OnDragOver(MyGeometry, DragDropEvent);
  537. }
  538. virtual FReply OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override
  539. {
  540. return AssetColumnItem->OnDrop(MyGeometry, DragDropEvent);
  541. }
  542. virtual bool OnVisualizeTooltip(const TSharedPtr<SWidget>& TooltipContent) override
  543. {
  544. // We take the content from the asset column item during construction,
  545. // so let the item handle the tooltip callback
  546. return AssetColumnItem->OnVisualizeTooltip(TooltipContent);
  547. }
  548. virtual void OnToolTipClosing() override
  549. {
  550. AssetColumnItem->OnToolTipClosing();
  551. }
  552. TSharedPtr<SExtAssetColumnItem> AssetColumnItem;
  553. };