ExtAssetViewWidgets.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #include "ExtAssetViewWidgets.h"
  3. #include "ExtAssetThumbnail.h"
  4. #include "ExtContentBrowser.h"
  5. #include "ExtContentBrowserSettings.h"
  6. #include "ExtContentBrowserSingleton.h"
  7. #include "ExtAssetViewTypes.h"
  8. #include "DragDropHandler.h"
  9. #include "ExtContentBrowserUtils.h"
  10. // Engine - Editor
  11. #include "UObject/UnrealType.h"
  12. #include "ObjectTools.h"
  13. #include "Engine/GameViewportClient.h"
  14. #include "Engine/Texture2D.h"
  15. #include "Materials/Material.h"
  16. #include "EditorFramework/AssetImportData.h"
  17. #include "Internationalization/BreakIterator.h"
  18. #include "Misc/EngineBuildSettings.h"
  19. // Asset
  20. #include "AssetRegistry/ARFilter.h"
  21. #include "AssetRegistry/AssetRegistryModule.h"
  22. #include "IAssetTools.h"
  23. #include "AssetToolsModule.h"
  24. #include "AutoReimport/AssetSourceFilenameCache.h"
  25. #include "DragAndDrop/AssetDragDropOp.h"
  26. // Slate
  27. #include "SlateOptMacros.h"
  28. #include "Framework/Application/SlateApplication.h"
  29. #include "Widgets/SOverlay.h"
  30. #include "Widgets/Images/SImage.h"
  31. #include "Widgets/Text/SInlineEditableTextBlock.h"
  32. #include "Widgets/Images/SLayeredImage.h"
  33. #include "ISourceControlProvider.h"
  34. #include "ISourceControlModule.h"
  35. #include "SourceControlHelpers.h"
  36. // Collection
  37. #include "CollectionManagerTypes.h"
  38. #include "ICollectionManager.h"
  39. #include "CollectionManagerModule.h"
  40. //
  41. #include "ActorFolder.h"
  42. #define LOCTEXT_NAMESPACE "ExtContentBrowser"
  43. ///////////////////////////////
  44. // FAssetViewModeUtils
  45. ///////////////////////////////
  46. FReply FAssetViewModeUtils::OnViewModeKeyDown( const TSet< TSharedPtr<FExtAssetViewItem> >& SelectedItems, const FKeyEvent& InKeyEvent )
  47. {
  48. // All asset views use Ctrl-C to copy references to assets
  49. if ( InKeyEvent.IsControlDown() && InKeyEvent.GetCharacter() == 'C'
  50. && !InKeyEvent.IsShiftDown() && !InKeyEvent.IsAltDown()
  51. )
  52. {
  53. FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
  54. TArray<FExtAssetData> SelectedAssets;
  55. for ( auto ItemIt = SelectedItems.CreateConstIterator(); ItemIt; ++ItemIt)
  56. {
  57. const TSharedPtr<FExtAssetViewItem>& Item = *ItemIt;
  58. if(Item.IsValid())
  59. {
  60. if(Item->GetType() == EExtAssetItemType::Folder)
  61. {
  62. // we need to recurse & copy references to all folder contents
  63. FARFilter Filter;
  64. Filter.PackagePaths.Add(*StaticCastSharedPtr<FExtAssetViewFolder>(Item)->FolderPath);
  65. // Add assets found in the asset registry
  66. //AssetRegistryModule.Get().GetAssets(Filter, SelectedAssets);
  67. }
  68. else
  69. {
  70. SelectedAssets.Add(StaticCastSharedPtr<FExtAssetViewAsset>(Item)->Data);
  71. }
  72. }
  73. }
  74. //ContentBrowserUtils::CopyAssetReferencesToClipboard(SelectedAssets);
  75. return FReply::Handled();
  76. }
  77. return FReply::Unhandled();
  78. }
  79. ///////////////////////////////
  80. // FAssetViewModeUtils
  81. ///////////////////////////////
  82. TSharedRef<SWidget> FExtAssetViewItemHelper::CreateListItemContents(SExtAssetListItem* const InListItem, const TSharedRef<SWidget>& InThumbnail, FName& OutItemShadowBorder)
  83. {
  84. return CreateListTileItemContents(InListItem, InThumbnail, OutItemShadowBorder);
  85. }
  86. TSharedRef<SWidget> FExtAssetViewItemHelper::CreateTileItemContents(SExtAssetTileItem* const InTileItem, const TSharedRef<SWidget>& InThumbnail, FName& OutItemShadowBorder)
  87. {
  88. return CreateListTileItemContents(InTileItem, InThumbnail, OutItemShadowBorder);
  89. }
  90. template <typename T>
  91. TSharedRef<SWidget> FExtAssetViewItemHelper::CreateListTileItemContents(T* const InTileOrListItem, const TSharedRef<SWidget>& InThumbnail, FName& OutItemShadowBorder)
  92. {
  93. TSharedRef<SOverlay> ItemContentsOverlay = SNew(SOverlay);
  94. OutItemShadowBorder = FName("ContentBrowser.AssetTileItem.DropShadow");
  95. if (InTileOrListItem->IsFolder())
  96. {
  97. // TODO: Allow items to customize their widget
  98. TSharedPtr<FExtAssetViewFolder> AssetFolderItem = StaticCastSharedPtr<FExtAssetViewFolder>(InTileOrListItem->AssetItem);
  99. const FSlateBrush* FolderBaseImage = FAppStyle::GetBrush("ContentBrowser.ListViewFolderIcon");
  100. // Folder base
  101. ItemContentsOverlay->AddSlot()
  102. .Padding(FMargin(5))
  103. [
  104. SNew(SBorder)
  105. .BorderImage(FAppStyle::Get().GetBrush("ContentBrowser.FolderItem.DropShadow"))
  106. .Padding(FMargin(0,0,2.0f,2.0f))
  107. [
  108. SNew(SImage)
  109. .Image(FolderBaseImage)
  110. .ColorAndOpacity(InTileOrListItem, &T::GetAssetColor)
  111. ]
  112. ];
  113. }
  114. else
  115. {
  116. // The actual thumbnail
  117. ItemContentsOverlay->AddSlot()
  118. [
  119. InThumbnail
  120. ];
  121. // Source control state
  122. ItemContentsOverlay->AddSlot()
  123. .HAlign(HAlign_Right)
  124. .VAlign(VAlign_Top)
  125. .Padding(FMargin(0.0f, 3.0f, 3.0f, 0.0f))
  126. [
  127. SNew(SBox)
  128. .WidthOverride(InTileOrListItem, &T::GetStateIconImageSize)
  129. .HeightOverride(InTileOrListItem, &T::GetStateIconImageSize)
  130. [
  131. InTileOrListItem->GenerateSourceControlIconWidget()
  132. ]
  133. ];
  134. // Extra external state hook
  135. ItemContentsOverlay->AddSlot()
  136. .HAlign(HAlign_Left)
  137. .VAlign(VAlign_Top)
  138. [
  139. SNew(SBox)
  140. .MaxDesiredWidth(InTileOrListItem, &T::GetExtraStateIconMaxWidth)
  141. .MaxDesiredHeight(InTileOrListItem, &T::GetStateIconImageSize)
  142. [
  143. InTileOrListItem->GenerateExtraStateIconWidget(TAttribute<float>(InTileOrListItem, &T::GetExtraStateIconWidth))
  144. ]
  145. ];
  146. // Dirty state
  147. ItemContentsOverlay->AddSlot()
  148. .HAlign(HAlign_Left)
  149. .VAlign(VAlign_Bottom)
  150. [
  151. SNew(SBox)
  152. .MaxDesiredWidth(InTileOrListItem, &T::GetStateIconImageSize)
  153. .MaxDesiredHeight(InTileOrListItem, &T::GetStateIconImageSize)
  154. [
  155. SNew(SImage)
  156. .Image(InTileOrListItem, &T::GetDirtyImage)
  157. ]
  158. ];
  159. }
  160. return ItemContentsOverlay;
  161. }
  162. ///////////////////////////////
  163. // Asset view item tool tip
  164. ///////////////////////////////
  165. class SExtAssetViewItemToolTip : public SToolTip
  166. {
  167. public:
  168. SLATE_BEGIN_ARGS(SExtAssetViewItemToolTip)
  169. : _AssetViewItem()
  170. { }
  171. SLATE_ARGUMENT(TSharedPtr<SExtAssetViewItem>, AssetViewItem)
  172. SLATE_END_ARGS()
  173. void Construct(const FArguments& InArgs)
  174. {
  175. AssetViewItem = InArgs._AssetViewItem;
  176. SToolTip::Construct(
  177. SToolTip::FArguments()
  178. .TextMargin(1.0f)
  179. .BorderImage(FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.ToolTipBorder"))
  180. );
  181. }
  182. // IToolTip interface
  183. virtual bool IsEmpty() const override
  184. {
  185. return !AssetViewItem.IsValid();
  186. }
  187. virtual void OnOpening() override
  188. {
  189. TSharedPtr<SExtAssetViewItem> AssetViewItemPin = AssetViewItem.Pin();
  190. if (AssetViewItemPin.IsValid())
  191. {
  192. SetContentWidget(AssetViewItemPin->CreateToolTipWidget());
  193. }
  194. }
  195. virtual void OnClosed() override
  196. {
  197. SetContentWidget(SNullWidget::NullWidget);
  198. }
  199. private:
  200. TWeakPtr<SExtAssetViewItem> AssetViewItem;
  201. };
  202. ///////////////////////////////
  203. // Asset view modes
  204. ///////////////////////////////
  205. FReply SExtAssetTileView::OnKeyDown( const FGeometry& InGeometry, const FKeyEvent& InKeyEvent )
  206. {
  207. FReply Reply = FAssetViewModeUtils::OnViewModeKeyDown(SelectedItems, InKeyEvent);
  208. if ( Reply.IsEventHandled() )
  209. {
  210. return Reply;
  211. }
  212. else
  213. {
  214. return STileView<TSharedPtr<FExtAssetViewItem>>::OnKeyDown(InGeometry, InKeyEvent);
  215. }
  216. }
  217. void SExtAssetTileView::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
  218. {
  219. // Regreshing an asset view is an intensive task. Do not do this while a user
  220. // is dragging arround content for maximum responsiveness.
  221. // Also prevents a re-entrancy crash caused by potentially complex thumbnail generators.
  222. if (!FSlateApplication::Get().IsDragDropping())
  223. {
  224. STileView<TSharedPtr<FExtAssetViewItem>>::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
  225. }
  226. }
  227. bool SExtAssetTileView::HasWidgetForAsset(const FName& AssetPathName)
  228. {
  229. for (const TSharedPtr<FExtAssetViewItem>& Item : WidgetGenerator.ItemsWithGeneratedWidgets)
  230. {
  231. if (Item.IsValid() && Item->GetType() == EExtAssetItemType::Normal)
  232. {
  233. const FName& ObjectPath = StaticCastSharedPtr<FExtAssetViewAsset>(Item)->Data.ObjectPath;
  234. if (ObjectPath == AssetPathName)
  235. {
  236. return true;
  237. }
  238. }
  239. }
  240. return false;
  241. }
  242. FReply SExtAssetListView::OnKeyDown(const FGeometry& InGeometry, const FKeyEvent& InKeyEvent)
  243. {
  244. FReply Reply = FAssetViewModeUtils::OnViewModeKeyDown(SelectedItems, InKeyEvent);
  245. if ( Reply.IsEventHandled() )
  246. {
  247. return Reply;
  248. }
  249. else
  250. {
  251. return SListView<TSharedPtr<FExtAssetViewItem>>::OnKeyDown(InGeometry, InKeyEvent);
  252. }
  253. }
  254. void SExtAssetListView::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
  255. {
  256. // Regreshing an asset view is an intensive task. Do not do this while a user
  257. // is dragging arround content for maximum responsiveness.
  258. // Also prevents a re-entrancy crash caused by potentially complex thumbnail generators.
  259. if (!FSlateApplication::Get().IsDragDropping())
  260. {
  261. SListView<TSharedPtr<FExtAssetViewItem>>::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
  262. }
  263. }
  264. bool SExtAssetListView::HasWidgetForAsset(const FName& AssetPathName)
  265. {
  266. for (const TSharedPtr<FExtAssetViewItem>& Item : WidgetGenerator.ItemsWithGeneratedWidgets)
  267. {
  268. if (Item.IsValid() && Item->GetType() == EExtAssetItemType::Normal)
  269. {
  270. const FName& ObjectPath = StaticCastSharedPtr<FExtAssetViewAsset>(Item)->Data.ObjectPath;
  271. if (ObjectPath == AssetPathName)
  272. {
  273. return true;
  274. }
  275. }
  276. }
  277. return false;
  278. }
  279. FReply SExtAssetColumnView::OnKeyDown(const FGeometry& InGeometry, const FKeyEvent& InKeyEvent)
  280. {
  281. FReply Reply = FAssetViewModeUtils::OnViewModeKeyDown(SelectedItems, InKeyEvent);
  282. if ( Reply.IsEventHandled() )
  283. {
  284. return Reply;
  285. }
  286. else
  287. {
  288. return SListView<TSharedPtr<FExtAssetViewItem>>::OnKeyDown(InGeometry, InKeyEvent);
  289. }
  290. }
  291. void SExtAssetColumnView::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
  292. {
  293. // Regreshing an asset view is an intensive task. Do not do this while a user
  294. // is dragging arround content for maximum responsiveness.
  295. // Also prevents a re-entrancy crash caused by potentially complex thumbnail generators.
  296. if (!FSlateApplication::Get().IsDragDropping())
  297. {
  298. return SListView<TSharedPtr<FExtAssetViewItem>>::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
  299. }
  300. }
  301. ///////////////////////////////
  302. // SExtAssetViewItem
  303. ///////////////////////////////
  304. SExtAssetViewItem::~SExtAssetViewItem()
  305. {
  306. if (AssetItem.IsValid())
  307. {
  308. AssetItem->OnAssetDataChanged.RemoveAll(this);
  309. }
  310. OnItemDestroyed.ExecuteIfBound(AssetItem);
  311. if (!GExitPurge)
  312. {
  313. const bool bIsGarbageCollectingOnGameThread = (IsInGameThread() && IsGarbageCollecting());
  314. if (!bIsGarbageCollectingOnGameThread)
  315. {
  316. // This hack is here to make abnormal shutdowns less frequent. Crashes here are the result UI's being shut down as a result of GC at edtior shutdown. This code attemps to call FindObject which is not allowed during GC.
  317. SetForceMipLevelsToBeResident(false);
  318. }
  319. }
  320. }
  321. void SExtAssetViewItem::Construct( const FArguments& InArgs )
  322. {
  323. AssetItem = InArgs._AssetItem;
  324. OnRenameBegin = InArgs._OnRenameBegin;
  325. OnRenameCommit = InArgs._OnRenameCommit;
  326. OnVerifyRenameCommit = InArgs._OnVerifyRenameCommit;
  327. OnItemDestroyed = InArgs._OnItemDestroyed;
  328. ShouldAllowToolTip = InArgs._ShouldAllowToolTip;
  329. ThumbnailEditMode = InArgs._ThumbnailEditMode;
  330. HighlightText = InArgs._HighlightText;
  331. OnAssetsOrPathsDragDropped = InArgs._OnAssetsOrPathsDragDropped;
  332. OnFilesDragDropped = InArgs._OnFilesDragDropped;
  333. OnIsAssetValidForCustomToolTip = InArgs._OnIsAssetValidForCustomToolTip;
  334. OnGetCustomAssetToolTip = InArgs._OnGetCustomAssetToolTip;
  335. OnVisualizeAssetToolTip = InArgs._OnVisualizeAssetToolTip;
  336. OnAssetToolTipClosing = InArgs._OnAssetToolTipClosing;
  337. bDraggedOver = false;
  338. bPackageDirty = false;
  339. OnAssetDataChanged();
  340. AssetItem->OnAssetDataChanged.AddSP(this, &SExtAssetViewItem::OnAssetDataChanged);
  341. AssetDirtyBrush = FAppStyle::GetBrush("ContentBrowser.ContentDirty");
  342. // Set our tooltip - this will refresh each time it's opened to make sure it's up-to-date
  343. SetToolTip(SNew(SExtAssetViewItemToolTip).AssetViewItem(SharedThis(this)));
  344. SourceControlStateDelay = 0.0f;
  345. bSourceControlStateRequested = false;
  346. ISourceControlModule::Get().RegisterProviderChanged(FSourceControlProviderChanged::FDelegate::CreateSP(this, &SExtAssetViewItem::HandleSourceControlProviderChanged));
  347. SourceControlStateChangedDelegateHandle = ISourceControlModule::Get().GetProvider().RegisterSourceControlStateChanged_Handle(FSourceControlStateChanged::FDelegate::CreateSP(this, &SExtAssetViewItem::HandleSourceControlStateChanged));
  348. // Source control state may have already been cached, make sure the control is in sync with
  349. // cached state as the delegate is not going to be invoked again until source control state
  350. // changes. This will be necessary any time the widget is destroyed and recreated after source
  351. // control state has been cached; for instance when the widget is killed via FWidgetGenerator::OnEndGenerationPass
  352. // or a view is refreshed due to user filtering/navigating):
  353. HandleSourceControlStateChanged();
  354. }
  355. void SExtAssetViewItem::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
  356. {
  357. const float PrevSizeX = LastGeometry.Size.X;
  358. LastGeometry = AllottedGeometry;
  359. // Set cached wrap text width based on new "LastGeometry" value.
  360. // We set this only when changed because binding a delegate to text wrapping attributes is expensive
  361. if( PrevSizeX != AllottedGeometry.Size.X && InlineRenameWidget.IsValid() )
  362. {
  363. InlineRenameWidget->SetWrapTextAt( GetNameTextWrapWidth() );
  364. }
  365. UpdatePackageDirtyState();
  366. UpdateSourceControlState((float)InDeltaTime);
  367. }
  368. TSharedPtr<IToolTip> SExtAssetViewItem::GetToolTip()
  369. {
  370. return ShouldAllowToolTip.Get() ? SCompoundWidget::GetToolTip() : NULL;
  371. }
  372. bool SExtAssetViewItem::ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const
  373. {
  374. OutIsKnownDragOperation = false;
  375. return IsFolder() && DragDropHandler::ValidateDragDropOnAssetFolder(MyGeometry, DragDropEvent, StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderPath, OutIsKnownDragOperation);
  376. }
  377. void SExtAssetViewItem::OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  378. {
  379. ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
  380. }
  381. void SExtAssetViewItem::OnDragLeave( const FDragDropEvent& DragDropEvent )
  382. {
  383. if(IsFolder())
  384. {
  385. TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
  386. if (Operation.IsValid())
  387. {
  388. Operation->SetCursorOverride(TOptional<EMouseCursor::Type>());
  389. if (Operation->IsOfType<FAssetDragDropOp>())
  390. {
  391. TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>(Operation);
  392. DragDropOp->ResetToDefaultToolTip();
  393. }
  394. }
  395. }
  396. bDraggedOver = false;
  397. }
  398. FReply SExtAssetViewItem::OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  399. {
  400. ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
  401. return (bDraggedOver) ? FReply::Handled() : FReply::Unhandled();
  402. }
  403. FReply SExtAssetViewItem::OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  404. {
  405. if (ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver)) // updates bDraggedOver
  406. {
  407. bDraggedOver = false;
  408. check(AssetItem->GetType() == EExtAssetItemType::Folder);
  409. TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
  410. if (!Operation.IsValid())
  411. {
  412. return FReply::Unhandled();
  413. }
  414. if (Operation->IsOfType<FExternalDragOperation>())
  415. {
  416. TSharedPtr<FExternalDragOperation> DragDropOp = StaticCastSharedPtr<FExternalDragOperation>(Operation);
  417. OnFilesDragDropped.ExecuteIfBound(DragDropOp->GetFiles(), StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderPath);
  418. return FReply::Handled();
  419. }
  420. if (Operation->IsOfType<FAssetDragDropOp>())
  421. {
  422. TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>(Operation);
  423. OnAssetsOrPathsDragDropped.ExecuteIfBound(DragDropOp->GetAssets(), DragDropOp->GetAssetPaths(), StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderPath);
  424. return FReply::Handled();
  425. }
  426. }
  427. if (bDraggedOver)
  428. {
  429. // We were able to handle this operation, but could not due to another error - still report this drop as handled so it doesn't fall through to other widgets
  430. bDraggedOver = false;
  431. return FReply::Handled();
  432. }
  433. return FReply::Unhandled();
  434. }
  435. bool SExtAssetViewItem::IsNameReadOnly() const
  436. {
  437. return true;
  438. }
  439. void SExtAssetViewItem::HandleBeginNameChange( const FText& OriginalText )
  440. {
  441. OnRenameBegin.ExecuteIfBound(AssetItem, OriginalText.ToString(), LastGeometry.GetLayoutBoundingRect());
  442. }
  443. void SExtAssetViewItem::HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo )
  444. {
  445. OnRenameCommit.ExecuteIfBound(AssetItem, NewText.ToString(), LastGeometry.GetLayoutBoundingRect(), CommitInfo);
  446. }
  447. bool SExtAssetViewItem::HandleVerifyNameChanged( const FText& NewText, FText& OutErrorMessage )
  448. {
  449. return !OnVerifyRenameCommit.IsBound() || OnVerifyRenameCommit.Execute(AssetItem, NewText, LastGeometry.GetLayoutBoundingRect(), OutErrorMessage);
  450. }
  451. void SExtAssetViewItem::OnAssetDataChanged()
  452. {
  453. CachePackageName();
  454. AssetPackage = FindObjectSafe<UPackage>(NULL, *CachedPackageName);
  455. UpdatePackageDirtyState();
  456. AssetTypeActions.Reset();
  457. if ( AssetItem->GetType() != EExtAssetItemType::Folder )
  458. {
  459. UClass* AssetClass = FindObject<UClass>(nullptr, *StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.AssetClass.ToString());
  460. if (AssetClass)
  461. {
  462. FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools"));
  463. AssetTypeActions = AssetToolsModule.Get().GetAssetTypeActionsForClass(AssetClass).Pin();
  464. }
  465. }
  466. if ( InlineRenameWidget.IsValid() )
  467. {
  468. InlineRenameWidget->SetText( GetNameText() );
  469. }
  470. CacheDisplayTags();
  471. }
  472. void SExtAssetViewItem::DirtyStateChanged()
  473. {
  474. }
  475. FText SExtAssetViewItem::GetAssetClassText() const
  476. {
  477. if (!AssetItem.IsValid())
  478. {
  479. return FText();
  480. }
  481. if (AssetItem->GetType() == EExtAssetItemType::Folder)
  482. {
  483. return LOCTEXT("FolderName", "Folder");
  484. }
  485. if (AssetTypeActions.IsValid())
  486. {
  487. FText Name = AssetTypeActions.Pin()->GetName();
  488. if (!Name.IsEmpty())
  489. {
  490. return Name;
  491. }
  492. }
  493. return FText::FromName(StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.AssetClass);
  494. }
  495. void SExtAssetViewItem::HandleSourceControlProviderChanged(ISourceControlProvider& OldProvider, ISourceControlProvider& NewProvider)
  496. {
  497. OldProvider.UnregisterSourceControlStateChanged_Handle(SourceControlStateChangedDelegateHandle);
  498. SourceControlStateChangedDelegateHandle = NewProvider.RegisterSourceControlStateChanged_Handle(FSourceControlStateChanged::FDelegate::CreateSP(this, &SExtAssetViewItem::HandleSourceControlStateChanged));
  499. // Reset this so the state will be queried from the new provider on the next Tick
  500. SourceControlStateDelay = 0.0f;
  501. bSourceControlStateRequested = false;
  502. HandleSourceControlStateChanged();
  503. }
  504. void SExtAssetViewItem::HandleSourceControlStateChanged()
  505. {
  506. if ( ISourceControlModule::Get().IsEnabled() && AssetItem.IsValid() && (AssetItem->GetType() == EExtAssetItemType::Normal) && !AssetItem->IsTemporaryItem() && !FPackageName::IsScriptPackage(CachedPackageName) )
  507. {
  508. FSourceControlStatePtr SourceControlState = ISourceControlModule::Get().GetProvider().GetState(CachedPackageFileName, EStateCacheUsage::Use);
  509. if(SourceControlState.IsValid())
  510. {
  511. if (SCCStateWidget.IsValid())
  512. {
  513. SCCStateWidget->SetFromSlateIcon(SourceControlState->GetIcon());
  514. }
  515. }
  516. }
  517. }
  518. const FSlateBrush* SExtAssetViewItem::GetDirtyImage() const
  519. {
  520. return IsDirty() ? AssetDirtyBrush : NULL;
  521. }
  522. TSharedRef<SWidget> SExtAssetViewItem::GenerateSourceControlIconWidget()
  523. {
  524. TSharedRef<SLayeredImage> Image = SNew(SLayeredImage).Image(FStyleDefaults::GetNoBrush());
  525. SCCStateWidget = Image;
  526. return Image;
  527. }
  528. TSharedRef<SWidget> SExtAssetViewItem::GenerateExtraStateIconWidget(TAttribute<float> InMaxExtraStateIconWidth) const
  529. {
  530. #if ECB_TODO // Extra icon support
  531. TArray<FOnGenerateAssetViewExtraStateIndicators>& ExtraStateIconGenerators = FModuleManager::GetModuleChecked<FExtContentBrowserModule>(TEXT("ExtContentBrowser")).GetAllAssetViewExtraStateIconGenerators();
  532. if (AssetItem->GetType() != EAssetItemType::Folder && ExtraStateIconGenerators.Num() > 0)
  533. {
  534. FAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  535. TSharedPtr<SHorizontalBox> Content = SNew(SHorizontalBox);
  536. for (const auto& Generator : ExtraStateIconGenerators)
  537. {
  538. if (Generator.IsBound())
  539. {
  540. Content->AddSlot()
  541. .HAlign(HAlign_Left)
  542. .MaxWidth(InMaxExtraStateIconWidth)
  543. [
  544. Generator.Execute(AssetData)
  545. ];
  546. }
  547. }
  548. return Content.ToSharedRef();
  549. }
  550. #endif
  551. return SNullWidget::NullWidget;
  552. }
  553. TSharedRef<SWidget> SExtAssetViewItem::GenerateExtraStateTooltipWidget() const
  554. {
  555. #if ECB_TODO // Extra icon support
  556. TArray<FOnGenerateAssetViewExtraStateIndicators>& ExtraStateTooltipGenerators = FModuleManager::GetModuleChecked<FExtContentBrowserModule>(TEXT("ContentBrowser")).GetAllAssetViewExtraStateTooltipGenerators();
  557. if (AssetItem->GetType() != EAssetItemType::Folder && ExtraStateTooltipGenerators.Num() > 0)
  558. {
  559. FAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  560. TSharedPtr<SVerticalBox> Content = SNew(SVerticalBox);
  561. for (const auto& Generator : ExtraStateTooltipGenerators)
  562. {
  563. if (Generator.IsBound())
  564. {
  565. Content->AddSlot()
  566. [
  567. Generator.Execute(AssetData)
  568. ];
  569. }
  570. }
  571. return Content.ToSharedRef();
  572. }
  573. #endif
  574. return SNullWidget::NullWidget;
  575. }
  576. EVisibility SExtAssetViewItem::GetThumbnailEditModeUIVisibility() const
  577. {
  578. return !IsFolder() && ThumbnailEditMode.Get() ? EVisibility::Visible : EVisibility::Collapsed;
  579. }
  580. BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
  581. TSharedRef<SWidget> SExtAssetViewItem::CreateToolTipWidget() const
  582. {
  583. if ( AssetItem.IsValid() )
  584. {
  585. #if ECB_TODO // Custom tooltip
  586. bool bTryCustomAssetToolTip = true;
  587. if (OnIsAssetValidForCustomToolTip.IsBound() && AssetItem->GetType() != EAssetItemType::Folder)
  588. {
  589. FExtAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  590. bTryCustomAssetToolTip = OnIsAssetValidForCustomToolTip.Execute(AssetData);
  591. }
  592. if(bTryCustomAssetToolTip && OnGetCustomAssetToolTip.IsBound() && AssetItem->GetType() != EAssetItemType::Folder)
  593. {
  594. FExtAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  595. return OnGetCustomAssetToolTip.Execute(AssetData);
  596. }
  597. else
  598. #endif
  599. if(AssetItem->GetType() != EExtAssetItemType::Folder)
  600. {
  601. const FExtAssetData& AssetData = StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data;
  602. // The tooltip contains the name, class, path, and asset registry tags
  603. const FText NameText = FText::FromName( AssetData.AssetName );
  604. const FText ClassText = FText::Format( LOCTEXT("ClassName", "({0})"), GetAssetClassText() );
  605. // Create a box to hold every line of info in the body of the tooltip
  606. TSharedRef<SVerticalBox> InfoBox = SNew(SVerticalBox);
  607. // Add File Path
  608. AddToToolTipInfoBox( InfoBox, LOCTEXT("TileViewTooltipPath", "Path"), FText::FromName(AssetData.PackageFilePath), false);
  609. // Saved By Engine Version
  610. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipEngine", "Engine"), FText::FromString(AssetData.SavedByEngineVersion.ToString(EVersionComponent::Patch)), false);
  611. #if ECB_DEBUG
  612. // File Version
  613. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipFileVersion", "File Version"), FText::AsNumber(AssetData.FileVersionUE4), false);
  614. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipSavedByEngineDetail", "Saved By Engine"), FText::FromString(AssetData.SavedByEngineVersion.ToString(EVersionComponent::Branch)), false);
  615. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipCompatibleEngineDetail", "Compatible Engine"), FText::FromString(AssetData.CompatibleWithEngineVersion.ToString(EVersionComponent::Branch)), false);
  616. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipPackageName", "PackageName"), FText::FromName(AssetData.PackageName), false);
  617. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipPackagePath", "PackagePath"), FText::FromName(AssetData.PackagePath), false);
  618. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipObjectPath", "ObjectPath"), FText::FromName(AssetData.ObjectPath), false);
  619. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipAssetName", "AssetName"), FText::FromName(AssetData.AssetName), false);
  620. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipAssetClass", "AssetClass"), FText::FromName(AssetData.AssetClass), false);
  621. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipAssetContentRootDir", "AssetContentRootDir"), FText::FromName(AssetData.AssetContentRoot), false);
  622. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipAssetRelativePath", "AssetRelativePath"), FText::FromName(AssetData.AssetRelativePath), false);
  623. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipHasThumbnail", "HasThumbnail"), FText::AsNumber(AssetData.HasThumbnail()), false);
  624. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipNumTagsAndValues", "Num of TagsAndValues"), FText::AsNumber(AssetData.TagsAndValues.Num()), false);
  625. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipHardDependentPackages", "Num of Hard Dependencies"), FText::AsNumber(AssetData.HardDependentPackages.Num()), false);
  626. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipSoftReferencesList", "Num of Soft References"), FText::AsNumber(AssetData.SoftReferencesList.Num()), false);
  627. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipAssetCount", "Num of Assets"), FText::AsNumber(AssetData.AssetCount), false);
  628. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipThumbCount", "Num of Thumbnails"), FText::AsNumber(AssetData.ThumbCount), false);
  629. AddToToolTipInfoBox(InfoBox, LOCTEXT("TileViewTooltipFileSize", "File Size"), FText::AsNumber(AssetData.FileSize), false);
  630. #endif
  631. // Add Collections
  632. #if ECB_WIP_COLLECTION
  633. {
  634. FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
  635. const FString CollectionNames = CollectionManagerModule.Get().GetCollectionsStringForObject(AssetData.ObjectPath, ECollectionShareType::CST_All, ECollectionRecursionFlags::Self, GetDefault<UExtContentBrowserSettings>()->bShowFullCollectionNameInToolTip);
  636. if (!CollectionNames.IsEmpty())
  637. {
  638. AddToToolTipInfoBox(InfoBox, LOCTEXT("AssetToolTipKey_Collections", "Collections"), FText::FromString(CollectionNames), false);
  639. }
  640. }
  641. #endif
  642. // Add tags
  643. for (const auto& DisplayTagItem : CachedDisplayTags)
  644. {
  645. AddToToolTipInfoBox(InfoBox, DisplayTagItem.DisplayKey, DisplayTagItem.DisplayValue, DisplayTagItem.bImportant);
  646. }
  647. // Add asset source files
  648. TOptional<FAssetImportInfo> ImportInfo = FExtContentBrowserSingleton::GetAssetRegistry().ExtractAssetImportInfo(AssetData);
  649. if (ImportInfo.IsSet())
  650. {
  651. for (const auto& File : ImportInfo->SourceFiles)
  652. {
  653. FText SourceLabel = LOCTEXT("TileViewTooltipSourceFile", "Source File");
  654. if (File.DisplayLabelName.Len() > 0)
  655. {
  656. SourceLabel = FText::FromString(FText(LOCTEXT("TileViewTooltipSourceFile", "Source File")).ToString() + TEXT(" (") + File.DisplayLabelName + TEXT(")"));
  657. }
  658. AddToToolTipInfoBox( InfoBox, SourceLabel, FText::FromString(File.RelativeFilename), false );
  659. }
  660. }
  661. TSharedRef<SVerticalBox> OverallTooltipVBox = SNew(SVerticalBox);
  662. // Top section (asset name, type, is checked out)
  663. OverallTooltipVBox->AddSlot()
  664. .AutoHeight()
  665. .Padding(0, 0, 0, 4)
  666. [
  667. SNew(SBorder)
  668. .Padding(6)
  669. .BorderImage(FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.ContentBorder"))
  670. [
  671. SNew(SVerticalBox)
  672. + SVerticalBox::Slot()
  673. .AutoHeight()
  674. [
  675. SNew(SHorizontalBox)
  676. + SHorizontalBox::Slot()
  677. .AutoWidth()
  678. .VAlign(VAlign_Center)
  679. .Padding(0, 0, 4, 0)
  680. [
  681. SNew(STextBlock)
  682. .Text(NameText)
  683. .Font(FAppStyle::GetFontStyle("ContentBrowser.TileViewTooltip.NameFont"))
  684. ]
  685. + SHorizontalBox::Slot()
  686. .AutoWidth()
  687. .VAlign(VAlign_Center)
  688. [
  689. SNew(STextBlock).Text(ClassText)
  690. .HighlightText(HighlightText)
  691. ]
  692. ]
  693. + SVerticalBox::Slot()
  694. .AutoHeight()
  695. [
  696. GenerateExtraStateTooltipWidget()
  697. ]
  698. ]
  699. ];
  700. // Middle section (user description, if present)
  701. FText UserDescription = GetAssetUserDescription();
  702. if (!UserDescription.IsEmpty())
  703. {
  704. OverallTooltipVBox->AddSlot()
  705. .AutoHeight()
  706. .Padding(0, 0, 0, 4)
  707. [
  708. SNew(SBorder)
  709. .Padding(6)
  710. .BorderImage(FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.ContentBorder"))
  711. [
  712. SNew(STextBlock)
  713. .WrapTextAt(300.0f)
  714. .Font(FAppStyle::GetFontStyle("ContentBrowser.TileViewTooltip.AssetUserDescriptionFont"))
  715. .Text(UserDescription)
  716. ]
  717. ];
  718. }
  719. // Bottom section (asset registry tags)
  720. OverallTooltipVBox->AddSlot()
  721. .AutoHeight()
  722. [
  723. SNew(SBorder)
  724. .Padding(6)
  725. .BorderImage(FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.ContentBorder"))
  726. [
  727. InfoBox
  728. ]
  729. ];
  730. return SNew(SBorder)
  731. .Padding(6)
  732. .BorderImage( FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.NonContentBorder") )
  733. [
  734. OverallTooltipVBox
  735. ];
  736. }
  737. else
  738. {
  739. const FText& FolderName = StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderName;
  740. const FString& FolderPath = StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderPath;
  741. // Create a box to hold every line of info in the body of the tooltip
  742. TSharedRef<SVerticalBox> InfoBox = SNew(SVerticalBox);
  743. AddToToolTipInfoBox( InfoBox, LOCTEXT("TileViewTooltipPath", "Path"), FText::FromString(FolderPath), false );
  744. return SNew(SBorder)
  745. .Padding(6)
  746. .BorderImage( FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.NonContentBorder") )
  747. [
  748. SNew(SVerticalBox)
  749. +SVerticalBox::Slot()
  750. .AutoHeight()
  751. .Padding(0, 0, 0, 4)
  752. [
  753. SNew(SBorder)
  754. .Padding(6)
  755. .BorderImage( FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.ContentBorder") )
  756. [
  757. SNew(SVerticalBox)
  758. +SVerticalBox::Slot()
  759. .AutoHeight()
  760. [
  761. SNew(SHorizontalBox)
  762. +SHorizontalBox::Slot()
  763. .AutoWidth()
  764. .VAlign(VAlign_Center)
  765. .Padding(0, 0, 4, 0)
  766. [
  767. SNew(STextBlock)
  768. .Text( FolderName )
  769. .Font( FAppStyle::GetFontStyle("ContentBrowser.TileViewTooltip.NameFont") )
  770. ]
  771. +SHorizontalBox::Slot()
  772. .AutoWidth()
  773. .VAlign(VAlign_Center)
  774. [
  775. SNew(STextBlock)
  776. .Text( LOCTEXT("FolderNameBracketed", "(Folder)") )
  777. ]
  778. ]
  779. ]
  780. ]
  781. +SVerticalBox::Slot()
  782. .AutoHeight()
  783. [
  784. SNew(SBorder)
  785. .Padding(6)
  786. .BorderImage( FAppStyle::GetBrush("ContentBrowser.TileViewTooltip.ContentBorder") )
  787. [
  788. InfoBox
  789. ]
  790. ]
  791. ];
  792. }
  793. }
  794. else
  795. {
  796. // Return an empty tooltip since the asset item wasn't valid
  797. return SNullWidget::NullWidget;
  798. }
  799. }
  800. END_SLATE_FUNCTION_BUILD_OPTIMIZATION
  801. FText SExtAssetViewItem::GetAssetUserDescription() const
  802. {
  803. #if ECB_TODO // Get Asset User Description
  804. if (AssetItem.IsValid() && AssetTypeActions.IsValid())
  805. {
  806. if (AssetItem->GetType() != EAssetItemType::Folder)
  807. {
  808. const FAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  809. return AssetTypeActions.Pin()->GetAssetDescription(AssetData);
  810. }
  811. }
  812. #endif
  813. return FText::GetEmpty();
  814. }
  815. void SExtAssetViewItem::AddToToolTipInfoBox(const TSharedRef<SVerticalBox>& InfoBox, const FText& Key, const FText& Value, bool bImportant) const
  816. {
  817. FWidgetStyle ImportantStyle;
  818. ImportantStyle.SetForegroundColor(FLinearColor(1, 0.5, 0, 1));
  819. InfoBox->AddSlot()
  820. .AutoHeight()
  821. .Padding(0, 1)
  822. [
  823. SNew(SHorizontalBox)
  824. +SHorizontalBox::Slot()
  825. .AutoWidth()
  826. .Padding(0, 0, 4, 0)
  827. [
  828. SNew(STextBlock) .Text( FText::Format(LOCTEXT("AssetViewTooltipFormat", "{0}:"), Key ) )
  829. .ColorAndOpacity(bImportant ? ImportantStyle.GetSubduedForegroundColor() : FSlateColor::UseSubduedForeground())
  830. ]
  831. +SHorizontalBox::Slot()
  832. .AutoWidth()
  833. [
  834. SNew(STextBlock) .Text( Value )
  835. .ColorAndOpacity(bImportant ? ImportantStyle.GetForegroundColor() : FSlateColor::UseForeground())
  836. .HighlightText((Key.ToString() == TEXT("Path")) ? HighlightText : FText())
  837. .WrapTextAt(700.0f)
  838. ]
  839. ];
  840. }
  841. void SExtAssetViewItem::UpdatePackageDirtyState()
  842. {
  843. bool bNewIsDirty = false;
  844. // Only update the dirty state for non-temporary asset items that aren't a built in script
  845. if ( AssetItem.IsValid() && !AssetItem->IsTemporaryItem() && AssetItem->GetType() != EExtAssetItemType::Folder && !FPackageName::IsScriptPackage(CachedPackageName) )
  846. {
  847. if ( AssetPackage.IsValid() )
  848. {
  849. bNewIsDirty = AssetPackage->IsDirty();
  850. }
  851. }
  852. if ( bNewIsDirty != bPackageDirty )
  853. {
  854. bPackageDirty = bNewIsDirty;
  855. DirtyStateChanged();
  856. }
  857. }
  858. bool SExtAssetViewItem::IsDirty() const
  859. {
  860. return bPackageDirty;
  861. }
  862. void SExtAssetViewItem::UpdateSourceControlState(float InDeltaTime)
  863. {
  864. SourceControlStateDelay += InDeltaTime;
  865. static ISourceControlModule& SourceControlModule = ISourceControlModule::Get();
  866. if ( !bSourceControlStateRequested && SourceControlStateDelay > 1.0f && SourceControlModule.IsEnabled() && AssetItem.IsValid() )
  867. {
  868. // Only update the SCC state for non-temporary asset items that aren't a built in script
  869. if ( !AssetItem->IsTemporaryItem() && AssetItem->GetType() != EExtAssetItemType::Folder && !FPackageName::IsScriptPackage(CachedPackageName) && !FPackageName::IsMemoryPackage(CachedPackageName) && !FPackageName::IsTempPackage(CachedPackageName))
  870. {
  871. // Request the most recent SCC state for this asset
  872. SourceControlModule.QueueStatusUpdate(CachedPackageFileName);
  873. }
  874. bSourceControlStateRequested = true;
  875. }
  876. }
  877. void SExtAssetViewItem::CachePackageName()
  878. {
  879. #if ECB_LEGACY
  880. if(AssetItem.IsValid())
  881. {
  882. if(AssetItem->GetType() != EAssetItemType::Folder)
  883. {
  884. CachedPackageName = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data.PackageName.ToString();
  885. CachedPackageFileName = SourceControlHelpers::PackageFilename(CachedPackageName);
  886. }
  887. else
  888. {
  889. CachedPackageName = StaticCastSharedPtr<FAssetViewFolder>(AssetItem)->FolderName.ToString();
  890. }
  891. }
  892. #endif
  893. }
  894. void SExtAssetViewItem::CacheDisplayTags()
  895. {
  896. CachedDisplayTags.Reset();
  897. if (AssetItem->GetType() == EExtAssetItemType::Folder)
  898. {
  899. return;
  900. }
  901. const FExtAssetData& AssetData = StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data;
  902. // Find the asset CDO so we can get the meta-data for the tags
  903. UClass* AssetClass = FindObject<UClass>(nullptr, *AssetData.AssetClass.ToString());
  904. const UObject* AssetCDO = AssetClass ? GetDefault<UObject>(AssetClass) : nullptr;
  905. struct FTagDisplayMetaData
  906. {
  907. FTagDisplayMetaData()
  908. : MetaData()
  909. , Type(UObject::FAssetRegistryTag::TT_Hidden)
  910. , DisplayFlags(UObject::FAssetRegistryTag::TD_None)
  911. {
  912. }
  913. UObject::FAssetRegistryTagMetadata MetaData;
  914. UObject::FAssetRegistryTag::ETagType Type;
  915. uint32 DisplayFlags;
  916. };
  917. bool bHasTagMetaDataMap = false;
  918. // Build up the meta-data needed to correctly process the tags for display
  919. TMap<FName, FTagDisplayMetaData> TagMetaDataMap;
  920. if (AssetCDO)
  921. {
  922. bHasTagMetaDataMap = true;
  923. // Add the internal meta-data
  924. {
  925. TMap<FName, UObject::FAssetRegistryTagMetadata> TmpMetaData;
  926. AssetCDO->GetAssetRegistryTagMetadata(TmpMetaData);
  927. for (const auto& TmpMetaDataPair : TmpMetaData)
  928. {
  929. FTagDisplayMetaData& TagMetaData = TagMetaDataMap.FindOrAdd(TmpMetaDataPair.Key);
  930. TagMetaData.MetaData = TmpMetaDataPair.Value;
  931. }
  932. }
  933. // Add the type and display flags
  934. {
  935. TArray<UObject::FAssetRegistryTag> TmpTags;
  936. if (AssetCDO->GetClass()->IsChildOf(UActorFolder::StaticClass()))
  937. {
  938. }
  939. else
  940. {
  941. AssetCDO->GetAssetRegistryTags(TmpTags);
  942. }
  943. for (const UObject::FAssetRegistryTag& TmpTag : TmpTags)
  944. {
  945. FTagDisplayMetaData& TagMetaData = TagMetaDataMap.FindOrAdd(TmpTag.Name);
  946. TagMetaData.Type = TmpTag.Type;
  947. TagMetaData.DisplayFlags = TmpTag.DisplayFlags;
  948. }
  949. }
  950. }
  951. // Add all asset registry tags and values
  952. for (const auto& TagAndValuePair : AssetData.TagsAndValues)
  953. {
  954. // Skip tags that are not registered
  955. #if !ECB_DEBUG
  956. if (bHasTagMetaDataMap && !TagMetaDataMap.Contains(TagAndValuePair.Key))
  957. {
  958. continue;
  959. }
  960. #endif
  961. FTagDisplayMetaData* TagMetaData = NULL;
  962. if (bHasTagMetaDataMap && TagMetaDataMap.Contains(TagAndValuePair.Key))
  963. {
  964. TagMetaData = TagMetaDataMap.Find(TagAndValuePair.Key);
  965. // Skip tags that are set to be hidden
  966. if (TagMetaData && TagMetaData->Type == UObject::FAssetRegistryTag::TT_Hidden)
  967. {
  968. continue;
  969. }
  970. }
  971. const bool bHasTagMetaData = TagMetaData != NULL;
  972. FProperty* TagField = AssetClass != NULL ? FindFProperty<FProperty>(AssetClass, TagAndValuePair.Key) : NULL;
  973. // Build the display name for this tag
  974. FText DisplayName;
  975. if (bHasTagMetaData && !TagMetaData->MetaData.DisplayName.IsEmpty())
  976. {
  977. DisplayName = TagMetaData->MetaData.DisplayName;
  978. }
  979. else if (TagField)
  980. {
  981. DisplayName = TagField->GetDisplayNameText();
  982. }
  983. else
  984. {
  985. // We have no type information by this point, so no idea if it's a bool :(
  986. const bool bIsBool = false;
  987. DisplayName = FText::FromString(FName::NameToDisplayString(TagAndValuePair.Key.ToString(), bIsBool));
  988. }
  989. // Build the display value for this tag
  990. FText DisplayValue;
  991. {
  992. auto ReformatNumberStringForDisplay = [](const FString& InNumberString) -> FText
  993. {
  994. // Respect the number of decimal places in the source string when converting for display
  995. int32 NumDecimalPlaces = 0;
  996. {
  997. int32 DotIndex = INDEX_NONE;
  998. if (InNumberString.FindChar(TEXT('.'), DotIndex))
  999. {
  1000. NumDecimalPlaces = InNumberString.Len() - DotIndex - 1;
  1001. }
  1002. }
  1003. if (NumDecimalPlaces > 0)
  1004. {
  1005. // Convert the number as a double
  1006. double Num = 0.0;
  1007. LexFromString(Num, *InNumberString);
  1008. const FNumberFormattingOptions NumFormatOpts = FNumberFormattingOptions()
  1009. .SetMinimumFractionalDigits(NumDecimalPlaces)
  1010. .SetMaximumFractionalDigits(NumDecimalPlaces);
  1011. return FText::AsNumber(Num, &NumFormatOpts);
  1012. }
  1013. else
  1014. {
  1015. const bool bIsSigned = InNumberString.Len() > 0 && (InNumberString[0] == TEXT('-') || InNumberString[0] == TEXT('+'));
  1016. if (bIsSigned)
  1017. {
  1018. // Convert the number as a signed int
  1019. int64 Num = 0;
  1020. LexFromString(Num, *InNumberString);
  1021. return FText::AsNumber(Num);
  1022. }
  1023. else
  1024. {
  1025. // Convert the number as an unsigned int
  1026. uint64 Num = 0;
  1027. LexFromString(Num, *InNumberString);
  1028. return FText::AsNumber(Num);
  1029. }
  1030. }
  1031. return FText::GetEmpty();
  1032. };
  1033. bool bHasSetDisplayValue = false;
  1034. const FString AttributeValueStr = TagAndValuePair.Value.GetValue();
  1035. // Numerical tags need to format the specified number based on the display flags
  1036. if (!bHasSetDisplayValue && bHasTagMetaData && TagMetaData->Type == UObject::FAssetRegistryTag::TT_Numerical && AttributeValueStr.IsNumeric())
  1037. {
  1038. bHasSetDisplayValue = true;
  1039. const bool bAsMemory = !!(TagMetaData->DisplayFlags & UObject::FAssetRegistryTag::TD_Memory);
  1040. if (bAsMemory)
  1041. {
  1042. // Memory should be a 64-bit unsigned number of bytes
  1043. uint64 NumBytes = 0;
  1044. LexFromString(NumBytes, *AttributeValueStr);
  1045. DisplayValue = FText::AsMemory(NumBytes);
  1046. }
  1047. else
  1048. {
  1049. DisplayValue = ReformatNumberStringForDisplay(AttributeValueStr);
  1050. }
  1051. }
  1052. // Dimensional tags need to be split into their component numbers, with each component number re-format
  1053. if (!bHasSetDisplayValue && bHasTagMetaData && TagMetaData->Type == UObject::FAssetRegistryTag::TT_Dimensional)
  1054. {
  1055. TArray<FString> NumberStrTokens;
  1056. AttributeValueStr.ParseIntoArray(NumberStrTokens, TEXT("x"), true);
  1057. if (NumberStrTokens.Num() > 0 && NumberStrTokens.Num() <= 3)
  1058. {
  1059. bHasSetDisplayValue = true;
  1060. switch (NumberStrTokens.Num())
  1061. {
  1062. case 1:
  1063. DisplayValue = ReformatNumberStringForDisplay(NumberStrTokens[0]);
  1064. break;
  1065. case 2:
  1066. DisplayValue = FText::Format(LOCTEXT("DisplayTag2xFmt", "{0} \u00D7 {1}"), ReformatNumberStringForDisplay(NumberStrTokens[0]), ReformatNumberStringForDisplay(NumberStrTokens[1]));
  1067. break;
  1068. case 3:
  1069. DisplayValue = FText::Format(LOCTEXT("DisplayTag3xFmt", "{0} \u00D7 {1} \u00D7 {2}"), ReformatNumberStringForDisplay(NumberStrTokens[0]), ReformatNumberStringForDisplay(NumberStrTokens[1]), ReformatNumberStringForDisplay(NumberStrTokens[2]));
  1070. break;
  1071. default:
  1072. break;
  1073. }
  1074. }
  1075. }
  1076. // Chronological tags need to format the specified timestamp based on the display flags
  1077. if (!bHasSetDisplayValue && bHasTagMetaData && TagMetaData->Type == UObject::FAssetRegistryTag::TT_Chronological)
  1078. {
  1079. bHasSetDisplayValue = true;
  1080. FDateTime Timestamp;
  1081. if (FDateTime::Parse(AttributeValueStr, Timestamp))
  1082. {
  1083. const bool bDisplayDate = !!(TagMetaData->DisplayFlags & UObject::FAssetRegistryTag::TD_Date);
  1084. const bool bDisplayTime = !!(TagMetaData->DisplayFlags & UObject::FAssetRegistryTag::TD_Time);
  1085. const FString TimeZone = (TagMetaData->DisplayFlags & UObject::FAssetRegistryTag::TD_InvariantTz) ? FText::GetInvariantTimeZone() : FString();
  1086. if (bDisplayDate && bDisplayTime)
  1087. {
  1088. DisplayValue = FText::AsDateTime(Timestamp, EDateTimeStyle::Short, EDateTimeStyle::Short, TimeZone);
  1089. }
  1090. else if (bDisplayDate)
  1091. {
  1092. DisplayValue = FText::AsDate(Timestamp, EDateTimeStyle::Short, TimeZone);
  1093. }
  1094. else if (bDisplayTime)
  1095. {
  1096. DisplayValue = FText::AsTime(Timestamp, EDateTimeStyle::Short, TimeZone);
  1097. }
  1098. }
  1099. }
  1100. // The tag value might be localized text, so we need to parse it for display
  1101. if (!bHasSetDisplayValue && FTextStringHelper::IsComplexText(*AttributeValueStr))
  1102. {
  1103. bHasSetDisplayValue = FTextStringHelper::ReadFromBuffer(*AttributeValueStr, DisplayValue) != nullptr;
  1104. }
  1105. // Do our best to build something valid from the string value
  1106. if (!bHasSetDisplayValue)
  1107. {
  1108. bHasSetDisplayValue = true;
  1109. // Since all we have at this point is a string, we can't be very smart here.
  1110. // We need to strip some noise off class paths in some cases, but can't load the asset to inspect its UPROPERTYs manually due to performance concerns.
  1111. FString ValueString = FPackageName::ExportTextPathToObjectPath(AttributeValueStr);
  1112. const TCHAR StringToRemove[] = TEXT("/Script/");
  1113. if (ValueString.StartsWith(StringToRemove))
  1114. {
  1115. // Remove the class path for native classes, and also remove Engine. for engine classes
  1116. const int32 SizeOfPrefix = UE_ARRAY_COUNT(StringToRemove) - 1;
  1117. ValueString = ValueString.Mid(SizeOfPrefix, ValueString.Len() - SizeOfPrefix).Replace(TEXT("Engine."), TEXT(""));
  1118. }
  1119. if (TagField)
  1120. {
  1121. FProperty* TagProp = nullptr;
  1122. UEnum* TagEnum = nullptr;
  1123. if (FByteProperty* ByteProp = CastField<FByteProperty>(TagField))
  1124. {
  1125. TagProp = ByteProp;
  1126. TagEnum = ByteProp->Enum;
  1127. }
  1128. else if (FEnumProperty* EnumProp = CastField<FEnumProperty>(TagField))
  1129. {
  1130. TagProp = EnumProp;
  1131. TagEnum = EnumProp->GetEnum();
  1132. }
  1133. // Strip off enum prefixes if they exist
  1134. if (TagProp)
  1135. {
  1136. if (TagEnum)
  1137. {
  1138. const FString EnumPrefix = TagEnum->GenerateEnumPrefix();
  1139. if (EnumPrefix.Len() && ValueString.StartsWith(EnumPrefix))
  1140. {
  1141. ValueString = ValueString.RightChop(EnumPrefix.Len() + 1); // +1 to skip over the underscore
  1142. }
  1143. }
  1144. ValueString = FName::NameToDisplayString(ValueString, false);
  1145. }
  1146. }
  1147. DisplayValue = FText::FromString(MoveTemp(ValueString));
  1148. }
  1149. // Add suffix to the value, if one is defined for this tag
  1150. if (bHasTagMetaData && !TagMetaData->MetaData.Suffix.IsEmpty())
  1151. {
  1152. DisplayValue = FText::Format(LOCTEXT("DisplayTagSuffixFmt", "{0} {1}"), DisplayValue, TagMetaData->MetaData.Suffix);
  1153. }
  1154. }
  1155. if (!DisplayValue.IsEmpty())
  1156. {
  1157. const bool bImportant = bHasTagMetaData && !TagMetaData->MetaData.ImportantValue.IsEmpty() && TagMetaData->MetaData.ImportantValue == TagAndValuePair.Value;
  1158. CachedDisplayTags.Add(FTagDisplayItem(TagAndValuePair.Key, DisplayName, DisplayValue, bImportant));
  1159. }
  1160. }
  1161. }
  1162. const FSlateBrush* SExtAssetViewItem::GetBorderImage() const
  1163. {
  1164. return bDraggedOver ? FAppStyle::GetBrush("Menu.Background") : FAppStyle::GetBrush("NoBorder");
  1165. }
  1166. bool SExtAssetViewItem::IsFolder() const
  1167. {
  1168. return AssetItem.IsValid() && AssetItem->GetType() == EExtAssetItemType::Folder;
  1169. }
  1170. FText SExtAssetViewItem::GetNameText() const
  1171. {
  1172. if(AssetItem.IsValid())
  1173. {
  1174. if(AssetItem->GetType() != EExtAssetItemType::Folder)
  1175. {
  1176. auto& AssetData = StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data;
  1177. #if ECB_TODO // todo: AssetName should fallback to filename when parsing even invalid
  1178. if (AssetData.IsValid() || AssetData.PackageFilePath == NAME_None)
  1179. {
  1180. return FText::FromName(AssetData.AssetName);
  1181. }
  1182. else
  1183. {
  1184. return FText::FromString(FPaths::GetBaseFilename(AssetData.PackageFilePath.ToString()));
  1185. }
  1186. #endif
  1187. return FText::FromName(AssetData.AssetName);
  1188. }
  1189. else
  1190. {
  1191. return StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderName;
  1192. }
  1193. }
  1194. return FText();
  1195. }
  1196. FSlateColor SExtAssetViewItem::GetAssetColor() const
  1197. {
  1198. if(AssetItem.IsValid())
  1199. {
  1200. if(AssetItem->GetType() == EExtAssetItemType::Folder)
  1201. {
  1202. TSharedPtr<FExtAssetViewFolder> AssetFolderItem = StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem);
  1203. TSharedPtr<FLinearColor> Color;
  1204. #if ECB_WIP_COLLECTION
  1205. if (AssetFolderItem->bCollectionFolder)
  1206. {
  1207. FName CollectionName;
  1208. ECollectionShareType::Type CollectionFolderShareType = ECollectionShareType::CST_All;
  1209. ContentBrowserUtils::IsCollectionPath(AssetFolderItem->FolderPath, &CollectionName, &CollectionFolderShareType);
  1210. Color = CollectionViewUtils::LoadColor( CollectionName.ToString(), CollectionFolderShareType );
  1211. }
  1212. else
  1213. #endif
  1214. {
  1215. #if ECB_LEGACY
  1216. Color = ExtContentBrowserUtils::LoadColor( AssetFolderItem->FolderPath );
  1217. #endif
  1218. }
  1219. #if ECB_LEGACY
  1220. if ( Color.IsValid() )
  1221. {
  1222. return *Color.Get();
  1223. }
  1224. #endif
  1225. FLinearColor FolderColor;
  1226. if (ExtContentBrowserUtils::LoadFolderColor(AssetFolderItem->FolderPath, FolderColor))
  1227. {
  1228. return FolderColor;
  1229. }
  1230. else
  1231. {
  1232. return ExtContentBrowserUtils::GetDefaultColor();
  1233. }
  1234. }
  1235. else if(AssetTypeActions.IsValid())
  1236. {
  1237. return AssetTypeActions.Pin()->GetTypeColor().ReinterpretAsLinear();
  1238. }
  1239. }
  1240. return ExtContentBrowserUtils::GetDefaultColor();
  1241. }
  1242. void SExtAssetViewItem::SetForceMipLevelsToBeResident(bool bForce) const
  1243. {
  1244. #if ECB_LEGACY
  1245. if(AssetItem.IsValid() && AssetItem->GetType() == EAssetItemType::Normal)
  1246. {
  1247. const FExtAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  1248. if(AssetData.IsValid() && AssetData.IsAssetLoaded())
  1249. {
  1250. UObject* Asset = AssetData.GetAsset();
  1251. if(Asset != nullptr)
  1252. {
  1253. if(UTexture2D* Texture2D = Cast<UTexture2D>(Asset))
  1254. {
  1255. Texture2D->bForceMiplevelsToBeResident = bForce;
  1256. }
  1257. else if(UMaterial* Material = Cast<UMaterial>(Asset))
  1258. {
  1259. Material->SetForceMipLevelsToBeResident(bForce, bForce, -1.0f);
  1260. }
  1261. }
  1262. }
  1263. }
  1264. #endif
  1265. }
  1266. bool SExtAssetViewItem::OnVisualizeTooltip(const TSharedPtr<SWidget>& TooltipContent)
  1267. {
  1268. #if ECB_LEGACY
  1269. if(OnVisualizeAssetToolTip.IsBound() && TooltipContent.IsValid() && AssetItem->GetType() != EAssetItemType::Folder)
  1270. {
  1271. FExtAssetData& AssetData = StaticCastSharedPtr<FAssetViewAsset>(AssetItem)->Data;
  1272. return OnVisualizeAssetToolTip.Execute(TooltipContent, AssetData);
  1273. }
  1274. #endif
  1275. // No custom behaviour, return false to allow slate to visualize the widget
  1276. return false;
  1277. }
  1278. void SExtAssetViewItem::OnToolTipClosing()
  1279. {
  1280. OnAssetToolTipClosing.ExecuteIfBound();
  1281. }
  1282. ///////////////////////////////
  1283. // SExtAssetListItem
  1284. ///////////////////////////////
  1285. SExtAssetListItem::~SExtAssetListItem()
  1286. {
  1287. }
  1288. BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
  1289. void SExtAssetListItem::Construct( const FArguments& InArgs )
  1290. {
  1291. SExtAssetViewItem::Construct( SExtAssetViewItem::FArguments()
  1292. .AssetItem(InArgs._AssetItem)
  1293. .OnRenameBegin(InArgs._OnRenameBegin)
  1294. .OnRenameCommit(InArgs._OnRenameCommit)
  1295. .OnVerifyRenameCommit(InArgs._OnVerifyRenameCommit)
  1296. .OnItemDestroyed(InArgs._OnItemDestroyed)
  1297. .ShouldAllowToolTip(InArgs._ShouldAllowToolTip)
  1298. .ThumbnailEditMode(InArgs._ThumbnailEditMode)
  1299. .HighlightText(InArgs._HighlightText)
  1300. .OnAssetsOrPathsDragDropped(InArgs._OnAssetsOrPathsDragDropped)
  1301. .OnFilesDragDropped(InArgs._OnFilesDragDropped)
  1302. .OnIsAssetValidForCustomToolTip(InArgs._OnIsAssetValidForCustomToolTip)
  1303. .OnGetCustomAssetToolTip(InArgs._OnGetCustomAssetToolTip)
  1304. .OnVisualizeAssetToolTip(InArgs._OnVisualizeAssetToolTip)
  1305. .OnAssetToolTipClosing( InArgs._OnAssetToolTipClosing )
  1306. );
  1307. AssetThumbnail = InArgs._AssetThumbnail;
  1308. ItemHeight = InArgs._ItemHeight;
  1309. const float ThumbnailPadding = InArgs._ThumbnailPadding;
  1310. TSharedPtr<SWidget> Thumbnail;
  1311. if ( AssetItem.IsValid() && AssetThumbnail.IsValid() )
  1312. {
  1313. FExtAssetThumbnailConfig ThumbnailConfig;
  1314. ThumbnailConfig.bAllowFadeIn = true;
  1315. ThumbnailConfig.bAllowHintText = InArgs._AllowThumbnailHintLabel;
  1316. ThumbnailConfig.bForceGenericThumbnail = (AssetItem->GetType() == EExtAssetItemType::Creation);
  1317. //ThumbnailConfig.bAllowAssetSpecificThumbnailOverlay = (AssetItem->GetType() != EExtAssetItemType::Creation);
  1318. ThumbnailConfig.bAllowAssetSpecificThumbnailOverlay = false;
  1319. ThumbnailConfig.ThumbnailLabel = InArgs._ThumbnailLabel;
  1320. ThumbnailConfig.HighlightedText = InArgs._HighlightText;
  1321. ThumbnailConfig.HintColorAndOpacity = InArgs._ThumbnailHintColorAndOpacity;
  1322. Thumbnail = AssetThumbnail->MakeThumbnailWidget(ThumbnailConfig);
  1323. }
  1324. else
  1325. {
  1326. Thumbnail = SNew(SImage) .Image( FAppStyle::GetDefaultBrush() );
  1327. }
  1328. FName ItemShadowBorderName;
  1329. TSharedRef<SWidget> ItemContents = FExtAssetViewItemHelper::CreateListItemContents(this, Thumbnail.ToSharedRef(), ItemShadowBorderName);
  1330. ChildSlot
  1331. [
  1332. SNew(SBorder)
  1333. .BorderImage(this, &SExtAssetViewItem::GetBorderImage)
  1334. .Padding(0)
  1335. .AddMetaData<FTagMetaData>(FTagMetaData(AssetItem->GetType() == EExtAssetItemType::Normal ? StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.ObjectPath : NAME_None))
  1336. [
  1337. SNew(SHorizontalBox)
  1338. // Viewport
  1339. +SHorizontalBox::Slot()
  1340. .AutoWidth()
  1341. .VAlign(VAlign_Center)
  1342. [
  1343. SNew( SBox )
  1344. .Padding(ThumbnailPadding - 4.f)
  1345. .WidthOverride( this, &SExtAssetListItem::GetThumbnailBoxSize )
  1346. .HeightOverride( this, &SExtAssetListItem::GetThumbnailBoxSize )
  1347. [
  1348. // Drop shadow border
  1349. SNew(SBorder)
  1350. .Padding(4.f)
  1351. .BorderImage(FAppStyle::GetBrush(ItemShadowBorderName))
  1352. [
  1353. ItemContents
  1354. ]
  1355. ]
  1356. ]
  1357. +SHorizontalBox::Slot()
  1358. .AutoWidth()
  1359. .Padding(6, 0, 0, 0)
  1360. .VAlign(VAlign_Center)
  1361. [
  1362. SNew(SVerticalBox)
  1363. +SVerticalBox::Slot()
  1364. .AutoHeight()
  1365. .Padding(0, 1)
  1366. [
  1367. SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
  1368. .Font(FAppStyle::GetFontStyle("ContentBrowser.AssetTileViewNameFont"))
  1369. .Text( GetNameText() )
  1370. .OnBeginTextEdit(this, &SExtAssetListItem::HandleBeginNameChange)
  1371. .OnTextCommitted(this, &SExtAssetListItem::HandleNameCommitted)
  1372. .OnVerifyTextChanged(this, &SExtAssetListItem::HandleVerifyNameChanged)
  1373. .HighlightText(InArgs._HighlightText)
  1374. .IsSelected(InArgs._IsSelected)
  1375. .IsReadOnly(this, &SExtAssetListItem::IsNameReadOnly)
  1376. ]
  1377. +SVerticalBox::Slot()
  1378. .AutoHeight()
  1379. .Padding(0, 1)
  1380. [
  1381. // Class
  1382. SAssignNew(ClassText, STextBlock)
  1383. .Font(FAppStyle::GetFontStyle("ContentBrowser.AssetListViewClassFont"))
  1384. .Text(GetAssetClassText())
  1385. .HighlightText(InArgs._HighlightText)
  1386. ]
  1387. ]
  1388. ]
  1389. ];
  1390. if(AssetItem.IsValid())
  1391. {
  1392. AssetItem->RenamedRequestEvent.BindSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::EnterEditingMode);
  1393. AssetItem->RenameCanceledEvent.BindSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::ExitEditingMode);
  1394. }
  1395. SetForceMipLevelsToBeResident(true);
  1396. }
  1397. END_SLATE_FUNCTION_BUILD_OPTIMIZATION
  1398. void SExtAssetListItem::OnAssetDataChanged()
  1399. {
  1400. SExtAssetViewItem::OnAssetDataChanged();
  1401. if (ClassText.IsValid())
  1402. {
  1403. ClassText->SetText(GetAssetClassText());
  1404. }
  1405. if (AssetItem->GetType() != EExtAssetItemType::Folder && AssetThumbnail.IsValid())
  1406. {
  1407. AssetThumbnail->SetAsset(StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data);
  1408. }
  1409. }
  1410. float SExtAssetListItem::GetExtraStateIconWidth() const
  1411. {
  1412. return GetStateIconImageSize().Get();
  1413. }
  1414. FOptionalSize SExtAssetListItem::GetExtraStateIconMaxWidth() const
  1415. {
  1416. return GetThumbnailBoxSize().Get() * 0.7;
  1417. }
  1418. FOptionalSize SExtAssetListItem::GetStateIconImageSize() const
  1419. {
  1420. float IconSize = GetThumbnailBoxSize().Get() * 0.3;
  1421. return IconSize > 12 ? IconSize : 12;
  1422. }
  1423. FOptionalSize SExtAssetListItem::GetThumbnailBoxSize() const
  1424. {
  1425. return FOptionalSize( ItemHeight.Get() );
  1426. }
  1427. ///////////////////////////////
  1428. // SExtAssetTileItem
  1429. ///////////////////////////////
  1430. SExtAssetTileItem::~SExtAssetTileItem()
  1431. {
  1432. }
  1433. BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
  1434. void SExtAssetTileItem::Construct( const FArguments& InArgs )
  1435. {
  1436. SExtAssetViewItem::Construct( SExtAssetViewItem::FArguments()
  1437. .AssetItem(InArgs._AssetItem)
  1438. .OnRenameBegin(InArgs._OnRenameBegin)
  1439. .OnRenameCommit(InArgs._OnRenameCommit)
  1440. .OnVerifyRenameCommit(InArgs._OnVerifyRenameCommit)
  1441. .OnItemDestroyed(InArgs._OnItemDestroyed)
  1442. .ShouldAllowToolTip(InArgs._ShouldAllowToolTip)
  1443. .ThumbnailEditMode(InArgs._ThumbnailEditMode)
  1444. .HighlightText(InArgs._HighlightText)
  1445. .OnAssetsOrPathsDragDropped(InArgs._OnAssetsOrPathsDragDropped)
  1446. .OnFilesDragDropped(InArgs._OnFilesDragDropped)
  1447. .OnIsAssetValidForCustomToolTip(InArgs._OnIsAssetValidForCustomToolTip)
  1448. .OnGetCustomAssetToolTip(InArgs._OnGetCustomAssetToolTip)
  1449. .OnVisualizeAssetToolTip(InArgs._OnVisualizeAssetToolTip)
  1450. .OnAssetToolTipClosing( InArgs._OnAssetToolTipClosing )
  1451. );
  1452. AssetThumbnail = InArgs._AssetThumbnail;
  1453. ItemWidth = InArgs._ItemWidth;
  1454. ThumbnailPadding = IsFolder() ? InArgs._ThumbnailPadding + 5.0f : InArgs._ThumbnailPadding;
  1455. TSharedPtr<SWidget> Thumbnail;
  1456. if ( AssetItem.IsValid() && AssetThumbnail.IsValid() )
  1457. {
  1458. FExtAssetThumbnailConfig ThumbnailConfig;
  1459. ThumbnailConfig.bAllowFadeIn = true;
  1460. ThumbnailConfig.bAllowHintText = InArgs._AllowThumbnailHintLabel;
  1461. ThumbnailConfig.bForceGenericThumbnail = (AssetItem->GetType() == EExtAssetItemType::Creation);
  1462. ThumbnailConfig.bAllowAssetSpecificThumbnailOverlay = true;// (AssetItem->GetType() != EAssetItemType::Creation);
  1463. ThumbnailConfig.ThumbnailLabel = InArgs._ThumbnailLabel;
  1464. ThumbnailConfig.HighlightedText = InArgs._HighlightText;
  1465. ThumbnailConfig.HintColorAndOpacity = InArgs._ThumbnailHintColorAndOpacity;
  1466. Thumbnail = AssetThumbnail->MakeThumbnailWidget(ThumbnailConfig);
  1467. }
  1468. else
  1469. {
  1470. Thumbnail = SNew(SImage) .Image( FAppStyle::GetDefaultBrush() );
  1471. }
  1472. FName ItemShadowBorderName;
  1473. TSharedRef<SWidget> ItemContents = FExtAssetViewItemHelper::CreateTileItemContents(this, Thumbnail.ToSharedRef(), ItemShadowBorderName);
  1474. ChildSlot
  1475. [
  1476. SNew(SBorder)
  1477. .BorderImage(this, &SExtAssetViewItem::GetBorderImage)
  1478. .Padding(0)
  1479. .AddMetaData<FTagMetaData>(FTagMetaData((AssetItem->GetType() == EExtAssetItemType::Normal) ? StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.ObjectPath : ((AssetItem->GetType() == EExtAssetItemType::Folder) ? FName(*StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderPath) : NAME_None)))
  1480. [
  1481. SNew(SVerticalBox)
  1482. // Thumbnail
  1483. +SVerticalBox::Slot()
  1484. .AutoHeight()
  1485. .HAlign(HAlign_Center)
  1486. [
  1487. // The remainder of the space is reserved for the name.
  1488. SNew(SBox)
  1489. .Padding(ThumbnailPadding - 4.f)
  1490. .WidthOverride(this, &SExtAssetTileItem::GetThumbnailBoxSize)
  1491. .HeightOverride( this, &SExtAssetTileItem::GetThumbnailBoxSize )
  1492. [
  1493. // Drop shadow border
  1494. SNew(SBorder)
  1495. .Padding(4.f)
  1496. .BorderImage(FAppStyle::GetBrush(ItemShadowBorderName))
  1497. [
  1498. ItemContents
  1499. ]
  1500. ]
  1501. ]
  1502. +SVerticalBox::Slot()
  1503. .Padding(FMargin(1.f, 0))
  1504. .HAlign(HAlign_Center)
  1505. .VAlign(VAlign_Center)
  1506. .FillHeight(1.f)
  1507. [
  1508. SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
  1509. .Font( this, &SExtAssetTileItem::GetThumbnailFont )
  1510. .Text( GetNameText() )
  1511. .OnBeginTextEdit(this, &SExtAssetTileItem::HandleBeginNameChange)
  1512. .OnTextCommitted(this, &SExtAssetTileItem::HandleNameCommitted)
  1513. .OnVerifyTextChanged(this, &SExtAssetTileItem::HandleVerifyNameChanged)
  1514. .HighlightText(InArgs._HighlightText)
  1515. .IsSelected(InArgs._IsSelected)
  1516. .IsReadOnly(this, &SExtAssetTileItem::IsNameReadOnly)
  1517. .Justification(ETextJustify::Center)
  1518. .LineBreakPolicy(FBreakIterator::CreateCamelCaseBreakIterator())
  1519. ]
  1520. ]
  1521. ];
  1522. if(AssetItem.IsValid())
  1523. {
  1524. AssetItem->RenamedRequestEvent.BindSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::EnterEditingMode);
  1525. AssetItem->RenameCanceledEvent.BindSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::ExitEditingMode);
  1526. }
  1527. SetForceMipLevelsToBeResident(true);
  1528. }
  1529. END_SLATE_FUNCTION_BUILD_OPTIMIZATION
  1530. void SExtAssetTileItem::OnAssetDataChanged()
  1531. {
  1532. SExtAssetViewItem::OnAssetDataChanged();
  1533. if (AssetItem->GetType() != EExtAssetItemType::Folder && AssetThumbnail.IsValid())
  1534. {
  1535. AssetThumbnail->SetAsset(StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data);
  1536. }
  1537. }
  1538. float SExtAssetTileItem::GetExtraStateIconWidth() const
  1539. {
  1540. return GetStateIconImageSize().Get();
  1541. }
  1542. FOptionalSize SExtAssetTileItem::GetExtraStateIconMaxWidth() const
  1543. {
  1544. return GetThumbnailBoxSize().Get() * 0.8;
  1545. }
  1546. FOptionalSize SExtAssetTileItem::GetStateIconImageSize() const
  1547. {
  1548. float IconSize = GetThumbnailBoxSize().Get() * 0.2;
  1549. return IconSize > 12 ? IconSize : 12;
  1550. }
  1551. FOptionalSize SExtAssetTileItem::GetThumbnailBoxSize() const
  1552. {
  1553. return FOptionalSize(ItemWidth.Get());
  1554. }
  1555. FSlateFontInfo SExtAssetTileItem::GetThumbnailFont() const
  1556. {
  1557. FOptionalSize ThumbSize = GetThumbnailBoxSize();
  1558. if ( ThumbSize.IsSet() )
  1559. {
  1560. float Size = ThumbSize.Get();
  1561. if ( Size < 50 )
  1562. {
  1563. const static FName SmallFontName("ContentBrowser.AssetTileViewNameFontVerySmall");
  1564. return FAppStyle::GetFontStyle(SmallFontName);
  1565. }
  1566. else if ( Size < 85 )
  1567. {
  1568. const static FName SmallFontName("ContentBrowser.AssetTileViewNameFontSmall");
  1569. return FAppStyle::GetFontStyle(SmallFontName);
  1570. }
  1571. }
  1572. const static FName RegularFont("ContentBrowser.AssetTileViewNameFont");
  1573. return FAppStyle::GetFontStyle(RegularFont);
  1574. }
  1575. ///////////////////////////////
  1576. // SAssetColumnItem
  1577. ///////////////////////////////
  1578. /** Custom box for the Name column of an asset */
  1579. class SAssetColumnItemNameBox : public SCompoundWidget
  1580. {
  1581. public:
  1582. SLATE_BEGIN_ARGS( SAssetColumnItemNameBox ) {}
  1583. /** The color of the asset */
  1584. SLATE_ATTRIBUTE( FMargin, Padding )
  1585. /** The widget content presented in the box */
  1586. SLATE_DEFAULT_SLOT(FArguments, Content)
  1587. SLATE_END_ARGS()
  1588. ~SAssetColumnItemNameBox() {}
  1589. void Construct( const FArguments& InArgs, const TSharedRef<SExtAssetColumnItem>& InOwnerAssetColumnItem )
  1590. {
  1591. OwnerAssetColumnItem = InOwnerAssetColumnItem;
  1592. ChildSlot
  1593. [
  1594. SNew(SBox)
  1595. .Padding(InArgs._Padding)
  1596. [
  1597. InArgs._Content.Widget
  1598. ]
  1599. ];
  1600. }
  1601. virtual TSharedPtr<IToolTip> GetToolTip() override
  1602. {
  1603. if ( OwnerAssetColumnItem.IsValid() )
  1604. {
  1605. return OwnerAssetColumnItem.Pin()->GetToolTip();
  1606. }
  1607. return nullptr;
  1608. }
  1609. /** Forward the event to the view item that this name box belongs to */
  1610. virtual void OnToolTipClosing() override
  1611. {
  1612. if ( OwnerAssetColumnItem.IsValid() )
  1613. {
  1614. OwnerAssetColumnItem.Pin()->OnToolTipClosing();
  1615. }
  1616. }
  1617. private:
  1618. TWeakPtr<SExtAssetViewItem> OwnerAssetColumnItem;
  1619. };
  1620. void SExtAssetColumnItem::Construct( const FArguments& InArgs )
  1621. {
  1622. SExtAssetViewItem::Construct( SExtAssetViewItem::FArguments()
  1623. .AssetItem(InArgs._AssetItem)
  1624. .OnRenameBegin(InArgs._OnRenameBegin)
  1625. .OnRenameCommit(InArgs._OnRenameCommit)
  1626. .OnVerifyRenameCommit(InArgs._OnVerifyRenameCommit)
  1627. .OnItemDestroyed(InArgs._OnItemDestroyed)
  1628. .HighlightText(InArgs._HighlightText)
  1629. .OnAssetsOrPathsDragDropped(InArgs._OnAssetsOrPathsDragDropped)
  1630. .OnFilesDragDropped(InArgs._OnFilesDragDropped)
  1631. .OnIsAssetValidForCustomToolTip(InArgs._OnIsAssetValidForCustomToolTip)
  1632. .OnGetCustomAssetToolTip(InArgs._OnGetCustomAssetToolTip)
  1633. .OnVisualizeAssetToolTip(InArgs._OnVisualizeAssetToolTip)
  1634. .OnAssetToolTipClosing(InArgs._OnAssetToolTipClosing)
  1635. );
  1636. HighlightText = InArgs._HighlightText;
  1637. }
  1638. BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
  1639. TSharedRef<SWidget> SExtAssetColumnItem::GenerateWidgetForColumn( const FName& ColumnName, FIsSelected InIsSelected )
  1640. {
  1641. TSharedPtr<SWidget> Content;
  1642. // A little right padding so text from this column does not run directly into text from the next.
  1643. static const FMargin ColumnItemPadding( 5, 0, 5, 0 );
  1644. if ( ColumnName == "Name" )
  1645. {
  1646. const FSlateBrush* IconBrush;
  1647. if(IsFolder())
  1648. {
  1649. IconBrush = FAppStyle::GetBrush("ContentBrowser.ColumnViewFolderIcon");
  1650. }
  1651. else
  1652. {
  1653. IconBrush = FAppStyle::GetBrush("ContentBrowser.ColumnViewAssetIcon");
  1654. }
  1655. // Make icon overlays (eg, SCC and dirty status) a reasonable size in relation to the icon size (note: it is assumed this icon is square)
  1656. const float IconOverlaySize = IconBrush->ImageSize.X * 0.6f;
  1657. Content = SNew(SHorizontalBox)
  1658. .AddMetaData<FTagMetaData>(FTagMetaData(AssetItem->GetType() == EExtAssetItemType::Normal ? StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.ObjectPath : NAME_None))
  1659. // Icon
  1660. +SHorizontalBox::Slot()
  1661. .AutoWidth()
  1662. .Padding(0, 0, 4, 0)
  1663. [
  1664. SNew(SOverlay)
  1665. // The actual icon
  1666. +SOverlay::Slot()
  1667. [
  1668. SNew(SImage)
  1669. .Image( IconBrush )
  1670. .ColorAndOpacity(this, &SExtAssetColumnItem::GetAssetColor)
  1671. ]
  1672. // Source control state
  1673. +SOverlay::Slot()
  1674. .HAlign(HAlign_Right)
  1675. .VAlign(VAlign_Top)
  1676. [
  1677. SNew(SBox)
  1678. .WidthOverride(IconOverlaySize)
  1679. .HeightOverride(IconOverlaySize)
  1680. [
  1681. SAssignNew(SCCStateWidget, SLayeredImage)
  1682. .Image(FStyleDefaults::GetNoBrush())
  1683. ]
  1684. ]
  1685. // Extra external state hook
  1686. + SOverlay::Slot()
  1687. .HAlign(HAlign_Left)
  1688. .VAlign(VAlign_Top)
  1689. [
  1690. SNew(SBox)
  1691. .HeightOverride(IconOverlaySize)
  1692. .MaxDesiredWidth(IconOverlaySize)
  1693. [
  1694. GenerateExtraStateIconWidget(IconOverlaySize)
  1695. ]
  1696. ]
  1697. // Dirty state
  1698. +SOverlay::Slot()
  1699. .HAlign(HAlign_Left)
  1700. .VAlign(VAlign_Bottom)
  1701. [
  1702. SNew(SBox)
  1703. .WidthOverride(IconOverlaySize)
  1704. .HeightOverride(IconOverlaySize)
  1705. [
  1706. SNew(SImage)
  1707. .Image(this, &SExtAssetColumnItem::GetDirtyImage)
  1708. ]
  1709. ]
  1710. ]
  1711. // Editable Name
  1712. +SHorizontalBox::Slot()
  1713. .AutoWidth()
  1714. [
  1715. SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
  1716. .Text( GetNameText() )
  1717. .OnBeginTextEdit(this, &SExtAssetColumnItem::HandleBeginNameChange)
  1718. .OnTextCommitted(this, &SExtAssetColumnItem::HandleNameCommitted)
  1719. .OnVerifyTextChanged(this, &SExtAssetColumnItem::HandleVerifyNameChanged)
  1720. .HighlightText(HighlightText)
  1721. .IsSelected(InIsSelected)
  1722. .IsReadOnly(this, &SExtAssetColumnItem::IsNameReadOnly)
  1723. ];
  1724. if(AssetItem.IsValid())
  1725. {
  1726. AssetItem->RenamedRequestEvent.BindSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::EnterEditingMode);
  1727. AssetItem->RenameCanceledEvent.BindSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::ExitEditingMode);
  1728. }
  1729. return SNew(SBorder)
  1730. .BorderImage(this, &SExtAssetViewItem::GetBorderImage)
  1731. .Padding(0)
  1732. .VAlign(VAlign_Center)
  1733. .HAlign(HAlign_Left)
  1734. [
  1735. SNew( SAssetColumnItemNameBox, SharedThis(this) )
  1736. .Padding( ColumnItemPadding )
  1737. [
  1738. Content.ToSharedRef()
  1739. ]
  1740. ];
  1741. }
  1742. else if ( ColumnName == "Class" )
  1743. {
  1744. Content = SAssignNew(ClassText, STextBlock)
  1745. .ToolTipText( this, &SExtAssetColumnItem::GetAssetClassText )
  1746. .Text( GetAssetClassText() )
  1747. .HighlightText( HighlightText );
  1748. }
  1749. else if ( ColumnName == "Path" )
  1750. {
  1751. Content = SAssignNew(PathText, STextBlock)
  1752. .ToolTipText( this, &SExtAssetColumnItem::GetAssetPathText )
  1753. .Text( GetAssetPathText() )
  1754. .HighlightText( HighlightText );
  1755. }
  1756. else
  1757. {
  1758. Content = SNew(STextBlock)
  1759. .ToolTipText( TAttribute<FText>::Create( TAttribute<FText>::FGetter::CreateSP(this, &SExtAssetColumnItem::GetAssetTagText, ColumnName) ) )
  1760. .Text( TAttribute<FText>::Create( TAttribute<FText>::FGetter::CreateSP(this, &SExtAssetColumnItem::GetAssetTagText, ColumnName) ) );
  1761. }
  1762. return SNew(SBox)
  1763. .Padding( ColumnItemPadding )
  1764. .VAlign(VAlign_Center)
  1765. .HAlign(HAlign_Left)
  1766. [
  1767. Content.ToSharedRef()
  1768. ];
  1769. }
  1770. END_SLATE_FUNCTION_BUILD_OPTIMIZATION
  1771. void SExtAssetColumnItem::OnAssetDataChanged()
  1772. {
  1773. SExtAssetViewItem::OnAssetDataChanged();
  1774. if ( ClassText.IsValid() )
  1775. {
  1776. ClassText->SetText( GetAssetClassText() );
  1777. }
  1778. if ( PathText.IsValid() )
  1779. {
  1780. PathText->SetText( GetAssetPathText() );
  1781. }
  1782. }
  1783. FString SExtAssetColumnItem::GetAssetNameToolTipText() const
  1784. {
  1785. if ( AssetItem.IsValid() )
  1786. {
  1787. if(AssetItem->GetType() == EExtAssetItemType::Folder)
  1788. {
  1789. FString Result = StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderName.ToString();
  1790. Result += TEXT("\n");
  1791. Result += LOCTEXT("FolderName", "Folder").ToString();
  1792. return Result;
  1793. }
  1794. else
  1795. {
  1796. const FString AssetName = StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.AssetName.ToString();
  1797. const FString AssetType = StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.AssetClass.ToString();
  1798. FString Result = AssetName;
  1799. Result += TEXT("\n");
  1800. Result += AssetType;
  1801. return Result;
  1802. }
  1803. }
  1804. else
  1805. {
  1806. return FString();
  1807. }
  1808. }
  1809. FText SExtAssetColumnItem::GetAssetPathText() const
  1810. {
  1811. if ( AssetItem.IsValid() )
  1812. {
  1813. if(AssetItem->GetType() != EExtAssetItemType::Folder)
  1814. {
  1815. return FText::FromName(StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem)->Data.PackageFilePath);
  1816. }
  1817. else
  1818. {
  1819. return FText::FromString(StaticCastSharedPtr<FExtAssetViewFolder>(AssetItem)->FolderPath);
  1820. }
  1821. }
  1822. else
  1823. {
  1824. return FText();
  1825. }
  1826. }
  1827. FText SExtAssetColumnItem::GetAssetTagText(FName AssetTag) const
  1828. {
  1829. if ( AssetItem.IsValid() )
  1830. {
  1831. if(AssetItem->GetType() != EExtAssetItemType::Folder)
  1832. {
  1833. const TSharedPtr<FExtAssetViewAsset>& ItemAsAsset = StaticCastSharedPtr<FExtAssetViewAsset>(AssetItem);
  1834. // Check custom type
  1835. {
  1836. FText* FoundText = ItemAsAsset->CustomColumnDisplayText.Find(AssetTag);
  1837. if (FoundText)
  1838. {
  1839. return *FoundText;
  1840. }
  1841. }
  1842. // Check display tags
  1843. {
  1844. const FTagDisplayItem* FoundTagItem = CachedDisplayTags.FindByPredicate([AssetTag](const FTagDisplayItem& TagItem)
  1845. {
  1846. return TagItem.TagKey == AssetTag;
  1847. });
  1848. if (FoundTagItem)
  1849. {
  1850. return FoundTagItem->DisplayValue;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. return FText();
  1856. }
  1857. #undef LOCTEXT_NAMESPACE