A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueGraphNode.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3
4#include "CoreTypes.h"
5#include "UObject/ObjectMacros.h"
6
7#include "Nodes/DlgNode_End.h"
12
13#include "DialogueGraphNode.generated.h"
14
15class UEdGraphPin;
16class DialogueGraphNode_Edge;
17class UToolMenu;
18class UGraphNodeContextMenuContext;
19
22{
24 {
26
27 // A result of DoesEdgeMatchEdgeIndex
29
30 // The length of the arrays mismatch, there is one more edge (located at the end) than pin connection
32
33 // The length of the arrays mismatch, there is one more pin connection (located at the end) than edges
35
36 // Diff type not supported
38 };
39
42
52 int32 Index = INDEX_NONE;
53
55 FString Message;
56};
57
58UCLASS()
60{
61 GENERATED_BODY()
62
63public:
64 //
65 // Begin UObject Interface.
66 //
67
72 void PostLoad() override;
73
79 void PostEditImport() override;
80
86 void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
87
92 void PostEditChangeChainProperty(struct FPropertyChangedChainEvent& PropertyChangedEvent) override;
93
103 bool Modify(bool bAlwaysMarkDirty = true) override;
104
105 //
106 // Begin UEdGraphNode interface
107 //
108
110 FText GetNodeTitle(ENodeTitleType::Type TitleType) const override;
111
113 FText GetTooltipText() const override;
114 FString GetDocumentationExcerptName() const override;
115
117 bool CanDuplicateNode() const override { return !IsRootNode(); }
118
120 bool CanUserDeleteNode() const override { return !IsRootNode(); }
121
123 void PrepareForCopying() override;
124
131 void NodeConnectionListChanged() override
132 {
133 CheckDialogueNodeSyncWithGraphNode(true);
134 ApplyCompilerWarnings();
135 }
136
138 void PinConnectionListChanged(UEdGraphPin* Pin) override;
139
141#if ENGINE_MINOR_VERSION >= 24
142 void GetNodeContextMenuActions(UToolMenu* Menu, UGraphNodeContextMenuContext* Context) const override;
143#else
144 void GetContextMenuActions(const FGraphNodeContextMenuBuilder& Context) const override;
145#endif
146
152 void AutowireNewNode(UEdGraphPin* FromPin) override;
153
154 // Begin UDialogueGraphNode_Base interface
155
157 bool CanHaveInputConnections() const override { return NodeIndex != INDEX_NONE && !IsRootNode(); }
158
160 bool CanHaveOutputConnections() const override { return !IsEndNode(); }
161
163 bool HasOutputConnectionToNode(const UEdGraphNode* TargetNode) const override;
164
166 FLinearColor GetNodeBackgroundColor() const override;
167
169 void PostCopyNode() override;
170
172 void CheckAll() const override
173 {
174#if DO_CHECK
175 Super::CheckAll();
176 check(IsDialogueNodeSet());
177 CheckDialogueNodeIndexMatchesNode();
178 CheckDialogueNodeSyncWithGraphNode(true);
179#endif
180 }
181
183 virtual bool IsRootNode() const { return false; }
184
185 //
186 // Begin own functions
187 //
188
190 bool IsEndNode() const { return DialogueNode->IsA<UDlgNode_End>(); }
191
193 bool IsSpeechNode() const { return DialogueNode->IsA<UDlgNode_Speech>(); }
194
196 bool IsVirtualParentNode() const
197 {
198 if (const UDlgNode_Speech* Node = Cast<UDlgNode_Speech>(DialogueNode))
199 {
200 return Node->IsVirtualParent();
201 }
202
203 return false;
204 }
205
207 bool IsSelectorNode() const { return DialogueNode->IsA<UDlgNode_Selector>(); }
208
210 bool IsSelectorFirstNode() const
211 {
212 if (const UDlgNode_Selector* Node = Cast<UDlgNode_Selector>(DialogueNode))
213 {
215 }
216
217 return false;
218 }
219
221 bool IsSelectorRandomNode() const
222 {
223 if (const UDlgNode_Selector* Node = Cast<UDlgNode_Selector>(DialogueNode))
224 {
225 return Node->GetSelectorType() == EDlgNodeSelectorType::Random;
226 }
227
228 return false;
229 }
230
232 bool IsSpeechSequenceNode() const { return DialogueNode->IsA<UDlgNode_SpeechSequence>(); }
233
235 bool HasEnterConditions() const
236 {
237 return DialogueNode ? DialogueNode->HasAnyEnterConditions() : false;
238 }
239
241 bool HasEnterEvents() const
242 {
243 return DialogueNode ? DialogueNode->HasAnyEnterEvents() : false;
244 }
245
247 bool HasVoicePropertiesSet() const;
248
250 bool HasGenericDataSet() const;
251
253 int32 GetNodeDepth() const { return NodeDepth; }
254
256 void SetNodeDepth(int32 NewNodeDepth) { NodeDepth = NewNodeDepth; }
257
259 virtual void SetDialogueNode(UDlgNode* InNode)
260 {
261 DialogueNode = InNode;
262 DialogueNode->SetFlags(RF_Transactional);
263 DialogueNode->SetGraphNode(this);
264 RegisterListeners();
265 }
266
268 virtual void SetDialogueNodeIndex(int32 InIndex)
269 {
270 check(InIndex > INDEX_NONE);
271 NodeIndex = InIndex;
272 }
273
274 // Where should the edges pointing to this node be positioned at
275 // NOTE: we use this because otherwise the edges don't get rendered
276 FIntPoint GetDefaultEdgePosition() const { return GetPosition() + FIntPoint(5, 5); }
277
283 void SetDialogueNodeDataChecked(int32 InIndex, UDlgNode* InNode);
284
286 template <typename DlgNodeType>
287 const DlgNodeType& GetDialogueNode() const { return *CastChecked<DlgNodeType>(DialogueNode); }
288
290 template <typename DlgNodeType>
291 DlgNodeType* GetMutableDialogueNode() { return CastChecked<DlgNodeType>(DialogueNode); }
292
293 // Specialization for the methods above (by overloading) for the base type UDlgNode type so that we do not need to cast
294 const UDlgNode& GetDialogueNode() const { return *DialogueNode; }
295 UDlgNode* GetMutableDialogueNode() const { return DialogueNode; }
298 bool IsDialogueNodeSet() const { return DialogueNode != nullptr; }
299
301 virtual int32 GetDialogueNodeIndex() const { return NodeIndex; }
302
304 int32 GetChildEdgeIndexForChildNodeIndex(int32 ChildNodeIndex) const;
305
307 void SetEdgeTargetIndexAt(int32 EdgeIndex, int32 NewTargetIndex);
308
310 void SetEdgeTextAt(int32 EdgeIndex, const FText& NewText);
311
312 // Sets all the node children (edges).
313 // NOTE: USE WITH CAUTION
314 void SetEdges(const TArray<FDlgEdge>& InEdges);
315
316 // Updates the edges data from the DialogueNode
317 // NOTE: USE WITH CAUTION
318 void UpdateEdgesFromDialogueNode();
319
321 void ApplyCompilerWarnings();
322
324 int32 EstimateNodeWidth() const;
325
327 void CheckDialogueNodeIndexMatchesNode() const;
328
330 void CheckDialogueNodeSyncWithGraphNode(bool bStrictCheck = false) const;
331
333 TArray<UDialogueGraphNode*> GetParentNodes() const;
334
336 TArray<UDialogueGraphNode*> GetChildNodes() const;
337
339 TArray<UDialogueGraphNode_Edge*> GetParentEdgeNodes(bool bCheckChild = true) const;
340
342 TArray<UDialogueGraphNode_Edge*> GetChildEdgeNodes(bool bCheckParent = true) const;
343
345 bool HasChildEdgeNode(const UDialogueGraphNode_Edge* ChildEdgeToFind) const;
346
348 bool HasParentEdgeNode(const UDialogueGraphNode_Edge* ParentEdgeToFind) const;
349
351 void SortChildrenBasedOnXLocation();
352
354 bool GetForceHideNode() const { return bForceHideNode; }
355
357 void SetForceHideNode(bool bHide) { bForceHideNode = bHide; }
358
360 bool ShouldDrawNode() const { return !bForceHideNode; }
361
363 static FName GetMemberNameDialogueNode() { return GET_MEMBER_NAME_CHECKED(UDialogueGraphNode, DialogueNode); }
364 static FName GetMemberNameNodeIndex() { return GET_MEMBER_NAME_CHECKED(UDialogueGraphNode, NodeIndex); }
366protected:
367 // Begin UDialogueGraphNode_Base interface
369 virtual void CreateInputPin()
370 {
371 static const FName PinName(TEXT("Input Pin"));
372 FCreatePinParams PinParams;
373 PinParams.Index = INDEX_PIN_Input;
374 CreatePin(EGPD_Input, UDialogueGraphSchema::PIN_CATEGORY_Input, PinName, PinParams);
375 }
376
378 virtual void CreateOutputPin()
379 {
380 static const FName PinName(TEXT("Output Pin"));
381 FCreatePinParams PinParams;
382 PinParams.Index = INDEX_PIN_Output;
383 CreatePin(EGPD_Output, UDialogueGraphSchema::PIN_CATEGORY_Output, PinName, PinParams);
384
385 // This enables or disables dragging of the pin from the Node, see SGraphPin::OnPinMouseDown for details
386 GetOutputPin()->bNotConnectable = IsEndNode();
387 }
388
390 void RegisterListeners() override;
391
392 //
393 // Begin own functions
394 //
395
397 void OnDialogueNodePropertyChanged(const FPropertyChangedEvent& PropertyChangedEvent, int32 EdgeIndexChanged);
398
400 void ResetDialogueNodeOwner();
401
402private:
404 const FDiffNodeEdgeLinkedToPinResult FindDifferenceBetweenNodeEdgesAndLinkedToPins() const;
405
407 bool DoesEdgeMatchEdgeIndex(const FDlgEdge& Edge, int32 EdgeIndex, FString& OutMessage) const;
408
409protected:
411 UPROPERTY(EditAnywhere, Instanced, Category = DialogueGraphNode, Meta = (ShowOnlyInnerProperties))
412 UDlgNode* DialogueNode;
413
415 UPROPERTY(VisibleAnywhere, Category = DialogueGraphNode)
416 int32 NodeIndex = INDEX_NONE;
417
418 // Indicates the distance from the start node. This is only set after the graph is compiled.
419 UPROPERTY()
420 int32 NodeDepth = INDEX_NONE;
421
425 bool bForceHideNode = false;
426};
static constexpr int32 INDEX_PIN_Output
virtual FIntPoint GetPosition() const
UEdGraphPin * GetOutputPin() const
static constexpr int32 INDEX_PIN_Input
void CheckDialogueNodeIndexMatchesNode() const
virtual void CreateInputPin()
int32 EstimateNodeWidth() const
bool HasParentEdgeNode(const UDialogueGraphNode_Edge *ParentEdgeToFind) const
bool DoesEdgeMatchEdgeIndex(const FDlgEdge &Edge, int32 EdgeIndex, FString &OutMessage) const
void PinConnectionListChanged(UEdGraphPin *Pin) override
bool CanUserDeleteNode() const override
UDlgNode * GetMutableDialogueNode() const
void SetDialogueNodeDataChecked(int32 InIndex, UDlgNode *InNode)
bool HasEnterEvents() const
virtual int32 GetDialogueNodeIndex() const
void SetNodeDepth(int32 NewNodeDepth)
bool CanHaveOutputConnections() const override
bool IsSelectorNode() const
void CheckDialogueNodeSyncWithGraphNode(bool bStrictCheck=false) const
void AutowireNewNode(UEdGraphPin *FromPin) override
virtual void SetDialogueNode(UDlgNode *InNode)
void SetForceHideNode(bool bHide)
int32 GetChildEdgeIndexForChildNodeIndex(int32 ChildNodeIndex) const
int32 GetNodeDepth() const
virtual void CreateOutputPin()
void NodeConnectionListChanged() override
static FName GetMemberNameDialogueNode()
void SetEdgeTextAt(int32 EdgeIndex, const FText &NewText)
TArray< UDialogueGraphNode * > GetChildNodes() const
bool CanDuplicateNode() const override
bool HasVoicePropertiesSet() const
bool ShouldDrawNode() const
bool IsSelectorFirstNode() const
void OnDialogueNodePropertyChanged(const FPropertyChangedEvent &PropertyChangedEvent, int32 EdgeIndexChanged)
int32 NodeDepth
UPROPERTY()
bool HasChildEdgeNode(const UDialogueGraphNode_Edge *ChildEdgeToFind) const
DlgNodeType * GetMutableDialogueNode()
TArray< UDialogueGraphNode * > GetParentNodes() const
bool CanHaveInputConnections() const override
FIntPoint GetDefaultEdgePosition() const
static FName GetMemberNameNodeIndex()
virtual void SetDialogueNodeIndex(int32 InIndex)
FLinearColor GetNodeBackgroundColor() const override
int32 NodeIndex
UPROPERTY(VisibleAnywhere, Category = DialogueGraphNode)
bool HasOutputConnectionToNode(const UEdGraphNode *TargetNode) const override
bool IsVirtualParentNode() const
bool IsDialogueNodeSet() const
const DlgNodeType & GetDialogueNode() const
void CheckAll() const override
void PostEditChangeProperty(FPropertyChangedEvent &PropertyChangedEvent) override
void RegisterListeners() override
void PostCopyNode() override
virtual bool IsRootNode() const
TArray< UDialogueGraphNode_Edge * > GetChildEdgeNodes(bool bCheckParent=true) const
void PostEditImport() override
bool IsSelectorRandomNode() const
TArray< UDialogueGraphNode_Edge * > GetParentEdgeNodes(bool bCheckChild=true) const
void PostLoad() override
FText GetNodeTitle(ENodeTitleType::Type TitleType) const override
void GetContextMenuActions(const FGraphNodeContextMenuBuilder &Context) const override
void PostEditChangeChainProperty(struct FPropertyChangedChainEvent &PropertyChangedEvent) override
const FDiffNodeEdgeLinkedToPinResult FindDifferenceBetweenNodeEdgesAndLinkedToPins() const
bool GetForceHideNode() const
UDlgNode * DialogueNode
UPROPERTY(EditAnywhere, Instanced, Category = DialogueGraphNode, Meta = (ShowOnlyInnerProperties))
bool IsSpeechSequenceNode() const
bool Modify(bool bAlwaysMarkDirty=true) override
FString GetDocumentationExcerptName() const override
const UDlgNode & GetDialogueNode() const
void PrepareForCopying() override
FText GetTooltipText() const override
bool HasEnterConditions() const
void SetEdgeTargetIndexAt(int32 EdgeIndex, int32 NewTargetIndex)
void SetEdges(const TArray< FDlgEdge > &InEdges)
static const FName PIN_CATEGORY_Output
static const FName PIN_CATEGORY_Input
UCLASS(BlueprintType, ClassGroup = "Dialogue")
Definition DlgNode_End.h:21
UCLASS(BlueprintType, ClassGroup = "Dialogue")
EDlgNodeSelectorType GetSelectorType() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
UCLASS(BlueprintType, ClassGroup = "Dialogue")
virtual bool IsVirtualParent() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
UCLASS(BlueprintType, ClassGroup = "Dialogue")
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
virtual bool HasAnyEnterEvents() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:164
virtual bool HasAnyEnterConditions() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:139
USTRUCT(BlueprintType)
Definition DlgEdge.h:25