Halfway through with repair of right-click menus
This commit is contained in:
67
Plugins/UEWingman/Deprecated/Enum_Create.h
Normal file
67
Plugins/UEWingman/Deprecated/Enum_Create.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "WingServer.h"
|
||||
#include "WingHandler.h"
|
||||
#include "WingUtils.h"
|
||||
#include "Engine/UserDefinedEnum.h"
|
||||
#include "Kismet2/EnumEditorUtils.h"
|
||||
#include "Factories/EnumFactory.h"
|
||||
#include "WingPackageMaker.h"
|
||||
#include "Enum_Create.generated.h"
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UCLASS()
|
||||
class UWing_Enum_Create : public UObject, public IWingHandler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(meta=(Description="Full package path for the new enum (e.g. '/Game/DataTypes/E_MyEnum')"))
|
||||
FString AssetPath;
|
||||
|
||||
UPROPERTY(meta=(Description="Array of enum value names"))
|
||||
FWingJsonArray Values;
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Create a new UserDefinedEnum asset with the specified values.");
|
||||
}
|
||||
|
||||
virtual void Handle() override
|
||||
{
|
||||
WingPackageMaker Maker(AssetPath);
|
||||
if (!Maker.Ok()) return;
|
||||
|
||||
TArray<FString> EnumValues;
|
||||
for (const TSharedPtr<FJsonValue>& Val : Values.Array)
|
||||
{
|
||||
FString Str = Val->AsString();
|
||||
if (!Str.IsEmpty()) EnumValues.Add(Str);
|
||||
}
|
||||
if (EnumValues.Num() == 0)
|
||||
{
|
||||
UWingServer::Print(TEXT("ERROR: Values must be a non-empty array of strings\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the enum using AssetTools.
|
||||
UUserDefinedEnum* NewEnum = Maker.CreateAsset<UUserDefinedEnum, UEnumFactory>();
|
||||
if (!NewEnum) return;
|
||||
|
||||
// Add enum values — UUserDefinedEnum starts with a MAX value.
|
||||
// We need to add entries before MAX.
|
||||
for (int32 i = 0; i < EnumValues.Num(); ++i)
|
||||
{
|
||||
FEnumEditorUtils::AddNewEnumeratorForUserDefinedEnum(NewEnum);
|
||||
int32 NewIndex = NewEnum->NumEnums() - 2;
|
||||
FEnumEditorUtils::SetEnumeratorDisplayName(NewEnum, NewIndex, FText::FromString(EnumValues[i]));
|
||||
}
|
||||
|
||||
UWingServer::Printf(TEXT("Created %s with %d values\n"), *NewEnum->GetPathName(), EnumValues.Num());
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user