A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueGraphNode_Edge.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3
4#include "DialogueGraphNode.h"
5
6#define LOCTEXT_NAMESPACE "DialogueGraphNode_Edge"
7
9// Begin UObject interface
10void UDialogueGraphNode_Edge::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
11{
12 Super::PostEditChangeProperty(PropertyChangedEvent);
13
14 // Special case when redoing
15 if (HasParentNode() && HasChildNode())
16 {
17 // Always keep in sync with the Edge of the Dialogue Node
18 FDlgEdge* ParentNodeDialogueEdge = GetMutableDialogueEdgeFromParentNode();
19
20 // This happens when we copy and paste sometimes, the parent/child nodes does not have this edge
21 // Most likely caused by duplicate PinIds
22 if ((ParentNodeDialogueEdge == nullptr || DialogueEdge.TargetIndex != ParentNodeDialogueEdge->TargetIndex) &&
23 (!GetParentNode()->HasChildEdgeNode(this) || !GetChildNode()->HasParentEdgeNode(this)))
24 {
25 return;
26 }
27
28 // Node is correct but the data isn't? :O
29 check(ParentNodeDialogueEdge);
30 check(DialogueEdge.TargetIndex == ParentNodeDialogueEdge->TargetIndex);
31 *ParentNodeDialogueEdge = DialogueEdge;
32 }
33}
34
35bool UDialogueGraphNode_Edge::Modify(bool bAlwaysMarkDirty)
36{
37 if (!CanModify())
38 {
39 return false;
40 }
41
42 bool bWasModified = Super::Modify(bAlwaysMarkDirty);
43 // Notify the Parent of this Change
44 if (HasParentNode())
45 {
46 bWasModified = bWasModified && GetParentNode()->Modify(bAlwaysMarkDirty);
47 }
48
49 return bWasModified;
50}
51// End UObject interface
53
55// Begin UEdGraphNode interface
57{
58 Super::AllocateDefaultPins();
59 GetInputPin()->bHidden = true;
60 GetOutputPin()->bHidden = true;
61}
62
63FText UDialogueGraphNode_Edge::GetNodeTitle(ENodeTitleType::Type TitleType) const
64{
65 return LOCTEXT("GetNodeTitle", "Edge Node Type");
66}
67
69{
70 return FText::Format(LOCTEXT("EdegeXToY", "Edge from node {0} to {1}\nText = {2}"),
71 GetParentNode()->GetDialogueNodeIndex(), GetChildNode()->GetDialogueNodeIndex(),
73}
74
76{
77 if (Pin->LinkedTo.Num() == 0)
78 {
79 // (input pin) ParentNode (output pin) -> (EdgeInputPin) ThisNode (EdgeOutputPin) -> (input pin) ChildNode (output pin)
80 if (Pin->Direction == EGPD_Output)
81 {
82 // The other pin is input
83 UEdGraphPin* InputPin = GetInputPin();
84
85 // Try to remove the reference from the parent to this node if there is still a link.
86 if (InputPin && InputPin->LinkedTo.Num() > 0)
87 {
88 UDialogueGraphNode* ParentNode = GetParentNode();
89 const TArray<UDialogueGraphNode_Edge*> ParentChildEdgeNodes = ParentNode->GetChildEdgeNodes();
90 const int32 ParentThisEdgeIndex = ParentChildEdgeNodes.Find(this);
91 check(ParentThisEdgeIndex != INDEX_NONE);
92 ParentNode->GetMutableDialogueNode()->RemoveChildAt(ParentThisEdgeIndex);
93 }
94 }
95
96 // Commit suicide; transitions must always have an input and output connection
97 Modify();
98 DestroyNode();
99 return;
100 }
101
102 // Modifed one of the pins, most likely a result of CONNECT_RESPONSE_BREAK_OTHERS
103 const int32 NewTargetIndex = GetChildNode()->GetDialogueNodeIndex();
104 if (NewTargetIndex != DialogueEdge.TargetIndex)
105 {
106 // (input pin) Parent Node (output pin) -> (input pin) ThisEdge Node (output pin) -> (input pin) New ChildNode (output pin)
107 // Find ThisEdge node index, in the array of child edge nodes of the Parent node.
108 // This matches the Edge Index of the Dialogue Edges array we must modify the Target Index of
109 UDialogueGraphNode* ParentNode = GetParentNode();
110 const TArray<UDialogueGraphNode_Edge*> ParentChildEdgeNodes = ParentNode->GetChildEdgeNodes();
111 const int32 ParentThisEdgeIndex = ParentChildEdgeNodes.Find(this);
112 check(ParentThisEdgeIndex != INDEX_NONE);
113
114 // Change the Parent Edge Target Index
115 UDlgNode* ParentNodeDialogue = ParentNode->GetMutableDialogueNode();
116 check(ParentNodeDialogue->GetNodeChildren()[ParentThisEdgeIndex].TargetIndex == DialogueEdge.TargetIndex);
117 ParentNodeDialogue->GetSafeMutableNodeChildAt(ParentThisEdgeIndex)->TargetIndex = NewTargetIndex;
118 DialogueEdge.TargetIndex = NewTargetIndex;
119 }
120}
121
123{
124 Super::PostPasteNode();
125 // We don't want to paste nodes in that aren't fully linked (edges nodes have fixed pins as they
126 // really describe the connection between two other nodes). If we find one missing link, get rid of the node.
127 for (UEdGraphPin* Pin : Pins)
128 {
129 if (Pin->LinkedTo.Num() == 0)
130 {
131 DestroyNode();
132 break;
133 }
134 }
135}
136// End UEdGraphNode interface
138
140// Begin own functions
142{
143 check(ParentNode != ChildNode);
144
145 // (input pin) ParentNode (output pin) -> (input pin) EdgeNode aka ThisNode (output pin) -> (input pin) ChildNode (output pin)
146 UEdGraphPin* ThisInputPin = GetInputPin();
147 UEdGraphPin* ThisOutputPin = GetOutputPin();
148 ThisInputPin->Modify();
149 ThisInputPin->LinkedTo.Empty();
150 ThisOutputPin->Modify();
151 ThisOutputPin->LinkedTo.Empty();
152
153 // Previous (ParentNode) to ThisNode
154 ParentNode->GetOutputPin()->MakeLinkTo(ThisInputPin);
155
156 // ThisNode to Next (ChildNode)
157 ThisOutputPin->MakeLinkTo(ChildNode->GetInputPin());
158
159 check(ThisInputPin->LinkedTo.Num() == 1);
160 check(ThisOutputPin->LinkedTo.Num() == 1);
161
162 // Set the Edge
163 const FDlgEdge* ParentNodeDialogueEdge = GetMutableDialogueEdgeFromParentNode();
164 if (ParentNodeDialogueEdge != nullptr)
165 {
166 // Already exists
167 DialogueEdge = *ParentNodeDialogueEdge;
168 }
169 else
170 {
171 // Add one Edge at the end of the array
172 const FDlgEdge EdgeToAdd = FDlgEdge(ChildNode->GetDialogueNodeIndex());
173 ParentNode->GetMutableDialogueNode()->AddNodeChild(EdgeToAdd);
174 DialogueEdge = EdgeToAdd;
175 }
176}
177
178FLinearColor UDialogueGraphNode_Edge::GetEdgeColor(bool bIsHovered) const
179{
180 const UDlgSystemSettings* Settings = GetDefault<UDlgSystemSettings>();
181 if (bIsHovered)
182 {
183 return Settings->WireHoveredColor;
184 }
185
186 // Use color scheme for primary/secondary edges
187 if (Settings->bShowPrimarySecondaryEdges)
188 {
189 return bIsPrimaryEdge ? Settings->WirePrimaryEdgeColor : Settings->WireSecondaryEdgeColor;
190 }
191
192 // Wire has conditions
194 {
195 return Settings->WireWithConditionsColor;
196 }
197
198 // Normal coloring
199 return Settings->WireBaseColor;
200}
201
203{
204 UDialogueGraphNode* ParentNode = GetParentNode();
205 const UDialogueGraphNode* ChildNode = GetChildNode();
206 return ParentNode->GetMutableDialogueNode()->GetMutableNodeChildForTargetIndex(ChildNode->GetDialogueNodeIndex());
207}
208// End own functions
210
211#undef LOCTEXT_NAMESPACE
UEdGraphPin * GetOutputPin() const
UEdGraphPin * GetInputPin() const
bool Modify(bool bAlwaysMarkDirty=true) override
UDialogueGraphNode * GetChildNode() const
void PinConnectionListChanged(UEdGraphPin *Pin) override
UDialogueGraphNode * GetParentNode() const
FDlgEdge DialogueEdge
UPROPERTY(EditAnywhere, Category = DialogueGraphNode, Meta = (ShowOnlyInnerProperties))
void CreateConnections(UDialogueGraphNode *ParentNode, UDialogueGraphNode *ChildNode)
FText GetNodeTitle(ENodeTitleType::Type TitleType) const override
void PostEditChangeProperty(FPropertyChangedEvent &PropertyChangedEvent) override
FLinearColor GetEdgeColor(bool bIsHovered) const
FText GetTooltipText() const override
FDlgEdge * GetMutableDialogueEdgeFromParentNode() const
virtual int32 GetDialogueNodeIndex() const
DlgNodeType * GetMutableDialogueNode()
TArray< UDialogueGraphNode_Edge * > GetChildEdgeNodes(bool bCheckParent=true) const
bool Modify(bool bAlwaysMarkDirty=true) override
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
virtual FDlgEdge * GetSafeMutableNodeChildAt(int32 EdgeIndex)
Definition DlgNode.h:213
virtual const TArray< FDlgEdge > & GetNodeChildren() const
Gets this nodes children (edges) as a const/mutable array.
Definition DlgNode.h:184
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
FLinearColor WireHoveredColor
UPROPERTY(Category = "Graph Edge Color", Config, EditAnywhere)
FLinearColor WireSecondaryEdgeColor
UPROPERTY(Category = "Graph Edge Color", Config, EditAnywhere)
bool bShowDifferentColorForConditionWires
UPROPERTY(Category = "Graph Edge Color", Config, EditAnywhere)
bool bShowPrimarySecondaryEdges
UPROPERTY(Category = "Graph Edge", Config, EditAnywhere)
FLinearColor WireBaseColor
UPROPERTY(Category = "Graph Edge Color", Config, EditAnywhere)
FLinearColor WirePrimaryEdgeColor
UPROPERTY(Category = "Graph Edge Color", Config, EditAnywhere)
FLinearColor WireWithConditionsColor
UPROPERTY(Category = "Graph Edge Color", Config, EditAnywhere)
USTRUCT(BlueprintType)
Definition DlgEdge.h:25
int32 TargetIndex
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge", Meta = (ClampMin = -1))
Definition DlgEdge.h:126
const FText & GetUnformattedText() const
Definition DlgEdge.h:103