-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathFlowGraphNode.cpp
More file actions
1998 lines (1668 loc) · 52 KB
/
FlowGraphNode.cpp
File metadata and controls
1998 lines (1668 loc) · 52 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/Nodes/FlowGraphNode.h"
#include "FlowAsset.h"
#include "AddOns/FlowNodeAddOn.h"
#include "Nodes/FlowNode.h"
#include "Debugger/FlowDebuggerSubsystem.h"
#include "FlowEditorCommands.h"
#include "Graph/FlowGraph.h"
#include "Graph/FlowGraphEditorSettings.h"
#include "Graph/FlowGraphSchema.h"
#include "Graph/FlowGraphSettings.h"
#include "Graph/Widgets/SFlowGraphNode.h"
#include "Graph/Widgets/SGraphEditorActionMenuFlow.h"
#include "BlueprintNodeHelpers.h"
#include "Developer/ToolMenus/Public/ToolMenus.h"
#include "DiffResults.h"
#include "Editor.h"
#include "FlowLogChannels.h"
#include "Framework/Commands/GenericCommands.h"
#include "GraphDiffControl.h"
#include "GraphEditorActions.h"
#include "HAL/FileManager.h"
#include "Kismet2/KismetEditorUtilities.h"
#include "ScopedTransaction.h"
#include "SourceCodeNavigation.h"
#include "Subsystems/AssetEditorSubsystem.h"
#include "Textures/SlateIcon.h"
#include "ToolMenuSection.h"
#include "Editor/Transactor.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(FlowGraphNode)
#define LOCTEXT_NAMESPACE "FlowGraphNode"
UFlowGraphNode::UFlowGraphNode(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, NodeInstance(nullptr)
, bBlueprintCompilationPending(false)
, bIsReconstructingNode(false)
, bIsDestroyingNode(false)
, bNeedsFullReconstruction(false)
{
OrphanedPinSaveMode = ESaveOrphanPinMode::SaveAll;
}
void UFlowGraphNode::SetNodeTemplate(UFlowNodeBase* InNodeInstance)
{
ensure(InNodeInstance);
NodeInstance = InNodeInstance;
NodeInstanceClass = InNodeInstance->GetClass();
}
const UFlowNodeBase* UFlowGraphNode::GetNodeTemplate() const
{
return NodeInstance;
}
UFlowNodeBase* UFlowGraphNode::GetFlowNodeBase() const
{
if (NodeInstance)
{
if (const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
if (const UFlowAsset* FlowAsset = FlowNode->GetFlowAsset())
{
if (const UFlowAsset* InspectedInstance = FlowAsset->GetInspectedInstance())
{
return InspectedInstance->GetNode(FlowNode->GetGuid());
}
}
}
return NodeInstance;
}
return nullptr;
}
void UFlowGraphNode::PostLoad()
{
Super::PostLoad();
if (NodeInstance)
{
NodeInstance->FixNode(this); // fix already created nodes
SubscribeToExternalChanges();
}
RebuildPinArraysOnLoad();
}
void UFlowGraphNode::PostDuplicate(bool bDuplicateForPIE)
{
Super::PostDuplicate(bDuplicateForPIE);
if (!bDuplicateForPIE)
{
CreateNewGuid();
UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
if (FlowNode && FlowNode->GetFlowAsset())
{
FlowNode->GetFlowAsset()->RegisterNode(NodeGuid, FlowNode);
}
}
}
void UFlowGraphNode::PostEditImport()
{
Super::PostEditImport();
PostCopyNode();
SubscribeToExternalChanges();
// Reset the owning graph after an edit import
ResetNodeOwner();
if (NodeInstance)
{
InitializeInstance();
}
}
void UFlowGraphNode::PostPlacedNewNode()
{
Super::PostPlacedNewNode();
SubscribeToExternalChanges();
// note: NodeInstance can be already spawned by paste operation, don't override it
if (NodeInstanceClass.IsPending())
{
NodeInstanceClass.LoadSynchronous();
}
if (NodeInstance == nullptr)
{
if (const UClass* NodeClass = NodeInstanceClass.Get())
{
const UEdGraph* Graph = GetGraph();
if (Graph && Graph->GetOuter())
{
NodeInstance = NewObject<UFlowNodeBase>(Graph->GetOuter(), NodeClass);
NodeInstance->SetFlags(RF_Transactional);
InitializeInstance();
}
}
}
}
void UFlowGraphNode::PrepareForCopying()
{
Super::PrepareForCopying();
if (NodeInstance)
{
// Temporarily take ownership of the node instance, so that it is not deleted when cutting
NodeInstance->Rename(nullptr, this, REN_DontCreateRedirectors | REN_DoNotDirty);
}
}
void UFlowGraphNode::PostPasteNode()
{
Super::PostPasteNode();
//prep reconstruct the node, necessary for copy-paste to handle the reconstruct.
bNeedsFullReconstruction = true;
}
void UFlowGraphNode::PostCopyNode()
{
// Make sure this NodeInstance is owned by the FlowAsset it's being pasted into
if (NodeInstance)
{
UFlowAsset* FlowAsset = GetFlowAsset();
if (NodeInstance->GetOuter() != FlowAsset)
{
// Ensures NodeInstance is owned by the FlowAsset
NodeInstance->Rename(nullptr, FlowAsset, REN_DontCreateRedirectors);
}
NodeInstance->SetGraphNode(this);
}
// Reset the node's owning graph prior to copying
ResetNodeOwner();
}
void UFlowGraphNode::SubscribeToExternalChanges()
{
if (NodeInstance)
{
NodeInstance->OnReconstructionRequested.BindUObject(this, &UFlowGraphNode::OnExternalChange);
for (UFlowGraphNode* SubNode : SubNodes)
{
if (SubNode->NodeInstance)
{
SubNode->NodeInstance->OnAddOnRequestedParentReconstruction.BindUObject(this, &UFlowGraphNode::OnExternalChange);
}
}
}
}
void UFlowGraphNode::OnExternalChange()
{
if (bIsReconstructingNode)
{
return;
}
// Do not create transaction here, since this function triggers from modifying UFlowNode's property, which itself already made inside of transaction.
Modify();
bNeedsFullReconstruction = true;
ReconstructNode();
GetGraph()->NotifyNodeChanged(this);
}
void UFlowGraphNode::OnGraphRefresh()
{
ReconstructNode();
}
bool UFlowGraphNode::CanPlaceBreakpoints() const
{
return true;
}
bool UFlowGraphNode::CanCreateUnderSpecifiedSchema(const UEdGraphSchema* Schema) const
{
return Schema->IsA(UFlowGraphSchema::StaticClass());
}
void UFlowGraphNode::AutowireNewNode(UEdGraphPin* FromPin)
{
if (FromPin != nullptr)
{
const UFlowGraphSchema* Schema = CastChecked<UFlowGraphSchema>(GetSchema());
TSet<UEdGraphNode*> NodeList;
// auto-connect from dragged pin to first compatible pin on the new node
for (UEdGraphPin* Pin : Pins)
{
check(Pin);
FPinConnectionResponse Response = Schema->CanCreateConnection(FromPin, Pin);
if (CONNECT_RESPONSE_MAKE == Response.Response)
{
if (Schema->TryCreateConnection(FromPin, Pin))
{
NodeList.Add(FromPin->GetOwningNode());
NodeList.Add(this);
}
break;
}
else if (CONNECT_RESPONSE_BREAK_OTHERS_A == Response.Response)
{
InsertNewNode(FromPin, Pin, NodeList);
break;
}
}
// Send all nodes that received a new pin connection a notification
for (auto It = NodeList.CreateConstIterator(); It; ++It)
{
UEdGraphNode* Node = (*It);
Node->NodeConnectionListChanged();
}
}
}
void UFlowGraphNode::InsertNewNode(UEdGraphPin* FromPin, UEdGraphPin* NewLinkPin, TSet<UEdGraphNode*>& OutNodeList)
{
const UFlowGraphSchema* Schema = CastChecked<UFlowGraphSchema>(GetSchema());
// The pin we are creating from already has a connection that needs to be broken. We want to "insert" the new node in between, so that the output of the new node is hooked up too
UEdGraphPin* OldLinkedPin = FromPin->LinkedTo[0];
check(OldLinkedPin);
FromPin->BreakAllPinLinks();
// Hook up the old linked pin to the first valid output pin on the new node
for (int32 PinIndex = 0; PinIndex < Pins.Num(); PinIndex++)
{
UEdGraphPin* OutputExecPin = Pins[PinIndex];
check(OutputExecPin);
if (CONNECT_RESPONSE_MAKE == Schema->CanCreateConnection(OldLinkedPin, OutputExecPin).Response)
{
if (Schema->TryCreateConnection(OldLinkedPin, OutputExecPin))
{
OutNodeList.Add(OldLinkedPin->GetOwningNode());
OutNodeList.Add(this);
}
break;
}
}
if (Schema->TryCreateConnection(FromPin, NewLinkPin))
{
OutNodeList.Add(FromPin->GetOwningNode());
OutNodeList.Add(this);
}
}
void UFlowGraphNode::ReconstructNode()
{
if (!CanReconstructNode())
{
return;
}
bIsReconstructingNode = true;
FScopedTransaction Transaction(LOCTEXT("ReconstructNode", "Reconstruct Node"), !GUndo);
const bool bNodeDataPinsUpdated = TryUpdateAutoDataPins(); // This must be called first, it updates the underlying data for data pins of the Flow Node
const bool bNodeExecPinsUpdated = TryUpdateNodePins(); // Updates all pins of the Flow Node (native pins, meta auto pins, and context pins which include data pins for now)
const bool bAreGraphPinsMismatched = !CheckGraphPinsMatchNodePins(); // This must be called last since it checks the existing graph node against the cleaned up Flow Node instance
const bool bGraphNodeRequiresReconstruction = bNeedsFullReconstruction || bNodeDataPinsUpdated || bNodeExecPinsUpdated || bAreGraphPinsMismatched;
if (bGraphNodeRequiresReconstruction)
{
Modify();
TArray<UEdGraphPin*> OldPins(Pins);
Pins.Reset();
InputPins.Reset();
OutputPins.Reset();
AllocateDefaultPins();
RewireOldPinsToNewPins(OldPins);
// Destroy old pins
for (UEdGraphPin* OldPin : OldPins)
{
OldPin->Modify();
OldPin->BreakAllPinLinks();
DestroyPin(OldPin);
}
// clear breakpoints for destroyed pins
if (UFlowDebuggerSubsystem* DebuggerSubsystem = GEngine->GetEngineSubsystem<UFlowDebuggerSubsystem>())
{
DebuggerSubsystem->RemoveObsoletePinBreakpoints(this);
}
bNeedsFullReconstruction = false;
}
if (UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
FlowNode->UpdateNodeConfigText();
}
// This ensures the graph editor 'Refresh' button still rebuilds all the graph widgets even if the FlowGraphNode has nothing to update
// Ideally we could get rid of the 'Refresh' button, but I think it will keep being useful, esp. for users making rough custom widgets
(void)OnReconstructNodeCompleted.ExecuteIfBound();
bIsReconstructingNode = false;
}
void UFlowGraphNode::AllocateDefaultPins()
{
check(Pins.Num() == 0);
if (UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
for (const FFlowPin& InputPin : FlowNode->InputPins)
{
CreateInputPin(InputPin);
}
for (const FFlowPin& OutputPin : FlowNode->OutputPins)
{
CreateOutputPin(OutputPin);
}
}
}
void UFlowGraphNode::RewireOldPinsToNewPins(TArray<UEdGraphPin*>& InOldPins)
{
TArray<UEdGraphPin*> OrphanedOldPins;
TArray<bool> NewPinMatched; // Tracks whether a NewPin has already been matched to an OldPin
TMap<UEdGraphPin*, UEdGraphPin*> MatchedPins; // Old to New
const int32 NumNewPins = Pins.Num();
NewPinMatched.AddDefaulted(NumNewPins);
// Rewire any connection to pins that are matched by name (O(N^2) right now)
// NOTE: we iterate backwards through the list because ReconstructSinglePin()
// destroys pins as we go along (clearing out parent pointers, etc.);
// we need the parent pin chain intact for DoPinsMatchForReconstruction();
// we want to destroy old pins from the split children (leaves) up, so
// we do this since split child pins are ordered later in the list
// (after their parents)
for (int32 OldPinIndex = InOldPins.Num() - 1; OldPinIndex >= 0; --OldPinIndex)
{
UEdGraphPin* OldPin = InOldPins[OldPinIndex];
// common case is for InOldPins and Pins to match, so we start searching from the current index:
bool bMatched = false;
int32 NewPinIndex = (NumNewPins ? OldPinIndex % NumNewPins : 0);
for (int32 NewPinCount = NumNewPins - 1; NewPinCount >= 0; --NewPinCount)
{
// if Pins grows then we may skip entries and fail to find a match or NewPinMatched will not be accurate
check(NumNewPins == Pins.Num());
if (!NewPinMatched[NewPinIndex])
{
UEdGraphPin* NewPin = Pins[NewPinIndex];
if (NewPin->PinName == OldPin->PinName)
{
ReconstructSinglePin(NewPin, OldPin);
MatchedPins.Add(OldPin, NewPin);
bMatched = true;
NewPinMatched[NewPinIndex] = true;
break;
}
}
NewPinIndex = (NewPinIndex + 1) % Pins.Num();
}
// Orphaned pins are those that existed in the OldPins array but do not in the NewPins.
// We will save these pins and add them to the NewPins array if they are linked to other pins or have non-default value unless:
// * The node has been flagged to not save orphaned pins
// * The pin has been flagged not be saved if orphaned
// * The pin is hidden
if (UEdGraphPin::AreOrphanPinsEnabled() && !bDisableOrphanPinSaving && OrphanedPinSaveMode == ESaveOrphanPinMode::SaveAll
&& !bMatched && !OldPin->bHidden && OldPin->ShouldSavePinIfOrphaned() && OldPin->LinkedTo.Num() > 0)
{
OldPin->bOrphanedPin = true;
OldPin->bNotConnectable = true;
OrphanedOldPins.Add(OldPin);
InOldPins.RemoveAt(OldPinIndex, 1, EAllowShrinking::No);
}
}
// The orphaned pins get placed after the rest of the new pins
for (int32 OrphanedIndex = OrphanedOldPins.Num() - 1; OrphanedIndex >= 0; --OrphanedIndex)
{
UEdGraphPin* OrphanedPin = OrphanedOldPins[OrphanedIndex];
if (OrphanedPin->ParentPin == nullptr)
{
Pins.Add(OrphanedPin);
switch (OrphanedPin->Direction)
{
case EGPD_Input:
InputPins.Add(OrphanedPin);
break;
case EGPD_Output:
OutputPins.Add(OrphanedPin);
break;
default: ;
}
}
}
}
void UFlowGraphNode::ReconstructSinglePin(UEdGraphPin* NewPin, UEdGraphPin* OldPin)
{
check(NewPin && OldPin);
// Copy over modified persistent data
NewPin->MovePersistentDataFromOldPin(*OldPin);
}
void UFlowGraphNode::GetNodeContextMenuActions(class UToolMenu* Menu, class UGraphNodeContextMenuContext* Context) const
{
const FGenericCommands& GenericCommands = FGenericCommands::Get();
const FGraphEditorCommandsImpl& GraphCommands = FGraphEditorCommands::Get();
const FFlowGraphCommands& FlowGraphCommands = FFlowGraphCommands::Get();
if (Context->Pin)
{
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphPinActions", LOCTEXT("PinActionsMenuHeader", "Pin Actions"));
if (Context->Pin->LinkedTo.Num() > 0)
{
Section.AddMenuEntry(GraphCommands.BreakPinLinks);
}
if (Context->Pin->Direction == EGPD_Input && CanUserRemoveInput(Context->Pin))
{
Section.AddMenuEntry(FlowGraphCommands.RemovePin);
}
else if (Context->Pin->Direction == EGPD_Output && CanUserRemoveOutput(Context->Pin))
{
Section.AddMenuEntry(FlowGraphCommands.RemovePin);
}
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphPinBreakpoints", LOCTEXT("PinBreakpointsMenuHeader", "Pin Breakpoints"));
Section.AddMenuEntry(FlowGraphCommands.AddPinBreakpoint);
Section.AddMenuEntry(FlowGraphCommands.RemovePinBreakpoint);
Section.AddMenuEntry(FlowGraphCommands.EnablePinBreakpoint);
Section.AddMenuEntry(FlowGraphCommands.DisablePinBreakpoint);
Section.AddMenuEntry(FlowGraphCommands.TogglePinBreakpoint);
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphPinExecutionOverride", LOCTEXT("PinExecutionOverrideMenuHeader", "Execution Override"));
Section.AddMenuEntry(FlowGraphCommands.ForcePinActivation);
}
}
else if (Context->Node)
{
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphNodeAddOns", LOCTEXT("NodeAddOnsMenuHeader", "AddOns"));
Section.AddSubMenu(
"AttachAddOn",
LOCTEXT("AttachAddOn", "Attach AddOn..."),
LOCTEXT("AttachAddOnTooltip", "Attaches an AddOn to the Node"),
FNewToolMenuDelegate::CreateUObject(this, &UFlowGraphNode::CreateAttachAddOnSubMenu, static_cast<UEdGraph*>(Context->Graph))
);
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphNodeActions", LOCTEXT("NodeActionsMenuHeader", "Node Actions"));
Section.AddMenuEntry(GenericCommands.Delete);
Section.AddMenuEntry(GenericCommands.Cut);
Section.AddMenuEntry(GenericCommands.Copy);
Section.AddMenuEntry(GenericCommands.Duplicate);
Section.AddMenuEntry(GraphCommands.BreakNodeLinks);
if (SupportsContextPins())
{
Section.AddMenuEntry(FlowGraphCommands.ReconstructNode);
}
if (CanUserAddInput())
{
Section.AddMenuEntry(FlowGraphCommands.AddInput);
}
if (CanUserAddOutput())
{
Section.AddMenuEntry(FlowGraphCommands.AddOutput);
}
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphNodeBreakpoints", LOCTEXT("NodeBreakpointsMenuHeader", "Node Breakpoints"));
Section.AddMenuEntry(GraphCommands.AddBreakpoint);
Section.AddMenuEntry(GraphCommands.RemoveBreakpoint);
Section.AddMenuEntry(GraphCommands.EnableBreakpoint);
Section.AddMenuEntry(GraphCommands.DisableBreakpoint);
Section.AddMenuEntry(GraphCommands.ToggleBreakpoint);
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphNodeExecutionOverride", LOCTEXT("NodeExecutionOverrideMenuHeader", "Execution Override"));
if (CanSetSignalMode(EFlowSignalMode::Enabled))
{
Section.AddMenuEntry(FlowGraphCommands.EnableNode);
}
if (CanSetSignalMode(EFlowSignalMode::Disabled))
{
Section.AddMenuEntry(FlowGraphCommands.DisableNode);
}
if (CanSetSignalMode(EFlowSignalMode::PassThrough))
{
Section.AddMenuEntry(FlowGraphCommands.SetPassThrough);
}
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphNodeJumps", LOCTEXT("NodeJumpsMenuHeader", "Jumps"));
if (CanFocusViewport())
{
Section.AddMenuEntry(FlowGraphCommands.FocusViewport);
}
if (CanJumpToDefinition())
{
Section.AddMenuEntry(FlowGraphCommands.JumpToNodeDefinition);
}
}
{
FToolMenuSection& Section = Menu->AddSection("FlowGraphNodeOrganisation", LOCTEXT("NodeOrganisation", "Organisation"));
Section.AddSubMenu("Alignment", LOCTEXT("AlignmentHeader", "Alignment"), FText(), FNewToolMenuDelegate::CreateLambda([](UToolMenu* SubMenu)
{
FToolMenuSection& SubMenuSection = SubMenu->AddSection("EdGraphSchemaAlignment", LOCTEXT("AlignHeader", "Align"));
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().AlignNodesTop);
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().AlignNodesMiddle);
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().AlignNodesBottom);
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().AlignNodesLeft);
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().AlignNodesCenter);
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().AlignNodesRight);
SubMenuSection.AddMenuEntry(FGraphEditorCommands::Get().StraightenConnections);
}));
}
}
}
void UFlowGraphNode::CreateAttachAddOnSubMenu(UToolMenu* Menu, UEdGraph* Graph) const
{
UFlowGraphNode* MutableThis = const_cast<UFlowGraphNode*>(this);
const TSharedRef<SGraphEditorActionMenuFlow> Widget =
SNew(SGraphEditorActionMenuFlow)
.GraphObj(Graph)
.GraphNode(MutableThis)
.AutoExpandActionMenu(true);
Menu->AddMenuEntry("Section", FToolMenuEntry::InitWidget("Widget", Widget, FText(), true));
}
bool UFlowGraphNode::CanUserDeleteNode() const
{
return NodeInstance ? NodeInstance->bCanDelete : Super::CanUserDeleteNode();
}
bool UFlowGraphNode::CanDuplicateNode() const
{
if (NodeInstance)
{
return NodeInstance->bCanDuplicate;
}
// support code paths calling this method on CDO, where there's no Flow Node Instance
if (AssignedNodeClasses.Num() > 0)
{
// we simply allow action if any Assigned Node Class accepts it, as the action is disallowed in special node likes StartNode
for (const UClass* Class : AssignedNodeClasses)
{
const UFlowNode* NodeDefaults = Class->GetDefaultObject<UFlowNode>();
if (NodeDefaults && NodeDefaults->bCanDuplicate)
{
return true;
}
}
return false;
}
return true;
}
bool UFlowGraphNode::CanPasteHere(const UEdGraph* TargetGraph) const
{
const UFlowGraph* FlowGraph = Cast<UFlowGraph>(TargetGraph);
if (FlowGraph == nullptr)
{
return false;
}
return Super::CanPasteHere(TargetGraph) && FlowGraph->GetFlowAsset()->IsNodeOrAddOnClassAllowed(NodeInstanceClass.Get());
}
TSharedPtr<SGraphNode> UFlowGraphNode::CreateVisualWidget()
{
return SNew(SFlowGraphNode, this);
}
FText UFlowGraphNode::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if (NodeInstance)
{
if (UFlowGraphEditorSettings::Get()->bShowNodeClass)
{
FString CleanAssetName;
if (NodeInstance->GetClass()->ClassGeneratedBy)
{
NodeInstance->GetClass()->GetPathName(nullptr, CleanAssetName);
const int32 SubStringIdx = CleanAssetName.Find(".", ESearchCase::IgnoreCase, ESearchDir::FromEnd);
CleanAssetName.LeftInline(SubStringIdx);
}
else
{
CleanAssetName = NodeInstance->GetClass()->GetName();
}
FFormatNamedArguments Args;
Args.Add(TEXT("NodeTitle"), NodeInstance->GetNodeTitle());
Args.Add(TEXT("AssetName"), FText::FromString(CleanAssetName));
return FText::Format(INVTEXT("{NodeTitle}\n{AssetName}"), Args);
}
return NodeInstance->GetNodeTitle();
}
return Super::GetNodeTitle(TitleType);
}
FLinearColor UFlowGraphNode::GetNodeTitleColor() const
{
if (NodeInstance)
{
FLinearColor DynamicColor;
if (NodeInstance->GetDynamicTitleColor(DynamicColor))
{
return DynamicColor;
}
if (const FLinearColor* StyleColor = UFlowGraphSettings::Get()->LookupNodeTitleColorForNode(*NodeInstance))
{
return *StyleColor;
}
}
return Super::GetNodeTitleColor();
}
FSlateIcon UFlowGraphNode::GetIconAndTint(FLinearColor& OutColor) const
{
return FSlateIcon();
}
FText UFlowGraphNode::GetTooltipText() const
{
FText Tooltip;
if (NodeInstance)
{
Tooltip = NodeInstance->GetNodeToolTip();
}
if (Tooltip.IsEmpty())
{
Tooltip = GetNodeTitle(ENodeTitleType::ListView);
}
return Tooltip;
}
FString UFlowGraphNode::GetNodeDescription() const
{
if (NodeInstance && (GEditor->PlayWorld == nullptr || UFlowGraphEditorSettings::Get()->bShowNodeDescriptionWhilePlaying))
{
if (UFlowGraphEditorSettings::Get()->bShowAddonNodeDescriptions)
{
return NodeInstance->GetNodeDescriptionWithAddons();
}
return NodeInstance->GetNodeDescription();
}
return FString();
}
UFlowNode* UFlowGraphNode::GetInspectedNodeInstance() const
{
const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
return FlowNode ? FlowNode->GetInspectedInstance() : nullptr;
}
EFlowNodeState UFlowGraphNode::GetActivationState() const
{
if (const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
if (const UFlowNode* InspectedInstance = FlowNode->GetInspectedInstance())
{
return InspectedInstance->GetActivationState();
}
}
return EFlowNodeState::NeverActivated;
}
FString UFlowGraphNode::GetStatusString() const
{
if (const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
if (const UFlowNode* InspectedInstance = FlowNode->GetInspectedInstance())
{
return InspectedInstance->GetStatusStringForNodeAndAddOns();
}
}
return FString();
}
FLinearColor UFlowGraphNode::GetStatusBackgroundColor() const
{
if (const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
if (const UFlowNode* InspectedInstance = FlowNode->GetInspectedInstance())
{
FLinearColor ObtainedColor;
if (InspectedInstance->GetStatusBackgroundColor(ObtainedColor))
{
return ObtainedColor;
}
}
}
return UFlowGraphSettings::Get()->NodeStatusBackground;
}
bool UFlowGraphNode::IsContentPreloaded() const
{
if (const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance))
{
if (const UFlowNode* InspectedInstance = FlowNode->GetInspectedInstance())
{
return InspectedInstance->bPreloaded;
}
}
return false;
}
bool UFlowGraphNode::CanFocusViewport() const
{
UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
return FlowNode ? (GEditor->bIsSimulatingInEditor && FlowNode->GetActorToFocus()) : false;
}
bool UFlowGraphNode::CanJumpToDefinition() const
{
return NodeInstance != nullptr;
}
void UFlowGraphNode::JumpToDefinition() const
{
if (NodeInstance)
{
if (NodeInstance->GetClass()->IsNative())
{
if (FSourceCodeNavigation::CanNavigateToClass(NodeInstance->GetClass()))
{
if (FSourceCodeNavigation::NavigateToClass(NodeInstance->GetClass()))
{
return;
}
}
// Failing that, fall back to the older method which will still get the file open assuming it exists
FString NativeParentClassHeaderPath;
if (FSourceCodeNavigation::FindClassHeaderPath(NodeInstance->GetClass(), NativeParentClassHeaderPath) && (IFileManager::Get().FileSize(*NativeParentClassHeaderPath) != INDEX_NONE))
{
const FString AbsNativeParentClassHeaderPath = FPaths::ConvertRelativePathToFull(NativeParentClassHeaderPath);
FSourceCodeNavigation::OpenSourceFile(AbsNativeParentClassHeaderPath);
}
}
else
{
FKismetEditorUtilities::BringKismetToFocusAttentionOnObject(NodeInstance->GetClass());
}
}
}
bool UFlowGraphNode::SupportsCommentBubble() const
{
if (IsSubNode())
{
return false;
}
return Super::SupportsCommentBubble();
}
void UFlowGraphNode::OnNodeDoubleClicked() const
{
UFlowNodeBase* FlowNodeBase = GetFlowNodeBase();
if (IsValid(FlowNodeBase))
{
if (UFlowGraphEditorSettings::Get()->NodeDoubleClickTarget == EFlowNodeDoubleClickTarget::NodeDefinition)
{
JumpToDefinition();
}
else
{
FString AssetPath;
UObject* AssetToEdit = nullptr;
if (UFlowNode* FlowNode = Cast<UFlowNode>(FlowNodeBase))
{
AssetPath = FlowNode->GetAssetPath();
AssetToEdit = FlowNode->GetAssetToEdit();
}
if (!AssetPath.IsEmpty())
{
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(AssetPath);
}
else if (AssetToEdit)
{
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(AssetToEdit);
if (GEditor->PlayWorld != nullptr)
{
OnNodeDoubleClickedInPIE();
}
}
else if (UFlowGraphEditorSettings::Get()->NodeDoubleClickTarget == EFlowNodeDoubleClickTarget::PrimaryAssetOrNodeDefinition)
{
JumpToDefinition();
}
}
}
}
void UFlowGraphNode::CreateInputPin(const FFlowPin& FlowPin, const int32 Index /*= INDEX_NONE*/)
{
if (FlowPin.PinName.IsNone())
{
return;
}
const FEdGraphPinType EdGraphPinType = FlowPin.BuildEdGraphPinType();
check(!EdGraphPinType.PinCategory.IsNone());
UEdGraphPin* NewPin = CreatePin(EGPD_Input, EdGraphPinType, FlowPin.PinName, Index);
check(NewPin);
if (!FlowPin.PinFriendlyName.IsEmpty())
{
NewPin->bAllowFriendlyName = true;
NewPin->PinFriendlyName = FlowPin.PinFriendlyName;
}
NewPin->PinToolTip = FlowPin.PinToolTip;
InputPins.Emplace(NewPin);
}
void UFlowGraphNode::CreateOutputPin(const FFlowPin& FlowPin, const int32 Index /*= INDEX_NONE*/)
{
if (FlowPin.PinName.IsNone())
{
return;
}
const FEdGraphPinType EdGraphPinType = FlowPin.BuildEdGraphPinType();
check(!EdGraphPinType.PinCategory.IsNone());
UEdGraphPin* NewPin = CreatePin(EGPD_Output, EdGraphPinType, FlowPin.PinName, Index);
check(NewPin);
if (!FlowPin.PinFriendlyName.IsEmpty())
{
NewPin->bAllowFriendlyName = true;
NewPin->PinFriendlyName = FlowPin.PinFriendlyName;
}
NewPin->PinToolTip = FlowPin.PinToolTip;
OutputPins.Emplace(NewPin);
}
void UFlowGraphNode::RemoveOrphanedPin(UEdGraphPin* Pin)
{
const FScopedTransaction Transaction(LOCTEXT("RemoveOrphanedPin", "Remove Orphaned Pin"));
Modify();
if (UFlowDebuggerSubsystem* DebuggerSubsystem = GEngine->GetEngineSubsystem<UFlowDebuggerSubsystem>())
{
DebuggerSubsystem->RemovePinBreakpoint(NodeGuid, Pin->PinName);
}
Pin->MarkAsGarbage();
Pins.Remove(Pin);
ReconstructNode();
GetGraph()->NotifyNodeChanged(this);
}
bool UFlowGraphNode::SupportsContextPins() const
{
return NodeInstance && NodeInstance->SupportsContextPins();
}
bool UFlowGraphNode::CanUserAddInput() const
{
const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
return FlowNode && FlowNode->CanUserAddInput() && InputPins.Num() < 256;
}
bool UFlowGraphNode::CanUserAddOutput() const
{
const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
return FlowNode && FlowNode->CanUserAddOutput() && OutputPins.Num() < 256;
}
bool UFlowGraphNode::CanUserRemoveInput(const UEdGraphPin* Pin) const
{
const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
return FlowNode && !FlowNode->GetClass()->GetDefaultObject<UFlowNode>()->InputPins.Contains(Pin->PinName);
}
bool UFlowGraphNode::CanUserRemoveOutput(const UEdGraphPin* Pin) const
{
const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
return FlowNode && !FlowNode->GetClass()->GetDefaultObject<UFlowNode>()->OutputPins.Contains(Pin->PinName);
}
void UFlowGraphNode::AddUserInput()
{
const UFlowNode* FlowNode = Cast<UFlowNode>(NodeInstance);
AddInstancePin(EGPD_Input, FlowNode->CountNumberedInputs());
}