A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgNode_SpeechSequence.cpp
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
3#include "DlgContext.h"
5
6
7#if WITH_EDITOR
8void UDlgNode_SpeechSequence::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
9{
10 Super::PostEditChangeProperty(PropertyChangedEvent);
11
12 // fill edges automatically based on input data
14}
15#endif
16
17void UDlgNode_SpeechSequence::UpdateTextsValuesFromDefaultsAndRemappings(const UDlgSystemSettings& Settings, bool bEdges, bool bUpdateGraphNode)
18{
20 {
21 // We only care about edges here
22 if (Settings.bSetDefaultEdgeTexts)
23 {
24 // Inner edges always point to a normal node and are always the unique edge child
25 if (Entry.EdgeText.IsEmpty())
26 {
27 Entry.EdgeText = Settings.DefaultTextEdgeToNormalNode;
28 }
29 }
30
33 }
34 Super::UpdateTextsValuesFromDefaultsAndRemappings(Settings, bEdges, bUpdateGraphNode);
35}
36
37void UDlgNode_SpeechSequence::UpdateTextsNamespacesAndKeys(const UDlgSystemSettings& Settings, bool bEdges, bool bUpdateGraphNode)
38{
39 UObject* Outer = GetOuter();
40 if (!IsValid(Outer))
41 {
42 return;
43 }
44
46 {
47 FDlgLocalizationHelper::UpdateTextNamespaceAndKey(Outer, Settings, Entry.Text);
48 FDlgLocalizationHelper::UpdateTextNamespaceAndKey(Outer, Settings, Entry.EdgeText);
49 }
50
51 Super::UpdateTextsNamespacesAndKeys(Settings, bEdges, bUpdateGraphNode);
52}
53
54bool UDlgNode_SpeechSequence::HandleNodeEnter(UDlgContext& Context, TSet<const UDlgNode*> NodesEnteredWithThisStep)
55{
56 ActualIndex = 0;
57 return Super::HandleNodeEnter(Context, NodesEnteredWithThisStep);
58}
59
60bool UDlgNode_SpeechSequence::ReevaluateChildren(UDlgContext& Context, TSet<const UDlgNode*> AlreadyEvaluated)
61{
62 TArray<FDlgEdge>& Options = Context.GetMutableOptionsArray();
63 TArray<FDlgEdgeData>& AllOptions = Context.GetAllMutableOptionsArray();
64 Options.Empty();
65 AllOptions.Empty();
66
67 // If the last entry is active the real edges are used
68 if (ActualIndex == SpeechSequence.Num() - 1)
69 return Super::ReevaluateChildren(Context, AlreadyEvaluated);
70
71 // give the context the fake inner edge
72 if (InnerEdges.IsValidIndex(ActualIndex))
73 {
74 Options.Add(InnerEdges[ActualIndex]);
75 AllOptions.Add(FDlgEdgeData{ true, InnerEdges[ActualIndex] });
76 return true;
77 }
78
79 return false;
80}
81
83{
84 // Actual index is valid, and not the last node in the speech sequence, increment
85 if (ActualIndex >= 0 && ActualIndex < SpeechSequence.Num() - 1)
86 {
87 ActualIndex += 1;
88 return ReevaluateChildren(Context, {this});
89 }
90
91 // node finished -> generate true children
92 ActualIndex = 0;
93 Super::ReevaluateChildren(Context, { this });
94 return Super::OptionSelected(OptionIndex, Context);
95}
96
98{
99 // Is the new option index valid? set that for the actual index
100 if (SpeechSequence.IsValidIndex(OptionIndex))
101 {
102 ActualIndex = OptionIndex;
103 return ReevaluateChildren(Context, { this });
104 }
105
106 // node finished -> generate true children
107 ActualIndex = 0;
108 Super::ReevaluateChildren(Context, { this });
109 return Super::OptionSelected(OptionIndex, Context);
110}
111
113{
114 if (SpeechSequence.IsValidIndex(ActualIndex))
115 {
116 return SpeechSequence[ActualIndex].Text;
117 }
118
119 return FText::GetEmpty();
120}
121
123{
124 if (SpeechSequence.IsValidIndex(ActualIndex))
125 {
126 return SpeechSequence[ActualIndex].NodeData;
127 }
128
129 return nullptr;
130}
131
133{
134 if (SpeechSequence.IsValidIndex(ActualIndex))
135 {
136 return SpeechSequence[ActualIndex].VoiceSoundWave;
137 }
138
139 return nullptr;
140}
141
143{
144 if (SpeechSequence.IsValidIndex(ActualIndex))
145 {
146 return SpeechSequence[ActualIndex].VoiceDialogueWave;
147 }
148
149 return nullptr;
150}
151
153{
154 if (SpeechSequence.IsValidIndex(ActualIndex))
155 {
156 return SpeechSequence[ActualIndex].GenericData;
157 }
158
159 return nullptr;
160}
161
163{
164 if (SpeechSequence.IsValidIndex(ActualIndex))
165 {
166 return SpeechSequence[ActualIndex].SpeakerState;
167 }
168
169 return NAME_None;
170}
171
173{
174 for (const auto& SpeechEntry : SpeechSequence)
175 {
176 OutStates.Add(SpeechEntry.SpeakerState);
177 }
178}
179
181{
182 if (SpeechSequence.IsValidIndex(ActualIndex))
183 {
184 return SpeechSequence[ActualIndex].Speaker;
185 }
186
187 return OwnerName;
188}
189
190void UDlgNode_SpeechSequence::GetAssociatedParticipants(TArray<FName>& OutArray) const
191{
192 Super::GetAssociatedParticipants(OutArray);
193
194 for (const FDlgSpeechSequenceEntry& Entry : SpeechSequence)
195 {
196 if (Entry.Speaker != NAME_None)
197 {
198 OutArray.AddUnique(Entry.Speaker);
199 }
200 }
201}
202
204{
205 InnerEdges.Empty();
206 for (const FDlgSpeechSequenceEntry& Entry : SpeechSequence)
207 {
208 FDlgEdge Edge;
209 Edge.SetUnformattedText(Entry.EdgeText);
210 InnerEdges.Add(Edge);
211 }
212}
static void UpdateTextFromRemapping(const UDlgSystemSettings &Settings, FText &OutText)
static void UpdateTextNamespaceAndKey(const UObject *Object, const UDlgSystemSettings &Settings, FText &Text)
UCLASS(BlueprintType)
Definition DlgContext.h:96
TArray< FDlgEdge > & GetMutableOptionsArray()
Definition DlgContext.h:249
TArray< FDlgEdgeData > & GetAllMutableOptionsArray()
Definition DlgContext.h:304
void AddAllSpeakerStatesIntoSet(TSet< FName > &OutStates) const override
UDlgNodeData * GetNodeData() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
bool OptionSelectedFromReplicated(int32 OptionIndex, UDlgContext &Context)
void UpdateTextsValuesFromDefaultsAndRemappings(const UDlgSystemSettings &Settings, bool bEdges, bool bUpdateGraphNode=true) override
FName GetNodeParticipantName() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
void GetAssociatedParticipants(TArray< FName > &OutArray) const override
bool OptionSelected(int32 OptionIndex, UDlgContext &Context) override
void UpdateTextsNamespacesAndKeys(const UDlgSystemSettings &Settings, bool bEdges, bool bUpdateGraphNode=true) override
bool HandleNodeEnter(UDlgContext &Context, TSet< const UDlgNode * > NodesEnteredWithThisStep) override
const FText & GetNodeText() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
bool ReevaluateChildren(UDlgContext &Context, TSet< const UDlgNode * > AlreadyEvaluated) override
UDialogueWave * GetNodeVoiceDialogueWave() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
USoundBase * GetNodeVoiceSoundBase() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
UObject * GetNodeGenericData() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
FName GetSpeakerState() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
TArray< FDlgEdge > InnerEdges
UPROPERTY()
TArray< FDlgSpeechSequenceEntry > SpeechSequence
UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
UCLASS(Blueprintable, BlueprintType, Abstract, EditInlineNew)
Definition DlgNodeData.h:18
FName OwnerName
UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (DisplayName = "Participant Name"))
Definition DlgNode.h:359
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
bool bSetDefaultEdgeTexts
UPROPERTY(Category = "Default Texts", Config, EditAnywhere, DisplayName = "Set Default Edge Texts")
FText DefaultTextEdgeToNormalNode
UPROPERTY(Category = "Default Texts", Config, EditAnywhere, DisplayName = "Edge Text To Normal Node")
USTRUCT(BlueprintType)
Definition DlgContext.h:28
USTRUCT(BlueprintType)
Definition DlgEdge.h:25
void SetUnformattedText(const FText &NewText)
Definition DlgEdge.h:87
USTRUCT(BlueprintType)