-
Notifications
You must be signed in to change notification settings - Fork 352
Expand file tree
/
Copy pathSFlowGraphNode.cpp
More file actions
1228 lines (1056 loc) · 34.9 KB
/
SFlowGraphNode.cpp
File metadata and controls
1228 lines (1056 loc) · 34.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright https://github.com/MothCocoon/FlowGraph/graphs/contributors
#include "Graph/Widgets/SFlowGraphNode.h"
#include "DragFlowGraphNode.h"
#include "FlowEditorStyle.h"
#include "Graph/FlowGraph.h"
#include "Graph/FlowGraphSettings.h"
#include "Nodes/FlowNode.h"
#include "Debugger/FlowDebuggerSubsystem.h"
#include "EdGraph/EdGraphPin.h"
#include "Editor.h"
#include "GraphEditorSettings.h"
#include "IDocumentation.h"
#include "Input/Reply.h"
#include "Internationalization/BreakIterator.h"
#include "Layout/Margin.h"
#include "Misc/Attribute.h"
#include "NodeFactory.h"
#include "SCommentBubble.h"
#include "ScopedTransaction.h"
#include "SGraphNode.h"
#include "SGraphPanel.h"
#include "SGraphPin.h"
#include "SlateOptMacros.h"
#include "SLevelOfDetailBranchNode.h"
#include "SNodePanel.h"
#include "Styling/SlateColor.h"
#include "TutorialMetaData.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/Layout/SBorder.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/SOverlay.h"
#include "Widgets/SToolTip.h"
#include "Widgets/Text/SInlineEditableTextBlock.h"
#define LOCTEXT_NAMESPACE "SFlowGraphNode"
SFlowGraphPinExec::SFlowGraphPinExec()
{
PinColorModifier = UFlowGraphSettings::Get()->ExecPinColorModifier;
}
void SFlowGraphPinExec::Construct(const FArguments& InArgs, UEdGraphPin* InPin)
{
SGraphPinExec::Construct(SGraphPinExec::FArguments(), InPin);
bUsePinColorForText = true;
PinColorModifier = InArgs._PinModifierColor;
}
const FLinearColor SFlowGraphNode::UnselectedNodeTint = FLinearColor(1.0f, 1.0f, 1.0f, 0.5f);
const FLinearColor SFlowGraphNode::ConfigBoxColor = FLinearColor(0.04f, 0.04f, 0.04f, 1.0f);
void SFlowGraphNode::Construct(const FArguments& InArgs, UFlowGraphNode* InNode)
{
GraphNode = InNode;
FlowGraphNode = InNode;
DebuggerSubsystem = GEngine->GetEngineSubsystem<UFlowDebuggerSubsystem>();
check(FlowGraphNode);
FlowGraphNode->OnSignalModeChanged.BindRaw(this, &SFlowGraphNode::UpdateGraphNode);
FlowGraphNode->OnReconstructNodeCompleted.BindRaw(this, &SFlowGraphNode::UpdateGraphNode);
SetCursor(EMouseCursor::CardinalCross);
UpdateGraphNode();
bDragMarkerVisible = false;
}
SFlowGraphNode::~SFlowGraphNode()
{
check(FlowGraphNode);
FlowGraphNode->OnSignalModeChanged.Unbind();
FlowGraphNode->OnReconstructNodeCompleted.Unbind();
FlowGraphNode = nullptr;
}
void SFlowGraphNode::GetNodeInfoPopups(FNodeInfoContext* Context, TArray<FGraphInformationPopupInfo>& Popups) const
{
const FString& Description = FlowGraphNode->GetNodeDescription();
if (!Description.IsEmpty())
{
const FGraphInformationPopupInfo DescriptionPopup = FGraphInformationPopupInfo(nullptr, UFlowGraphSettings::Get()->NodeDescriptionBackground, Description);
Popups.Add(DescriptionPopup);
}
if (GEditor->PlayWorld)
{
const FString Status = FlowGraphNode->GetStatusString();
if (!Status.IsEmpty())
{
const FGraphInformationPopupInfo DescriptionPopup = FGraphInformationPopupInfo(nullptr, FlowGraphNode->GetStatusBackgroundColor(), Status);
Popups.Add(DescriptionPopup);
}
else if (FlowGraphNode->IsContentPreloaded())
{
const FGraphInformationPopupInfo DescriptionPopup = FGraphInformationPopupInfo(nullptr, UFlowGraphSettings::Get()->NodeStatusBackground, TEXT("Preloaded"));
Popups.Add(DescriptionPopup);
}
}
}
const FSlateBrush* SFlowGraphNode::GetShadowBrush(bool bSelected) const
{
if (GEditor->PlayWorld)
{
switch (FlowGraphNode->GetActivationState())
{
case EFlowNodeState::NeverActivated:
return SGraphNode::GetShadowBrush(bSelected);
case EFlowNodeState::Active:
return FFlowEditorStyle::Get()->GetBrush(TEXT("Flow.Node.ActiveShadow"));
case EFlowNodeState::Completed:
case EFlowNodeState::Aborted:
return FFlowEditorStyle::Get()->GetBrush(TEXT("Flow.Node.WasActiveShadow"));
default: ;
}
}
return SGraphNode::GetShadowBrush(bSelected);
}
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION < 6
void SFlowGraphNode::GetOverlayBrushes(bool bSelected, const FVector2D WidgetSize, TArray<FOverlayBrushInfo>& Brushes) const
#else
void SFlowGraphNode::GetOverlayBrushes(bool bSelected, const FVector2f& WidgetSize, TArray<FOverlayBrushInfo>& Brushes) const
#endif
{
check(DebuggerSubsystem.IsValid());
// Node breakpoint
if (const FFlowBreakpoint* NodeBreakpoint = DebuggerSubsystem->FindBreakpoint(FlowGraphNode->NodeGuid))
{
FOverlayBrushInfo NodeBrush;
if (NodeBreakpoint->IsHit())
{
NodeBrush.Brush = FFlowEditorStyle::Get()->GetBrush(TEXT("FlowGraph.BreakpointHit"));
NodeBrush.OverlayOffset.X = WidgetSize.X - 12.0f;
}
else
{
NodeBrush.Brush = FFlowEditorStyle::Get()->GetBrush(NodeBreakpoint->IsEnabled() ? TEXT("FlowGraph.BreakpointEnabled") : TEXT("FlowGraph.BreakpointDisabled"));
NodeBrush.OverlayOffset.X = WidgetSize.X;
}
NodeBrush.OverlayOffset.Y = -NodeBrush.Brush->ImageSize.Y;
NodeBrush.AnimationEnvelope = FVector2D(0.f, 10.f);
Brushes.Add(NodeBrush);
}
// Pin breakpoints
for (UEdGraphPin* Pin : FlowGraphNode->Pins)
{
if (const FFlowBreakpoint* PinBreakpoint = DebuggerSubsystem->FindBreakpoint(Pin->GetOwningNode()->NodeGuid, Pin->PinName))
{
if (Pin->Direction == EGPD_Input)
{
GetPinBrush(true, WidgetSize.X, FlowGraphNode->InputPins.IndexOfByKey(Pin), PinBreakpoint, Brushes);
}
else
{
GetPinBrush(false, WidgetSize.X, FlowGraphNode->OutputPins.IndexOfByKey(Pin), PinBreakpoint, Brushes);
}
}
}
}
void SFlowGraphNode::GetPinBrush(const bool bLeftSide, const float WidgetWidth, const int32 PinIndex, const FFlowBreakpoint* Breakpoint, TArray<FOverlayBrushInfo>& Brushes) const
{
FOverlayBrushInfo PinBrush;
if (Breakpoint->IsHit())
{
PinBrush.Brush = FFlowEditorStyle::Get()->GetBrush(TEXT("FlowGraph.PinBreakpointHit"));
PinBrush.OverlayOffset.X = bLeftSide ? 0.0f : (WidgetWidth - 36.0f);
PinBrush.OverlayOffset.Y = 12.0f + PinIndex * 28.0f;
}
else
{
PinBrush.Brush = FFlowEditorStyle::Get()->GetBrush(Breakpoint->IsEnabled() ? TEXT("FlowGraph.BreakpointEnabled") : TEXT("FlowGraph.BreakpointDisabled"));
PinBrush.OverlayOffset.X = bLeftSide ? -24.0f : WidgetWidth;
PinBrush.OverlayOffset.Y = 16.0f + PinIndex * 28.0f;
}
PinBrush.AnimationEnvelope = FVector2D(0.f, 10.f);
Brushes.Add(PinBrush);
}
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SFlowGraphNode::UpdateGraphNode()
{
InputPins.Empty();
OutputPins.Empty();
// Reset variables that are going to be exposed, in case we are refreshing an already set node.
RightNodeBox.Reset();
LeftNodeBox.Reset();
// ______________________
// | TITLE AREA |
// +-------+------+-------+
// | (>) L | | R (>) |
// | (>) E | | I (>) |
// | (>) F | | G (>) |
// | (>) T | | H (>) |
// | | | T (>) |
// |_______|______|_______|
//
TSharedPtr<SVerticalBox> MainVerticalBox;
SetupErrorReporting();
const TSharedPtr<SNodeTitle> NodeTitle = SNew(SNodeTitle, GraphNode);
// Get node icon
IconColor = FLinearColor::White;
const FSlateBrush* IconBrush = nullptr;
if (GraphNode && GraphNode->ShowPaletteIconOnNode())
{
IconBrush = GraphNode->GetIconAndTint(IconColor).GetOptionalIcon();
}
// Compute the SubNode padding indent based on the parentage depth for this node
const FMargin NodePadding = ComputeSubNodeChildIndentPaddingMargin();
const TSharedRef<SOverlay> DefaultTitleAreaWidget = SNew(SOverlay)
+ SOverlay::Slot()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Center)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.HAlign(HAlign_Fill)
[
SNew(SBorder)
.BorderImage(FFlowEditorStyle::GetBrush("Flow.Node.Title"))
// The extra margin on the right is for making the color spill stretch well past the node title
.Padding(FMargin(10, 5, 30, 3))
.BorderBackgroundColor(this, &SFlowGraphNode::GetBorderBackgroundColor)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.VAlign(VAlign_Top)
.Padding(FMargin(0.f, 0.f, 4.f, 0.f))
.AutoWidth()
[
SNew(SImage)
.Image(IconBrush)
.ColorAndOpacity(this, &SFlowGraphNode::GetNodeTitleIconColor)
]
+ SHorizontalBox::Slot()
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
CreateTitleWidget(NodeTitle)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
NodeTitle.ToSharedRef()
]
]
]
]
];
SetDefaultTitleAreaWidget(DefaultTitleAreaWidget);
const TSharedRef<SWidget> TitleAreaWidget =
SNew(SLevelOfDetailBranchNode)
.UseLowDetailSlot(this, &SFlowGraphNode::UseLowDetailNodeTitles)
.LowDetail()
[
SNew(SBorder)
.BorderImage(FFlowEditorStyle::GetBrush("Flow.Node.Title"))
.Padding(FMargin(75.0f, 22.0f)) // Saving enough space for a 'typical' title so the transition isn't quite so abrupt
.BorderBackgroundColor(this, &SGraphNode::GetNodeTitleColor)
]
.HighDetail()
[
DefaultTitleAreaWidget
];
// Set up a meta tag for this node
FGraphNodeMetaData TagMeta(TEXT("FlowGraphNode"));
PopulateMetaTag(&TagMeta);
this->ContentScale.Bind(this, &SGraphNode::GetContentScale);
const TSharedPtr<SVerticalBox> InnerVerticalBox = SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Top)
.Padding(Settings->GetNonPinNodeBodyPadding())
[
TitleAreaWidget
]
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Top)
[
CreateNodeContentArea()
];
const TSharedPtr<SWidget> EnabledStateWidget = GetEnabledStateWidget();
if (EnabledStateWidget.IsValid())
{
InnerVerticalBox->AddSlot()
.AutoHeight()
.HAlign(HAlign_Fill)
.VAlign(VAlign_Top)
.Padding(FMargin(2, 0))
[
EnabledStateWidget.ToSharedRef()
];
}
InnerVerticalBox->AddSlot()
.AutoHeight()
.Padding(Settings->GetNonPinNodeBodyPadding())
[
ErrorReporting->AsWidget()
];
this->GetOrAddSlot(ENodeZone::Center)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SAssignNew(MainVerticalBox, SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(FMargin(NodePadding.Left, 0.0f, NodePadding.Right, 0.0f))
[
SNew(SOverlay)
.AddMetaData<FGraphNodeMetaData>(TagMeta)
+ SOverlay::Slot()
.Padding(Settings->GetNonPinNodeBodyPadding())
[
SNew(SImage)
.Image(GetNodeBodyBrush())
.ColorAndOpacity(this, &SFlowGraphNode::GetNodeBodyColor)
]
+ SOverlay::Slot()
[
InnerVerticalBox.ToSharedRef()
]
]
];
if (GraphNode && GraphNode->SupportsCommentBubble())
{
// Create comment bubble
TSharedPtr<SCommentBubble> CommentBubble;
const FSlateColor CommentColor = GetDefault<UGraphEditorSettings>()->DefaultCommentNodeTitleColor;
SAssignNew(CommentBubble, SCommentBubble)
.GraphNode(GraphNode)
.Text(this, &SGraphNode::GetNodeComment)
.OnTextCommitted(this, &SGraphNode::OnCommentTextCommitted)
.OnToggled(this, &SGraphNode::OnCommentBubbleToggled)
.ColorAndOpacity(CommentColor)
.AllowPinning(true)
.EnableTitleBarBubble(true)
.EnableBubbleCtrls(true)
.GraphLOD(this, &SGraphNode::GetCurrentLOD)
.IsGraphNodeHovered(this, &SGraphNode::IsHovered);
GetOrAddSlot(ENodeZone::TopCenter)
#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION < 6
.SlotOffset(TAttribute<FVector2D>(CommentBubble.Get(), &SCommentBubble::GetOffset))
.SlotSize(TAttribute<FVector2D>(CommentBubble.Get(), &SCommentBubble::GetSize))
#else
.SlotOffset2f(TAttribute<FVector2f>(CommentBubble.Get(), &SCommentBubble::GetOffset2f))
.SlotSize2f(TAttribute<FVector2f>(CommentBubble.Get(), &SCommentBubble::GetSize2f))
#endif
.AllowScaling(TAttribute<bool>(CommentBubble.Get(), &SCommentBubble::IsScalingAllowed))
.VAlign(VAlign_Top)
[
CommentBubble.ToSharedRef()
];
}
CreateBelowWidgetControls(MainVerticalBox);
CreatePinWidgets();
CreateInputSideAddButton(LeftNodeBox);
CreateOutputSideAddButton(RightNodeBox);
CreateBelowPinControls(InnerVerticalBox);
CreateAdvancedViewArrow(InnerVerticalBox);
}
FSlateColor SFlowGraphNode::GetBorderBackgroundColor() const
{
return SGraphNode::GetNodeTitleColor();
}
FSlateColor SFlowGraphNode::GetConfigBoxBackgroundColor() const
{
FLinearColor NodeColor = ConfigBoxColor;
if (FlowGraphNode && !IsFlowGraphNodeSelected(FlowGraphNode))
{
NodeColor *= UnselectedNodeTint;
}
return NodeColor;
}
void SFlowGraphNode::CreateBelowPinControls(const TSharedPtr<SVerticalBox> InnerVerticalBox)
{
static const FMargin ConfigBoxPadding = FMargin(2.0f, 0.0f, 1.0f, 0.0f);
// Add a box to wrap around the Config Text area to make it a more visually distinct part of the node
TSharedPtr<SVerticalBox> BelowPinsBox;
InnerVerticalBox->AddSlot()
.AutoHeight()
.Padding(ConfigBoxPadding)
[
SNew(SBorder)
.BorderImage(FAppStyle::GetBrush("Graph.StateNode.Body"))
.BorderBackgroundColor(this, &SFlowGraphNode::GetConfigBoxBackgroundColor)
.Visibility(this, &SFlowGraphNode::GetNodeConfigTextVisibility)
[
SAssignNew(BelowPinsBox, SVerticalBox)
]
];
CreateConfigText(BelowPinsBox);
CreateOrRebuildSubNodeBox(InnerVerticalBox);
}
void SFlowGraphNode::AddSubNodeWidget(const TSharedPtr<SGraphNode>& NewSubNodeWidget)
{
if (OwnerGraphPanelPtr.IsValid())
{
NewSubNodeWidget->SetOwner(OwnerGraphPanelPtr.Pin().ToSharedRef());
OwnerGraphPanelPtr.Pin()->AttachGraphEvents(NewSubNodeWidget);
}
NewSubNodeWidget->UpdateGraphNode();
AddSubNode(NewSubNodeWidget);
}
FMargin SFlowGraphNode::ComputeSubNodeChildIndentPaddingMargin() const
{
if (!IsValid(FlowGraphNode) || !FlowGraphNode->IsSubNode())
{
return FMargin();
}
const UFlowGraphNode* CurrentAncestor = FlowGraphNode->GetParentNode();
// Compute the parent depth, so it can be used to determine the indent level for this subnode
int32 ParentDepth = 0;
while (IsValid(CurrentAncestor))
{
++ParentDepth;
CurrentAncestor = CurrentAncestor->GetParentNode();
}
constexpr float VerticalDefaultPadding = 2.0f;
constexpr float HorizontalDefaultPadding = 2.0f;
constexpr float IndentedHorizontalPadding = 6.0f;
constexpr float RightPadding = HorizontalDefaultPadding;
float LeftPadding;
if (ParentDepth > 0)
{
// Increase the padding by the parent depth for this node
LeftPadding = IndentedHorizontalPadding * ParentDepth;
}
else
{
LeftPadding = 0.0f;
}
return FMargin(LeftPadding, VerticalDefaultPadding, RightPadding, VerticalDefaultPadding);
}
void SFlowGraphNode::CreateConfigText(const TSharedPtr<SVerticalBox>& InnerVerticalBox)
{
static const FMargin ConfigTextPadding = FMargin(2.0f, 0.0f, 0.0f, 3.0f);
InnerVerticalBox->AddSlot()
.AutoHeight()
.Padding(ConfigTextPadding)
[
SAssignNew(ConfigTextBlock, STextBlock)
.AutoWrapText(true)
.LineBreakPolicy(FBreakIterator::CreateWordBreakIterator())
.Text(this, &SFlowGraphNode::GetNodeConfigText)
];
}
FText SFlowGraphNode::GetNodeConfigText() const
{
if (const UFlowNodeBase* FlowNodeBase = FlowGraphNode->GetFlowNodeBase())
{
return FlowNodeBase->GetNodeConfigText();
}
return FText::GetEmpty();
}
EVisibility SFlowGraphNode::GetNodeConfigTextVisibility() const
{
// Hide in lower LODs
const TSharedPtr<SGraphPanel> OwnerPanel = GetOwnerPanel();
if (!OwnerPanel.IsValid() || OwnerPanel->GetCurrentLOD() >= EGraphRenderingLOD::MediumDetail)
{
if (ConfigTextBlock && !ConfigTextBlock->GetText().IsEmptyOrWhitespace())
{
return EVisibility::Visible;
}
}
return EVisibility::Collapsed;
}
void SFlowGraphNode::CreateOrRebuildSubNodeBox(const TSharedPtr<SVerticalBox>& InnerVerticalBox)
{
if (SubNodeBox.IsValid())
{
SubNodeBox->ClearChildren();
}
else
{
SAssignNew(SubNodeBox, SVerticalBox);
}
SubNodes.Reset();
if (FlowGraphNode)
{
for (UFlowGraphNode* SubNode : FlowGraphNode->SubNodes)
{
TSharedPtr<SGraphNode> NewNode = FNodeFactory::CreateNodeWidget(SubNode);
AddSubNodeWidget(NewNode);
}
}
InnerVerticalBox->AddSlot()
.AutoHeight()
[
SubNodeBox.ToSharedRef()
];
}
bool SFlowGraphNode::IsFlowGraphNodeSelected(UFlowGraphNode* Node) const
{
return GetOwnerPanel().IsValid() && GetOwnerPanel()->SelectionManager.SelectedNodes.Contains(Node);
}
void SFlowGraphNode::UpdateErrorInfo()
{
if (const UFlowNodeBase* FlowNodeBase = FlowGraphNode->GetFlowNodeBase())
{
if (FlowNodeBase->ValidationLog.Messages.Num() > 0)
{
EMessageSeverity::Type MaxSeverity = EMessageSeverity::Info;
for (const TSharedRef<FTokenizedMessage>& Message : FlowNodeBase->ValidationLog.Messages)
{
if (Message->GetSeverity() < MaxSeverity)
{
MaxSeverity = Message->GetSeverity();
}
}
switch(MaxSeverity)
{
case EMessageSeverity::Error:
ErrorMsg = FString(TEXT("ERROR!"));
ErrorColor = FAppStyle::GetColor("ErrorReporting.BackgroundColor");
break;
case EMessageSeverity::PerformanceWarning:
case EMessageSeverity::Warning:
ErrorMsg = FString(TEXT("WARNING!"));
ErrorColor = FAppStyle::GetColor("ErrorReporting.WarningBackgroundColor");
break;
case EMessageSeverity::Info:
ErrorMsg = FString(TEXT("NOTE"));
ErrorColor = FAppStyle::GetColor("InfoReporting.BackgroundColor");
break;
default:
break;
}
return;
}
if (FlowNodeBase->GetClass()->HasAnyClassFlags(CLASS_Deprecated) || FlowNodeBase->bNodeDeprecated)
{
ErrorMsg = FlowNodeBase->ReplacedBy ? FString::Printf(TEXT(" REPLACED BY: %s "), *FlowNodeBase->ReplacedBy->GetName()) : FString(TEXT(" DEPRECATED! "));
ErrorColor = FAppStyle::GetColor("ErrorReporting.WarningBackgroundColor");
return;
}
}
SGraphNode::UpdateErrorInfo();
}
TSharedRef<SWidget> SFlowGraphNode::CreateTitleWidget(TSharedPtr<SNodeTitle> NodeTitle)
{
SAssignNew(InlineEditableText, SInlineEditableTextBlock)
.Style(FAppStyle::Get(), "Graph.Node.NodeTitleInlineEditableText")
.Text(NodeTitle.Get(), &SNodeTitle::GetHeadTitle)
.OnVerifyTextChanged(this, &SFlowGraphNode::OnVerifyNameTextChanged)
.OnTextCommitted(this, &SFlowGraphNode::OnNameTextCommited)
.IsReadOnly(this, &SFlowGraphNode::IsNameReadOnly)
.IsSelected(this, &SFlowGraphNode::IsSelectedExclusively);
InlineEditableText->SetColorAndOpacity(TAttribute<FLinearColor>::Create(TAttribute<FLinearColor>::FGetter::CreateSP(this, &SFlowGraphNode::GetNodeTitleTextColor)));
return InlineEditableText.ToSharedRef();
}
TSharedRef<SWidget> SFlowGraphNode::CreateNodeContentArea()
{
return SNew(SBorder)
.BorderImage(FAppStyle::GetBrush("NoBorder"))
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
+SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.FillWidth(1.0f)
[
SAssignNew(LeftNodeBox, SVerticalBox)
]
+SHorizontalBox::Slot()
.AutoWidth()
.HAlign(HAlign_Right)
[
SAssignNew(RightNodeBox, SVerticalBox)
]
];
}
const FSlateBrush* SFlowGraphNode::GetNodeBodyBrush() const
{
return FFlowEditorStyle::GetBrush("Flow.Node.Body");
}
FSlateColor SFlowGraphNode::GetNodeTitleColor() const
{
FLinearColor ReturnTitleColor = GraphNode->IsDeprecated() ? FLinearColor::Red : GetNodeObj()->GetNodeTitleColor();
if (FlowGraphNode->GetSignalMode() == EFlowSignalMode::Enabled)
{
ReturnTitleColor.A = FadeCurve.GetLerp();
}
else
{
ReturnTitleColor *= FLinearColor(0.5f, 0.5f, 0.5f, 0.4f);
}
if (!IsFlowGraphNodeSelected(FlowGraphNode) && FlowGraphNode->IsSubNode())
{
ReturnTitleColor *= UnselectedNodeTint;
}
return ReturnTitleColor;
}
FSlateColor SFlowGraphNode::GetNodeBodyColor() const
{
FLinearColor ReturnBodyColor = GraphNode->GetNodeBodyTintColor();
if (FlowGraphNode->GetSignalMode() != EFlowSignalMode::Enabled)
{
ReturnBodyColor *= FLinearColor(1.0f, 1.0f, 1.0f, 0.5f);
}
else if (!IsFlowGraphNodeSelected(FlowGraphNode) && FlowGraphNode->IsSubNode())
{
ReturnBodyColor *= UnselectedNodeTint;
}
return ReturnBodyColor;
}
FSlateColor SFlowGraphNode::GetNodeTitleIconColor() const
{
FLinearColor ReturnIconColor = IconColor;
if (FlowGraphNode->GetSignalMode() != EFlowSignalMode::Enabled)
{
ReturnIconColor *= FLinearColor(1.0f, 1.0f, 1.0f, 0.3f);
}
else if (!IsFlowGraphNodeSelected(FlowGraphNode) && FlowGraphNode->IsSubNode())
{
ReturnIconColor *= UnselectedNodeTint;
}
return ReturnIconColor;
}
FLinearColor SFlowGraphNode::GetNodeTitleTextColor() const
{
FLinearColor ReturnTextColor = FLinearColor::White;
if (FlowGraphNode->GetSignalMode() != EFlowSignalMode::Enabled)
{
ReturnTextColor *= FLinearColor(1.0f, 1.0f, 1.0f, 0.3f);
}
else if (!IsFlowGraphNodeSelected(FlowGraphNode) && FlowGraphNode->IsSubNode())
{
ReturnTextColor *= UnselectedNodeTint;
}
return ReturnTextColor;
}
TSharedPtr<SWidget> SFlowGraphNode::GetEnabledStateWidget() const
{
if (FlowGraphNode->IsSubNode())
{
// SubNodes don't get enabled/disabled on their own,
// they follow the enabled/disabled setting of their owning flow node
return TSharedPtr<SWidget>();
}
if (FlowGraphNode->GetSignalMode() != EFlowSignalMode::Enabled && !GraphNode->IsAutomaticallyPlacedGhostNode())
{
const bool bPassThrough = FlowGraphNode->GetSignalMode() == EFlowSignalMode::PassThrough;
const FText StatusMessage = bPassThrough ? LOCTEXT("PassThrough", "Pass Through") : LOCTEXT("DisabledNode", "Disabled");
const FText StatusMessageTooltip = bPassThrough ?
LOCTEXT("PassThroughTooltip", "This node won't execute internal logic, but it will trigger all connected outputs") :
LOCTEXT("DisabledNodeTooltip", "This node is disabled and will not be executed");
return SNew(SBorder)
.BorderImage(FAppStyle::GetBrush(bPassThrough ? "Graph.Node.DevelopmentBanner" : "Graph.Node.DisabledBanner"))
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
[
SNew(STextBlock)
.Text(StatusMessage)
.ToolTipText(StatusMessageTooltip)
.Justification(ETextJustify::Center)
.ColorAndOpacity(FLinearColor::White)
.ShadowOffset(FVector2D::UnitVector)
.Visibility(EVisibility::Visible)
];
}
return TSharedPtr<SWidget>();
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
TSharedPtr<SToolTip> SFlowGraphNode::GetComplexTooltip()
{
return IDocumentation::Get()->CreateToolTip(TAttribute<FText>(this, &SGraphNode::GetNodeTooltip), nullptr, GraphNode->GetDocumentationLink(), GraphNode->GetDocumentationExcerptName());
}
void SFlowGraphNode::CreateInputSideAddButton(const TSharedPtr<SVerticalBox> OutputBox)
{
if (FlowGraphNode->CanUserAddInput())
{
TSharedPtr<SWidget> AddPinWidget;
SAssignNew(AddPinWidget, SHorizontalBox)
+SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
.Padding(0, 0, 7, 0)
[
SNew(SImage)
.Image(FAppStyle::GetBrush(TEXT("Icons.PlusCircle")))
]
+SHorizontalBox::Slot()
.AutoWidth()
.HAlign(HAlign_Left)
[
SNew(STextBlock)
.Text(LOCTEXT("FlowNodeAddPinButton", "Add pin"))
.ColorAndOpacity(FLinearColor::White)
];
AddPinButton(OutputBox, AddPinWidget.ToSharedRef(), EGPD_Input);
}
}
void SFlowGraphNode::CreateOutputSideAddButton(const TSharedPtr<SVerticalBox> OutputBox)
{
if (FlowGraphNode->CanUserAddOutput())
{
TSharedPtr<SWidget> AddPinWidget;
SAssignNew(AddPinWidget, SHorizontalBox)
+SHorizontalBox::Slot()
.AutoWidth()
.HAlign(HAlign_Left)
[
SNew(STextBlock)
.Text(LOCTEXT("FlowNodeAddPinButton", "Add pin"))
.ColorAndOpacity(FLinearColor::White)
]
+SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
.Padding(7, 0, 0, 0)
[
SNew(SImage)
.Image(FAppStyle::GetBrush(TEXT("Icons.PlusCircle")))
];
AddPinButton(OutputBox, AddPinWidget.ToSharedRef(), EGPD_Output);
}
}
void SFlowGraphNode::AddPinButton(TSharedPtr<SVerticalBox> OutputBox, const TSharedRef<SWidget> ButtonContent, const EEdGraphPinDirection Direction, const FString DocumentationExcerpt, const TSharedPtr<SToolTip> CustomTooltip)
{
const FText PinTooltipText = (Direction == EEdGraphPinDirection::EGPD_Input) ? LOCTEXT("FlowNodeAddPinButton_InputTooltip", "Adds an input pin") : LOCTEXT("FlowNodeAddPinButton_OutputTooltip", "Adds an output pin");
TSharedPtr<SToolTip> Tooltip;
if (CustomTooltip.IsValid())
{
Tooltip = CustomTooltip;
}
else if (!DocumentationExcerpt.IsEmpty())
{
Tooltip = IDocumentation::Get()->CreateToolTip(PinTooltipText, nullptr, GraphNode->GetDocumentationLink(), DocumentationExcerpt);
}
const TSharedRef<SButton> AddPinButton = SNew(SButton)
.ContentPadding(0.0f)
.ButtonStyle(FAppStyle::Get(), "NoBorder")
.OnClicked(this, &SFlowGraphNode::OnAddFlowPin, Direction)
.IsEnabled(this, &SFlowGraphNode::IsNodeEditable)
.ToolTipText(PinTooltipText)
.ToolTip(Tooltip)
.Visibility(this, &SFlowGraphNode::IsAddPinButtonVisible)
[
ButtonContent
];
AddPinButton->SetCursor(EMouseCursor::Hand);
FMargin AddPinPadding = (Direction == EEdGraphPinDirection::EGPD_Input) ? Settings->GetInputPinPadding() : Settings->GetOutputPinPadding();
AddPinPadding.Top += 6.0f;
OutputBox->AddSlot()
.AutoHeight()
.VAlign(VAlign_Center)
.Padding(AddPinPadding)
[
AddPinButton
];
}
FReply SFlowGraphNode::OnAddFlowPin(const EEdGraphPinDirection Direction)
{
switch (Direction)
{
case EGPD_Input:
FlowGraphNode->AddUserInput();
break;
case EGPD_Output:
FlowGraphNode->AddUserOutput();
break;
default:
break;
}
return FReply::Handled();
}
void SFlowGraphNode::AddSubNode(const TSharedPtr<SGraphNode> SubNodeWidget)
{
SubNodes.Add(SubNodeWidget);
SubNodeBox->AddSlot().AutoHeight()
[
SubNodeWidget.ToSharedRef()
];
}
FText SFlowGraphNode::GetTitle() const
{
return GraphNode ? GraphNode->GetNodeTitle(ENodeTitleType::FullTitle) : FText::GetEmpty();
}
FText SFlowGraphNode::GetDescription() const
{
return FlowGraphNode ? FlowGraphNode->GetDescription() : FText::GetEmpty();
}
EVisibility SFlowGraphNode::GetDescriptionVisibility() const
{
// LOD this out once things get too small
const TSharedPtr<SGraphPanel> OwnerPanel = GetOwnerPanel();
return (!OwnerPanel.IsValid() || OwnerPanel->GetCurrentLOD() > EGraphRenderingLOD::LowDetail) ? EVisibility::Visible : EVisibility::Collapsed;
}
void SFlowGraphNode::AddPin(const TSharedRef<SGraphPin>& PinToAdd)
{
PinToAdd->SetOwner(SharedThis(this));
const UEdGraphPin* PinObj = PinToAdd->GetPinObj();
if (PinObj && PinObj->bAdvancedView)
{
PinToAdd->SetVisibility(TAttribute<EVisibility>(PinToAdd, &SGraphPin::IsPinVisibleAsAdvanced));
}
if (PinToAdd->GetDirection() == EEdGraphPinDirection::EGPD_Input)
{
LeftNodeBox->AddSlot()
.AutoHeight()
.HAlign(HAlign_Left)
.VAlign(VAlign_Center)
.Padding(Settings->GetInputPinPadding())
[
PinToAdd
];
InputPins.Add(PinToAdd);
}
else // Direction == EEdGraphPinDirection::EGPD_Output
{
RightNodeBox->AddSlot()
.AutoHeight()
.HAlign(HAlign_Right)
.VAlign(VAlign_Center)
.Padding(Settings->GetOutputPinPadding())
[
PinToAdd
];
OutputPins.Add(PinToAdd);
}
}
FReply SFlowGraphNode::OnMouseMove(const FGeometry& SenderGeometry, const FPointerEvent& MouseEvent)
{
if (MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton) && !(GEditor->bIsSimulatingInEditor || GEditor->PlayWorld))
{
// if we are holding mouse over a subnode
if (FlowGraphNode && FlowGraphNode->IsSubNode())
{
const TSharedRef<SGraphPanel>& Panel = GetOwnerPanel().ToSharedRef();
const TSharedRef<SGraphNode>& Node = SharedThis(this);
return FReply::Handled().BeginDragDrop(FDragFlowGraphNode::New(Panel, Node));
}
}
if (!MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton) && bDragMarkerVisible)
{
SetDragMarker(false);
}
return FReply::Unhandled();
}
TSharedRef<SGraphNode> SFlowGraphNode::GetNodeUnderMouse(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
const TSharedPtr<SGraphNode> SubNode = GetSubNodeUnderCursor(MyGeometry, MouseEvent);
if (SubNode.IsValid())
{
return SubNode.ToSharedRef();
}
else
{
return StaticCastSharedRef<SGraphNode>(AsShared());
}
}
FReply SFlowGraphNode::OnMouseButtonDown(const FGeometry& SenderGeometry, const FPointerEvent& MouseEvent)
{
if (FlowGraphNode && FlowGraphNode->IsSubNode())
{
GetOwnerPanel()->SelectionManager.ClickedOnNode(FlowGraphNode, MouseEvent);
return FReply::Handled();
}
return FReply::Unhandled();
}
TSharedPtr<SGraphNode> SFlowGraphNode::GetSubNodeUnderCursor(const FGeometry& WidgetGeometry, const FPointerEvent& MouseEvent)
{
// We just need to find the one WidgetToFind among our descendants.
TSet< TSharedRef<SWidget> > SubWidgetsSet;
for (int32 i = 0; i < SubNodes.Num(); i++)
{
SubWidgetsSet.Add(SubNodes[i].ToSharedRef());
}
TMap<TSharedRef<SWidget>, FArrangedWidget> Result;
FindChildGeometries(WidgetGeometry, SubWidgetsSet, Result);
TSharedPtr<SGraphNode> ResultNode;
if (Result.Num() <= 0)
{
return ResultNode;
}