A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgNode_Speech.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3
4#include "Nodes/DlgNode.h"
5#include "DlgTextArgument.h"
6#include "DlgNode_Speech.generated.h"
7
8class USoundWave;
9class UDialogueWave;
10struct FDlgTextArgument;
11
15UCLASS(BlueprintType, ClassGroup = "Dialogue")
16class DLGSYSTEM_API UDlgNode_Speech : public UDlgNode
17{
18 GENERATED_BODY()
20public:
21 // Begin UObject Interface.
22 FString GetDesc() override
23 {
24 if (bIsVirtualParent)
25 {
26 return TEXT("Virtual Parent Node. Acts like a fake parent (proxy) to other child nodes. (aka makes it get the grandchildren)\nOn revaluate children, it does not get the direct children but the children of the first satisfied direct child node (grandchildren).\nIt should have at least one satisified child otherwise the Dialogue is terminated.");
27 }
28
29 return TEXT("Normal dialogue node - someone says something.");
30 }
31
32#if WITH_EDITOR
38 void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
39#endif
40
41 //
42 // Begin UDlgNode Interface.
43 //
44
45 bool HandleNodeEnter(UDlgContext& Context, TSet<const UDlgNode*> NodesEnteredWithThisStep) override;
46 bool ReevaluateChildren(UDlgContext& Context, TSet<const UDlgNode*> AlreadyEvaluated) override;
47 void GetAssociatedParticipants(TArray<FName>& OutArray) const override;
48
49 void UpdateTextsValuesFromDefaultsAndRemappings(const UDlgSystemSettings& Settings, bool bEdges, bool bUpdateGraphNode = true) override;
50 void UpdateTextsNamespacesAndKeys(const UDlgSystemSettings& Settings, bool bEdges, bool bUpdateGraphNode = true) override;
51 void RebuildConstructedText(const UDlgContext& Context) override;
52 void RebuildTextArguments(bool bEdges, bool bUpdateGraphNode = true) override
53 {
54 Super::RebuildTextArguments(bEdges, bUpdateGraphNode);
56 }
57 void RebuildTextArgumentsFromPreview(const FText& Preview) override { FDlgTextArgument::UpdateTextArgumentArray(Preview, TextArguments); }
58 const TArray<FDlgTextArgument>& GetTextArguments() const override { return TextArguments; };
59
60 // Getters:
61 const FText& GetNodeText() const override
62 {
63 if (TextArguments.Num() > 0 && !ConstructedText.IsEmpty())
64 {
65 return ConstructedText;
66 }
67 return Text;
68 }
69 const FText& GetNodeUnformattedText() const override { return Text; }
70 UDlgNodeData* GetNodeData() const override { return NodeData; }
71
72 // stuff we have to keep for legacy reason (but would make more sense to remove them from the plugin as they could be created in NodeData):
73 FName GetSpeakerState() const override { return SpeakerState; }
74 USoundBase* GetNodeVoiceSoundBase() const override { return VoiceSoundWave; }
75 UDialogueWave* GetNodeVoiceDialogueWave() const override { return VoiceDialogueWave; }
76 UObject* GetNodeGenericData() const override { return GenericData; }
78 void AddAllSpeakerStatesIntoSet(TSet<FName>& OutStates) const override { OutStates.Add(SpeakerState); }
80#if WITH_EDITOR
81 FString GetNodeTypeString() const override { return bIsVirtualParent ? TEXT("Virtual Parent") : TEXT("Speech"); }
82#endif
83
84 //
85 // Begin own functions.
86 //
87
88 // Is this node a virtual parent?
89 UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
90 virtual bool IsVirtualParent() const { return bIsVirtualParent; }
91
92 // Sets the virtual parent status
93 virtual void SetIsVirtualParent(bool bValue) { bIsVirtualParent = bValue; }
94
95 // Sets the RawNodeText of the Node and rebuilds the constructed text
96 virtual void SetNodeText(const FText& InText)
97 {
98 Text = InText;
99 RebuildTextArguments(false);
100 }
101
102 void SetNodeData(UDlgNodeData* InNodeData) { NodeData = InNodeData; }
103 void SetSpeakerState(FName InSpeakerState) { SpeakerState = InSpeakerState; }
104 void SetVoiceSoundBase(USoundBase* InVoiceSoundBase) { VoiceSoundWave = InVoiceSoundBase; }
105 void SetVoiceDialogueWave(UDialogueWave* InVoiceDialogueWave) { VoiceDialogueWave = InVoiceDialogueWave; }
106 void SetGenericData(UObject* InGenericData) { GenericData = InGenericData; }
107
108 // Helper functions to get the names of some properties. Used by the DlgSystemEditor module.
109 static FName GetMemberNameText() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, Text); }
110 static FName GetMemberNameTextArguments() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, TextArguments); }
111 static FName GetMemberNameNodeData() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, NodeData); }
112 static FName GetMemberNameVoiceSoundWave() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, VoiceSoundWave); }
113 static FName GetMemberNameVoiceDialogueWave() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, VoiceDialogueWave); }
114 static FName GetMemberNameGenericData() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, GenericData); }
115 static FName GetMemberNameSpeakerState() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, SpeakerState); }
116 static FName GetMemberNameIsVirtualParent() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, bIsVirtualParent); }
117 static FName GetMemberNameVirtualParentFireDirectChildEnterEvents() { return GET_MEMBER_NAME_CHECKED(UDlgNode_Speech, bVirtualParentFireDirectChildEnterEvents); }
119protected:
120 // Make this Node act like a fake parent (proxy) to other child nodes (makes it get the granchildren).
121 // On reevaluate children, it does not get the direct children but the children of the first satisfied direct child node (grandchildren).
122 //
123 // NOTE: It should have at least one satisfied child otherwise the Dialogue is terminated.
124 // NOTE: The first satisfied direct child will be added to the visited history when this node is entered.
125 // NOTE: Most Common usage for this is to make loops.
126 UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
127 bool bIsVirtualParent = false;
128
129 // If true the first satisfied Direct Child of this Virtual Parent Node will fire its Enter Events after this node is entered (and fires its enter events).
130 UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
131 bool bVirtualParentFireDirectChildEnterEvents = true;
132
133 // Text that will appear when this node participant name speaks to someone else.
134 // If you want replaceable portions inside your Text nodes just add {identifier} inside it and set the value it should have at runtime.
135 UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (MultiLine = true))
136 FText Text;
137
138 // If you want replaceable portions inside your Text nodes just add {identifier} inside it and set the value it should have at runtime.
139 UPROPERTY(EditAnywhere, EditFixedSize, Category = "Dialogue|Node")
140 TArray<FDlgTextArgument> TextArguments;
141
142 // State of the speaker attached to this node. Passed to the GetParticipantIcon function.
143 UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
144 FName SpeakerState;
145
146 // User Defined Custom Node data you can customize yourself with your own data types
147 //
148 // Create a new Blueprint derived from DlgNodeData (or DlgNodeDataHideCategories)
149 UPROPERTY(EditAnywhere, Instanced, Category = "Dialogue|Node")
150 UDlgNodeData* NodeData = nullptr;
152 // Voice attached to this node. The Sound Wave variant.
153 // NOTE: You should probably use the NodeData
154 UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (DlgSaveOnlyReference))
155 USoundBase* VoiceSoundWave = nullptr;
156
157 // Voice attached to this node. The Dialogue Wave variant. Only the first wave from the dialogue context array should be used.
158 // NOTE: You should probably use the NodeData
159 UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (DlgSaveOnlyReference))
160 UDialogueWave* VoiceDialogueWave = nullptr;
161
162 // Any generic object you would like
163 // NOTE: You should probably use the NodeData
164 UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (DlgSaveOnlyReference))
165 UObject* GenericData = nullptr;
167 // Constructed at runtime from the original text and the arguments if there is any.
168 FText ConstructedText;
169
170 int32 VirtualParentFirstSatisfiedDirectChildIndex = INDEX_NONE;
171};
UCLASS(BlueprintType)
Definition DlgContext.h:96
UCLASS(BlueprintType, ClassGroup = "Dialogue")
static FName GetMemberNameIsVirtualParent()
TArray< FDlgTextArgument > TextArguments
UPROPERTY(EditAnywhere, EditFixedSize, Category = "Dialogue|Node")
static FName GetMemberNameVoiceDialogueWave()
FName SpeakerState
UPROPERTY(EditAnywhere, Category = "Dialogue|Node")
virtual bool IsVirtualParent() const
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
const FText & GetNodeText() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
void SetSpeakerState(FName InSpeakerState)
static FName GetMemberNameNodeData()
FName GetSpeakerState() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
FText Text
UPROPERTY(EditAnywhere, Category = "Dialogue|Node", Meta = (MultiLine = true))
void AddAllSpeakerStatesIntoSet(TSet< FName > &OutStates) const override
virtual void SetIsVirtualParent(bool bValue)
void SetVoiceDialogueWave(UDialogueWave *InVoiceDialogueWave)
void SetGenericData(UObject *InGenericData)
UObject * GetNodeGenericData() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
UDialogueWave * GetNodeVoiceDialogueWave() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
USoundBase * GetNodeVoiceSoundBase() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
void SetNodeData(UDlgNodeData *InNodeData)
static FName GetMemberNameVirtualParentFireDirectChildEnterEvents()
static FName GetMemberNameTextArguments()
void SetVoiceSoundBase(USoundBase *InVoiceSoundBase)
static FName GetMemberNameSpeakerState()
void RebuildTextArguments(bool bEdges, bool bUpdateGraphNode=true) override
static FName GetMemberNameText()
FString GetDesc() override
static FName GetMemberNameVoiceSoundWave()
const TArray< FDlgTextArgument > & GetTextArguments() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
UDlgNodeData * GetNodeData() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
void RebuildTextArgumentsFromPreview(const FText &Preview) override
virtual void SetNodeText(const FText &InText)
const FText & GetNodeUnformattedText() const override
UFUNCTION(BlueprintPure, Category = "Dialogue|Node")
static FName GetMemberNameGenericData()
UCLASS(Blueprintable, BlueprintType, Abstract, EditInlineNew)
Definition DlgNodeData.h:18
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
virtual bool HandleNodeEnter(UDlgContext &Context, TSet< const UDlgNode * > NodesEnteredWithThisStep)
Definition DlgNode.cpp:129
virtual void GetAssociatedParticipants(TArray< FName > &OutArray) const
Definition DlgNode.cpp:347
virtual void RebuildTextArguments(bool bEdges, bool bUpdateGraphNode=true)
Definition DlgNode.cpp:324
virtual void RebuildConstructedText(const UDlgContext &Context)
Definition DlgNode.h:247
virtual void UpdateTextsNamespacesAndKeys(const UDlgSystemSettings &Settings, bool bEdges, bool bUpdateGraphNode=true)
Definition DlgNode.cpp:307
virtual void UpdateTextsValuesFromDefaultsAndRemappings(const UDlgSystemSettings &Settings, bool bEdges, bool bUpdateGraphNode=true)
Definition DlgNode.cpp:271
virtual bool ReevaluateChildren(UDlgContext &Context, TSet< const UDlgNode * > AlreadyEvaluated)
Definition DlgNode.cpp:157
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
USTRUCT(BlueprintType)
static void UpdateTextArgumentArray(const FText &Text, TArray< FDlgTextArgument > &InOutArgumentArray)