BlueprintGraph_Delete
This commit is contained in:
BIN
Content/Testing/BP_Test.uasset
LFS
BIN
Content/Testing/BP_Test.uasset
LFS
Binary file not shown.
@@ -1,93 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
|
||||||
#include "WingServer.h"
|
|
||||||
#include "WingHandler.h"
|
|
||||||
#include "WingFetcher.h"
|
|
||||||
#include "WingUtils.h"
|
|
||||||
#include "Engine/Blueprint.h"
|
|
||||||
#include "EdGraph/EdGraph.h"
|
|
||||||
#include "Kismet2/BlueprintEditorUtils.h"
|
|
||||||
#include "BlueprintGraph_Delete.generated.h"
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
UCLASS()
|
|
||||||
class UWing_BlueprintGraph_Delete : public UObject, public IWingHandler
|
|
||||||
{
|
|
||||||
GENERATED_BODY()
|
|
||||||
|
|
||||||
public:
|
|
||||||
UPROPERTY(meta=(Description="Path to a blueprint, e.g. /Game/Foo/Bar"))
|
|
||||||
FString Blueprint;
|
|
||||||
|
|
||||||
UPROPERTY(meta=(Description="Name of the graph to delete"))
|
|
||||||
FString Graph;
|
|
||||||
|
|
||||||
virtual FString GetDescription() const override
|
|
||||||
{
|
|
||||||
return TEXT("Delete a function or macro graph from a Blueprint. Cannot delete EventGraph pages.");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Handle() override
|
|
||||||
{
|
|
||||||
WingFetcher F;
|
|
||||||
F.Walk(Blueprint);
|
|
||||||
if (!F.Ok()) return;
|
|
||||||
|
|
||||||
UBlueprint* BP = F.Cast<UBlueprint>();
|
|
||||||
if (!BP) return;
|
|
||||||
|
|
||||||
// Search function graphs, then macro graphs
|
|
||||||
UEdGraph* TargetGraph = nullptr;
|
|
||||||
FString GraphType;
|
|
||||||
|
|
||||||
for (UEdGraph* G : BP->FunctionGraphs)
|
|
||||||
{
|
|
||||||
if (G && WingUtils::Identifies(Graph, G))
|
|
||||||
{
|
|
||||||
TargetGraph = G;
|
|
||||||
GraphType = TEXT("function");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!TargetGraph)
|
|
||||||
{
|
|
||||||
for (UEdGraph* G : BP->MacroGraphs)
|
|
||||||
{
|
|
||||||
if (G && WingUtils::Identifies(Graph, G))
|
|
||||||
{
|
|
||||||
TargetGraph = G;
|
|
||||||
GraphType = TEXT("macro");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's an UbergraphPage (EventGraph) — disallow deletion
|
|
||||||
if (!TargetGraph)
|
|
||||||
{
|
|
||||||
for (UEdGraph* G : BP->UbergraphPages)
|
|
||||||
{
|
|
||||||
if (G && WingUtils::Identifies(Graph, G))
|
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("ERROR: Cannot delete UbergraphPage '%s'. EventGraph pages cannot be deleted.\n"),
|
|
||||||
*WingUtils::FormatName(G));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UWingServer::Printf(TEXT("ERROR: Graph '%s' not found in blueprint %s\n"),
|
|
||||||
*Graph, *WingUtils::FormatName(BP));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the graph
|
|
||||||
FString GraphName = WingUtils::FormatName(TargetGraph);
|
|
||||||
FBlueprintEditorUtils::RemoveGraph(BP, TargetGraph, EGraphRemoveFlags::Default);
|
|
||||||
|
|
||||||
UWingServer::Printf(TEXT("Deleted %s graph %s\n"), *GraphType, *GraphName);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
|
||||||
#include "WingServer.h"
|
|
||||||
#include "WingHandler.h"
|
|
||||||
#include "WingFetcher.h"
|
|
||||||
#include "WingUtils.h"
|
|
||||||
#include "Engine/Blueprint.h"
|
|
||||||
#include "EdGraph/EdGraph.h"
|
|
||||||
#include "Kismet2/BlueprintEditorUtils.h"
|
|
||||||
#include "BlueprintGraph_Rename.generated.h"
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
UCLASS()
|
|
||||||
class UWing_BlueprintGraph_Rename : public UObject, public IWingHandler
|
|
||||||
{
|
|
||||||
GENERATED_BODY()
|
|
||||||
|
|
||||||
public:
|
|
||||||
UPROPERTY(meta=(Description="Path to the graph, e.g. /Game/Foo,graph:MyFunction"))
|
|
||||||
FString Graph;
|
|
||||||
|
|
||||||
UPROPERTY(meta=(Description="New name for the graph"))
|
|
||||||
FString NewName;
|
|
||||||
|
|
||||||
virtual FString GetDescription() const override
|
|
||||||
{
|
|
||||||
return TEXT("Rename a function or macro graph in a Blueprint. Cannot rename EventGraph pages.");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Handle() override
|
|
||||||
{
|
|
||||||
WingFetcher F;
|
|
||||||
UEdGraph* TargetGraph = F.Walk(Graph).Cast<UEdGraph>();
|
|
||||||
if (!TargetGraph) return;
|
|
||||||
|
|
||||||
UBlueprint* BP = Cast<UBlueprint>(TargetGraph->GetOuter());
|
|
||||||
if (!BP)
|
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("Error: Graph '%s' is not owned by a Blueprint.\n"), *Graph);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's an UbergraphPage -- disallow rename
|
|
||||||
if (BP->UbergraphPages.Contains(TargetGraph))
|
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("Error: Cannot rename UbergraphPage '%s'. EventGraph pages cannot be renamed.\n"),
|
|
||||||
*WingUtils::FormatName(TargetGraph));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify it's a function or macro graph
|
|
||||||
bool bIsFunction = BP->FunctionGraphs.Contains(TargetGraph);
|
|
||||||
bool bIsMacro = BP->MacroGraphs.Contains(TargetGraph);
|
|
||||||
if (!bIsFunction && !bIsMacro)
|
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("Error: Graph '%s' is not a function or macro graph.\n"),
|
|
||||||
*WingUtils::FormatName(TargetGraph));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for name collision
|
|
||||||
for (UEdGraph* Existing : WingUtils::FindAllNamed(NewName, WingUtils::AllGraphs(BP)))
|
|
||||||
{
|
|
||||||
if (Existing != TargetGraph)
|
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("Error: A graph named '%s' already exists in '%s'.\n"),
|
|
||||||
*NewName, *WingUtils::FormatName(BP));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FBlueprintEditorUtils::RenameGraph(TargetGraph, NewName);
|
|
||||||
|
|
||||||
UWingServer::Printf(TEXT("Renamed to %s %s\n"),
|
|
||||||
bIsFunction ? TEXT("function") : TEXT("macro"),
|
|
||||||
*WingUtils::FormatName(TargetGraph));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "WingServer.h"
|
||||||
|
#include "WingHandler.h"
|
||||||
|
#include "WingFetcher.h"
|
||||||
|
#include "WingUtils.h"
|
||||||
|
#include "Engine/Blueprint.h"
|
||||||
|
#include "EdGraph/EdGraph.h"
|
||||||
|
#include "Kismet2/BlueprintEditorUtils.h"
|
||||||
|
#include "BlueprintGraph_Delete.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class UWing_BlueprintGraph_Delete : public UObject, public IWingHandler
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(meta=(Description="Path to the graph, e.g. /Game/MyBP,graph:MyFunction"))
|
||||||
|
FString Graph;
|
||||||
|
|
||||||
|
virtual FString GetDescription() const override
|
||||||
|
{
|
||||||
|
return TEXT("Delete a function or macro graph from a Blueprint.");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Handle() override
|
||||||
|
{
|
||||||
|
WingFetcher F;
|
||||||
|
UEdGraph* FoundGraph = F.Walk(Graph).Cast<UEdGraph>();
|
||||||
|
if (!FoundGraph) return;
|
||||||
|
|
||||||
|
UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForGraph(FoundGraph);
|
||||||
|
if (!BP)
|
||||||
|
{
|
||||||
|
UWingServer::Print(TEXT("ERROR: Could not find owning blueprint for this graph.\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BP->FunctionGraphs.Contains(FoundGraph) && !BP->MacroGraphs.Contains(FoundGraph))
|
||||||
|
{
|
||||||
|
UWingServer::Printf(TEXT("ERROR: %s is not a function or macro graph.\n"), *WingUtils::FormatName(FoundGraph));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FBlueprintEditorUtils::RemoveGraph(BP, FoundGraph, EGraphRemoveFlags::Recompile);
|
||||||
|
|
||||||
|
UWingServer::Printf(TEXT("Deleted graph from %s\n"), *WingUtils::FormatName(BP));
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user