├── Config ├── DefaultEditor.ini ├── DefaultGame.ini └── DefaultEngine.ini ├── README.md ├── ClassDiagramPart1.png ├── Source ├── UMGtoSlate │ ├── ToSWidget.h │ ├── UCS_GameInstance.cpp │ ├── UMGtoSlate.h │ ├── UMGtoSlateGameModeBase.cpp │ ├── UMGtoSlate.cpp │ ├── UMGConvSlateLib.cpp │ ├── ToObjects │ │ ├── ToSImage.cpp │ │ ├── ToSImage.h │ │ ├── ToSConstraintCanvas.h │ │ └── ToSConstraintCanvas.cpp │ ├── UCS_GameInstance.h │ ├── UMGtoSlateGameModeBase.h │ ├── UMGConvSlateLib.h │ ├── SeparationLib.h │ ├── UMGtoSlate.Build.cs │ ├── ToSWidget.cpp │ ├── SeparationLib.cpp │ ├── StrAssembleLib.h │ └── StrAssembleLib.cpp ├── UMGtoSlate.Target.cs └── UMGtoSlateEditor.Target.cs ├── Content └── TestOutputSlate │ ├── Test.uasset │ ├── OutputSlate.uasset │ └── testOutputSlate.umap ├── UMGtoSlate.uproject ├── CorrespondTable.txt ├── .gitattributes ├── .gitignore └── UMGtoSlate.sln /Config/DefaultEditor.ini: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sxh910924/UMGConvertSlate/HEAD/README.md -------------------------------------------------------------------------------- /ClassDiagramPart1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sxh910924/UMGConvertSlate/HEAD/ClassDiagramPart1.png -------------------------------------------------------------------------------- /Config/DefaultGame.ini: -------------------------------------------------------------------------------- 1 | [/Script/EngineSettings.GeneralProjectSettings] 2 | ProjectID=CB0C84964A96A8E00A395E9CC8D8D5A5 3 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/ToSWidget.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sxh910924/UMGConvertSlate/HEAD/Source/UMGtoSlate/ToSWidget.h -------------------------------------------------------------------------------- /Content/TestOutputSlate/Test.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sxh910924/UMGConvertSlate/HEAD/Content/TestOutputSlate/Test.uasset -------------------------------------------------------------------------------- /Content/TestOutputSlate/OutputSlate.uasset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sxh910924/UMGConvertSlate/HEAD/Content/TestOutputSlate/OutputSlate.uasset -------------------------------------------------------------------------------- /Content/TestOutputSlate/testOutputSlate.umap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sxh910924/UMGConvertSlate/HEAD/Content/TestOutputSlate/testOutputSlate.umap -------------------------------------------------------------------------------- /Source/UMGtoSlate/UCS_GameInstance.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "UCS_GameInstance.h" 4 | 5 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGtoSlate.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "UMG.h" 7 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGtoSlateGameModeBase.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "UMGtoSlateGameModeBase.h" 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGtoSlate.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "UMGtoSlate.h" 4 | #include "Modules/ModuleManager.h" 5 | 6 | IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, UMGtoSlate, "UMGtoSlate" ); 7 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGConvSlateLib.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "UMGConvSlateLib.h" 4 | #include "FileHelper.h" 5 | 6 | void UUMGConvSlateLib::CopyTextFunc(FString InString) 7 | { 8 | FFileHelper::SaveStringToFile(InString,TEXT("E:/123/aa.txt")); 9 | } 10 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/ToObjects/ToSImage.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "ToSImage.h" 4 | 5 | UToSImage::UToSImage() 6 | { 7 | UToSWidget::ToSWidgetClassName = FString(TEXT("SImage")); 8 | UToSWidget::ToSWidgetDefaultVisibility = ESlateVisibility::Visible; 9 | } 10 | -------------------------------------------------------------------------------- /UMGtoSlate.uproject: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "EngineAssociation": "4.17", 4 | "Category": "", 5 | "Description": "", 6 | "Modules": [ 7 | { 8 | "Name": "UMGtoSlate", 9 | "Type": "Runtime", 10 | "LoadingPhase": "Default", 11 | "AdditionalDependencies": [ 12 | "Engine", 13 | "CoreUObject" 14 | ] 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /Source/UMGtoSlate.Target.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class UMGtoSlateTarget : TargetRules 7 | { 8 | public UMGtoSlateTarget(TargetInfo Target) : base(Target) 9 | { 10 | Type = TargetType.Game; 11 | 12 | ExtraModuleNames.AddRange( new string[] { "UMGtoSlate" } ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UCS_GameInstance.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Engine/GameInstance.h" 7 | #include "UCS_GameInstance.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class UMGTOSLATE_API UUCS_GameInstance : public UGameInstance 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/ToObjects/ToSImage.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "ToSWidget.h" 7 | #include "ToSImage.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class UMGTOSLATE_API UToSImage : public UToSWidget 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | 19 | UToSImage(); 20 | 21 | 22 | }; 23 | -------------------------------------------------------------------------------- /Source/UMGtoSlateEditor.Target.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | using System.Collections.Generic; 5 | 6 | public class UMGtoSlateEditorTarget : TargetRules 7 | { 8 | public UMGtoSlateEditorTarget(TargetInfo Target) : base(Target) 9 | { 10 | Type = TargetType.Editor; 11 | 12 | ExtraModuleNames.AddRange( new string[] { "UMGtoSlate" } ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGtoSlateGameModeBase.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "GameFramework/GameModeBase.h" 7 | #include "UMGtoSlateGameModeBase.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class UMGTOSLATE_API AUMGtoSlateGameModeBase : public AGameModeBase 14 | { 15 | GENERATED_BODY() 16 | 17 | 18 | 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGConvSlateLib.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Kismet/BlueprintFunctionLibrary.h" 7 | #include "UMGConvSlateLib.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class UMGTOSLATE_API UUMGConvSlateLib : public UBlueprintFunctionLibrary 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | 19 | UFUNCTION(BlueprintCallable,Category = "test") 20 | static void CopyTextFunc(FString InString); 21 | 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/ToObjects/ToSConstraintCanvas.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "ToSWidget.h" 7 | #include "ToSConstraintCanvas.generated.h" 8 | 9 | /** 10 | * 11 | */ 12 | UCLASS() 13 | class UMGTOSLATE_API UToSConstraintCanvas : public UToSWidget 14 | { 15 | GENERATED_BODY() 16 | 17 | public: 18 | 19 | UToSConstraintCanvas(); 20 | 21 | virtual void GenerateChildWidget() override; 22 | 23 | virtual void GenerateSlotProperty(const int32 SlotIndex) override; 24 | 25 | private: 26 | 27 | UCanvasPanel* m_CanvasPanel; 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/SeparationLib.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "UMGtoSlate.h" 7 | #include "Kismet/BlueprintFunctionLibrary.h" 8 | #include "Widget.h" 9 | #include "SeparationLib.generated.h" 10 | 11 | /** 12 | * 分离器 13 | */ 14 | UCLASS() 15 | class UMGTOSLATE_API USeparationLib : public UBlueprintFunctionLibrary 16 | { 17 | GENERATED_BODY() 18 | 19 | public: 20 | 21 | // 生成slate代码 22 | UFUNCTION(BlueprintCallable, Category = "UMGConvertSlate") 23 | static void GenerateSlateCode(UWidget* InWidget); 24 | 25 | // 生成转换对象 26 | static void GenerateToObjectsMap(); 27 | 28 | public: 29 | 30 | // 用于指定转换类的Map 31 | static TMap SwitchMap; 32 | 33 | // 层计数 34 | static int32 LayerCount; 35 | 36 | }; 37 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/UMGtoSlate.Build.cs: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class UMGtoSlate : ModuleRules 6 | { 7 | public UMGtoSlate(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" }); 12 | 13 | // PrivateDependencyModuleNames.AddRange(new string[] { }); 14 | 15 | //Uncomment if you are using Slate UI 16 | PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); 17 | 18 | PublicIncludePaths.AddRange(new string[] 19 | { 20 | "UMGtoSlate/ToObjects" 21 | }); 22 | 23 | // Uncomment if you are using online features 24 | // PrivateDependencyModuleNames.Add("OnlineSubsystem"); 25 | 26 | // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CorrespondTable.txt: -------------------------------------------------------------------------------- 1 | left is UMG widget 2 | right is Slate widget 3 | 4 | part1 5 | CanvasPanel(UCanvasPanel) = SConstraintCanvas 6 | Image(UImage) = SImage 7 | Border(UBorder) = SBorder 8 | Button(UButton) = SButton 9 | CheckBox(UCheckBox) = SCheckBox 10 | Text(UTextBlock) = STextBlock 11 | EditableText(UEditableText) = SEditableText 12 | TextBox(UEditableTextBox) = SEditableTextBox 13 | GridPanel(UGridPanel) = SGridPanel 14 | HorizontalBox(UHorizontalBox) = SHorizontalBox 15 | VerticalBox(UVerticalBox) = SVerticalBox 16 | Overlay(UOverlay) = SOverlay 17 | ScrollBox(UScrollBox) = SScrollBox 18 | SizeBox(USizeBox) = SBox 19 | UniformGridPanel(UUniformGridPanel) = SUniformGridPanel 20 | WidgetSwitcher(UWidgetSwitcher) = SWidgetSwitcher 21 | WrapBox(UWrapBox) = SWrapBox 22 | Spacer(USpacer) = SSpacer 23 | MenuAnchor(UMenuAnchor) = SMenuAnchor 24 | BackgroundBlur(UBackgroundBlur) = SBackgroundBlur 25 | 26 | part2,Do not do part2 temporarily 27 | EditableText(Multi-Line) 28 | NativeWidgetHost 29 | Throbber 30 | InputKeySelector 31 | WindowTitleBarArea 32 | NameedSlot 33 | ProgressBar 34 | Slider 35 | ExpandableArea 36 | ComboBox(String) 37 | SpinBox 38 | TextBox(Multi-Line) 39 | InvalidationBox 40 | RetainerBox 41 | SafeZone 42 | ScaleBox 43 | CircularThrobber -------------------------------------------------------------------------------- /Config/DefaultEngine.ini: -------------------------------------------------------------------------------- 1 | [URL] 2 | 3 | [/Script/HardwareTargeting.HardwareTargetingSettings] 4 | TargetedHardwareClass=Desktop 5 | AppliedTargetedHardwareClass=Desktop 6 | DefaultGraphicsPerformance=Maximum 7 | AppliedDefaultGraphicsPerformance=Maximum 8 | 9 | [/Script/EngineSettings.GameMapsSettings] 10 | EditorStartupMap=/Game/TestOutputSlate/testOutputSlate.testOutputSlate 11 | GameDefaultMap=/Game/TestOutputSlate/testOutputSlate.testOutputSlate 12 | GameInstanceClass=/Script/UMGtoSlate.UCS_GameInstance 13 | 14 | [/Script/Engine.PhysicsSettings] 15 | DefaultGravityZ=-980.000000 16 | DefaultTerminalVelocity=4000.000000 17 | DefaultFluidFriction=0.300000 18 | SimulateScratchMemorySize=262144 19 | RagdollAggregateThreshold=4 20 | TriangleMeshTriangleMinAreaThreshold=5.000000 21 | bEnableAsyncScene=False 22 | bEnableShapeSharing=False 23 | bEnablePCM=True 24 | bEnableStabilization=False 25 | bWarnMissingLocks=True 26 | bEnable2DPhysics=False 27 | LockedAxis=Invalid 28 | DefaultDegreesOfFreedom=Full3D 29 | BounceThresholdVelocity=200.000000 30 | FrictionCombineMode=Average 31 | RestitutionCombineMode=Average 32 | MaxAngularVelocity=3600.000000 33 | MaxDepenetrationVelocity=0.000000 34 | ContactOffsetMultiplier=0.020000 35 | MinContactOffset=2.000000 36 | MaxContactOffset=8.000000 37 | bSimulateSkeletalMeshOnDedicatedServer=True 38 | DefaultShapeComplexity=CTF_UseSimpleAndComplex 39 | bDefaultHasComplexCollision=True 40 | bSuppressFaceRemapTable=False 41 | bSupportUVFromHitResults=False 42 | bDisableActiveActors=False 43 | bDisableCCD=False 44 | bEnableEnhancedDeterminism=False 45 | MaxPhysicsDeltaTime=0.033333 46 | bSubstepping=False 47 | bSubsteppingAsync=False 48 | MaxSubstepDeltaTime=0.016667 49 | MaxSubsteps=6 50 | SyncSceneSmoothingFactor=0.000000 51 | AsyncSceneSmoothingFactor=0.990000 52 | InitialAverageFrameRate=0.016667 53 | PhysXTreeRebuildRate=10 54 | 55 | 56 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/ToSWidget.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "ToSWidget.h" 4 | #include "StrAssembleLib.h" 5 | 6 | void UToSWidget::GenerateHead(UWidget* NewWidget) 7 | { 8 | ThisWidget = NewWidget; 9 | if (ToSWidgetClassName.IsEmpty()) 10 | { 11 | // error 12 | } 13 | else 14 | { 15 | HeadString = UStrAssembleLib::Str_SNew(ToSWidgetClassName); 16 | } 17 | } 18 | 19 | void UToSWidget::GenerateWidgetProperty() 20 | { 21 | ESlateVisibility vis = ThisWidget->GetVisibility(); 22 | if (vis != ToSWidgetDefaultVisibility) 23 | { 24 | WidgetProperty.Add(UStrAssembleLib::Str_Visibility(vis)); 25 | } 26 | } 27 | 28 | int32 UToSWidget::GetPanalWidgetChildrenCount() const 29 | { 30 | UPanelWidget* panel = Cast(ThisWidget); 31 | if (panel) 32 | { 33 | return panel->GetChildrenCount(); 34 | } 35 | else 36 | { 37 | return 0; 38 | } 39 | } 40 | 41 | void UToSWidget::AddSlotProperty(const int32 SlotIndex, const TArray PropertyArr) 42 | { 43 | if (PropertyArr.Num() == 0) return; 44 | const bool exist = this->SlotProperty.Contains(SlotIndex); 45 | if (exist) 46 | { 47 | SlotProperty[SlotIndex] += PropertyArr; 48 | } 49 | else 50 | { 51 | SlotProperty.Emplace(SlotIndex, PropertyArr); 52 | } 53 | } 54 | 55 | void UToSWidget::AddSlotProperty(const int32 SlotIndex, const FString &PropertyValue) 56 | { 57 | const bool exist = this->SlotProperty.Contains(SlotIndex); 58 | if (exist) 59 | { 60 | SlotProperty[SlotIndex].Add(PropertyValue); 61 | } 62 | else 63 | { 64 | TArray firstArr; 65 | firstArr.Add(PropertyValue); 66 | SlotProperty.Emplace(SlotIndex, firstArr); 67 | } 68 | } 69 | 70 | void UToSWidget::LoopPanelSlot() 71 | { 72 | for (int32 loop = 0; loop < ChildSlotCount; ++loop) 73 | { 74 | PanelSlotLoop.ExecuteIfBound(loop); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/SeparationLib.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "SeparationLib.h" 4 | 5 | #include "ToSConstraintCanvas.h" 6 | #include "ToSImage.h" 7 | #include "StrAssembleLib.h" 8 | 9 | TMap USeparationLib::SwitchMap; 10 | 11 | int32 USeparationLib::LayerCount = -1; 12 | 13 | void USeparationLib::GenerateSlateCode(UWidget* InWidget) 14 | { 15 | USeparationLib::GenerateToObjectsMap(); 16 | 17 | //static int32 namePlus = 0; 18 | 19 | FString className = InWidget->GetClass()->GetName(); 20 | UE_LOG(LogClass, Warning, TEXT("class name %s"), *className); 21 | if (SwitchMap.Contains(className)) 22 | { 23 | UE_LOG(LogClass, Warning, TEXT("SwitchMap has key %s"),*className); 24 | UToSWidget* targetToSWidget = NewObject(); 25 | UClass* targetClass = SwitchMap[className]; 26 | //FName objectName = FName(*FString::FromInt(++namePlus)); 27 | targetToSWidget = NewObject(targetToSWidget, targetClass); 28 | if (targetToSWidget) 29 | { 30 | ++LayerCount; 31 | targetToSWidget->TabCount = LayerCount; 32 | targetToSWidget->GenerateHead(InWidget); 33 | UStrAssembleLib::Str_Final_Head(targetToSWidget); 34 | 35 | targetToSWidget->GenerateWidgetProperty(); 36 | UStrAssembleLib::Str_Final_Widget(targetToSWidget); 37 | 38 | targetToSWidget->GenerateSpecialWidgetProperty(); 39 | UStrAssembleLib::Str_Final_SpecialWidget(targetToSWidget); 40 | 41 | targetToSWidget->GenerateChildWidget(); 42 | UStrAssembleLib::AddUToSWidget(targetToSWidget); 43 | 44 | --LayerCount; 45 | if (LayerCount==-1) 46 | { 47 | // 全部转换完毕,进入文本转换 48 | UStrAssembleLib::Str_FinalSlateCode(); 49 | } 50 | } 51 | } 52 | else 53 | { 54 | UE_LOG(LogClass, Warning, TEXT("SwitchMap don't has key %s"), *className); 55 | } 56 | } 57 | 58 | void USeparationLib::GenerateToObjectsMap() 59 | { 60 | if (SwitchMap.Num() > 0) return; 61 | SwitchMap.Emplace(FString(TEXT("CanvasPanel")), UToSConstraintCanvas::StaticClass()); 62 | SwitchMap.Emplace(FString(TEXT("Image")), UToSImage::StaticClass()); 63 | } 64 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/ToObjects/ToSConstraintCanvas.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "ToSConstraintCanvas.h" 4 | #include "StrAssembleLib.h" 5 | #include "SeparationLib.h" 6 | 7 | UToSConstraintCanvas::UToSConstraintCanvas() 8 | { 9 | UToSWidget::ToSWidgetClassName = FString(TEXT("SConstraintCanvas")); 10 | UToSWidget::ToSWidgetDefaultVisibility = ESlateVisibility::SelfHitTestInvisible; 11 | } 12 | 13 | void UToSConstraintCanvas::GenerateChildWidget() 14 | { 15 | UToSWidget::ChildSlotCount = GetPanalWidgetChildrenCount(); 16 | if (ChildSlotCount == 0) return; 17 | 18 | m_CanvasPanel = Cast(UToSWidget::ThisWidget); 19 | if (!m_CanvasPanel) return; 20 | 21 | // 复用循环需要做 22 | UToSWidget::PanelSlotLoop.BindUObject(this, &UToSConstraintCanvas::GenerateSlotProperty); 23 | UToSWidget::LoopPanelSlot(); 24 | } 25 | 26 | void UToSConstraintCanvas::GenerateSlotProperty(const int32 SlotIndex) 27 | { 28 | UCanvasPanelSlot* cps = Cast(m_CanvasPanel->GetChildAt(SlotIndex)->Slot); 29 | if (cps) 30 | { 31 | FString slotHead = UStrAssembleLib::Str_NormalSlotHead(UToSWidget::ToSWidgetClassName); 32 | AddSlotProperty(SlotIndex, slotHead); 33 | 34 | if (cps->LayoutData.Alignment != FVector2D(0.5f,0.5f)) 35 | { 36 | FString alignment = UStrAssembleLib::Str_Alignment(cps->LayoutData.Alignment); 37 | AddSlotProperty(SlotIndex, alignment); 38 | } 39 | 40 | if (cps->LayoutData.Offsets != FMargin(0, 0, 1, 1)) 41 | { 42 | FString offset = UStrAssembleLib::Str_Offset(cps->LayoutData.Offsets); 43 | AddSlotProperty(SlotIndex, offset); 44 | } 45 | 46 | if (cps->ZOrder != 0) 47 | { 48 | FString zorder = UStrAssembleLib::Str_ZOrder(cps->ZOrder); 49 | AddSlotProperty(SlotIndex, zorder); 50 | } 51 | 52 | if (cps->bAutoSize != false) 53 | { 54 | FString autoSize = UStrAssembleLib::Str_AutoSize(cps->bAutoSize); 55 | AddSlotProperty(SlotIndex, autoSize); 56 | } 57 | 58 | if (!UStrAssembleLib::AnchorsIsEqual(cps->LayoutData.Anchors, FAnchors())) 59 | { 60 | FString anchors = UStrAssembleLib::Str_AnchorsSlot(cps->LayoutData.Anchors); 61 | AddSlotProperty(SlotIndex, anchors); 62 | } 63 | 64 | // 拼装slot到最终字符串 65 | TArray &slotProperty = SlotProperty[SlotIndex]; 66 | UStrAssembleLib::Str_Final_Slot(this, slotProperty); 67 | 68 | // [ 69 | UStrAssembleLib::Str_Final_SquareBracket(this, FString(TEXT("["))); 70 | 71 | // 处理Slot里面的对象 72 | UWidget* slotWidget = Cast(m_CanvasPanel->GetChildAt(SlotIndex)); 73 | if (slotWidget) 74 | { 75 | USeparationLib::GenerateSlateCode(slotWidget); 76 | } 77 | 78 | // ] 79 | UStrAssembleLib::Str_Final_SquareBracket(this, FString(TEXT("]"))); 80 | 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/StrAssembleLib.h: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "UMGtoSlate.h" 7 | #include "Kismet/BlueprintFunctionLibrary.h" 8 | #include "StrAssembleLib.generated.h" 9 | 10 | class UToSWidget; 11 | 12 | /** 13 | * 14 | */ 15 | UCLASS() 16 | class UMGTOSLATE_API UStrAssembleLib : public UBlueprintFunctionLibrary 17 | { 18 | GENERATED_BODY() 19 | 20 | public: // 基础字符串 21 | 22 | // 返回“SNew(ClassName)” 23 | static FString Str_SNew(const FString &ClassName); 24 | 25 | // 返回“.Visibility(EVisibility::Visible)” 26 | static FString Str_Visibility(ESlateVisibility SlateVisibility); 27 | 28 | // 返回数组,数组内“.Alignment(FVector2D())” 29 | static FString Str_Alignment(FVector2D Alignment); 30 | 31 | // 返回数组,数组内“FVector2D()” 32 | static FString Str_Vector2D(FVector2D Vector2d); 33 | 34 | // 返回“.HAlign(HAlign_Left)” 35 | static FString Str_AlignmentH(float AlignmentH); 36 | 37 | // 返回“.VAlign(VAlign_Top)” 38 | static FString Str_AlignmentV(float AlignmentV); 39 | 40 | // 返回“.Offset(FMargin(1,1,1,0))” 41 | static FString Str_Offset(FMargin Offset); 42 | 43 | // 返回“FMargin(1,1,1,0)” 44 | static FString Str_Margin(FMargin Margin); 45 | 46 | // 返回“.ZOrder(0)” 47 | static FString Str_ZOrder(int32 ZOrder); 48 | 49 | // 返回“.AutoSize(true)” 50 | static FString Str_AutoSize(bool bAutoSize); 51 | 52 | // 返回“.Anchors(FAnchors())” 53 | static FString Str_AnchorsSlot(FAnchors Anchors); 54 | 55 | // 返回“FAnchors()” 56 | static FString Str_Anchors(FAnchors Anchors); 57 | 58 | // 是否相等 59 | static bool AnchorsIsEqual(const FAnchors &Anchors1, const FAnchors &Anchors2); 60 | 61 | // 返回“+ ClassName::Slot()” 62 | static FString Str_NormalSlotHead(const FString &ClassName); 63 | 64 | // 添加UToWidget,以备最终转化使用 65 | static void AddUToSWidget(UToSWidget* ToWidget); 66 | 67 | // 返回多个“\t” 68 | static FString Str_Tab(const int32 TabCount); 69 | 70 | // 返回一个“\n” 71 | static FString Str_NewLine(); 72 | 73 | // 返回最后的slate代码 74 | static void Str_FinalSlateCode(); 75 | 76 | public: // 行字符串 77 | 78 | // 拼头 79 | static void Str_Final_Head(UToSWidget* ToWidget); 80 | 81 | // 拼widget通用属性 82 | static void Str_Final_Widget(UToSWidget* ToWidget); 83 | 84 | // 拼widget特殊属性 85 | static void Str_Final_SpecialWidget(UToSWidget* ToWidget); 86 | 87 | // 拼Slot 88 | static void Str_Final_Slot(UToSWidget* ToWidget, TArray &SlotPropertyArr); 89 | 90 | // 拼[或] 91 | static void Str_Final_SquareBracket(UToSWidget* ToWidget, FString SquareBracketValue); 92 | 93 | 94 | 95 | private: 96 | 97 | // 保存所有待转换对象 98 | static TArray ToWidgets; 99 | 100 | // 最终的slate代码 101 | static FString FinalSlateCode; 102 | 103 | }; 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | 244 | # ue4 temp forder 245 | Binaries 246 | Intermediate 247 | Saved 248 | -------------------------------------------------------------------------------- /UMGtoSlate.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{D25FCCFC-9604-4E43-A0B3-52D06CF79AE9}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Games", "Games", "{97C97B83-72D0-43D9-88BF-E80AB180F8E0}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UE4", "Intermediate\ProjectFiles\UE4.vcxproj", "{D61824D2-79C1-488A-8FAA-1E6D08677D0D}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UMGtoSlate", "Intermediate\ProjectFiles\UMGtoSlate.vcxproj", "{347C4CEA-15CC-4133-96E5-BAB00FD89CF9}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | DebugGame Editor|Win32 = DebugGame Editor|Win32 17 | DebugGame Editor|Win64 = DebugGame Editor|Win64 18 | DebugGame|Win32 = DebugGame|Win32 19 | DebugGame|Win64 = DebugGame|Win64 20 | Development Editor|Win32 = Development Editor|Win32 21 | Development Editor|Win64 = Development Editor|Win64 22 | Development|Win32 = Development|Win32 23 | Development|Win64 = Development|Win64 24 | Shipping|Win32 = Shipping|Win32 25 | Shipping|Win64 = Shipping|Win64 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 29 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame Editor|Win32.Build.0 = BuiltWithUnrealBuildTool|Win32 30 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 31 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame Editor|Win64.Build.0 = BuiltWithUnrealBuildTool|Win32 32 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 33 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame|Win32.Build.0 = BuiltWithUnrealBuildTool|Win32 34 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 35 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.DebugGame|Win64.Build.0 = BuiltWithUnrealBuildTool|Win32 36 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 37 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development Editor|Win32.Build.0 = BuiltWithUnrealBuildTool|Win32 38 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 39 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development Editor|Win64.Build.0 = BuiltWithUnrealBuildTool|Win32 40 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 41 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development|Win32.Build.0 = BuiltWithUnrealBuildTool|Win32 42 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 43 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Development|Win64.Build.0 = BuiltWithUnrealBuildTool|Win32 44 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Shipping|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 45 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Shipping|Win32.Build.0 = BuiltWithUnrealBuildTool|Win32 46 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Shipping|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 47 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D}.Shipping|Win64.Build.0 = BuiltWithUnrealBuildTool|Win32 48 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame Editor|Win32.ActiveCfg = DebugGame_Editor|Win32 49 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame Editor|Win64.ActiveCfg = DebugGame_Editor|x64 50 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame Editor|Win64.Build.0 = DebugGame_Editor|x64 51 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame|Win32.ActiveCfg = DebugGame_Game|Win32 52 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame|Win32.Build.0 = DebugGame_Game|Win32 53 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame|Win64.ActiveCfg = DebugGame_Game|x64 54 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.DebugGame|Win64.Build.0 = DebugGame_Game|x64 55 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development Editor|Win32.ActiveCfg = Development_Editor|Win32 56 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development Editor|Win64.ActiveCfg = Development_Editor|x64 57 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development Editor|Win64.Build.0 = Development_Editor|x64 58 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development|Win32.ActiveCfg = Development_Game|Win32 59 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development|Win32.Build.0 = Development_Game|Win32 60 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development|Win64.ActiveCfg = Development_Game|x64 61 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Development|Win64.Build.0 = Development_Game|x64 62 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Shipping|Win32.ActiveCfg = Shipping_Game|Win32 63 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Shipping|Win32.Build.0 = Shipping_Game|Win32 64 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Shipping|Win64.ActiveCfg = Shipping_Game|x64 65 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9}.Shipping|Win64.Build.0 = Shipping_Game|x64 66 | EndGlobalSection 67 | GlobalSection(SolutionProperties) = preSolution 68 | HideSolutionNode = FALSE 69 | EndGlobalSection 70 | GlobalSection(NestedProjects) = preSolution 71 | {D61824D2-79C1-488A-8FAA-1E6D08677D0D} = {D25FCCFC-9604-4E43-A0B3-52D06CF79AE9} 72 | {347C4CEA-15CC-4133-96E5-BAB00FD89CF9} = {97C97B83-72D0-43D9-88BF-E80AB180F8E0} 73 | EndGlobalSection 74 | EndGlobal 75 | -------------------------------------------------------------------------------- /Source/UMGtoSlate/StrAssembleLib.cpp: -------------------------------------------------------------------------------- 1 | // Fill out your copyright notice in the Description page of Project Settings. 2 | 3 | #include "StrAssembleLib.h" 4 | #include "UMGConvSlateLib.h" 5 | #include "ToSWidget.h" 6 | 7 | TArray UStrAssembleLib::ToWidgets; 8 | FString UStrAssembleLib::FinalSlateCode = FString(); 9 | 10 | FString UStrAssembleLib::Str_SNew(const FString &ClassName) 11 | { 12 | return FString::Printf(TEXT("SNew(%s)"), *ClassName); 13 | } 14 | 15 | FString UStrAssembleLib::Str_Visibility(ESlateVisibility SlateVisibility) 16 | { 17 | FString ret; 18 | switch (SlateVisibility) 19 | { 20 | case ESlateVisibility::Visible: 21 | ret = FString(TEXT(".Visibility(EVisibility::Visible)")); 22 | break; 23 | case ESlateVisibility::Collapsed: 24 | ret = FString(TEXT(".Visibility(EVisibility::Collapsed)")); 25 | break; 26 | case ESlateVisibility::Hidden: 27 | ret = FString(TEXT(".Visibility(EVisibility::Hidden)")); 28 | break; 29 | case ESlateVisibility::HitTestInvisible: 30 | ret = FString(TEXT(".Visibility(EVisibility::HitTestInvisible)")); 31 | break; 32 | case ESlateVisibility::SelfHitTestInvisible: 33 | ret = FString(TEXT(".Visibility(EVisibility::SelfHitTestInvisible)")); 34 | break; 35 | } 36 | return ret; 37 | } 38 | 39 | FString UStrAssembleLib::Str_Alignment(FVector2D Alignment) 40 | { 41 | FString v2d = UStrAssembleLib::Str_Vector2D(Alignment); 42 | return FString::Printf(TEXT(".Alignment(%s)"),*v2d); 43 | } 44 | 45 | FString UStrAssembleLib::Str_Vector2D(FVector2D Vector2d) 46 | { 47 | FString ret; 48 | 49 | if (Vector2d.X == Vector2d.Y) 50 | { 51 | if (FMath::IsNearlyZero(Vector2d.X)) 52 | { 53 | ret = FString(TEXT("FVector2D()")); 54 | } 55 | else 56 | { 57 | ret = FString::Printf(TEXT("FVector2D(%.3ff)"), Vector2d.X); 58 | } 59 | } 60 | else 61 | { 62 | ret = FString::Printf(TEXT("FVector2D(%.3ff,%.3ff)"), Vector2d.X, Vector2d.Y); 63 | } 64 | 65 | return ret; 66 | } 67 | 68 | FString UStrAssembleLib::Str_AlignmentH(float AlignmentH) 69 | { 70 | FString ret; 71 | if (AlignmentH == 0.0f) 72 | { 73 | ret = FString(TEXT(".HAlign(HAlign_Left)")); 74 | } 75 | else if(AlignmentH == 0.5f) 76 | { 77 | ret = FString(TEXT(".HAlign(HAlign_Center)")); 78 | } 79 | else 80 | { 81 | ret = FString(TEXT(".HAlign(HAlign_Right)")); 82 | } 83 | return ret; 84 | } 85 | 86 | FString UStrAssembleLib::Str_AlignmentV(float AlignmentV) 87 | { 88 | FString ret; 89 | if (AlignmentV == 0.0f) 90 | { 91 | ret = FString(TEXT(".VAlign(VAlign_Top)")); 92 | } 93 | else if (AlignmentV == 0.5f) 94 | { 95 | ret = FString(TEXT(".VAlign(VAlign_Center)")); 96 | } 97 | else 98 | { 99 | ret = FString(TEXT(".VAlign(VAlign_Bottom)")); 100 | } 101 | return ret; 102 | } 103 | 104 | FString UStrAssembleLib::Str_Offset(FMargin Offset) 105 | { 106 | FString margin = UStrAssembleLib::Str_Margin(Offset); 107 | return FString::Printf(TEXT(".Offset(%s)"),*margin); 108 | } 109 | 110 | FString UStrAssembleLib::Str_Margin(FMargin Margin) 111 | { 112 | FString ret; 113 | if (Margin == FMargin()) 114 | { 115 | ret = FString::Printf(TEXT("FMargin()")); 116 | } 117 | else 118 | { 119 | if ((Margin.Left == Margin.Right) && (Margin.Right == Margin.Top) && (Margin.Top == Margin.Bottom)) 120 | { 121 | ret = FString::Printf(TEXT("FMargin(%.3ff)"), Margin.Left); 122 | } 123 | else if ((Margin.Left == Margin.Right) && (Margin.Top == Margin.Bottom)) 124 | { 125 | ret = FString::Printf(TEXT("FMargin(%.3ff,%.3ff)"), Margin.Left, Margin.Top); 126 | } 127 | else 128 | { 129 | ret = FString::Printf(TEXT("FMargin(%.3ff,%.3ff,%.3ff,%.3ff)"), Margin.Left, Margin.Top, Margin.Right, Margin.Bottom); 130 | } 131 | } 132 | 133 | return ret; 134 | } 135 | 136 | FString UStrAssembleLib::Str_ZOrder(int32 ZOrder) 137 | { 138 | return FString::Printf(TEXT(".ZOrder(%d)"), ZOrder); 139 | } 140 | 141 | FString UStrAssembleLib::Str_AutoSize(bool bAutoSize) 142 | { 143 | if (bAutoSize) 144 | { 145 | return FString::Printf(TEXT(".AutoSize(true)")); 146 | } 147 | else 148 | { 149 | return FString::Printf(TEXT(".AutoSize(false)")); 150 | } 151 | } 152 | 153 | FString UStrAssembleLib::Str_AnchorsSlot(FAnchors Anchors) 154 | { 155 | FString anchors = UStrAssembleLib::Str_Anchors(Anchors); 156 | return FString::Printf(TEXT(".Anchors(%s)"), *anchors); 157 | } 158 | 159 | FString UStrAssembleLib::Str_Anchors(FAnchors Anchors) 160 | { 161 | FString ret; 162 | if (UStrAssembleLib::AnchorsIsEqual(Anchors, FAnchors())) 163 | { 164 | ret = FString::Printf(TEXT("FAnchors()")); 165 | } 166 | else 167 | { 168 | if ((Anchors.Maximum.X == Anchors.Maximum.Y) && (Anchors.Maximum.Y == Anchors.Minimum.Y) && (Anchors.Minimum.Y == Anchors.Minimum.X)) 169 | { 170 | ret = FString::Printf(TEXT("FAnchors(%.1ff)"), Anchors.Maximum.X); 171 | } 172 | else if ( (Anchors.Minimum.X == Anchors.Maximum.X)&& (Anchors.Minimum.Y == Anchors.Maximum.Y) ) 173 | { 174 | ret = FString::Printf(TEXT("FAnchors(%.1ff,%.1ff)"), Anchors.Minimum.X, Anchors.Minimum.Y); 175 | } 176 | else 177 | { 178 | ret = FString::Printf(TEXT("FAnchors(%.1ff,%.1ff,%.1ff,%.1ff)"), Anchors.Minimum.X, Anchors.Minimum.Y, Anchors.Maximum.X, Anchors.Maximum.Y); 179 | } 180 | } 181 | return ret; 182 | } 183 | 184 | bool UStrAssembleLib::AnchorsIsEqual(const FAnchors &Anchors1, const FAnchors &Anchors2) 185 | { 186 | if (Anchors1.Minimum == Anchors2.Minimum) 187 | { 188 | if (Anchors1.Maximum == Anchors2.Maximum) 189 | { 190 | return true; 191 | } 192 | else 193 | { 194 | return false; 195 | } 196 | } 197 | else 198 | { 199 | return false; 200 | } 201 | } 202 | 203 | FString UStrAssembleLib::Str_NormalSlotHead(const FString &ClassName) 204 | { 205 | return FString::Printf(TEXT("+ %s::Slot()"),*ClassName); 206 | } 207 | 208 | void UStrAssembleLib::AddUToSWidget(UToSWidget* ToWidget) 209 | { 210 | if (ToWidget) 211 | { 212 | ToWidgets.Add(ToWidget); 213 | } 214 | } 215 | 216 | FString UStrAssembleLib::Str_Tab(const int32 TabCount) 217 | { 218 | FString ret; 219 | int32 count = 0; 220 | while (count < TabCount) 221 | { 222 | ret += FString(TEXT("\t")); 223 | ++count; 224 | } 225 | return ret; 226 | } 227 | 228 | FString UStrAssembleLib::Str_NewLine() 229 | { 230 | return FString(TEXT("\n")); 231 | } 232 | 233 | void UStrAssembleLib::Str_FinalSlateCode() 234 | { 235 | UUMGConvSlateLib::CopyTextFunc(FinalSlateCode); 236 | FinalSlateCode.Empty(); 237 | } 238 | 239 | void UStrAssembleLib::Str_Final_Head(UToSWidget* ToWidget) 240 | { 241 | if (ToWidget) 242 | { 243 | FString tab = UStrAssembleLib::Str_Tab(ToWidget->TabCount); 244 | FinalSlateCode += tab + ToWidget->HeadString + UStrAssembleLib::Str_NewLine(); 245 | } 246 | } 247 | 248 | void UStrAssembleLib::Str_Final_Widget(UToSWidget* ToWidget) 249 | { 250 | if (ToWidget) 251 | { 252 | // 拼通用属性 253 | for (FString wp : ToWidget->WidgetProperty) 254 | { 255 | FString tab = UStrAssembleLib::Str_Tab(ToWidget->TabCount); 256 | FinalSlateCode += tab + wp + UStrAssembleLib::Str_NewLine(); 257 | } 258 | } 259 | } 260 | 261 | void UStrAssembleLib::Str_Final_SpecialWidget(UToSWidget* ToWidget) 262 | { 263 | if (ToWidget) 264 | { 265 | // 拼特殊属性 266 | for (FString wsp : ToWidget->WidgetSpecialProperty) 267 | { 268 | FString tab = UStrAssembleLib::Str_Tab(ToWidget->TabCount); 269 | FinalSlateCode += tab + wsp + UStrAssembleLib::Str_NewLine(); 270 | } 271 | } 272 | } 273 | 274 | void UStrAssembleLib::Str_Final_Slot(UToSWidget* ToWidget, TArray &SlotPropertyArr) 275 | { 276 | if (ToWidget) 277 | { 278 | for (FString sp : SlotPropertyArr) 279 | { 280 | FString tab = UStrAssembleLib::Str_Tab(ToWidget->TabCount); 281 | FinalSlateCode += tab + sp + UStrAssembleLib::Str_NewLine(); 282 | } 283 | } 284 | } 285 | 286 | void UStrAssembleLib::Str_Final_SquareBracket(UToSWidget* ToWidget, FString SquareBracketValue) 287 | { 288 | if ( SquareBracketValue.Equals(TEXT("[")) || SquareBracketValue.Equals(TEXT("]")) ) 289 | { 290 | if (ToWidget) 291 | { 292 | FString tab = UStrAssembleLib::Str_Tab(ToWidget->TabCount); 293 | FinalSlateCode += tab + SquareBracketValue + UStrAssembleLib::Str_NewLine(); 294 | } 295 | } 296 | } 297 | --------------------------------------------------------------------------------