void UpdateThumbnailClass(const FName& InAssetName, UClass* InAssetClass) { ThumbnailClass = InAssetClass; bIsClassType = false; if( InAssetClass == UClass::StaticClass() ) { ThumbnailClass = FindObject<UClass>(ANY_PACKAGE, *InAssetName.ToString()); bIsClassType = true; } else if( InAssetClass == UBlueprint::StaticClass() ) { static const FName NativeParentClassTag = "NativeParentClass"; static const FName ParentClassTag = "ParentClass"; // We need to use the asset data to get the parent class as the blueprint may not be loaded const FAssetData& AssetData = AssetThumbnail->GetAssetData(); const FString* ParentClassNamePtr = AssetData.TagsAndValues.Find(NativeParentClassTag); if(!ParentClassNamePtr) { ParentClassNamePtr = AssetData.TagsAndValues.Find(ParentClassTag); } if(ParentClassNamePtr && !ParentClassNamePtr->IsEmpty()) { UObject* Outer = nullptr; FString ParentClassName = *ParentClassNamePtr; ResolveName(Outer, ParentClassName, false, false); ThumbnailClass = FindObject<UClass>(ANY_PACKAGE, *ParentClassName); } bIsClassType = true; } }
/** Constructs this widget with InArgs */ void Construct( const FArguments& InArgs ) { Style = InArgs._Style; HighlightedText = InArgs._HighlightedText; Label = InArgs._Label; HintColorAndOpacity = InArgs._HintColorAndOpacity; AllowHintText = InArgs._AllowHintText; ShowClassBackground = InArgs._ShowClassBackground; AssetThumbnail = InArgs._AssetThumbnail; bHasRenderedThumbnail = false; WidthLastFrame = 0; GenericThumbnailBorderPadding = 2.f; AssetThumbnail->OnAssetDataChanged().AddSP(this, &SAssetThumbnail::OnAssetDataChanged); const FAssetData& AssetData = AssetThumbnail->GetAssetData(); UClass* Class = FindObject<UClass>(ANY_PACKAGE, *AssetData.AssetClass.ToString()); FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools")); TWeakPtr<IAssetTypeActions> AssetTypeActions; if ( Class != NULL ) { AssetTypeActions = AssetToolsModule.Get().GetAssetTypeActionsForClass(Class); } AssetColor = FLinearColor::White; if ( AssetTypeActions.IsValid() ) { AssetColor = AssetTypeActions.Pin()->GetTypeColor(); } TSharedRef<SOverlay> OverlayWidget = SNew(SOverlay); FName Substyle; if ( Class == UClass::StaticClass() ) { Substyle = FName(".ClassBackground"); ClassAssetClass = FindObject<UClass>(ANY_PACKAGE, *AssetData.AssetName.ToString()); } else if(AssetTypeActions.IsValid()) { Substyle = FName(".AssetBackground"); } const FName BackgroundBrushName( *(Style.ToString() + Substyle.ToString()) ); ClassThumbnailBrushOverride = InArgs._ClassThumbnailBrushOverride; OverlayWidget->AddSlot() [ SNew(SBorder) .BorderImage( this, &SAssetThumbnail::GetBackgroundBrush ) .BorderBackgroundColor( this, &SAssetThumbnail::GetAssetColor ) .Padding( GenericThumbnailBorderPadding ) .VAlign(VAlign_Center) .HAlign(HAlign_Center) .Visibility(this, &SAssetThumbnail::GetClassThumbnailVisibility) [ SNew( SImage ) .Image( this, &SAssetThumbnail::GetClassThumbnailBrush ) ] ]; // The generic representation of the thumbnail, for use before the rendered version, if it exists OverlayWidget->AddSlot() [ SNew(SBorder) .BorderImage( this, &SAssetThumbnail::GetBackgroundBrush ) .BorderBackgroundColor( this, &SAssetThumbnail::GetAssetColor ) .Padding( GenericThumbnailBorderPadding ) .VAlign(VAlign_Center) .HAlign(HAlign_Center) .Visibility(this, &SAssetThumbnail::GetGenericThumbnailVisibility) [ SAssignNew(LabelTextBlock, STextBlock) .Text( GetLabelText() ) .Font( GetTextFont() ) .ColorAndOpacity( FEditorStyle::GetColor(Style, ".ColorAndOpacity") ) .ShadowOffset( FEditorStyle::GetVector(Style, ".ShadowOffset") ) .ShadowColorAndOpacity( FEditorStyle::GetColor(Style, ".ShadowColorAndOpacity") ) .WrapTextAt(this, &SAssetThumbnail::GetTextWrapWidth) .HighlightText( HighlightedText ) ] ]; if ( InArgs._ThumbnailPool.IsValid() && !InArgs._ForceGenericThumbnail && Class != UClass::StaticClass() ) { ViewportFadeAnimation = FCurveSequence(); ViewportFadeCurve = ViewportFadeAnimation.AddCurve(0.f, 0.25f, ECurveEaseFunction::QuadOut); TSharedPtr<SViewport> Viewport = SNew( SViewport ) .EnableGammaCorrection(false); Viewport->SetViewportInterface( AssetThumbnail.ToSharedRef() ); AssetThumbnail->GetViewportRenderTargetTexture(); // Access the render texture to push it on the stack if it isnt already rendered InArgs._ThumbnailPool->OnThumbnailRendered().AddSP(this, &SAssetThumbnail::OnThumbnailRendered); InArgs._ThumbnailPool->OnThumbnailRenderFailed().AddSP(this, &SAssetThumbnail::OnThumbnailRenderFailed); if ( ShouldRender() && (!InArgs._AllowFadeIn || InArgs._ThumbnailPool->IsRendered(AssetThumbnail)) ) { bHasRenderedThumbnail = true; ViewportFadeAnimation.JumpToEnd(); } // The viewport for the rendered thumbnail, if it exists OverlayWidget->AddSlot() [ SNew(SBorder) .Padding(0) .BorderImage(FEditorStyle::GetBrush("NoBrush")) .ColorAndOpacity(this, &SAssetThumbnail::GetViewportColorAndOpacity) .Visibility(this, &SAssetThumbnail::GetViewportVisibility) [ Viewport.ToSharedRef() ] ]; } OverlayWidget->AddSlot() .HAlign( HAlign_Center ) .VAlign( VAlign_Top ) .Padding(FMargin(2,2,2,2)) [ SNew(SBorder) .BorderImage( FEditorStyle::GetBrush( Style, ".HintBackground" ) ) .BorderBackgroundColor( this, &SAssetThumbnail::GetHintBackgroundColor) //Adjust the opacity of the border itself .ColorAndOpacity( HintColorAndOpacity ) //adjusts the opacity of the contents of the border .Visibility( this, &SAssetThumbnail::GetHintTextVisibility ) .Padding(0) [ SAssignNew( HintTextBlock, STextBlock ) .Text( GetLabelText() ) .Font( GetHintTextFont() ) .ColorAndOpacity( FEditorStyle::GetColor( Style, ".HintColorAndOpacity" ) ) .ShadowOffset( FEditorStyle::GetVector( Style, ".HintShadowOffset" ) ) .ShadowColorAndOpacity( FEditorStyle::GetColor( Style, ".HintShadowColorAndOpacity" ) ) .WrapTextAt(this, &SAssetThumbnail::GetTextWrapWidth) .HighlightText( HighlightedText ) ] ]; // The asset color strip, only visible when the rendered viewport is OverlayWidget->AddSlot() .HAlign(HAlign_Fill) .VAlign(VAlign_Bottom) [ SNew(SBorder) .BorderImage(FEditorStyle::GetBrush("WhiteBrush")) .BorderBackgroundColor(AssetColor) .Visibility(this, &SAssetThumbnail::GetViewportVisibility) .Padding(this, &SAssetThumbnail::GetAssetColorStripPadding) ]; ChildSlot [ OverlayWidget ]; }
/** Constructs this widget with InArgs */ void Construct( const FArguments& InArgs ) { Style = InArgs._Style; HighlightedText = InArgs._HighlightedText; Label = InArgs._Label; HintColorAndOpacity = InArgs._HintColorAndOpacity; bAllowHintText = InArgs._AllowHintText; AssetThumbnail = InArgs._AssetThumbnail; bHasRenderedThumbnail = false; WidthLastFrame = 0; GenericThumbnailBorderPadding = 2.f; AssetThumbnail->OnAssetDataChanged().AddSP(this, &SAssetThumbnail::OnAssetDataChanged); const FAssetData& AssetData = AssetThumbnail->GetAssetData(); UClass* Class = FindObject<UClass>(ANY_PACKAGE, *AssetData.AssetClass.ToString()); FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools")); TSharedPtr<IAssetTypeActions> AssetTypeActions; if ( Class != NULL ) { AssetTypeActions = AssetToolsModule.Get().GetAssetTypeActionsForClass(Class).Pin(); } AssetColor = FLinearColor::White; if( InArgs._AssetTypeColorOverride.IsSet() ) { AssetColor = InArgs._AssetTypeColorOverride.GetValue(); } else if ( AssetTypeActions.IsValid() ) { AssetColor = AssetTypeActions->GetTypeColor(); } TSharedRef<SOverlay> OverlayWidget = SNew(SOverlay); UpdateThumbnailClass(AssetData.AssetName, Class); ClassThumbnailBrushOverride = InArgs._ClassThumbnailBrushOverride; // The generic representation of the thumbnail, for use before the rendered version, if it exists OverlayWidget->AddSlot() [ SNew(SBorder) .BorderImage(GetAssetBackgroundBrush()) .BorderBackgroundColor(AssetColor.CopyWithNewOpacity(0.3f)) .Padding(GenericThumbnailBorderPadding) .VAlign(VAlign_Center) .HAlign(HAlign_Center) .Visibility(this, &SAssetThumbnail::GetGenericThumbnailVisibility) [ SNew(SOverlay) +SOverlay::Slot() [ SAssignNew(GenericLabelTextBlock, STextBlock) .Text(GetLabelText()) .Font(GetTextFont()) .Justification(ETextJustify::Center) .ColorAndOpacity(FEditorStyle::GetColor(Style, ".ColorAndOpacity")) .ShadowOffset(FEditorStyle::GetVector(Style, ".ShadowOffset")) .ShadowColorAndOpacity( FEditorStyle::GetColor(Style, ".ShadowColorAndOpacity")) .HighlightText(HighlightedText) ] +SOverlay::Slot() [ SAssignNew(GenericThumbnailImage, SImage) .Image(this, &SAssetThumbnail::GetClassThumbnailBrush) ] ] ]; if ( InArgs._ThumbnailPool.IsValid() && !InArgs._ForceGenericThumbnail ) { ViewportFadeAnimation = FCurveSequence(); ViewportFadeCurve = ViewportFadeAnimation.AddCurve(0.f, 0.25f, ECurveEaseFunction::QuadOut); TSharedPtr<SViewport> Viewport = SNew( SViewport ) .EnableGammaCorrection(false); Viewport->SetViewportInterface( AssetThumbnail.ToSharedRef() ); AssetThumbnail->GetViewportRenderTargetTexture(); // Access the render texture to push it on the stack if it isnt already rendered InArgs._ThumbnailPool->OnThumbnailRendered().AddSP(this, &SAssetThumbnail::OnThumbnailRendered); InArgs._ThumbnailPool->OnThumbnailRenderFailed().AddSP(this, &SAssetThumbnail::OnThumbnailRenderFailed); if ( ShouldRender() && (!InArgs._AllowFadeIn || InArgs._ThumbnailPool->IsRendered(AssetThumbnail)) ) { bHasRenderedThumbnail = true; ViewportFadeAnimation.JumpToEnd(); } // The viewport for the rendered thumbnail, if it exists OverlayWidget->AddSlot() [ SAssignNew(RenderedThumbnailWidget, SBorder) .Padding(0) .BorderImage(FEditorStyle::GetBrush("NoBrush")) .ColorAndOpacity(this, &SAssetThumbnail::GetViewportColorAndOpacity) [ Viewport.ToSharedRef() ] ]; } if( ThumbnailClass.Get() && bIsClassType ) { OverlayWidget->AddSlot() .VAlign(VAlign_Bottom) .HAlign(HAlign_Right) .Padding(TAttribute<FMargin>(this, &SAssetThumbnail::GetClassIconPadding)) [ SAssignNew(ClassIconWidget, SBorder) .BorderImage(FEditorStyle::GetNoBrush()) [ SNew(SImage) .Image(this, &SAssetThumbnail::GetClassIconBrush) ] ]; } if( bAllowHintText ) { OverlayWidget->AddSlot() .HAlign(HAlign_Center) .VAlign(VAlign_Top) .Padding(FMargin(2, 2, 2, 2)) [ SNew(SBorder) .BorderImage(FEditorStyle::GetBrush(Style, ".HintBackground")) .BorderBackgroundColor(this, &SAssetThumbnail::GetHintBackgroundColor) //Adjust the opacity of the border itself .ColorAndOpacity(HintColorAndOpacity) //adjusts the opacity of the contents of the border .Visibility(this, &SAssetThumbnail::GetHintTextVisibility) .Padding(0) [ SAssignNew(HintTextBlock, STextBlock) .Text(GetLabelText()) .Font(GetHintTextFont()) .ColorAndOpacity(FEditorStyle::GetColor(Style, ".HintColorAndOpacity")) .ShadowOffset(FEditorStyle::GetVector(Style, ".HintShadowOffset")) .ShadowColorAndOpacity(FEditorStyle::GetColor(Style, ".HintShadowColorAndOpacity")) .HighlightText(HighlightedText) ] ]; } // The asset color strip OverlayWidget->AddSlot() .HAlign(HAlign_Fill) .VAlign(VAlign_Bottom) [ SAssignNew(AssetColorStripWidget, SBorder) .BorderImage(FEditorStyle::GetBrush("WhiteBrush")) .BorderBackgroundColor(AssetColor) .Padding(this, &SAssetThumbnail::GetAssetColorStripPadding) ]; if( InArgs._AllowAssetSpecificThumbnailOverlay && AssetTypeActions.IsValid() ) { // Does the asset provide an additional thumbnail overlay? TSharedPtr<SWidget> AssetSpecificThumbnailOverlay = AssetTypeActions->GetThumbnailOverlay(AssetData); if( AssetSpecificThumbnailOverlay.IsValid() ) { OverlayWidget->AddSlot() [ AssetSpecificThumbnailOverlay.ToSharedRef() ]; } } ChildSlot [ OverlayWidget ]; UpdateThumbnailVisibilities(); }
void UpdateThumbnailClass() { const FAssetData& AssetData = AssetThumbnail->GetAssetData(); ThumbnailClass = FClassIconFinder::GetIconClassForAssetData(AssetData, &bIsClassType); }