// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "WidgetBlueprintEditor.h" #include "WidgetBlueprint.h" #include "WidgetReference.h" class FDragDropOperation; class FHittestGrid; class FMenuBuilder; class UWidgetBlueprint; class UWidgetSlotPair; class UWidgetTree; class SWindow; class UWidgetEditingProjectSettings; class FWidgetObjectTextFactory; class ULocalPlayer; ////////////////////////////////////////////////////////////////////////// // FWidgetBlueprintEditorUtils class UMGEDITOR_API FWidgetBlueprintEditorUtils { public: struct FWidgetThumbnailProperties { FVector2D ScaledSize; FVector2D Offset; }; struct FCreateWidgetFromBlueprintParams { EWidgetDesignFlags FlagsToApply; ULocalPlayer* LocalPlayer = nullptr; // Optionally specify if available }; static bool VerifyWidgetRename(TSharedRef BlueprintEditor, FWidgetReference Widget, const FText& NewName, FText& OutErrorMessage); static bool RenameWidget(TSharedRef BlueprintEditor, const FName& OldObjectName, const FString& NewDisplayName); static void ReplaceDesiredFocus(TSharedRef BlueprintEditor, const FName& OldName, const FName& NewName); static void ReplaceDesiredFocus(UWidgetBlueprint* Blueprint, const FName& OldName, const FName& NewName); static void SetDesiredFocus(TSharedRef BlueprintEditor, const FName DesiredFocusWidgetName); static void SetDesiredFocus(UWidgetBlueprint* Blueprint, const FName& DesiredFocusWidgetName); static void CreateWidgetContextMenu(FMenuBuilder& MenuBuilder, TSharedRef BlueprintEditor, FVector2D TargetLocation); static void CopyWidgets(UWidgetBlueprint* BP, TSet Widgets); static TArray PasteWidgets(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, FWidgetReference ParentWidget, FName SlotName, FVector2D PasteLocation); enum class EReplaceWidgetNamingMethod { // Will give the new widget the same name as the replaced widget if the widget classes are compatible // If it's using a generated name, the new generated name will be used and FBlueprintEditorUtils::ReplaceVariableReferences will be called MaintainNameAndReferences, // Same as MaintainNameAndReferences but doesn't check for matching classes or generated names MaintainNameAndReferencesForUnmatchingClass, // Will use the new widget's generated name and not make an effort to maintain references UseNewGeneratedName }; static void ReplaceWidgets(UWidgetBlueprint* BP, TSet Widgets, UClass* WidgetClass, EReplaceWidgetNamingMethod NewWidgetNamingMethod); UE_DEPRECATED(5.6, "FWidgetBlueprintEditorUtils::DeleteWidgets no longer takes in the BlueprintEditor, use the version without it instead") static void DeleteWidgets(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, TSet Widgets, bool bSilentDelete = false); enum class EDeleteWidgetWarningType { // If the widget being deleted is referenced in the graph, ask the user if the deletion should continue WarnAndAskUser, // Don't notify the user at all and delete the widget even if it is referenced DeleteSilently, }; static void DeleteWidgets(UWidgetBlueprint* BP, TSet Widgets, EDeleteWidgetWarningType WarningType); static void CutWidgets(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, TSet Widgets); static TArray DuplicateWidgets(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, TSet Widgets); static UUserWidget* CreateUserWidgetFromBlueprint(UObject* Outer, UWidgetBlueprint* BP, const FCreateWidgetFromBlueprintParams& Params); /** Performs cleanup on the specified UserWidget. */ static void DestroyUserWidget(UUserWidget* UserWidget); static bool IsAnySelectedWidgetLocked(TSet SelectedWidgets); static bool CanPasteWidgetsExtension(TSet SelectedWidgets); static UWidget* GetWidgetTemplateFromDragDrop(UWidgetBlueprint* Blueprint, UWidgetTree* RootWidgetTree, TSharedPtr& DragDropOp); static bool ShouldPreventDropOnTargetExtensions(const UWidget* Target, const TSharedPtr& DragDropOp, FText& OutFailureText); static bool IsBindWidgetProperty(const FProperty* InProperty); static bool IsBindWidgetProperty(const FProperty* InProperty, bool& bIsOptional); static bool IsBindWidgetAnimProperty(const FProperty* InProperty); static bool IsBindWidgetAnimProperty(const FProperty* InProperty, bool& bIsOptional); struct FUsableWidgetClassResult { const UClass* NativeParentClass = nullptr; EClassFlags AssetClassFlags = EClassFlags::CLASS_None; }; UE_DEPRECATED(5.3, "This function has been deprecated. Use the version of IsUsableWidgetClass that takes a second argument of TSharedRef.") static bool IsUsableWidgetClass(const UClass* WidgetClass); UE_DEPRECATED(5.3, "This function has been deprecated. Use the version of IsUsableWidgetClass that takes a second argument of TSharedRef.") static TValueOrError IsUsableWidgetClass(const FAssetData& WidgetAsset); static bool IsUsableWidgetClass(const UClass* WidgetClass, TSharedRef InCurrentActiveBlueprintEditor); static TValueOrError IsUsableWidgetClass(const FAssetData& WidgetAsset, TSharedRef InCurrentActiveBlueprintEditor); static void ExportWidgetsToText(TArray WidgetsToExport, /*out*/ FString& ExportedText); static void ImportWidgetsFromText(UWidgetBlueprint* BP, const FString& TextToImport, /*out*/ TSet& ImportedWidgetSet, /*out*/ TMap& PastedExtraSlotData); /** Exports the individual properties of an object to text and stores them in a map. */ static void ExportPropertiesToText(UObject* Object, TMap& ExportedProperties); /** Attempts to import any property in the map and apply it to a property with the same name on the object. */ static void ImportPropertiesFromText(UObject* Object, const TMap& ExportedProperties); static bool DoesClipboardTextContainWidget(UWidgetBlueprint* BP); static TScriptInterface FindNamedSlotHostForContent(UWidget* WidgetTemplate, UWidgetTree* WidgetTree); static UWidget* FindNamedSlotHostWidgetForContent(UWidget* WidgetTemplate, UWidgetTree* WidgetTree); static void FindAllAncestorNamedSlotHostWidgetsForContent(TArray& OutSlotHostWidgets, UWidget* WidgetTemplate, TSharedRef BlueprintEditor); static bool RemoveNamedSlotHostContent(UWidget* WidgetTemplate, TScriptInterface NamedSlotHost); static bool ReplaceNamedSlotHostContent(UWidget* WidgetTemplate, TScriptInterface NamedSlotHost, UWidget* NewContentWidget); static UWidgetTree* FindLatestWidgetTree(UWidgetBlueprint* Blueprint, UUserWidget* UserWidget); static int32 UpdateHittestGrid(FHittestGrid& HitTestGrid, TSharedRef Window, float Scale, FVector2D DrawSize, float DeltaTime); static TTuple GetWidgetPreviewAreaAndSize(UUserWidget* UserWidget, FVector2D DesiredSize, FVector2D PreviewSize, EDesignPreviewSizeMode ThumbnailSizeMode, TOptional ThumbnailCustomSize); static float GetWidgetPreviewDPIScale(UUserWidget* UserWidget, FVector2D PreviewSize); static EDesignPreviewSizeMode ConvertThumbnailSizeModeToDesignerSizeMode(EThumbnailPreviewSizeMode ThumbnailSizeMode, UUserWidget* WidgetInstance); static FVector2D GetWidgetPreviewUnScaledCustomSize(FVector2D DesiredSize, UUserWidget* UserWidget, TOptional ThumbnailCustomSize, EThumbnailPreviewSizeMode ThumbnailSizeMode = EThumbnailPreviewSizeMode::MatchDesignerMode); static TTuple GetThumbnailImageScaleAndOffset(FVector2D WidgetSize, FVector2D ThumbnailSize); static void SetTextureAsAssetThumbnail(UWidgetBlueprint* WidgetBlueprint, UTexture2D* ThumbnailTexture); static FText GetPaletteCategory(const TSubclassOf Widget); static FText GetPaletteCategory(const FAssetData& WidgetAsset, const TSubclassOf NativeClass); static TOptional DrawSWidgetInRenderTargetForThumbnail(UUserWidget* WidgetInstance, FRenderTarget* RenderTarget2D, FVector2D ThumbnailSize, TOptional ThumbnailCustomSize, EThumbnailPreviewSizeMode ThumbnailSizeMode = EThumbnailPreviewSizeMode::MatchDesignerMode); static TOptional DrawSWidgetInRenderTargetForThumbnail(UUserWidget* WidgetInstance, UTextureRenderTarget2D* RenderTarget2D, FVector2D ThumbnailSize, TOptional ThumbnailCustomSize, EThumbnailPreviewSizeMode ThumbnailSizeMode); static TOptional DrawSWidgetInRenderTarget(UUserWidget* WidgetInstance, UTextureRenderTarget2D* RenderTarget2D); static UWidgetEditingProjectSettings* GetRelevantMutableSettings(TWeakPtr CurrentEditor); static const UWidgetEditingProjectSettings* GetRelevantSettings(TWeakPtr CurrentEditor); static UWidgetBlueprint* GetWidgetBlueprintFromWidget(const UWidget* Widget); static TSet ResolveWidgetTemplates(const TSet& Widgets); private: static FString CopyWidgetsInternal(UWidgetBlueprint* BP, TSet Widgets); static TArray PasteWidgetsInternal(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, const FString& TextToImport, FWidgetReference ParentWidget, FName SlotName, FVector2D PasteLocation, bool bForceSibling, bool& TransactionSuccesful); static bool DisplayPasteWarningAndEarlyExit(); static void ExecuteOpenSelectedWidgetsForEdit( TSet SelectedWidgets ); static bool FindAndRemoveNamedSlotContent(UWidget* WidgetTemplate, UWidgetTree* WidgetTree); static bool CanOpenSelectedWidgetsForEdit( TSet SelectedWidgets ); static void BuildWrapWithMenu(FMenuBuilder& Menu, TSharedRef BlueprintEditor, UWidgetBlueprint* BP, TSet Widgets); static void WrapWidgets(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, TSet Widgets, UClass* WidgetClass); static void BuildReplaceWithMenu(FMenuBuilder& Menu, TSharedRef BlueprintEditor, UWidgetBlueprint* BP, TSet Widgets); static void ReplaceWidgetWithSelectedTemplate(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, FWidgetReference Widget); static bool CanBeReplacedWithTemplate(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, FWidgetReference Widget); static void ReplaceWidgetWithChildren(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, FWidgetReference Widget); static void ReplaceWidgetWithNamedSlot(TSharedRef BlueprintEditor, UWidgetBlueprint* BP, FWidgetReference Widget, FName NamedSlot); static FString FindNextValidName(UWidgetTree* WidgetTree, const FString& Name); static void FindUsedVariablesForWidgets(const TSet& Widgets, const UWidgetBlueprint* BP, TArray& UsedVariables, TArray& WidgetNames, bool bIncludeVariablesOnChildren); static bool ShouldContinueDeleteOperation(UWidgetBlueprint* BP, const TArray& WidgetNames); static bool ShouldContinueReplaceOperation(UWidgetBlueprint* BP, const TArray& WidgetNames); static TOptional DrawSWidgetInRenderTargetInternal(UUserWidget* WidgetInstance, FRenderTarget* RenderTarget2D, UTextureRenderTarget2D* TextureRenderTarget,FVector2D ThumbnailSize, bool bIsForThumbnail, TOptional ThumbnailCustomSize, EThumbnailPreviewSizeMode ThumbnailSizeMode); static bool IsDesiredFocusWidget(TSharedRef BlueprintEditor, UWidget* Widget); static bool IsDesiredFocusWidget(UWidgetBlueprint* Blueprint, UWidget* Widget); static FWidgetObjectTextFactory ProcessImportedText(UWidgetBlueprint* BP, const FString& TextToImport, /*out*/ UPackage*& TempPackage); };