chore: upgrade ts2lua-unreal to v0.3.1 with lowercase lib/module.lua & lib/class.lua and commit framework refactor
This commit is contained in:
1 parent
783dccf53d
commit
3572f2da43
206 files changed
+14442
-13186
No files matched your search
@@ -0,0 +1,278 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "SetupFrameworkAssetsCommandlet.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/Image.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Components/VerticalBox.h"
|
||||
#include "Components/VerticalBoxSlot.h"
|
||||
#include "Engine/Texture2D.h"
|
||||
#include "Engine/World.h"
|
||||
#include "GameFramework/WorldSettings.h"
|
||||
#include "HAL/FileManager.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "Kismet2/KismetEditorUtilities.h"
|
||||
#include "Misc/PackageName.h"
|
||||
#include "Misc/Paths.h"
|
||||
#include "UObject/Package.h"
|
||||
#include "UObject/SavePackage.h"
|
||||
#include "WidgetBlueprint.h"
|
||||
#include "WidgetBlueprintFactory.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
bool SaveAssetPackage(UPackage* Package, UObject* Asset, const FString& LongPackageName)
|
||||
{
|
||||
if (!Package || !Asset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const FString Extension = Asset->IsA<UWorld>()
|
||||
? 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);
|
||||
}
|
||||
}
|
||||
|
||||
USetupFrameworkAssetsCommandlet::USetupFrameworkAssetsCommandlet()
|
||||
{
|
||||
IsClient = true;
|
||||
IsEditor = true;
|
||||
IsServer = false;
|
||||
LogToConsole = true;
|
||||
}
|
||||
|
||||
int32 USetupFrameworkAssetsCommandlet::Main(const FString& Params)
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupFrameworkAssets] Creating Phase-0 baseline assets..."));
|
||||
|
||||
if (!CreateBootstrapMap())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupFrameworkAssets] Failed to create /Game/Maps/L_Bootstrap."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CreateMiniSettingsTexture())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupFrameworkAssets] Failed to create /Game/UI/Textures/T_MiniSettingsIcon."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CreateMiniSettingsWidgetBlueprint())
|
||||
{
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[SetupFrameworkAssets] Failed to create /Game/UI/WBP_MiniSettings."));
|
||||
return 1;
|
||||
}
|
||||
|
||||
UE_LOG(LogUnrealLuaDemoEditor, Display, TEXT("[SetupFrameworkAssets] All Phase-0 baseline assets created successfully."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool USetupFrameworkAssetsCommandlet::CreateBootstrapMap() const
|
||||
{
|
||||
const FString PackageName = TEXT("/Game/Maps/L_Bootstrap");
|
||||
UPackage* Package = CreatePackage(*PackageName);
|
||||
if (!Package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UWorld* NewWorld = UWorld::CreateWorld(EWorldType::Inactive, false, TEXT("L_Bootstrap"), 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 USetupFrameworkAssetsCommandlet::CreateMiniSettingsTexture() const
|
||||
{
|
||||
const FString PackageName = TEXT("/Game/UI/Textures/T_MiniSettingsIcon");
|
||||
const FString AssetName = TEXT("T_MiniSettingsIcon");
|
||||
|
||||
UPackage* Package = CreatePackage(*PackageName);
|
||||
if (!Package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr int32 Size = 128;
|
||||
UTexture2D* Texture = NewObject<UTexture2D>(Package, *AssetName, RF_Public | RF_Standalone);
|
||||
if (!Texture)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TArray<uint8> 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 bool bRing = (Dist >= 0.45f && Dist <= 0.78f);
|
||||
const bool bCore = (Dist <= 0.28f);
|
||||
|
||||
// BGRA8
|
||||
if (bCore)
|
||||
{
|
||||
Pixels[Idx + 0] = 255;
|
||||
Pixels[Idx + 1] = 220;
|
||||
Pixels[Idx + 2] = 60;
|
||||
Pixels[Idx + 3] = 255;
|
||||
}
|
||||
else if (bRing)
|
||||
{
|
||||
Pixels[Idx + 0] = 240;
|
||||
Pixels[Idx + 1] = 170;
|
||||
Pixels[Idx + 2] = 40;
|
||||
Pixels[Idx + 3] = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
Pixels[Idx + 0] = 48;
|
||||
Pixels[Idx + 1] = 36;
|
||||
Pixels[Idx + 2] = 28;
|
||||
Pixels[Idx + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 USetupFrameworkAssetsCommandlet::CreateMiniSettingsWidgetBlueprint() const
|
||||
{
|
||||
const FString PackageName = TEXT("/Game/UI/WBP_MiniSettings");
|
||||
const FString AssetName = TEXT("WBP_MiniSettings");
|
||||
|
||||
UPackage* Package = CreatePackage(*PackageName);
|
||||
if (!Package)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UWidgetBlueprintFactory* Factory = NewObject<UWidgetBlueprintFactory>();
|
||||
Factory->ParentClass = UUserWidget::StaticClass();
|
||||
|
||||
UWidgetBlueprint* WidgetBP = Cast<UWidgetBlueprint>(
|
||||
Factory->FactoryCreateNew(UWidgetBlueprint::StaticClass(), Package, *AssetName, RF_Public | RF_Standalone, nullptr, GWarn));
|
||||
if (!WidgetBP || !WidgetBP->WidgetTree)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UWidgetTree* Tree = WidgetBP->WidgetTree;
|
||||
|
||||
UCanvasPanel* RootCanvas = Tree->ConstructWidget<UCanvasPanel>(UCanvasPanel::StaticClass(), TEXT("RootCanvas"));
|
||||
Tree->RootWidget = RootCanvas;
|
||||
|
||||
UBorder* PanelBorder = Tree->ConstructWidget<UBorder>(UBorder::StaticClass(), TEXT("PanelBorder"));
|
||||
PanelBorder->SetBrushColor(FLinearColor(0.08f, 0.10f, 0.14f, 0.92f));
|
||||
PanelBorder->SetPadding(FMargin(24.0f));
|
||||
if (UCanvasPanelSlot* BorderSlot = RootCanvas->AddChildToCanvas(PanelBorder))
|
||||
{
|
||||
BorderSlot->SetAnchors(FAnchors(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
BorderSlot->SetAlignment(FVector2D(0.5f, 0.5f));
|
||||
BorderSlot->SetSize(FVector2D(420.0f, 360.0f));
|
||||
}
|
||||
|
||||
UVerticalBox* LayoutBox = Tree->ConstructWidget<UVerticalBox>(UVerticalBox::StaticClass(), TEXT("LayoutBox"));
|
||||
PanelBorder->SetContent(LayoutBox);
|
||||
|
||||
// 1. Named Image: ImgIcon
|
||||
UImage* ImgIcon = Tree->ConstructWidget<UImage>(UImage::StaticClass(), TEXT("ImgIcon"));
|
||||
ImgIcon->bIsVariable = true;
|
||||
ImgIcon->SetDesiredSizeOverride(FVector2D(96.0f, 96.0f));
|
||||
if (UVerticalBoxSlot* IconSlot = LayoutBox->AddChildToVerticalBox(ImgIcon))
|
||||
{
|
||||
IconSlot->SetHorizontalAlignment(HAlign_Center);
|
||||
IconSlot->SetPadding(FMargin(0.0f, 8.0f, 0.0f, 16.0f));
|
||||
}
|
||||
|
||||
// 2. Named TextBlock: TxtStatus
|
||||
UTextBlock* TxtStatus = Tree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TxtStatus"));
|
||||
TxtStatus->bIsVariable = true;
|
||||
TxtStatus->SetText(FText::FromString(TEXT("Mini Settings")));
|
||||
if (UVerticalBoxSlot* StatusSlot = LayoutBox->AddChildToVerticalBox(TxtStatus))
|
||||
{
|
||||
StatusSlot->SetHorizontalAlignment(HAlign_Center);
|
||||
StatusSlot->SetPadding(FMargin(0.0f, 0.0f, 0.0f, 16.0f));
|
||||
}
|
||||
|
||||
// 3. Named Button: BtnToggle (+ TxtToggleLabel)
|
||||
UButton* BtnToggle = Tree->ConstructWidget<UButton>(UButton::StaticClass(), TEXT("BtnToggle"));
|
||||
BtnToggle->bIsVariable = true;
|
||||
UTextBlock* TxtToggleLabel = Tree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TxtToggleLabel"));
|
||||
TxtToggleLabel->bIsVariable = true;
|
||||
TxtToggleLabel->SetText(FText::FromString(TEXT("Toggle Sound")));
|
||||
BtnToggle->AddChild(TxtToggleLabel);
|
||||
if (UVerticalBoxSlot* ToggleSlot = LayoutBox->AddChildToVerticalBox(BtnToggle))
|
||||
{
|
||||
ToggleSlot->SetHorizontalAlignment(HAlign_Fill);
|
||||
ToggleSlot->SetPadding(FMargin(0.0f, 0.0f, 0.0f, 12.0f));
|
||||
}
|
||||
|
||||
// 4. Named Button: BtnClose
|
||||
UButton* BtnClose = Tree->ConstructWidget<UButton>(UButton::StaticClass(), TEXT("BtnClose"));
|
||||
BtnClose->bIsVariable = true;
|
||||
UTextBlock* TxtCloseLabel = Tree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TxtCloseLabel"));
|
||||
TxtCloseLabel->SetText(FText::FromString(TEXT("Close")));
|
||||
BtnClose->AddChild(TxtCloseLabel);
|
||||
if (UVerticalBoxSlot* CloseSlot = LayoutBox->AddChildToVerticalBox(BtnClose))
|
||||
{
|
||||
CloseSlot->SetHorizontalAlignment(HAlign_Fill);
|
||||
}
|
||||
|
||||
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(WidgetBP);
|
||||
FKismetEditorUtilities::CompileBlueprint(WidgetBP);
|
||||
|
||||
FAssetRegistryModule::AssetCreated(WidgetBP);
|
||||
Package->MarkPackageDirty();
|
||||
|
||||
return SaveAssetPackage(Package, WidgetBP, PackageName);
|
||||
}
|
||||
Reference in new issue
Block a user