A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgNode.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5#include "Misc/Build.h"
6#include "UObject/Object.h"
7
8#if WITH_EDITOR
9#include "EdGraph/EdGraphNode.h"
10#endif
11
12#include "DlgEdge.h"
13#include "DlgCondition.h"
14#include "DlgEvent.h"
15#include "DlgNodeData.h"
16#include "DlgNode.generated.h"
17
18
20class UDlgContext;
21class UDlgNode;
22class USoundBase;
23class USoundWave;
24class UDialogueWave;
25struct FDlgTextArgument;
26class UDlgDialogue;
27
33UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
34class DLGSYSTEM_API UDlgNode : public UObject
35{
37
38public:
39 //
40 // Begin UObject Interface.
41 //
42
43 void Serialize(FArchive& Ar) override;
44 FString GetDesc() override { return TEXT("INVALID DESCRIPTION"); }
45 void PostLoad() override;
46 void PostInitProperties() override;
47 void PostDuplicate(bool bDuplicateForPIE) override;
48 void PostEditImport() override;
50 static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
51
52#if WITH_EDITOR
58 void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
59
64 void PostEditChangeChainProperty(struct FPropertyChangedChainEvent& PropertyChangedEvent) override;
65
66 //
67 // Begin own function
68 //
69
70 // Used internally by the Dialogue editor:
71 virtual FString GetNodeTypeString() const { return TEXT("INVALID"); }
72#endif //WITH_EDITOR
73
74#if WITH_EDITOR
75 void SetGraphNode(UEdGraphNode* InNode) { GraphNode = InNode; }
76 void ClearGraphNode() { GraphNode = nullptr; }
77 UEdGraphNode* GetGraphNode() const { return GraphNode; }
78#endif
79
81 DECLARE_EVENT_TwoParams(UDlgNode, FDialogueNodePropertyChanged, const FPropertyChangedEvent& /* PropertyChangedEvent */, int32 /* EdgeIndexChanged */);
82 FDialogueNodePropertyChanged OnDialogueNodePropertyChanged;
83
84 virtual bool HandleNodeEnter(UDlgContext& Context, TSet<const UDlgNode*> NodesEnteredWithThisStep);
85 virtual bool ReevaluateChildren(UDlgContext& Context, TSet<const UDlgNode*> AlreadyEvaluated);
87 virtual bool CheckNodeEnterConditions(const UDlgContext& Context, TSet<const UDlgNode*> AlreadyVisitedNodes) const;
88 bool HasAnySatisfiedChild(const UDlgContext& Context, TSet<const UDlgNode*> AlreadyVisitedNodes) const;
89
90 virtual bool OptionSelected(int32 OptionIndex, UDlgContext& Context);
91
92 //
93 // Getters/Setters:
94 //
95
96 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
97 FGuid GetGUID() const { return NodeGUID; }
98
99 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
100 bool HasGUID() const { return NodeGUID.IsValid(); }
101
102 void RegenerateGUID()
103 {
104 NodeGUID = FGuid::NewGuid();
105 Modify();
106 }
107
108 //
109 // For the ParticipantName
110 //
112 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
113 virtual FName GetNodeParticipantName() const { return OwnerName; }
114
115 virtual void SetNodeParticipantName(FName InName) { OwnerName = InName; }
116
117 //
118 // For the EnterConditions
119 //
120
121 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
122 virtual bool HasAnyEnterConditions() const { return GetNodeEnterConditions().Num() > 0; }
123
124 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
125 virtual const TArray<FDlgCondition>& GetNodeEnterConditions() const { return EnterConditions; }
126
127 virtual void SetNodeEnterConditions(const TArray<FDlgCondition>& InEnterConditions) { EnterConditions = InEnterConditions; }
128
129 // Gets the mutable enter condition at location EnterConditionIndex.
130 virtual FDlgCondition* GetMutableEnterConditionAt(int32 EnterConditionIndex)
131 {
132 check(EnterConditions.IsValidIndex(EnterConditionIndex));
133 return &EnterConditions[EnterConditionIndex];
134 }
135
136 //
137 // For the EnterEvents
138 //
140 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
141 virtual bool HasAnyEnterEvents() const { return GetNodeEnterEvents().Num() > 0; }
142
143 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
144 virtual const TArray<FDlgEvent>& GetNodeEnterEvents() const { return EnterEvents; }
146 virtual void SetNodeEnterEvents(const TArray<FDlgEvent>& InEnterEvents) { EnterEvents = InEnterEvents; }
148 //
149 // For the Children
150 //
151
153
154 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
155 virtual const TArray<FDlgEdge>& GetNodeChildren() const { return Children; }
156 virtual void SetNodeChildren(const TArray<FDlgEdge>& InChildren) { Children = InChildren; }
157
158 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
159 virtual int32 GetNumNodeChildren() const { return Children.Num(); }
160
161 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
162 virtual const FDlgEdge& GetNodeChildAt(int32 EdgeIndex) const { return Children[EdgeIndex]; }
163
164 // Adds an Edge to the end of the Children Array.
165 virtual void AddNodeChild(const FDlgEdge& InChild) { Children.Add(InChild); }
166
167 // Removes the Edge at the specified EdgeIndex location.
168 virtual void RemoveChildAt(int32 EdgeIndex)
169 {
170 check(Children.IsValidIndex(EdgeIndex));
171 Children.RemoveAt(EdgeIndex);
173
174 // Removes all edges/children
175 virtual void RemoveAllChildren() { Children.Empty(); }
176
177 // Gets the mutable edge/child at location EdgeIndex.
178 virtual FDlgEdge* GetSafeMutableNodeChildAt(int32 EdgeIndex)
179 {
180 check(Children.IsValidIndex(EdgeIndex));
181 return &Children[EdgeIndex];
182 }
183
184 // Unsafe version, can be null
185 virtual FDlgEdge* GetMutableNodeChildAt(int32 EdgeIndex)
186 {
187 return Children.IsValidIndex(EdgeIndex) ? &Children[EdgeIndex] : nullptr;
188 }
189
190 // Gets the mutable Edge that corresponds to the provided TargetIndex or nullptr if nothing was found.
191 virtual FDlgEdge* GetMutableNodeChildForTargetIndex(int32 TargetIndex);
192
193 // Gets all the edges (children) indices that DO NOT have a valid TargetIndex (is negative).
194 const TArray<int32> GetNodeOpenChildren_DEPRECATED() const;
195
196 // Gathers associated participants, they are only added to the array if they are not yet there
197 virtual void GetAssociatedParticipants(TArray<FName>& OutArray) const;
198
199 // Updates the value of the texts from the default values or the remappings (if any)
200 virtual void UpdateTextsValuesFromDefaultsAndRemappings(
201 const UDlgSystemSettings& Settings, bool bEdges, bool bUpdateGraphNode = true
202 );
204 // Updates the namespace and key of all the texts depending on the settings
205 virtual void UpdateTextsNamespacesAndKeys(const UDlgSystemSettings& Settings, bool bEdges, bool bUpdateGraphNode = true);
206
207 // Rebuilds ConstructedText
208 virtual void RebuildTextArguments(bool bEdges, bool bUpdateGraphNode = true);
209 virtual void RebuildTextArgumentsFromPreview(const FText& Preview) {}
211 // Constructs the ConstructedText.
212 virtual void RebuildConstructedText(const UDlgContext& Context) {}
214 // Gets the text arguments for this Node (if any). Used for FText::Format
215 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
216 virtual const TArray<FDlgTextArgument>& GetTextArguments() const
217 {
218 static TArray<FDlgTextArgument> EmptyArray;
219 return EmptyArray;
220 };
221
222 // Gets the Text of this Node. This can be the final formatted string.
223 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
224 virtual const FText& GetNodeText() const { return FText::GetEmpty(); }
225
226 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
227 virtual bool GetCheckChildrenOnEvaluation() const { return bCheckChildrenOnEvaluation; }
228
233 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
234 virtual const FText& GetNodeUnformattedText() const { return GetNodeText(); }
235
236 // Gets the voice of this Node as a SoundWave.
237 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
238 USoundWave* GetNodeVoiceSoundWave() const;
239
240 // Gets the voice of this Node as a SoundWave.
241 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
242 virtual USoundBase* GetNodeVoiceSoundBase() const { return nullptr; }
243
244 // Gets the voice of this Node as a DialogueWave. Only the first Dialogue context in the wave should be used.
245 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
246 virtual UDialogueWave* GetNodeVoiceDialogueWave() const { return nullptr; }
248 // Gets the speaker state ordered to this node (can be used e.g. for icon selection)
249 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
250 virtual FName GetSpeakerState() const { return NAME_None; }
251 virtual void AddAllSpeakerStatesIntoSet(TSet<FName>& OutStates) const {};
252
253 // Gets the generic data asset of this Node.
254 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
255 virtual UObject* GetNodeGenericData() const { return nullptr; }
256
257 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
258 virtual UDlgNodeData* GetNodeData() const { return nullptr; }
259
260 // Helper method to get directly the Dialogue (which is our parent)
261 UDlgDialogue* GetDialogue() const;
262
263 // Helper functions to get the names of some properties. Used by the DlgSystemEditor module.
264 static FName GetMemberNameOwnerName() { return GET_MEMBER_NAME_CHECKED(UDlgNode, OwnerName); }
265 static FName GetMemberNameCheckChildrenOnEvaluation() { return GET_MEMBER_NAME_CHECKED(UDlgNode, bCheckChildrenOnEvaluation); }
266 static FName GetMemberNameEnterConditions() { return GET_MEMBER_NAME_CHECKED(UDlgNode, EnterConditions); }
267 static FName GetMemberNameEnterEvents() { return GET_MEMBER_NAME_CHECKED(UDlgNode, EnterEvents); }
268 static FName GetMemberNameChildren() { return GET_MEMBER_NAME_CHECKED(UDlgNode, Children); }
269 static FName GetMemberNameGUID() { return GET_MEMBER_NAME_CHECKED(UDlgNode, NodeGUID); }
270
271 // Syncs the GraphNode Edges with our edges
272 void UpdateGraphNode();
273
274 // Fires this Node enter Events
275 void FireNodeEnterEvents(UDlgContext& Context);
276
277protected:
278#if WITH_EDITORONLY_DATA
279 // Node's Graph representation, used to get position.
280 UPROPERTY(Meta = (DlgNoExport))
281 UEdGraphNode* GraphNode = nullptr;
282
283 // Used to build the change event and broadcast it
284 int32 BroadcastPropertyEdgeIndexChanged = INDEX_NONE;
285#endif // WITH_EDITORONLY_DATA
286
287 // Name of a participant (speaker) associated with this node.
288 UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (DisplayName = "Participant Name"))
289 FName OwnerName;
290
295 UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
296 bool bCheckChildrenOnEvaluation = false;
297
298 // Conditions necessary to enter this node
299 UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
300 TArray<FDlgCondition> EnterConditions;
301
302 // Events fired when the node is reached in the dialogue
303 UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
304 TArray<FDlgEvent> EnterEvents;
305
306 // The Unique identifier for each Node. This is much safer than a Node Index.
307 // Compile/Save Asset to generate this
308 UPROPERTY(VisibleAnywhere, Category = "Dialogue|Node", AdvancedDisplay)
309 FGuid NodeGUID;
310 // NOTE: For some reason if this is named GUID the details panel does not work all the time for this, wtf unreal?
311
312 // Edges that point to Children of this Node
313 UPROPERTY(VisibleAnywhere, EditFixedSize, AdvancedDisplay, Category = "Dialogue|Node")
314 TArray<FDlgEdge> Children;
315};
UCLASS(BlueprintType)
Definition DlgContext.h:96
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
bool HasGUID() const
UFUNCTION(BlueprintPure, Category = "Dialogue|GUID")
FGuid GetGUID() const
UFUNCTION(BlueprintPure, Category = "Dialogue|GUID")
void Serialize(FArchive &Ar) override
void PostDuplicate(bool bDuplicateForPIE) override
FString GetDesc() override
Definition DlgDialogue.h:94
void RegenerateGUID()
void PostInitProperties() override
void PostLoad() override
void PostEditImport() override
UCLASS(Blueprintable, BlueprintType, Abstract, EditInlineNew)
Definition DlgNodeData.h:18
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
virtual bool GetCheckChildrenOnEvaluation() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:271
virtual const FText & GetNodeText() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:265
virtual FDlgEdge * GetSafeMutableNodeChildAt(int32 EdgeIndex)
Definition DlgNode.h:213
static FName GetMemberNameCheckChildrenOnEvaluation()
Definition DlgNode.h:330
virtual USoundBase * GetNodeVoiceSoundBase() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:295
FName OwnerName
UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (DisplayName = "Participant Name"))
Definition DlgNode.h:359
FDialogueNodePropertyChanged OnDialogueNodePropertyChanged
Definition DlgNode.h:87
virtual bool HasAnyEnterEvents() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:164
static FName GetMemberNameOwnerName()
Definition DlgNode.h:329
virtual const TArray< FDlgTextArgument > & GetTextArguments() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:254
FGuid GetGUID() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:105
static FName GetMemberNameGUID()
Definition DlgNode.h:334
void RegenerateGUID()
Definition DlgNode.h:113
DECLARE_EVENT_TwoParams(UDlgNode, FDialogueNodePropertyChanged, const FPropertyChangedEvent &, int32)
virtual void AddAllSpeakerStatesIntoSet(TSet< FName > &OutStates) const
Definition DlgNode.h:310
virtual void RebuildConstructedText(const UDlgContext &Context)
Definition DlgNode.h:247
virtual const TArray< FDlgEdge > & GetNodeChildren() const
Gets this nodes children (edges) as a const/mutable array.
Definition DlgNode.h:184
virtual int32 GetNumNodeChildren() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:191
TArray< FDlgCondition > EnterConditions
UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
Definition DlgNode.h:376
virtual FName GetNodeParticipantName() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:127
FGuid NodeGUID
UPROPERTY(VisibleAnywhere, Category = "Dialogue|Node", AdvancedDisplay)
Definition DlgNode.h:392
virtual const TArray< FDlgEvent > & GetNodeEnterEvents() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:170
virtual UDlgNodeData * GetNodeData() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:323
virtual FDlgCondition * GetMutableEnterConditionAt(int32 EnterConditionIndex)
Definition DlgNode.h:150
GENERATED_BODY()
virtual void SetNodeParticipantName(FName InName)
Definition DlgNode.h:129
virtual void RebuildTextArgumentsFromPreview(const FText &Preview)
Definition DlgNode.h:244
virtual FDlgEdge * GetMutableNodeChildAt(int32 EdgeIndex)
Definition DlgNode.h:220
virtual const FDlgEdge & GetNodeChildAt(int32 EdgeIndex) const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:197
virtual FName GetSpeakerState() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:309
static FName GetMemberNameEnterConditions()
Definition DlgNode.h:331
virtual bool HasAnyEnterConditions() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:139
bool HasGUID() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:111
TArray< FDlgEvent > EnterEvents
UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
Definition DlgNode.h:383
virtual void RemoveChildAt(int32 EdgeIndex)
Definition DlgNode.h:203
virtual void SetNodeEnterConditions(const TArray< FDlgCondition > &InEnterConditions)
Definition DlgNode.h:147
TArray< FDlgEdge > Children
UPROPERTY(VisibleAnywhere, EditFixedSize, AdvancedDisplay, Category = "Dialogue|Node")
Definition DlgNode.h:402
virtual UObject * GetNodeGenericData() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:317
FString GetDesc() override
Definition DlgNode.h:49
virtual UDialogueWave * GetNodeVoiceDialogueWave() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:302
virtual void AddNodeChild(const FDlgEdge &InChild)
Definition DlgNode.h:200
virtual const FText & GetNodeUnformattedText() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:281
virtual void SetNodeEnterEvents(const TArray< FDlgEvent > &InEnterEvents)
Definition DlgNode.h:172
static FName GetMemberNameEnterEvents()
Definition DlgNode.h:332
virtual void SetNodeChildren(const TArray< FDlgEdge > &InChildren)
Definition DlgNode.h:185
static FName GetMemberNameChildren()
Definition DlgNode.h:333
virtual const TArray< FDlgCondition > & GetNodeEnterConditions() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
Definition DlgNode.h:145
virtual void RemoveAllChildren()
Definition DlgNode.h:210
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
USTRUCT(Blueprintable)
USTRUCT(BlueprintType)
Definition DlgEdge.h:25
USTRUCT(BlueprintType)
Definition DlgEvent.h:59
USTRUCT(BlueprintType)