2026-03-10 01:42:43 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2026-03-18 10:17:58 -04:00
|
|
|
#include "WingServer.h"
|
2026-04-07 22:04:44 -04:00
|
|
|
#include "WingBasics.h"
|
2026-03-18 10:17:58 -04:00
|
|
|
#include "WingFetcher.h"
|
2026-03-26 19:16:59 -04:00
|
|
|
#include "WingProperty.h"
|
2026-03-18 10:17:58 -04:00
|
|
|
#include "WingUtils.h"
|
2026-03-12 19:12:37 -04:00
|
|
|
#include "EdGraph/EdGraph.h"
|
2026-04-08 01:48:49 -04:00
|
|
|
#include "EdGraph/EdGraphSchema.h"
|
2026-03-10 01:42:43 -04:00
|
|
|
#include "EdGraph/EdGraphPin.h"
|
2026-03-12 00:44:17 -04:00
|
|
|
#include "GraphPin_Connect.generated.h"
|
2026-03-10 01:42:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
USTRUCT()
|
|
|
|
|
struct FConnectPinsEntry
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
FString SourcePin;
|
|
|
|
|
|
|
|
|
|
UPROPERTY()
|
|
|
|
|
FString TargetPin;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2026-03-12 00:44:17 -04:00
|
|
|
UCLASS()
|
2026-04-01 17:45:33 -04:00
|
|
|
class UWing_GraphPin_Connect : public UWingHandler
|
2026-03-10 01:42:43 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
2026-04-03 19:07:39 -04:00
|
|
|
UPROPERTY(EditAnywhere, meta=(Description="Target graph"))
|
2026-03-12 21:31:41 -04:00
|
|
|
FString Graph;
|
2026-03-10 01:42:43 -04:00
|
|
|
|
2026-04-03 19:07:39 -04:00
|
|
|
UPROPERTY(EditAnywhere, meta=(Description="Array of {sourcePin, targetPin} objects"))
|
2026-03-18 10:17:58 -04:00
|
|
|
FWingJsonArray Connections;
|
2026-03-10 01:42:43 -04:00
|
|
|
|
2026-04-01 18:12:54 -04:00
|
|
|
virtual void Register() override
|
2026-03-10 01:42:43 -04:00
|
|
|
{
|
2026-04-01 18:12:54 -04:00
|
|
|
UWingServer::AddHandler(this,
|
2026-04-14 02:28:22 -04:00
|
|
|
TEXT("Connect pins between nodes in a graph (Blueprint or Material). "
|
|
|
|
|
"Pin IDs use fetcher path syntax relative to the graph, eg: "
|
|
|
|
|
"node:K2Node_CallFunction_0,pin:ReturnValue"));
|
2026-03-10 01:42:43 -04:00
|
|
|
}
|
2026-03-13 23:41:59 -04:00
|
|
|
virtual void Handle() override
|
2026-03-10 01:42:43 -04:00
|
|
|
{
|
2026-04-04 01:45:25 -04:00
|
|
|
WingFetcher F(WingOut::Stdout);
|
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-10 01:42:43 -04:00
|
|
|
|
|
|
|
|
int32 SuccessCount = 0;
|
2026-03-10 07:17:42 -04:00
|
|
|
int32 TotalCount = Connections.Array.Num();
|
2026-03-10 01:42:43 -04:00
|
|
|
|
2026-04-04 01:45:25 -04:00
|
|
|
FConnectPinsEntry Entry;
|
2026-04-27 19:06:57 -04:00
|
|
|
TArray<FWingProperty> EntryProps = FWingProperty::GetAll(nullptr, &Entry, FConnectPinsEntry::StaticStruct(), true);
|
2026-03-10 01:42:43 -04:00
|
|
|
for (const TSharedPtr<FJsonValue>& ConnVal : Connections.Array)
|
|
|
|
|
{
|
2026-04-04 01:45:25 -04:00
|
|
|
if (!FWingProperty::PopulateFromJson(EntryProps, *ConnVal, false, WingOut::Stdout))
|
2026-03-10 07:17:42 -04:00
|
|
|
continue;
|
2026-03-10 01:42:43 -04:00
|
|
|
|
2026-04-04 01:45:25 -04:00
|
|
|
WingFetcher FS(G, WingOut::Stdout);
|
2026-04-08 03:40:59 -04:00
|
|
|
UWingGraphPinRef* SourcePinRef = FS.Walk(Entry.SourcePin).Cast<UWingGraphPinRef>();
|
2026-04-07 19:23:37 -04:00
|
|
|
if (!SourcePinRef) continue;
|
2026-04-07 23:41:04 -04:00
|
|
|
UEdGraphPin* SourcePin = WingUtils::CheckGetPin(SourcePinRef->Node, SourcePinRef->PinName, WingOut::Stdout);
|
2026-03-10 01:42:43 -04:00
|
|
|
if (!SourcePin) continue;
|
|
|
|
|
|
2026-04-04 01:45:25 -04:00
|
|
|
WingFetcher FT(G, WingOut::Stdout);
|
2026-04-08 03:40:59 -04:00
|
|
|
UWingGraphPinRef* TargetPinRef = FT.Walk(Entry.TargetPin).Cast<UWingGraphPinRef>();
|
2026-04-07 19:23:37 -04:00
|
|
|
if (!TargetPinRef) continue;
|
2026-04-07 23:41:04 -04:00
|
|
|
UEdGraphPin* TargetPin = WingUtils::CheckGetPin(TargetPinRef->Node, TargetPinRef->PinName, WingOut::Stdout);
|
2026-03-10 01:42:43 -04:00
|
|
|
if (!TargetPin) continue;
|
|
|
|
|
|
2026-03-12 21:31:41 -04:00
|
|
|
const UEdGraphSchema* Schema = G->GetSchema();
|
2026-03-10 01:42:43 -04:00
|
|
|
const FPinConnectionResponse Response = Schema->CanCreateConnection(SourcePin, TargetPin);
|
|
|
|
|
if (Response.Response == CONNECT_RESPONSE_DISALLOW)
|
|
|
|
|
{
|
2026-04-04 01:45:25 -04:00
|
|
|
WingOut::Stdout.Printf(TEXT("error: Cannot connect %s.%s to %s.%s: %s\n"),
|
2026-03-18 10:17:58 -04:00
|
|
|
*WingUtils::FormatName(SourcePin->GetOwningNode()), *WingUtils::FormatName(SourcePin),
|
|
|
|
|
*WingUtils::FormatName(TargetPin->GetOwningNode()), *WingUtils::FormatName(TargetPin),
|
2026-03-10 07:17:42 -04:00
|
|
|
*Response.Message.ToString());
|
2026-03-10 01:42:43 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Schema->TryCreateConnection(SourcePin, TargetPin);
|
|
|
|
|
SuccessCount++;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 01:45:25 -04:00
|
|
|
WingOut::Stdout.Printf(TEXT("Connected %d/%d pins.\n"), SuccessCount, TotalCount);
|
2026-03-10 01:42:43 -04:00
|
|
|
}
|
|
|
|
|
};
|