Files
integration/Plugins/UEWingman/Source/UEWingman/Handlers/GraphPin_Disconnect.h

107 lines
2.7 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
2026-03-18 10:17:58 -04:00
#include "WingServer.h"
#include "WingHandler.h"
#include "WingFetcher.h"
#include "WingProperty.h"
2026-03-18 10:17:58 -04:00
#include "WingUtils.h"
2026-03-12 19:12:37 -04:00
#include "Engine/Blueprint.h"
#include "EdGraph/EdGraph.h"
2026-03-08 22:17:14 -04:00
#include "EdGraph/EdGraphPin.h"
2026-03-12 00:44:17 -04:00
#include "GraphPin_Disconnect.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
USTRUCT()
struct FDisconnectPinEntry
{
GENERATED_BODY()
UPROPERTY()
2026-03-10 01:42:43 -04:00
FString Pin;
2026-03-08 22:17:14 -04:00
UPROPERTY(meta=(Optional))
2026-03-10 01:42:43 -04:00
FString TargetPin;
2026-03-08 22:17:14 -04:00
};
2026-03-12 00:44:17 -04:00
UCLASS()
2026-04-01 17:45:33 -04:00
class UWing_GraphPin_Disconnect : public UWingHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
UPROPERTY(meta=(Description="Target graph"))
2026-03-12 21:31:41 -04:00
FString Graph;
2026-03-08 22:17:14 -04:00
UPROPERTY(meta=(Description="Array of {pin, targetPin?} objects. If targetPin is omitted, all connections on the pin are broken."))
2026-03-18 10:17:58 -04:00
FWingJsonArray Disconnections;
2026-03-08 22:17:14 -04:00
virtual FString GetDescription() const override
{
2026-03-12 21:31:41 -04:00
return TEXT("Disconnect pins in a graph (Blueprint or Material). "
2026-03-08 22:17:14 -04:00
"Can disconnect a specific link or all links on a pin.");
}
virtual void Handle() override
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
WingFetcher F;
2026-03-17 17:24:35 -04:00
UEdGraph* G = F.Walk(Graph).Cast<UEdGraph>();
2026-03-12 21:31:41 -04:00
if (!G) return;
2026-03-08 22:17:14 -04:00
int32 SuccessCount = 0;
int32 TotalDisconnected = 0;
for (const TSharedPtr<FJsonValue>& DiscVal : Disconnections.Array)
{
FDisconnectPinEntry Entry;
if (!FWingProperty::PopulateFromJson(FDisconnectPinEntry::StaticStruct(), &Entry, DiscVal)) continue;
2026-03-08 22:17:14 -04:00
2026-03-18 10:17:58 -04:00
WingFetcher FP(G);
2026-03-10 01:42:43 -04:00
UEdGraphPin* Pin = FP.Walk(Entry.Pin).Cast<UEdGraphPin>();
if (!Pin) continue;
2026-03-08 22:17:14 -04:00
int32 DisconnectedCount = 0;
2026-03-10 01:42:43 -04:00
if (!Entry.TargetPin.IsEmpty())
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
WingFetcher FT(G);
2026-03-10 01:42:43 -04:00
UEdGraphPin* Target = FT.Walk(Entry.TargetPin).Cast<UEdGraphPin>();
if (!Target) continue;
2026-03-08 22:17:14 -04:00
2026-03-10 01:42:43 -04:00
if (!Pin->LinkedTo.Contains(Target))
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Error: %s.%s is not connected to %s.%s\n"),
*WingUtils::FormatName(Pin->GetOwningNode()), *WingUtils::FormatName(Pin),
*WingUtils::FormatName(Target->GetOwningNode()), *WingUtils::FormatName(Target));
2026-03-08 22:17:14 -04:00
continue;
}
2026-03-10 01:42:43 -04:00
Pin->BreakLinkTo(Target);
2026-03-08 22:17:14 -04:00
DisconnectedCount = 1;
}
else
{
DisconnectedCount = Pin->LinkedTo.Num();
if (DisconnectedCount > 0)
{
Pin->BreakAllPinLinks(true);
}
}
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Disconnected %d link(s) from %s.%s\n"),
2026-03-10 07:17:42 -04:00
DisconnectedCount,
2026-03-18 10:17:58 -04:00
*WingUtils::FormatName(Pin->GetOwningNode()), *WingUtils::FormatName(Pin));
2026-03-08 22:17:14 -04:00
SuccessCount++;
TotalDisconnected += DisconnectedCount;
}
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Done: %d/%d succeeded, %d links broken.\n"),
2026-03-10 07:17:42 -04:00
SuccessCount, Disconnections.Array.Num(), TotalDisconnected);
2026-03-08 22:17:14 -04:00
}
};