// Copyright Epic Games, Inc. All Rights Reserved. #include "SetupDemoAssetsCommandlet.h" #include "UnrealLuaDemoEditor.h" #include "Core/LuaGameModeBase.h" #include "AssetRegistry/AssetRegistryModule.h" #include "Blueprint/WidgetTree.h" #include "Components/Border.h" #include "Components/Button.h" #include "Components/CanvasPanel.h" #include "Components/CanvasPanelSlot.h" #include "Components/CheckBox.h" #include "Components/ComboBoxString.h" #include "Components/EditableTextBox.h" #include "Components/HorizontalBox.h" #include "Components/HorizontalBoxSlot.h" #include "Components/Image.h" #include "Components/Overlay.h" #include "Components/OverlaySlot.h" #include "Components/ProgressBar.h" #include "Components/ScrollBox.h" #include "Components/SizeBox.h" #include "Components/Slider.h" #include "Components/Spacer.h" #include "Components/SpinBox.h" #include "Components/TextBlock.h" #include "Components/UniformGridPanel.h" #include "Components/UniformGridSlot.h" #include "Components/VerticalBox.h" #include "Components/VerticalBoxSlot.h" #include "Components/WidgetSwitcher.h" #include "Engine/Font.h" #include "Engine/FontFace.h" #include "Engine/Texture2D.h" #include "Engine/World.h" #include "Fonts/CompositeFont.h" #include "GameFramework/WorldSettings.h" #include "HAL/FileManager.h" #include "Kismet2/BlueprintEditorUtils.h" #include "Kismet2/KismetEditorUtilities.h" #include "Misc/FileHelper.h" #include "Misc/PackageName.h" #include "Misc/Paths.h" #include "Styling/SlateTypes.h" #include "UObject/Package.h" #include "UObject/SavePackage.h" #include "WidgetBlueprint.h" #include "WidgetBlueprintFactory.h" namespace { const FLinearColor ColorBgDeep(0.043f, 0.059f, 0.090f, 1.0f); const FLinearColor ColorPanel(0.082f, 0.114f, 0.173f, 0.96f); const FLinearColor ColorCard(0.110f, 0.153f, 0.227f, 0.98f); const FLinearColor ColorCardDark(0.067f, 0.094f, 0.145f, 0.96f); const FLinearColor ColorDivider(0.180f, 0.243f, 0.349f, 1.0f); const FLinearColor ColorAccentBlue(0.149f, 0.431f, 0.855f, 1.0f); const FLinearColor ColorAccentCyan(0.086f, 0.569f, 0.678f, 1.0f); const FLinearColor ColorAccentGreen(0.133f, 0.588f, 0.388f, 1.0f); const FLinearColor ColorAccentAmber(0.761f, 0.490f, 0.110f, 1.0f); const FLinearColor ColorAccentPurple(0.478f, 0.294f, 0.784f, 1.0f); const FLinearColor ColorAccentRed(0.745f, 0.212f, 0.255f, 1.0f); const FLinearColor ColorBtnNeutral(0.165f, 0.224f, 0.322f, 1.0f); const FLinearColor ColorTextPrimary(0.941f, 0.961f, 0.988f, 1.0f); const FLinearColor ColorTextSecondary(0.659f, 0.729f, 0.824f, 1.0f); const FLinearColor ColorTextAccent(0.451f, 0.788f, 0.980f, 1.0f); bool SaveAssetPackage(UPackage* Package, UObject* Asset, const FString& LongPackageName) { if (!Package || !Asset) { return false; } const FString Extension = Asset->IsA() ? FPackageName::GetMapPackageExtension() : FPackageName::GetAssetPackageExtension(); const FString Filename = FPackageName::LongPackageNameToFilename(LongPackageName, Extension); IFileManager::Get().MakeDirectory(*FPaths::GetPath(Filename), /*Tree=*/true); FSavePackageArgs SaveArgs; SaveArgs.TopLevelFlags = RF_Public | RF_Standalone; SaveArgs.Error = GError; SaveArgs.bWarnOfLongFilename = false; return UPackage::SavePackage(Package, Asset, *Filename, SaveArgs); } UWidgetBlueprint* BeginWidgetBlueprint(const FString& PackageName, const FString& AssetName, UPackage*& OutPackage) { OutPackage = CreatePackage(*PackageName); if (!OutPackage) { return nullptr; } UWidgetBlueprintFactory* Factory = NewObject(); Factory->ParentClass = UUserWidget::StaticClass(); UWidgetBlueprint* WidgetBP = Cast( Factory->FactoryCreateNew(UWidgetBlueprint::StaticClass(), OutPackage, *AssetName, RF_Public | RF_Standalone, nullptr, GWarn)); if (!WidgetBP || !WidgetBP->WidgetTree) { return nullptr; } return WidgetBP; } bool FinishWidgetBlueprint(UPackage* Package, UWidgetBlueprint* WidgetBP, const FString& PackageName) { if (!Package || !WidgetBP) { return false; } FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(WidgetBP); FKismetEditorUtilities::CompileBlueprint(WidgetBP); FAssetRegistryModule::AssetCreated(WidgetBP); Package->MarkPackageDirty(); return SaveAssetPackage(Package, WidgetBP, PackageName); } FSlateFontInfo MakeDemoFont(UFont* Font, int32 Size, const FName& StyleName = TEXT("Regular")) { FSlateFontInfo Info; if (Font) { Info = FSlateFontInfo(Font, Size, StyleName); } else { Info.Size = Size; } return Info; } UTextBlock* MakeText( UWidgetTree* Tree, const FName& Name, const FString& Text, UFont* Font, int32 FontSize, const FLinearColor& Color = ColorTextPrimary, bool bIsVariable = false, bool bAutoWrap = false) { UTextBlock* TB = Tree->ConstructWidget(UTextBlock::StaticClass(), Name); TB->bIsVariable = bIsVariable; TB->SetText(FText::FromString(Text)); TB->SetFont(MakeDemoFont(Font, FontSize)); TB->SetColorAndOpacity(FSlateColor(Color)); TB->SetAutoWrapText(bAutoWrap); return TB; } void ApplyButtonColorStyle(UButton* Button, const FLinearColor& BaseColor) { FButtonStyle Style = Button->GetStyle(); auto ConfigureBrush = [](FSlateBrush& Brush, const FLinearColor& Tint) { Brush.DrawAs = ESlateBrushDrawType::Box; Brush.TintColor = FSlateColor(Tint); Brush.Margin = FMargin(0.0f); }; const FLinearColor HoverColor( FMath::Clamp(BaseColor.R * 1.18f + 0.04f, 0.0f, 1.0f), FMath::Clamp(BaseColor.G * 1.18f + 0.04f, 0.0f, 1.0f), FMath::Clamp(BaseColor.B * 1.18f + 0.04f, 0.0f, 1.0f), BaseColor.A); const FLinearColor PressColor( BaseColor.R * 0.80f, BaseColor.G * 0.80f, BaseColor.B * 0.80f, BaseColor.A); const FLinearColor DisabledColor(0.18f, 0.20f, 0.24f, 0.65f); ConfigureBrush(Style.Normal, BaseColor); ConfigureBrush(Style.Hovered, HoverColor); ConfigureBrush(Style.Pressed, PressColor); ConfigureBrush(Style.Disabled, DisabledColor); Style.NormalPadding = FMargin(12.0f, 7.0f); Style.PressedPadding = FMargin(12.0f, 8.0f, 12.0f, 6.0f); Button->SetStyle(Style); } UButton* MakeButton( UWidgetTree* Tree, const FName& BtnName, const FName& TxtName, const FString& Label, UFont* Font, int32 FontSize, const FLinearColor& BgColor, bool bTxtIsVariable = false) { UButton* Btn = Tree->ConstructWidget(UButton::StaticClass(), BtnName); Btn->bIsVariable = true; ApplyButtonColorStyle(Btn, BgColor); UTextBlock* Txt = MakeText(Tree, TxtName, Label, Font, FontSize, ColorTextPrimary, bTxtIsVariable, false); Txt->SetJustification(ETextJustify::Center); Btn->AddChild(Txt); return Btn; } UBorder* MakeDivider(UWidgetTree* Tree, const FName& Name) { UBorder* Line = Tree->ConstructWidget(UBorder::StaticClass(), Name); Line->SetBrushColor(ColorDivider); Line->SetPadding(FMargin(0.0f)); USpacer* Sp = Tree->ConstructWidget(USpacer::StaticClass()); Sp->SetSize(FVector2D(1.0f, 2.0f)); Line->SetContent(Sp); return Line; } UBorder* MakeSectionCard(UWidgetTree* Tree, const FName& BorderName, UVerticalBox*& OutInnerBox) { UBorder* Card = Tree->ConstructWidget(UBorder::StaticClass(), BorderName); Card->SetBrushColor(ColorCard); Card->SetPadding(FMargin(14.0f, 12.0f)); OutInnerBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); Card->SetContent(OutInnerBox); return Card; } void AddFillChild(UVerticalBox* Box, UWidget* Child, const FMargin& Padding = FMargin(0.0f)) { if (UVerticalBoxSlot* VSlot = Box->AddChildToVerticalBox(Child)) { VSlot->SetHorizontalAlignment(HAlign_Fill); VSlot->SetPadding(Padding); } } void AddAutoHChild(UHorizontalBox* Box, UWidget* Child, const FMargin& Padding = FMargin(0.0f), EVerticalAlignment VAlign = VAlign_Center) { if (UHorizontalBoxSlot* HSlot = Box->AddChildToHorizontalBox(Child)) { HSlot->SetSize(FSlateChildSize(ESlateSizeRule::Automatic)); HSlot->SetVerticalAlignment(VAlign); HSlot->SetPadding(Padding); } } void AddFillHChild(UHorizontalBox* Box, UWidget* Child, const FMargin& Padding = FMargin(0.0f), EVerticalAlignment VAlign = VAlign_Center) { if (UHorizontalBoxSlot* HSlot = Box->AddChildToHorizontalBox(Child)) { HSlot->SetSize(FSlateChildSize(ESlateSizeRule::Fill)); HSlot->SetHorizontalAlignment(HAlign_Fill); HSlot->SetVerticalAlignment(VAlign); HSlot->SetPadding(Padding); } } void SetupFullCanvasSlot(UCanvasPanel* Root, UWidget* Child, const FMargin& Offsets = FMargin(0.0f)) { if (UCanvasPanelSlot* CSlot = Root->AddChildToCanvas(Child)) { CSlot->SetAnchors(FAnchors(0.0f, 0.0f, 1.0f, 1.0f)); CSlot->SetOffsets(Offsets); } } void SetupCenterCanvasSlot(UCanvasPanel* Root, UWidget* Child, const FVector2D& Size, const FVector2D& Position = FVector2D::ZeroVector) { if (UCanvasPanelSlot* CSlot = Root->AddChildToCanvas(Child)) { CSlot->SetAnchors(FAnchors(0.5f, 0.5f, 0.5f, 0.5f)); CSlot->SetAlignment(FVector2D(0.5f, 0.5f)); CSlot->SetPosition(Position); CSlot->SetSize(Size); } } } USetupDemoAssetsCommandlet::USetupDemoAssetsCommandlet() { IsClient = true; IsEditor = true; IsServer = false; LogToConsole = true; } int32 USetupDemoAssetsCommandlet::Main(const FString& Params) { UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupDemoAssets] Generating Chinese font, Demo textures, L_DemoUI map, and UI Demo blueprints...")); UFontFace* CJKFontFace = CreateChineseFontFace(); if (!CJKFontFace) { UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupDemoAssets] Failed to create /Game/UI/Fonts/FF_DemoCJK.")); return 1; } UFont* DemoFont = CreateDemoUIFont(CJKFontFace); if (!DemoFont) { UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupDemoAssets] Failed to create /Game/UI/Fonts/F_DemoUI.")); return 1; } if (!CreateDemoMap(TEXT("/Game/Maps/L_DemoUI"), TEXT("L_DemoUI"))) { UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupDemoAssets] Failed to create /Game/Maps/L_DemoUI.")); return 1; } if (!CreateProceduralTexture(TEXT("/Game/UI/Textures/T_DemoAvatar"), TEXT("T_DemoAvatar"), 0) || !CreateProceduralTexture(TEXT("/Game/UI/Textures/T_DemoBadgeA"), TEXT("T_DemoBadgeA"), 1) || !CreateProceduralTexture(TEXT("/Game/UI/Textures/T_DemoBadgeB"), TEXT("T_DemoBadgeB"), 2)) { UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupDemoAssets] Failed to create Demo textures.")); return 1; } const bool bAllWidgetsOk = CreateDemoHubBlueprint(DemoFont) && CreateDemoHubItemBlueprint(DemoFont) && CreateUIDemoMainBlueprint(DemoFont) && CreateUIDemoListItemBlueprint(DemoFont) && CreateUIDemoNormalBlueprint(DemoFont) && CreateUIDemoFullscreenBlueprint(DemoFont) && CreateUIDemoModalBlueprint(DemoFont) && CreateUIDemoCachedBlueprint(DemoFont) && CreateUIDemoMultiBlueprint(DemoFont) && CreateUIDemoToastBlueprint(DemoFont) && CreateUIDemoSystemBlueprint(DemoFont); if (!bAllWidgetsOk) { UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupDemoAssets] Failed to create one or more Demo Widget Blueprints.")); return 1; } UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupDemoAssets] All Chinese font & UI Demo assets created successfully.")); return 0; } UFontFace* USetupDemoAssetsCommandlet::CreateChineseFontFace() const { const FString PackageName = TEXT("/Game/UI/Fonts/FF_DemoCJK"); const FString AssetName = TEXT("FF_DemoCJK"); const FString EngineFontPath = FPaths::ConvertRelativePathToFull( FPaths::EngineContentDir() / TEXT("Slate/Fonts/DroidSansFallback.ttf")); TArray FontBytes; if (!FFileHelper::LoadFileToArray(FontBytes, *EngineFontPath) || FontBytes.Num() == 0) { UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupDemoAssets] Could not read CJK font file: %s"), *EngineFontPath); return nullptr; } UPackage* Package = CreatePackage(*PackageName); if (!Package) { return nullptr; } UFontFace* FontFace = NewObject(Package, *AssetName, RF_Public | RF_Standalone); if (!FontFace) { return nullptr; } FontFace->SourceFilename = EngineFontPath; FontFace->Hinting = EFontHinting::Default; FontFace->LoadingPolicy = EFontLoadingPolicy::Inline; FontFace->LayoutMethod = EFontLayoutMethod::Metrics; FontFace->FontFaceData = FFontFaceData::MakeFontFaceData(MoveTemp(FontBytes)); #if WITH_EDITORONLY_DATA FontFace->CacheSubFaces(); #endif FAssetRegistryModule::AssetCreated(FontFace); Package->MarkPackageDirty(); if (!SaveAssetPackage(Package, FontFace, PackageName)) { return nullptr; } UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupDemoAssets] Imported inline CJK UFontFace from %s"), *EngineFontPath); return FontFace; } UFont* USetupDemoAssetsCommandlet::CreateDemoUIFont(UFontFace* CJKFontFace) const { const FString PackageName = TEXT("/Game/UI/Fonts/F_DemoUI"); const FString AssetName = TEXT("F_DemoUI"); UPackage* Package = CreatePackage(*PackageName); if (!Package) { return nullptr; } UFont* Font = NewObject(Package, *AssetName, RF_Public | RF_Standalone); if (!Font) { return nullptr; } Font->FontCacheType = EFontCacheType::Runtime; FCompositeFont& CompositeFont = Font->GetMutableInternalCompositeFont(); CompositeFont.DefaultTypeface.Fonts.Reset(); { FTypefaceEntry RegularEntry(TEXT("Regular")); RegularEntry.Font = FFontData(CJKFontFace); CompositeFont.DefaultTypeface.Fonts.Add(MoveTemp(RegularEntry)); FTypefaceEntry BoldEntry(TEXT("Bold")); BoldEntry.Font = FFontData(CJKFontFace); CompositeFont.DefaultTypeface.Fonts.Add(MoveTemp(BoldEntry)); } CompositeFont.FallbackTypeface.Typeface.Fonts.Reset(); { FTypefaceEntry FallbackEntry(TEXT("Regular")); FallbackEntry.Font = FFontData(CJKFontFace); CompositeFont.FallbackTypeface.Typeface.Fonts.Add(MoveTemp(FallbackEntry)); } CompositeFont.FallbackTypeface.ScalingFactor = 1.0f; FAssetRegistryModule::AssetCreated(Font); Package->MarkPackageDirty(); if (!SaveAssetPackage(Package, Font, PackageName)) { return nullptr; } return Font; } bool USetupDemoAssetsCommandlet::CreateDemoMap(const FString& PackageName, const FString& MapName) const { UPackage* Package = CreatePackage(*PackageName); if (!Package) { return false; } UWorld* NewWorld = UWorld::CreateWorld(EWorldType::Inactive, false, *MapName, Package, true, ERHIFeatureLevel::Num); if (!NewWorld) { return false; } NewWorld->SetFlags(RF_Public | RF_Standalone); if (AWorldSettings* WS = NewWorld->GetWorldSettings()) { WS->DefaultGameMode = ALuaGameModeBase::StaticClass(); } FAssetRegistryModule::AssetCreated(NewWorld); Package->MarkPackageDirty(); const bool bSaved = SaveAssetPackage(Package, NewWorld, PackageName); NewWorld->DestroyWorld(false); return bSaved; } bool USetupDemoAssetsCommandlet::CreateProceduralTexture(const FString& PackageName, const FString& AssetName, int32 StyleIndex) const { UPackage* Package = CreatePackage(*PackageName); if (!Package) { return false; } constexpr int32 Size = 128; UTexture2D* Texture = NewObject(Package, *AssetName, RF_Public | RF_Standalone); if (!Texture) { return false; } TArray Pixels; Pixels.SetNumUninitialized(Size * Size * 4); for (int32 Y = 0; Y < Size; ++Y) { for (int32 X = 0; X < Size; ++X) { const int32 Idx = (Y * Size + X) * 4; const float Dx = (X - Size * 0.5f) / (Size * 0.5f); const float Dy = (Y - Size * 0.5f) / (Size * 0.5f); const float Dist = FMath::Sqrt(Dx * Dx + Dy * Dy); const float Diamond = FMath::Abs(Dx) + FMath::Abs(Dy); uint8 B = 32, G = 42, R = 58, A = 255; if (StyleIndex == 0) { // Avatar: cyan ring + bright core + head/shoulder silhouette const bool bOuterRing = Dist >= 0.78f && Dist <= 0.94f; const float HeadDist = FMath::Sqrt(Dx * Dx + (Dy + 0.18f) * (Dy + 0.18f)); const float BodyDist = FMath::Sqrt((Dx * 0.85f) * (Dx * 0.85f) + (Dy - 0.58f) * (Dy - 0.58f)); if (bOuterRing) { B = 245; G = 195; R = 64; } else if (HeadDist <= 0.25f || (BodyDist <= 0.48f && Dist <= 0.78f)) { B = 250; G = 235; R = 205; } else if (Dist <= 0.78f) { B = 110; G = 68; R = 32; } } else if (StyleIndex == 1) { // Badge A: emerald diamond emblem if (Diamond <= 0.42f) { B = 175; G = 250; R = 120; } else if (Diamond <= 0.78f) { B = 110; G = 195; R = 48; } else { B = 40; G = 60; R = 28; } } else { // Badge B: crimson-gold crest const bool bCross = (FMath::Abs(Dx) <= 0.16f && FMath::Abs(Dy) <= 0.65f) || (FMath::Abs(Dy) <= 0.16f && FMath::Abs(Dx) <= 0.65f); if (bCross) { B = 72; G = 215; R = 250; } else if (Dist <= 0.82f) { B = 75; G = 48; R = 190; } else { B = 42; G = 26; R = 58; } } Pixels[Idx + 0] = B; Pixels[Idx + 1] = G; Pixels[Idx + 2] = R; Pixels[Idx + 3] = A; } } Texture->Source.Init(Size, Size, 1, 1, TSF_BGRA8, Pixels.GetData()); Texture->LODGroup = TEXTUREGROUP_UI; Texture->CompressionSettings = TC_EditorIcon; Texture->MipGenSettings = TMGS_NoMipmaps; Texture->SRGB = true; Texture->UpdateResource(); Texture->PostEditChange(); FAssetRegistryModule::AssetCreated(Texture); Package->MarkPackageDirty(); return SaveAssetPackage(Package, Texture, PackageName); } bool USetupDemoAssetsCommandlet::CreateDemoHubBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_DemoHub"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_DemoHub"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* Backdrop = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("BgBackdrop")); Backdrop->SetBrushColor(ColorBgDeep); SetupFullCanvasSlot(Root, Backdrop); UBorder* HubCard = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("HubCard")); HubCard->SetBrushColor(ColorPanel); HubCard->SetPadding(FMargin(28.0f, 24.0f)); SetupCenterCanvasSlot(Root, HubCard, FVector2D(820.0f, 580.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass(), TEXT("HubLayout")); HubCard->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtHubTitle"), TEXT("UnrealLuaDemo 场景启动大厅"), DemoFont, 26, ColorTextPrimary, true), FMargin(0, 0, 0, 6)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtHubSubtitle"), TEXT("在 Bootstrap 关卡中选择并切换至各个功能 Demo 场景,切图时自动验证上下文与资源清理。"), DemoFont, 13, ColorTextSecondary, true, true), FMargin(0, 0, 0, 10)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtRuntimeInfo"), TEXT("运行时信息加载中..."), DemoFont, 12, ColorTextAccent, true), FMargin(0, 0, 0, 12)); AddFillChild(VBox, MakeDivider(Tree, TEXT("DivTop")), FMargin(0, 0, 0, 14)); UScrollBox* ScrollList = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("ScrollDemoList")); ScrollList->bIsVariable = true; if (UVerticalBoxSlot* ListSlot = VBox->AddChildToVerticalBox(ScrollList)) { ListSlot->SetSize(FSlateChildSize(ESlateSizeRule::Fill)); ListSlot->SetHorizontalAlignment(HAlign_Fill); ListSlot->SetVerticalAlignment(VAlign_Fill); ListSlot->SetPadding(FMargin(0, 0, 0, 14)); } AddFillChild(VBox, MakeDivider(Tree, TEXT("DivBottom")), FMargin(0, 0, 0, 12)); UHorizontalBox* Footer = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("FooterRow")); AddFillHChild(Footer, MakeText(Tree, TEXT("TxtHubHint"), TEXT("提示:进入任意 Demo 场景后可通过右上角「返回大厅」回到 L_Bootstrap"), DemoFont, 12, ColorTextSecondary, false, true), FMargin(0, 0, 12, 0)); AddAutoHChild(Footer, MakeButton(Tree, TEXT("BtnOpenMiniSettings"), TEXT("TxtMiniSettingsBtn"), TEXT("快捷验证:最小设置弹窗"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(VBox, Footer); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateDemoHubItemBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_DemoHubItem"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_DemoHubItem"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UBorder* Card = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("CardBorder")); Card->bIsVariable = true; Card->SetBrushColor(ColorCard); Card->SetPadding(FMargin(18.0f, 14.0f)); Tree->RootWidget = Card; UHorizontalBox* Row = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("CardRow")); Card->SetContent(Row); UVerticalBox* InfoCol = Tree->ConstructWidget(UVerticalBox::StaticClass(), TEXT("InfoCol")); AddFillChild(InfoCol, MakeText(Tree, TEXT("TxtDemoTitle"), TEXT("Demo 标题"), DemoFont, 18, ColorTextPrimary, true), FMargin(0, 0, 0, 4)); AddFillChild(InfoCol, MakeText(Tree, TEXT("TxtDemoDesc"), TEXT("Demo 简介说明"), DemoFont, 13, ColorTextSecondary, true, true), FMargin(0, 0, 0, 6)); AddFillChild(InfoCol, MakeText(Tree, TEXT("TxtDemoMeta"), TEXT("关卡:/Game/Maps/L_DemoUI"), DemoFont, 11, ColorTextAccent, true)); AddFillHChild(Row, InfoCol, FMargin(0, 0, 16, 0)); USizeBox* BtnWrap = Tree->ConstructWidget(USizeBox::StaticClass(), TEXT("BtnWrap")); BtnWrap->SetWidthOverride(132.0f); BtnWrap->SetHeightOverride(44.0f); BtnWrap->AddChild(MakeButton(Tree, TEXT("BtnEnterDemo"), TEXT("TxtEnterLabel"), TEXT("进入场景"), DemoFont, 14, ColorAccentBlue, true)); AddAutoHChild(Row, BtnWrap); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoMainBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoMain"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoMain"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* MainBg = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("MainBg")); MainBg->SetBrushColor(ColorBgDeep); SetupFullCanvasSlot(Root, MainBg); UVerticalBox* RootVBox = Tree->ConstructWidget(UVerticalBox::StaticClass(), TEXT("RootVBox")); SetupFullCanvasSlot(Root, RootVBox, FMargin(16.0f)); // ===== Zone 1: TopBar ===== UBorder* TopBar = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("TopBar")); TopBar->SetBrushColor(ColorPanel); TopBar->SetPadding(FMargin(16.0f, 10.0f)); UHorizontalBox* TopRow = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("TopRow")); TopBar->SetContent(TopRow); UImage* ImgAvatar = Tree->ConstructWidget(UImage::StaticClass(), TEXT("ImgPlayerAvatar")); ImgAvatar->bIsVariable = true; ImgAvatar->SetDesiredSizeOverride(FVector2D(48.0f, 48.0f)); AddAutoHChild(TopRow, ImgAvatar, FMargin(0, 0, 12, 0)); USizeBox* PlayerInfoWrap = Tree->ConstructWidget(USizeBox::StaticClass(), TEXT("PlayerInfoWrap")); PlayerInfoWrap->SetWidthOverride(230.0f); UVerticalBox* PlayerInfo = Tree->ConstructWidget(UVerticalBox::StaticClass(), TEXT("PlayerInfoBox")); AddFillChild(PlayerInfo, MakeText(Tree, TEXT("TxtPlayerName"), TEXT("冒险者_01 Lv.12"), DemoFont, 15, ColorTextPrimary, true), FMargin(0, 0, 0, 6)); UProgressBar* BarExp = Tree->ConstructWidget(UProgressBar::StaticClass(), TEXT("BarPlayerExp")); BarExp->bIsVariable = true; BarExp->SetPercent(0.65f); BarExp->SetFillColorAndOpacity(ColorAccentCyan); AddFillChild(PlayerInfo, BarExp); PlayerInfoWrap->AddChild(PlayerInfo); AddAutoHChild(TopRow, PlayerInfoWrap, FMargin(0, 0, 16, 0)); UBorder* StatsBadge = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("StatsBadge")); StatsBadge->SetBrushColor(ColorCardDark); StatsBadge->SetPadding(FMargin(14.0f, 8.0f)); StatsBadge->SetContent(MakeText(Tree, TEXT("TxtHudStats"), TEXT("窗口:1 | 缓存:0 | 绑定:0 | 输入:UI"), DemoFont, 13, ColorTextAccent, true)); AddFillHChild(TopRow, StatsBadge, FMargin(0, 0, 16, 0)); AddAutoHChild(TopRow, MakeButton(Tree, TEXT("BtnTopSettings"), TEXT("TxtTopSettings"), TEXT("设置"), DemoFont, 13, ColorBtnNeutral), FMargin(0, 0, 8, 0)); AddAutoHChild(TopRow, MakeButton(Tree, TEXT("BtnBackToHub"), TEXT("TxtBackToHub"), TEXT("返回大厅"), DemoFont, 13, ColorAccentRed)); AddFillChild(RootVBox, TopBar, FMargin(0, 0, 0, 12)); // ===== Zone 2: BodyRow (LeftNav | CenterStage | RightLog) ===== UHorizontalBox* BodyRow = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("BodyRow")); if (UVerticalBoxSlot* BodySlot = RootVBox->AddChildToVerticalBox(BodyRow)) { BodySlot->SetSize(FSlateChildSize(ESlateSizeRule::Fill)); BodySlot->SetHorizontalAlignment(HAlign_Fill); BodySlot->SetVerticalAlignment(VAlign_Fill); } // --- 2A. LeftNav (Window Type Showcase) --- USizeBox* LeftWrap = Tree->ConstructWidget(USizeBox::StaticClass(), TEXT("LeftWrap")); LeftWrap->SetWidthOverride(230.0f); UBorder* LeftPanel = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("LeftNavPanel")); LeftPanel->SetBrushColor(ColorPanel); LeftPanel->SetPadding(FMargin(12.0f)); UScrollBox* NavScroll = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("NavScroll")); LeftPanel->SetContent(NavScroll); LeftWrap->AddChild(LeftPanel); NavScroll->AddChild(MakeText(Tree, TEXT("TxtNavTitle"), TEXT("窗口类型测试"), DemoFont, 16, ColorTextPrimary)); USpacer* NavSp0 = Tree->ConstructWidget(USpacer::StaticClass()); NavSp0->SetSize(FVector2D(1.0f, 10.0f)); NavScroll->AddChild(NavSp0); auto AddNavBtn = [&](const FName& BtnName, const FName& TxtName, const FString& Label, const FLinearColor& Color) { UButton* Btn = MakeButton(Tree, BtnName, TxtName, Label, DemoFont, 13, Color); NavScroll->AddChild(Btn); USpacer* Sp = Tree->ConstructWidget(USpacer::StaticClass()); Sp->SetSize(FVector2D(1.0f, 8.0f)); NavScroll->AddChild(Sp); }; AddNavBtn(TEXT("BtnWinNormal"), TEXT("TxtWinNormal"), TEXT("普通窗口 (Normal)"), ColorAccentBlue); AddNavBtn(TEXT("BtnWinFullscreen"), TEXT("TxtWinFullscreen"), TEXT("全屏窗口 (Fullscreen)"), ColorAccentPurple); AddNavBtn(TEXT("BtnWinModal"), TEXT("TxtWinModal"), TEXT("模态弹窗 (Modal)"), ColorAccentAmber); AddNavBtn(TEXT("BtnWinCached"), TEXT("TxtWinCached"), TEXT("缓存窗口 (Cached)"), ColorAccentGreen); AddNavBtn(TEXT("BtnWinMulti"), TEXT("TxtWinMulti"), TEXT("多实例窗 (Multi +1)"), ColorAccentCyan); AddNavBtn(TEXT("BtnWinToast"), TEXT("TxtWinToast"), TEXT("飘字提示 (Toast)"), ColorBtnNeutral); AddNavBtn(TEXT("BtnWinSystem"), TEXT("TxtWinSystem"), TEXT("系统顶层 (System)"), ColorAccentRed); NavScroll->AddChild(MakeDivider(Tree, TEXT("NavDiv"))); USpacer* NavSp1 = Tree->ConstructWidget(USpacer::StaticClass()); NavSp1->SetSize(FVector2D(1.0f, 8.0f)); NavScroll->AddChild(NavSp1); AddNavBtn(TEXT("BtnEvictCache"), TEXT("TxtEvictCache"), TEXT("清空缓存池"), ColorBtnNeutral); AddNavBtn(TEXT("BtnCloseOthers"), TEXT("TxtCloseOthers"), TEXT("关闭其他窗口"), ColorBtnNeutral); AddAutoHChild(BodyRow, LeftWrap, FMargin(0, 0, 12, 0), VAlign_Fill); // --- 2B. CenterStage (Component Lab with WidgetSwitcher) --- UBorder* CenterPanel = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("CenterPanel")); CenterPanel->SetBrushColor(ColorPanel); CenterPanel->SetPadding(FMargin(14.0f)); UVerticalBox* CenterVBox = Tree->ConstructWidget(UVerticalBox::StaticClass(), TEXT("CenterVBox")); CenterPanel->SetContent(CenterVBox); UHorizontalBox* TabBar = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("TabBar")); AddFillHChild(TabBar, MakeButton(Tree, TEXT("BtnTabBasic"), TEXT("TxtTabBasic"), TEXT("1. 基础交互"), DemoFont, 13, ColorAccentBlue), FMargin(0, 0, 6, 0)); AddFillHChild(TabBar, MakeButton(Tree, TEXT("BtnTabInput"), TEXT("TxtTabInput"), TEXT("2. 输入与选择"), DemoFont, 13, ColorBtnNeutral), FMargin(0, 0, 6, 0)); AddFillHChild(TabBar, MakeButton(Tree, TEXT("BtnTabMedia"), TEXT("TxtTabMedia"), TEXT("3. 图片与列表"), DemoFont, 13, ColorBtnNeutral), FMargin(0, 0, 6, 0)); AddFillHChild(TabBar, MakeButton(Tree, TEXT("BtnTabDiag"), TEXT("TxtTabDiag"), TEXT("4. 框架诊断"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(CenterVBox, TabBar, FMargin(0, 0, 0, 12)); UWidgetSwitcher* TabSwitcher = Tree->ConstructWidget(UWidgetSwitcher::StaticClass(), TEXT("TabSwitcher")); TabSwitcher->bIsVariable = true; if (UVerticalBoxSlot* SwitchSlot = CenterVBox->AddChildToVerticalBox(TabSwitcher)) { SwitchSlot->SetSize(FSlateChildSize(ESlateSizeRule::Fill)); SwitchSlot->SetHorizontalAlignment(HAlign_Fill); SwitchSlot->SetVerticalAlignment(VAlign_Fill); } // ---- Page 0: Basic Controls ---- UScrollBox* PageBasic = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("PageBasic")); { // Section 1: Button UVerticalBox* SecBtn = nullptr; PageBasic->AddChild(MakeSectionCard(Tree, TEXT("CardBtn"), SecBtn)); AddFillChild(SecBtn, MakeText(Tree, TEXT("TxtSecBtnTitle"), TEXT("按钮测试(Click / Hover / Unhover / 禁用态)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 6)); AddFillChild(SecBtn, MakeText(Tree, TEXT("TxtBasicBtnStatus"), TEXT("按钮状态:点击 0 次 | 悬停:否 | 受控按钮:已启用"), DemoFont, 13, ColorTextAccent, true, true), FMargin(0, 0, 0, 10)); UHorizontalBox* BtnRow = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(BtnRow, MakeButton(Tree, TEXT("BtnDemoAction"), TEXT("TxtDemoAction"), TEXT("点击 / 悬停测试"), DemoFont, 13, ColorAccentBlue), FMargin(0, 0, 8, 0)); AddFillHChild(BtnRow, MakeButton(Tree, TEXT("BtnToggleDisable"), TEXT("TxtToggleDisable"), TEXT("切换启用 / 禁用"), DemoFont, 13, ColorBtnNeutral), FMargin(0, 0, 8, 0)); AddFillHChild(BtnRow, MakeButton(Tree, TEXT("BtnDemoTarget"), TEXT("TxtDemoTarget"), TEXT("目标受控按钮"), DemoFont, 13, ColorAccentGreen, true)); AddFillChild(SecBtn, BtnRow); USpacer* Sp1 = Tree->ConstructWidget(USpacer::StaticClass()); Sp1->SetSize(FVector2D(1.0f, 10.0f)); PageBasic->AddChild(Sp1); // Section 2: CheckBox UVerticalBox* SecCheck = nullptr; PageBasic->AddChild(MakeSectionCard(Tree, TEXT("CardCheck"), SecCheck)); AddFillChild(SecCheck, MakeText(Tree, TEXT("TxtSecCheckTitle"), TEXT("复选框测试(UCheckBox)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); UHorizontalBox* ChkRow = Tree->ConstructWidget(UHorizontalBox::StaticClass()); UCheckBox* ChkFeature = Tree->ConstructWidget(UCheckBox::StaticClass(), TEXT("ChkFeature")); ChkFeature->bIsVariable = true; AddAutoHChild(ChkRow, ChkFeature, FMargin(0, 0, 10, 0)); AddFillHChild(ChkRow, MakeText(Tree, TEXT("TxtCheckStatus"), TEXT("复选框状态:未勾选(点击切换)"), DemoFont, 13, ColorTextSecondary, true)); AddFillChild(SecCheck, ChkRow); USpacer* Sp2 = Tree->ConstructWidget(USpacer::StaticClass()); Sp2->SetSize(FVector2D(1.0f, 10.0f)); PageBasic->AddChild(Sp2); // Section 3: Slider + ProgressBar UVerticalBox* SecSlider = nullptr; PageBasic->AddChild(MakeSectionCard(Tree, TEXT("CardSlider"), SecSlider)); AddFillChild(SecSlider, MakeText(Tree, TEXT("TxtSecSliderTitle"), TEXT("滑条与进度条联动(USlider + UProgressBar)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 6)); AddFillChild(SecSlider, MakeText(Tree, TEXT("TxtSliderStatus"), TEXT("当前进度:50%(拖动滑条或点击自动动画)"), DemoFont, 13, ColorTextAccent, true), FMargin(0, 0, 0, 8)); USlider* SliderDemo = Tree->ConstructWidget(USlider::StaticClass(), TEXT("SliderDemo")); SliderDemo->bIsVariable = true; SliderDemo->SetMinValue(0.0f); SliderDemo->SetMaxValue(1.0f); SliderDemo->SetValue(0.5f); AddFillChild(SecSlider, SliderDemo, FMargin(0, 0, 0, 8)); UProgressBar* ProgressDemo = Tree->ConstructWidget(UProgressBar::StaticClass(), TEXT("ProgressDemo")); ProgressDemo->bIsVariable = true; ProgressDemo->SetPercent(0.5f); ProgressDemo->SetFillColorAndOpacity(ColorAccentGreen); AddFillChild(SecSlider, ProgressDemo, FMargin(0, 0, 0, 10)); UHorizontalBox* ProgBtns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(ProgBtns, MakeButton(Tree, TEXT("BtnProgressPlay"), TEXT("TxtProgressPlay"), TEXT("开始自动进度动画"), DemoFont, 13, ColorAccentCyan, true), FMargin(0, 0, 8, 0)); AddFillHChild(ProgBtns, MakeButton(Tree, TEXT("BtnProgressReset"), TEXT("TxtProgressReset"), TEXT("重置为 0%"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(SecSlider, ProgBtns); USpacer* Sp3 = Tree->ConstructWidget(USpacer::StaticClass()); Sp3->SetSize(FVector2D(1.0f, 10.0f)); PageBasic->AddChild(Sp3); // Section 4: SpinBox UVerticalBox* SecSpin = nullptr; PageBasic->AddChild(MakeSectionCard(Tree, TEXT("CardSpin"), SecSpin)); AddFillChild(SecSpin, MakeText(Tree, TEXT("TxtSecSpinTitle"), TEXT("数值微调器(USpinBox)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); UHorizontalBox* SpinRow = Tree->ConstructWidget(UHorizontalBox::StaticClass()); USpinBox* SpinDemo = Tree->ConstructWidget(USpinBox::StaticClass(), TEXT("SpinDemo")); SpinDemo->bIsVariable = true; SpinDemo->SetMinValue(0.0f); SpinDemo->SetMaxValue(999.0f); SpinDemo->SetMinSliderValue(0.0f); SpinDemo->SetMaxSliderValue(999.0f); SpinDemo->SetValue(100.0f); SpinDemo->SetDelta(5.0f); SpinDemo->SetFont(MakeDemoFont(DemoFont, 14)); USizeBox* SpinWrap = Tree->ConstructWidget(USizeBox::StaticClass()); SpinWrap->SetWidthOverride(160.0f); SpinWrap->AddChild(SpinDemo); AddAutoHChild(SpinRow, SpinWrap, FMargin(0, 0, 12, 0)); AddFillHChild(SpinRow, MakeText(Tree, TEXT("TxtSpinStatus"), TEXT("当前数值:100(范围 0 ~ 999)"), DemoFont, 13, ColorTextSecondary, true)); AddFillChild(SecSpin, SpinRow); } TabSwitcher->AddChild(PageBasic); // ---- Page 1: Input & Selection ---- UScrollBox* PageInput = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("PageInput")); { // Section 1: EditableTextBox UVerticalBox* SecEdit = nullptr; PageInput->AddChild(MakeSectionCard(Tree, TEXT("CardInput"), SecEdit)); AddFillChild(SecEdit, MakeText(Tree, TEXT("TxtSecInputTitle"), TEXT("单行输入框(UEditableTextBox)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 6)); AddFillChild(SecEdit, MakeText(Tree, TEXT("TxtInputDesc"), TEXT("输入中英文昵称,支持 OnTextChanged 实时字数统计,回车或点按钮应用到顶部玩家栏:"), DemoFont, 12, ColorTextSecondary, false, true), FMargin(0, 0, 0, 8)); UEditableTextBox* InputNick = Tree->ConstructWidget(UEditableTextBox::StaticClass(), TEXT("InputNickname")); InputNick->bIsVariable = true; InputNick->SetHintText(FText::FromString(TEXT("请输入新的玩家昵称(支持中文)..."))); FEditableTextBoxStyle EditStyle = InputNick->GetWidgetStyle(); EditStyle.SetFont(MakeDemoFont(DemoFont, 14)); EditStyle.BackgroundColor = FSlateColor(FLinearColor(0.95f, 0.97f, 1.0f, 1.0f)); EditStyle.ForegroundColor = FSlateColor(FLinearColor(0.08f, 0.10f, 0.14f, 1.0f)); InputNick->SetWidgetStyle(EditStyle); AddFillChild(SecEdit, InputNick, FMargin(0, 0, 0, 8)); UHorizontalBox* InputFoot = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(InputFoot, MakeText(Tree, TEXT("TxtInputStatus"), TEXT("实时内容:空(0 字符)"), DemoFont, 13, ColorTextAccent, true), FMargin(0, 0, 8, 0)); AddAutoHChild(InputFoot, MakeButton(Tree, TEXT("BtnApplyNickname"), TEXT("TxtApplyNickname"), TEXT("应用为顶部昵称"), DemoFont, 13, ColorAccentBlue)); AddFillChild(SecEdit, InputFoot); USpacer* Sp1 = Tree->ConstructWidget(USpacer::StaticClass()); Sp1->SetSize(FVector2D(1.0f, 10.0f)); PageInput->AddChild(Sp1); // Section 2: ComboBoxString UVerticalBox* SecCombo = nullptr; PageInput->AddChild(MakeSectionCard(Tree, TEXT("CardCombo"), SecCombo)); AddFillChild(SecCombo, MakeText(Tree, TEXT("TxtSecComboTitle"), TEXT("下拉选择框(UComboBoxString)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); UComboBoxString* ComboTheme = Tree->ConstructWidget(UComboBoxString::StaticClass(), TEXT("ComboTheme")); ComboTheme->bIsVariable = true; PRAGMA_DISABLE_DEPRECATION_WARNINGS ComboTheme->Font = MakeDemoFont(DemoFont, 14); PRAGMA_ENABLE_DEPRECATION_WARNINGS ComboTheme->AddOption(TEXT("深海蓝(普通)")); ComboTheme->AddOption(TEXT("翡翠绿(稀有)")); ComboTheme->AddOption(TEXT("琥珀金(传说)")); ComboTheme->AddOption(TEXT("星云紫(史诗)")); ComboTheme->SetSelectedOption(TEXT("深海蓝(普通)")); AddFillChild(SecCombo, ComboTheme, FMargin(0, 0, 0, 10)); UBorder* ThemePreview = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("BorderThemePreview")); ThemePreview->bIsVariable = true; ThemePreview->SetBrushColor(ColorAccentBlue); ThemePreview->SetPadding(FMargin(12.0f, 10.0f)); ThemePreview->SetContent(MakeText(Tree, TEXT("TxtComboStatus"), TEXT("当前选中:深海蓝(普通)"), DemoFont, 13, ColorTextPrimary, true)); AddFillChild(SecCombo, ThemePreview); USpacer* Sp2 = Tree->ConstructWidget(USpacer::StaticClass()); Sp2->SetSize(FVector2D(1.0f, 10.0f)); PageInput->AddChild(Sp2); // Section 3: TextBlock Typography UVerticalBox* SecText = nullptr; PageInput->AddChild(MakeSectionCard(Tree, TEXT("CardText"), SecText)); AddFillChild(SecText, MakeText(Tree, TEXT("TxtSecTextTitle"), TEXT("中文排版与样式切换(UTextBlock)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); AddFillChild(SecText, MakeText(Tree, TEXT("TxtRichSample"), TEXT("中英文混排示例:Unreal Engine 5.8 + UnLua + TypeScript 热更新框架,支持自动换行、动态字号与颜色切换。"), DemoFont, 14, ColorTextPrimary, true, true), FMargin(0, 0, 0, 10)); UHorizontalBox* TextBtns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(TextBtns, MakeButton(Tree, TEXT("BtnCycleTextColor"), TEXT("TxtCycleColor"), TEXT("切换文本颜色"), DemoFont, 13, ColorBtnNeutral), FMargin(0, 0, 8, 0)); AddFillHChild(TextBtns, MakeButton(Tree, TEXT("BtnCycleTextSize"), TEXT("TxtCycleSize"), TEXT("切换字号(14 / 18 / 22)"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(SecText, TextBtns); } TabSwitcher->AddChild(PageInput); // ---- Page 2: Media & Containers ---- UScrollBox* PageMedia = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("PageMedia")); { // Section 1: Image async load & visibility UVerticalBox* SecImg = nullptr; PageMedia->AddChild(MakeSectionCard(Tree, TEXT("CardImg"), SecImg)); AddFillChild(SecImg, MakeText(Tree, TEXT("TxtSecImgTitle"), TEXT("图片异步加载与可见性模式(UImage + ResourceService)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); UHorizontalBox* ImgRow = Tree->ConstructWidget(UHorizontalBox::StaticClass()); UImage* ImgPreview = Tree->ConstructWidget(UImage::StaticClass(), TEXT("ImgPreview")); ImgPreview->bIsVariable = true; ImgPreview->SetDesiredSizeOverride(FVector2D(88.0f, 88.0f)); AddAutoHChild(ImgRow, ImgPreview, FMargin(0, 0, 14, 0)); UVerticalBox* ImgCtrl = Tree->ConstructWidget(UVerticalBox::StaticClass()); AddFillChild(ImgCtrl, MakeText(Tree, TEXT("TxtImageStatus"), TEXT("当前贴图:冒险者头像 | 可见性:Visible"), DemoFont, 13, ColorTextAccent, true, true), FMargin(0, 0, 0, 8)); UHorizontalBox* ImgBtns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(ImgBtns, MakeButton(Tree, TEXT("BtnSwitchTex"), TEXT("TxtSwitchTex"), TEXT("异步切换贴图"), DemoFont, 12, ColorAccentBlue), FMargin(0, 0, 6, 0)); AddFillHChild(ImgBtns, MakeButton(Tree, TEXT("BtnTintTex"), TEXT("TxtTintTex"), TEXT("切换着色"), DemoFont, 12, ColorBtnNeutral), FMargin(0, 0, 6, 0)); AddFillHChild(ImgBtns, MakeButton(Tree, TEXT("BtnCycleVis"), TEXT("TxtCycleVis"), TEXT("切换可见性"), DemoFont, 12, ColorBtnNeutral)); AddFillChild(ImgCtrl, ImgBtns); AddFillHChild(ImgRow, ImgCtrl); AddFillChild(SecImg, ImgRow); USpacer* Sp1 = Tree->ConstructWidget(USpacer::StaticClass()); Sp1->SetSize(FVector2D(1.0f, 10.0f)); PageMedia->AddChild(Sp1); // Section 2: Dynamic ScrollBox List UVerticalBox* SecList = nullptr; PageMedia->AddChild(MakeSectionCard(Tree, TEXT("CardList"), SecList)); AddFillChild(SecList, MakeText(Tree, TEXT("TxtSecListTitle"), TEXT("动态滚动列表(UScrollBox + 子控件委托自动解绑)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 6)); AddFillChild(SecList, MakeText(Tree, TEXT("TxtListSummary"), TEXT("动态列表项:0 条(新增/删除时实时观察顶部绑定数变化)"), DemoFont, 12, ColorTextSecondary, true), FMargin(0, 0, 0, 8)); UHorizontalBox* ListBtns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(ListBtns, MakeButton(Tree, TEXT("BtnListAddOne"), TEXT("TxtListAddOne"), TEXT("新增 1 项"), DemoFont, 12, ColorAccentGreen), FMargin(0, 0, 6, 0)); AddFillHChild(ListBtns, MakeButton(Tree, TEXT("BtnListAddTen"), TEXT("TxtListAddTen"), TEXT("批量 +10 项"), DemoFont, 12, ColorAccentBlue), FMargin(0, 0, 6, 0)); AddFillHChild(ListBtns, MakeButton(Tree, TEXT("BtnListClear"), TEXT("TxtListClear"), TEXT("清空列表"), DemoFont, 12, ColorAccentRed)); AddFillChild(SecList, ListBtns, FMargin(0, 0, 0, 8)); USizeBox* ListWrap = Tree->ConstructWidget(USizeBox::StaticClass()); ListWrap->SetHeightOverride(180.0f); UBorder* ListBg = Tree->ConstructWidget(UBorder::StaticClass()); ListBg->SetBrushColor(ColorCardDark); ListBg->SetPadding(FMargin(6.0f)); UScrollBox* ScrollDyn = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("ScrollDynamicList")); ScrollDyn->bIsVariable = true; ListBg->SetContent(ScrollDyn); ListWrap->AddChild(ListBg); AddFillChild(SecList, ListWrap); USpacer* Sp2 = Tree->ConstructWidget(USpacer::StaticClass()); Sp2->SetSize(FVector2D(1.0f, 10.0f)); PageMedia->AddChild(Sp2); // Section 3: UniformGridPanel + Overlay Badge Showcase UVerticalBox* SecGrid = nullptr; PageMedia->AddChild(MakeSectionCard(Tree, TEXT("CardGrid"), SecGrid)); AddFillChild(SecGrid, MakeText(Tree, TEXT("TxtSecGridTitle"), TEXT("网格与角标叠层布局(UUniformGridPanel + UOverlay)"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); UUniformGridPanel* Grid = Tree->ConstructWidget(UUniformGridPanel::StaticClass(), TEXT("GridBadges")); Grid->bIsVariable = true; Grid->SetSlotPadding(FMargin(6.0f)); const TArray> BadgeSpecs = { { TEXT("武器槽"), TEXT("NEW") }, { TEXT("防具槽"), TEXT("HOT") }, { TEXT("饰品槽"), TEXT("LV.5") }, { TEXT("徽章槽"), TEXT("VIP") } }; const TArray TagColors = { ColorAccentBlue, ColorAccentRed, ColorAccentGreen, ColorAccentAmber }; for (int32 i = 0; i < BadgeSpecs.Num(); ++i) { UOverlay* CellOverlay = Tree->ConstructWidget(UOverlay::StaticClass()); UBorder* CellBg = Tree->ConstructWidget(UBorder::StaticClass()); CellBg->SetBrushColor(ColorCardDark); CellBg->SetPadding(FMargin(10.0f, 14.0f)); UTextBlock* CellTitle = MakeText(Tree, NAME_None, BadgeSpecs[i].Key, DemoFont, 13, ColorTextPrimary); CellTitle->SetJustification(ETextJustify::Center); CellBg->SetContent(CellTitle); if (UOverlaySlot* BgSlot = CellOverlay->AddChildToOverlay(CellBg)) { BgSlot->SetHorizontalAlignment(HAlign_Fill); BgSlot->SetVerticalAlignment(VAlign_Fill); } UBorder* CornerTag = Tree->ConstructWidget(UBorder::StaticClass()); CornerTag->SetBrushColor(TagColors[i]); CornerTag->SetPadding(FMargin(6.0f, 2.0f)); CornerTag->SetContent(MakeText(Tree, NAME_None, BadgeSpecs[i].Value, DemoFont, 10, ColorTextPrimary)); if (UOverlaySlot* TagSlot = CellOverlay->AddChildToOverlay(CornerTag)) { TagSlot->SetHorizontalAlignment(HAlign_Right); TagSlot->SetVerticalAlignment(VAlign_Top); } if (UUniformGridSlot* GSlot = Grid->AddChildToUniformGrid(CellOverlay, 0, i)) { GSlot->SetHorizontalAlignment(HAlign_Fill); GSlot->SetVerticalAlignment(VAlign_Fill); } } AddFillChild(SecGrid, Grid); } TabSwitcher->AddChild(PageMedia); // ---- Page 3: Diagnostics ---- UScrollBox* PageDiag = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("PageDiag")); { UVerticalBox* SecDiag = nullptr; PageDiag->AddChild(MakeSectionCard(Tree, TEXT("CardDiag"), SecDiag)); AddFillChild(SecDiag, MakeText(Tree, TEXT("TxtSecDiagTitle"), TEXT("UI 框架与运行时实时诊断"), DemoFont, 15, ColorTextPrimary), FMargin(0, 0, 0, 8)); AddFillChild(SecDiag, MakeText(Tree, TEXT("TxtDiagDetail"), TEXT("点击刷新查看窗口栈、资源引用与委托绑定详情..."), DemoFont, 13, ColorTextSecondary, true, true), FMargin(0, 0, 0, 12)); UHorizontalBox* DiagBtns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(DiagBtns, MakeButton(Tree, TEXT("BtnDiagRefresh"), TEXT("TxtDiagRefresh"), TEXT("刷新诊断"), DemoFont, 13, ColorAccentBlue), FMargin(0, 0, 8, 0)); AddFillHChild(DiagBtns, MakeButton(Tree, TEXT("BtnDiagConcurrent"), TEXT("TxtDiagConcurrent"), TEXT("并发双开单例测试"), DemoFont, 13, ColorAccentAmber), FMargin(0, 0, 8, 0)); AddFillHChild(DiagBtns, MakeButton(Tree, TEXT("BtnDiagCancelLoad"), TEXT("TxtDiagCancelLoad"), TEXT("加载中取消测试"), DemoFont, 13, ColorAccentPurple)); AddFillChild(SecDiag, DiagBtns); } TabSwitcher->AddChild(PageDiag); AddFillHChild(BodyRow, CenterPanel, FMargin(0, 0, 12, 0), VAlign_Fill); // --- 2C. RightLog (Live Event Inspector) --- USizeBox* RightWrap = Tree->ConstructWidget(USizeBox::StaticClass(), TEXT("RightWrap")); RightWrap->SetWidthOverride(290.0f); UBorder* RightPanel = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("RightLogPanel")); RightPanel->SetBrushColor(ColorCardDark); RightPanel->SetPadding(FMargin(12.0f)); UVerticalBox* LogVBox = Tree->ConstructWidget(UVerticalBox::StaticClass(), TEXT("LogVBox")); RightPanel->SetContent(LogVBox); RightWrap->AddChild(RightPanel); UHorizontalBox* LogHeader = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("LogHeader")); AddFillHChild(LogHeader, MakeText(Tree, TEXT("TxtLogTitle"), TEXT("实时事件与生命周期日志"), DemoFont, 14, ColorTextPrimary)); AddAutoHChild(LogHeader, MakeButton(Tree, TEXT("BtnClearLog"), TEXT("TxtClearLog"), TEXT("清空"), DemoFont, 11, ColorBtnNeutral)); AddFillChild(LogVBox, LogHeader, FMargin(0, 0, 0, 8)); AddFillChild(LogVBox, MakeDivider(Tree, TEXT("LogDiv")), FMargin(0, 0, 0, 8)); UScrollBox* ScrollLog = Tree->ConstructWidget(UScrollBox::StaticClass(), TEXT("ScrollEventLog")); ScrollLog->bIsVariable = true; ScrollLog->AddChild(MakeText(Tree, TEXT("TxtEventLog"), TEXT("[日志就绪]"), DemoFont, 12, ColorTextSecondary, true, true)); if (UVerticalBoxSlot* LogSlot = LogVBox->AddChildToVerticalBox(ScrollLog)) { LogSlot->SetSize(FSlateChildSize(ESlateSizeRule::Fill)); LogSlot->SetHorizontalAlignment(HAlign_Fill); LogSlot->SetVerticalAlignment(VAlign_Fill); } AddAutoHChild(BodyRow, RightWrap, FMargin(0), VAlign_Fill); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoListItemBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoListItem"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoListItem"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UBorder* Root = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("ItemBorder")); Root->SetBrushColor(ColorCard); Root->SetPadding(FMargin(10.0f, 6.0f)); Tree->RootWidget = Root; UHorizontalBox* Row = Tree->ConstructWidget(UHorizontalBox::StaticClass(), TEXT("ItemRow")); Root->SetContent(Row); AddFillHChild(Row, MakeText(Tree, TEXT("TxtItemTitle"), TEXT("列表项 #1"), DemoFont, 13, ColorTextPrimary, true), FMargin(0, 0, 8, 0)); AddAutoHChild(Row, MakeButton(Tree, TEXT("BtnItemAction"), TEXT("TxtItemAction"), TEXT("触发"), DemoFont, 12, ColorAccentBlue), FMargin(0, 0, 6, 0)); AddAutoHChild(Row, MakeButton(Tree, TEXT("BtnItemDelete"), TEXT("TxtItemDelete"), TEXT("删除"), DemoFont, 12, ColorAccentRed)); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoNormalBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoNormal"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoNormal"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* Card = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("NormalCard")); Card->SetBrushColor(ColorPanel); Card->SetPadding(FMargin(22.0f, 18.0f)); SetupCenterCanvasSlot(Root, Card, FVector2D(460.0f, 280.0f), FVector2D(40.0f, -20.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); Card->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtNormalTitle"), TEXT("普通信息窗口(Normal / Singleton)"), DemoFont, 18, ColorTextPrimary, true), FMargin(0, 0, 0, 8)); AddFillChild(VBox, MakeDivider(Tree, TEXT("NormalDiv")), FMargin(0, 0, 0, 10)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtNormalBody"), TEXT("Layer: normal | Type: normal | Singleton: true\n重复点击左侧入口不会双开,而是刷新内容并置顶。"), DemoFont, 13, ColorTextSecondary, true, true), FMargin(0, 0, 0, 16)); UHorizontalBox* Btns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnNormalPing"), TEXT("TxtNormalPing"), TEXT("触发交互 (+1)"), DemoFont, 13, ColorAccentBlue), FMargin(0, 0, 8, 0)); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnNormalClose"), TEXT("TxtNormalClose"), TEXT("关闭窗口"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(VBox, Btns); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoFullscreenBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoFullscreen"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoFullscreen"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* FullBg = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("FullBg")); FullBg->SetBrushColor(FLinearColor(0.063f, 0.055f, 0.118f, 1.0f)); SetupFullCanvasSlot(Root, FullBg); UBorder* CenterBox = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("FullCard")); CenterBox->SetBrushColor(ColorPanel); CenterBox->SetPadding(FMargin(32.0f, 26.0f)); SetupCenterCanvasSlot(Root, CenterBox, FVector2D(640.0f, 440.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); CenterBox->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtFullTitle"), TEXT("全屏角色图鉴(Fullscreen 窗口)"), DemoFont, 24, ColorTextPrimary, true), FMargin(0, 0, 0, 10)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtFullDesc"), TEXT("Layer: normal | Type: fullscreen\n打开全屏窗口时,UIManager 会自动隐藏下层主界面与普通窗口;关闭本页时自动恢复下层显示。"), DemoFont, 14, ColorTextSecondary, true, true), FMargin(0, 0, 0, 18)); UImage* ImgPreview = Tree->ConstructWidget(UImage::StaticClass(), TEXT("ImgFullPreview")); ImgPreview->bIsVariable = true; ImgPreview->SetDesiredSizeOverride(FVector2D(128.0f, 128.0f)); if (UVerticalBoxSlot* ImgSlot = VBox->AddChildToVerticalBox(ImgPreview)) { ImgSlot->SetHorizontalAlignment(HAlign_Center); ImgSlot->SetPadding(FMargin(0, 0, 0, 18)); } UHorizontalBox* Btns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnFullOpenModal"), TEXT("TxtFullModal"), TEXT("在全屏页上方弹出模态框"), DemoFont, 14, ColorAccentAmber), FMargin(0, 0, 12, 0)); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnFullClose"), TEXT("TxtFullClose"), TEXT("退出全屏(恢复主界面)"), DemoFont, 14, ColorAccentPurple)); AddFillChild(VBox, Btns); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoModalBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoModal"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoModal"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; // Fullscreen semi-transparent blocker prevents clicking underlying widgets UBorder* Mask = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("ModalMask")); Mask->SetBrushColor(FLinearColor(0.0f, 0.0f, 0.0f, 0.68f)); SetupFullCanvasSlot(Root, Mask); UBorder* Dialog = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("ModalDialog")); Dialog->SetBrushColor(ColorPanel); Dialog->SetPadding(FMargin(24.0f, 20.0f)); SetupCenterCanvasSlot(Root, Dialog, FVector2D(460.0f, 250.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); Dialog->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtModalTitle"), TEXT("二次确认模态弹窗"), DemoFont, 19, ColorTextPrimary, true), FMargin(0, 0, 0, 10)); AddFillChild(VBox, MakeDivider(Tree, TEXT("ModalDiv")), FMargin(0, 0, 0, 12)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtModalMessage"), TEXT("半透明遮罩已拦截底层点击。请选择确认或取消以测试回调透传。"), DemoFont, 14, ColorTextSecondary, true, true), FMargin(0, 0, 0, 20)); UHorizontalBox* Btns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnModalConfirm"), TEXT("TxtModalConfirm"), TEXT("确认"), DemoFont, 14, ColorAccentGreen), FMargin(0, 0, 12, 0)); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnModalCancel"), TEXT("TxtModalCancel"), TEXT("取消"), DemoFont, 14, ColorBtnNeutral)); AddFillChild(VBox, Btns); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoCachedBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoCached"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoCached"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* Card = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("CachedCard")); Card->SetBrushColor(ColorPanel); Card->SetPadding(FMargin(24.0f, 20.0f)); SetupCenterCanvasSlot(Root, Card, FVector2D(490.0f, 300.0f), FVector2D(-30.0f, 20.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); Card->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtCachedTitle"), TEXT("缓存复用窗口(cacheTag = cache)"), DemoFont, 18, ColorTextPrimary, true), FMargin(0, 0, 0, 8)); AddFillChild(VBox, MakeDivider(Tree, TEXT("CachedDiv")), FMargin(0, 0, 0, 12)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtCachedStats"), TEXT("复用次数:0 | 按钮点击:0\n关闭后进入缓存池并自动解绑委托,再次打开直接复用实例且点击不翻倍。"), DemoFont, 13, ColorTextAccent, true, true), FMargin(0, 0, 0, 18)); UHorizontalBox* Btns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnCachedAction"), TEXT("TxtCachedAction"), TEXT("点击测试 (+1)"), DemoFont, 13, ColorAccentGreen), FMargin(0, 0, 10, 0)); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnCachedClose"), TEXT("TxtCachedClose"), TEXT("关闭并放回缓存池"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(VBox, Btns); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoMultiBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoMulti"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoMulti"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* Card = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("MultiCard")); Card->bIsVariable = true; Card->SetBrushColor(ColorCard); Card->SetPadding(FMargin(18.0f, 16.0f)); SetupCenterCanvasSlot(Root, Card, FVector2D(360.0f, 220.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); Card->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtMultiTitle"), TEXT("多实例便签窗 #1"), DemoFont, 17, ColorTextPrimary, true), FMargin(0, 0, 0, 8)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtMultiBody"), TEXT("singleton = false\n每个实例独立偏移、独立计数、独立关闭。"), DemoFont, 13, ColorTextSecondary, true, true), FMargin(0, 0, 0, 16)); UHorizontalBox* Btns = Tree->ConstructWidget(UHorizontalBox::StaticClass()); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnMultiCount"), TEXT("TxtMultiCount"), TEXT("实例计数 +1"), DemoFont, 13, ColorAccentCyan), FMargin(0, 0, 8, 0)); AddFillHChild(Btns, MakeButton(Tree, TEXT("BtnMultiClose"), TEXT("TxtMultiClose"), TEXT("关闭本窗"), DemoFont, 13, ColorBtnNeutral)); AddFillChild(VBox, Btns); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoToastBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoToast"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoToast"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Root->SetVisibility(ESlateVisibility::SelfHitTestInvisible); Tree->RootWidget = Root; UBorder* Pill = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("ToastPill")); Pill->bIsVariable = true; Pill->SetVisibility(ESlateVisibility::SelfHitTestInvisible); Pill->SetBrushColor(FLinearColor(0.086f, 0.310f, 0.520f, 0.94f)); Pill->SetPadding(FMargin(22.0f, 10.0f)); if (UCanvasPanelSlot* CSlot = Root->AddChildToCanvas(Pill)) { CSlot->SetAnchors(FAnchors(0.5f, 0.0f, 0.5f, 0.0f)); CSlot->SetAlignment(FVector2D(0.5f, 0.0f)); CSlot->SetPosition(FVector2D(0.0f, 92.0f)); CSlot->SetAutoSize(true); } UTextBlock* Msg = MakeText(Tree, TEXT("TxtToastMessage"), TEXT("飘字提示:这是一条 Tips 层自动消失通知"), DemoFont, 14, ColorTextPrimary, true); Msg->SetJustification(ETextJustify::Center); Pill->SetContent(Msg); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); } bool USetupDemoAssetsCommandlet::CreateUIDemoSystemBlueprint(UFont* DemoFont) const { const FString PackageName = TEXT("/Game/UI/Demo/WBP_UIDemoSystem"); UPackage* Package = nullptr; UWidgetBlueprint* WidgetBP = BeginWidgetBlueprint(PackageName, TEXT("WBP_UIDemoSystem"), Package); if (!WidgetBP) { return false; } UWidgetTree* Tree = WidgetBP->WidgetTree; UCanvasPanel* Root = Tree->ConstructWidget(UCanvasPanel::StaticClass(), TEXT("RootCanvas")); Tree->RootWidget = Root; UBorder* Mask = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("SystemMask")); Mask->SetBrushColor(FLinearColor(0.10f, 0.03f, 0.04f, 0.76f)); SetupFullCanvasSlot(Root, Mask); UBorder* Dialog = Tree->ConstructWidget(UBorder::StaticClass(), TEXT("SystemDialog")); Dialog->SetBrushColor(FLinearColor(0.145f, 0.075f, 0.095f, 0.98f)); Dialog->SetPadding(FMargin(26.0f, 22.0f)); SetupCenterCanvasSlot(Root, Dialog, FVector2D(500.0f, 250.0f)); UVerticalBox* VBox = Tree->ConstructWidget(UVerticalBox::StaticClass()); Dialog->SetContent(VBox); AddFillChild(VBox, MakeText(Tree, TEXT("TxtSystemTitle"), TEXT("系统级顶层弹窗(Layer: system)"), DemoFont, 20, FLinearColor(1.0f, 0.62f, 0.62f, 1.0f), true), FMargin(0, 0, 0, 10)); AddFillChild(VBox, MakeDivider(Tree, TEXT("SysDiv")), FMargin(0, 0, 0, 12)); AddFillChild(VBox, MakeText(Tree, TEXT("TxtSystemBody"), TEXT("ZOrder 400+,优先级高于 normal / popup / tips 全部层级,常用于断线重连或强制系统公告。"), DemoFont, 14, ColorTextPrimary, true, true), FMargin(0, 0, 0, 20)); AddFillChild(VBox, MakeButton(Tree, TEXT("BtnSystemAck"), TEXT("TxtSystemAck"), TEXT("我知道了(关闭系统弹窗)"), DemoFont, 14, ColorAccentRed)); return FinishWidgetBlueprint(Package, WidgetBP, PackageName); }