74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "WingHandler.h"
|
|
#include "WingFetcher.h"
|
|
#include "WingUtils.h"
|
|
#include "WingTypes.h"
|
|
#include "WingServer.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
#include "BlueprintInterface_Remove.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UWing_Blueprint_RemoveInterface : public UWingHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Blueprint name or package path"))
|
|
FString Blueprint;
|
|
|
|
UPROPERTY(meta=(Description="Interface name to remove"))
|
|
FString Interface;
|
|
|
|
UPROPERTY(meta=(Optional, Description="If true, keep the function graphs as regular functions"))
|
|
bool PreserveFunctions = false;
|
|
|
|
virtual void Register() override
|
|
{
|
|
UWingServer::AddHandler(this,
|
|
TEXT("Remove a Blueprint Interface implementation from a Blueprint. "
|
|
"Optionally preserve the function graphs as regular functions."));
|
|
}
|
|
virtual void Handle() override
|
|
{
|
|
WingFetcher F;
|
|
UBlueprint* BP = F.Asset(Blueprint).Cast<UBlueprint>();
|
|
if (!BP) return;
|
|
|
|
// Resolve the interface name to a UClass*
|
|
UWingTypes::Requirements Req;
|
|
Req.BlueprintType = false;
|
|
Req.Blueprintable = false;
|
|
Req.AllowContainer = false;
|
|
UClass* FoundInterface = UWingTypes::TextToOneInterfaceType(Interface, Req);
|
|
if (!FoundInterface) return;
|
|
|
|
// Verify this blueprint actually implements it
|
|
bool Found = false;
|
|
for (const FBPInterfaceDescription& Desc : BP->ImplementedInterfaces)
|
|
{
|
|
if (Desc.Interface == FoundInterface) { Found = true; break; }
|
|
}
|
|
if (!Found)
|
|
{
|
|
UWingServer::Printf(TEXT("ERROR: Blueprint %s does not implement interface %s\n"),
|
|
*WingUtils::FormatName(BP), *WingUtils::FormatName(FoundInterface));
|
|
return;
|
|
}
|
|
|
|
FTopLevelAssetPath InterfacePath = FoundInterface->GetClassPathName();
|
|
FBlueprintEditorUtils::RemoveInterface(BP, InterfacePath, PreserveFunctions);
|
|
|
|
UWingServer::Printf(TEXT("Removed interface %s\n"), *WingUtils::FormatName(FoundInterface));
|
|
if (PreserveFunctions)
|
|
UWingServer::Print(TEXT("Function graphs preserved as regular functions.\n"));
|
|
}
|
|
};
|