69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPFetcher.h"
|
|
#include "MCPUtils.h"
|
|
#include "MCPServer.h"
|
|
#include "EdGraph/EdGraph.h"
|
|
#include "EdGraph/EdGraphNode.h"
|
|
#include "MaterialGraph/MaterialGraphNode.h"
|
|
#include "Materials/Material.h"
|
|
#include "IMaterialEditor.h"
|
|
#include "GraphNode_Delete.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_GraphNode_Delete : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Path to the node, e.g. /Game/Foo,graph:EventGraph,node:MyNode"))
|
|
FString Node;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Delete a node from a graph. "
|
|
"Cannot delete undeletable nodes (entry points, root nodes, etc).");
|
|
}
|
|
|
|
virtual void Handle(FStringBuilderBase& Result) override
|
|
{
|
|
MCPFetcher F;
|
|
UEdGraphNode* FoundNode = F.Walk(Node).Cast<UEdGraphNode>();
|
|
if (!FoundNode) return;
|
|
|
|
UEdGraph* Graph = FoundNode->GetGraph();
|
|
FString NodeTitle = MCPUtils::FormatName(FoundNode);
|
|
FString GraphName = MCPUtils::FormatName(Graph);
|
|
|
|
if (!FoundNode->CanUserDeleteNode())
|
|
{
|
|
UMCPServer::Printf(TEXT("ERROR: Cannot delete node '%s' in graph '%s' — it is not deletable.\n"),
|
|
*NodeTitle, *GraphName);
|
|
return;
|
|
}
|
|
|
|
if (Cast<UMaterialGraphNode>(FoundNode))
|
|
{
|
|
// Use the material editor's DeleteNodes to properly remove
|
|
// both the graph node and the underlying material expression.
|
|
IMaterialEditor* MatEditor = F.CastEditor<UMaterial, IMaterialEditor>();
|
|
if (!MatEditor) return;
|
|
MatEditor->DeleteNodes({FoundNode});
|
|
}
|
|
else
|
|
{
|
|
FoundNode->BreakAllNodeLinks();
|
|
Graph->RemoveNode(FoundNode);
|
|
}
|
|
|
|
Result.Appendf(TEXT("Deleted node '%s' from graph '%s'.\n"), *NodeTitle, *GraphName);
|
|
}
|
|
};
|