4#include "ScopedTransaction.h"
5#include "SGraphPanel.h"
7#include "Math/UnitConversion.h"
12#define LOCTEXT_NAMESPACE "SDialogueGraphPin"
19 SetCursor(EMouseCursor::Default);
26 SBorder::Construct(SBorder::FArguments()
30 .Cursor(
this, &Self::GetPinCursor)
31 .Padding(FMargin(10.f))
34 TAttribute<FText> ToolTipAttribute = TAttribute<FText>::Create(TAttribute<FText>::FGetter::CreateSP(
this, &
Self::GetTooltipText));
35 SetToolTipText(ToolTipAttribute);
42 bIsMovingLinks =
false;
43 if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton && IsEditingEnabled())
45 if (GraphPinObj->LinkedTo.Num() > 0)
47 if (MouseEvent.IsAltDown())
52 if (MouseEvent.IsControlDown())
59 if (!GraphPinObj->bNotConnectable)
62 TSharedPtr<SGraphNode> ThisOwnerNodeWidget = OwnerNodePtr.Pin();
63 if (ensure(ThisOwnerNodeWidget.IsValid()))
65 TArray<TSharedRef<SGraphPin>> DragPinArray;
66 DragPinArray.Add(SharedThis(
this));
67 return FReply::Handled().BeginDragDrop(SpawnPinDragEvent(ThisOwnerNodeWidget->GetOwnerPanel().ToSharedRef(), DragPinArray));
70 return FReply::Unhandled();
74 return FReply::Handled();
76 return FReply::Unhandled();
85 return FReply::Unhandled();
90 return Super::OnMouseMove(MyGeometry, MouseEvent);
95 if (!bIsHovered && GraphPinObj && !GraphPinObj->IsPendingKill() && GraphPinObj->GetOuter())
97 TSharedPtr<SGraphPanel> OwnerPanelPtr = OwnerNodePtr.Pin()->GetOwnerPanel();
98 check(OwnerPanelPtr.IsValid());
102 HoverPinSet.Add(GraphPinObj);
103 OwnerPanelPtr->AddPinToHoverSet(GraphPinObj);
105 if (GraphPinObj->LinkedTo.Num() > 0)
108 if (
UDialogueGraphNode* GraphNode = Cast<UDialogueGraphNode>(GraphPinObj->GetOwningNode()))
110 if (GraphPinObj->Direction == EGPD_Output)
115 HoverPinSet.Add(ChildNode->GetInputPin());
116 OwnerPanelPtr->AddPinToHoverSet(ChildNode->GetInputPin());
127 SCompoundWidget::OnMouseEnter(MyGeometry, MouseEvent);
132 Super::OnMouseLeave(MouseEvent);
141 Super::OnDragEnter(MyGeometry, DragDropEvent);
146 Super::OnDragLeave(DragDropEvent);
151 return Super::OnDragOver(MyGeometry, DragDropEvent);
156 return Super::OnDrop(MyGeometry, DragDropEvent);
166 TSharedPtr<SGraphNode> ThisOwnerNodeWidget = OwnerNodePtr.Pin();
167 check(ThisOwnerNodeWidget.IsValid());
168 const UDialogueGraphSchema* Schema = CastChecked<UDialogueGraphSchema>(GraphPinObj->GetSchema());
169 const FVector2D& MouseLocation = MouseEvent.GetScreenSpacePosition();
180 UEdGraphPin* ToPin = GraphPinObj->LinkedTo[0];
181 if (GraphPinObj->LinkedTo.Num() > 1)
189 return FReply::Handled();
198 TSharedPtr<SGraphNode> ThisOwnerNodeWidget = OwnerNodePtr.Pin();
199 check(ThisOwnerNodeWidget.IsValid());
200 TSharedPtr<SGraphPanel> OwnerPanelPtr = ThisOwnerNodeWidget->GetOwnerPanel();
201 check(OwnerPanelPtr.IsValid());
203 TArray<TSharedRef<SGraphPin>> DragPinArray;
204 DragPinArray.Add(SharedThis(
this));
207 UEdGraphPin* ToPin = GraphPinObj->LinkedTo[0];
208 if (GraphPinObj->LinkedTo.Num() > 1)
221 const UDialogueGraphSchema* Schema = CastChecked<UDialogueGraphSchema>(GraphPinObj->GetSchema());
224 bIsMovingLinks =
true;
226 return FReply::Handled().BeginDragDrop(SpawnPinDragEvent(ThisOwnerNodeWidget->GetOwnerPanel().ToSharedRef(), DragPinArray));
231 FText HoverText = FText::GetEmpty();
274 const UDialogueGraphNode* ThisGraphNode = CastChecked<UDialogueGraphNode>(GraphPinObj->GetOwningNode());
275 TSharedPtr<SGraphNode> ThisGraphNodeWidget = OwnerNodePtr.Pin();
276 check(ThisGraphNodeWidget.IsValid());
279 const FVector2D ThisGraphNodeClosestPosition = FGeometryHelper::FindClosestPointOnGeom(
280 ThisGraphNodeWidget->GetCachedGeometry(),
283 const FVector2D MP = (ThisGraphNodeClosestPosition - MousePosition).GetSafeNormal();
286 const TArray<UDialogueGraphNode_Edge*> ChildGraphEdges = ThisGraphNode->
GetChildEdgeNodes();
287 int32 BestEdgeIndex = 0;
290 float BestDotProduct = 0.0f;
291 const int32 ChildNum = ChildGraphEdges.Num();
292 for (int32 ChildIndex = 0; ChildIndex < ChildNum; ChildIndex++)
296 check(ChildNodeWidget.IsValid());
299 const FVector2D ClosestPointOnChild = FGeometryHelper::FindClosestPointOnGeom(ChildNodeWidget->GetCachedGeometry(), MousePosition);
302 const FVector2D MC = (ClosestPointOnChild - MousePosition).GetSafeNormal();
303 const float DotProduct = FMath::Abs(FVector2D::DotProduct(MC, MP));
304 if (DotProduct > BestDotProduct)
307 BestDotProduct = DotProduct;
308 BestEdgeIndex = ChildIndex;
312 return GraphPinObj->LinkedTo[BestEdgeIndex];;
318#undef LOCTEXT_NAMESPACE
static void SetLastTargetGraphEdgeBeforeDrag(const UEdGraph *Graph, UDialogueGraphNode_Edge *InEdge)
static bool IsPointInsideGeometry(const FVector2D &TestPoint, const FGeometry &Geometry)
FReply OnDrop(const FGeometry &MyGeometry, const FDragDropEvent &DragDropEvent) override
FText GetTooltipText() const
void OnDragLeave(const FDragDropEvent &DragDropEvent) override
void OnMouseEnter(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
FReply OnCtrlAndLeftMouseButtonDown(const FGeometry &SenderGeometry, const FPointerEvent &MouseEvent)
FReply OnMouseButtonUp(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
void OnMouseLeave(const FPointerEvent &MouseEvent) override
const FSlateBrush * GetPinBorder() const
FReply OnDragOver(const FGeometry &MyGeometry, const FDragDropEvent &DragDropEvent) override
FSlateColor GetPinColor() const override
FReply OnPinMouseDown(const FGeometry &SenderGeometry, const FPointerEvent &MouseEvent) override
FReply OnMouseMove(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent) override
UEdGraphPin * GetBestLinkedToPinFromSplineMousePosition(const FVector2D &MousePosition) const
void Construct(const FArguments &InArgs, UEdGraphPin *InPin)
FReply OnAltAndLeftMouseButtonDown(const FGeometry &SenderGeometry, const FPointerEvent &MouseEvent)
void OnDragEnter(const FGeometry &MyGeometry, const FDragDropEvent &DragDropEvent) override
TSharedPtr< SGraphNode > GetNodeWidget() const
UDialogueGraphNode * GetChildNode() const
TArray< UDialogueGraphNode_Edge * > GetChildEdgeNodes(bool bCheckParent=true) const
void BreakPinLinks(UEdGraphPin &TargetPin, bool bSendsNodeNotifcation) const override
void BreakLinkTo(UEdGraphPin *TargetPin, UEdGraphPin *ToPin, bool bSendsNodeNotifcation) const