A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgEdge.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
6#include "DlgCondition.h"
7#include "DlgEvent.h"
8#include "DlgTextArgument.h"
9
10#include "DlgEdge.generated.h"
11
13class UDlgContext;
14class UDlgNode;
15class UDlgDialogue;
16
20USTRUCT(BlueprintType)
21struct DLGSYSTEM_API FDlgEdge
22{
23 GENERATED_USTRUCT_BODY()
25public:
26 // Creates a simple edge without text, without conditions
27 FDlgEdge(int32 InTargetIndex = INDEX_NONE) : TargetIndex(InTargetIndex) {}
28
29 //
30 // ICppStructOps Interface
31 //
32
33 bool operator==(const FDlgEdge& Other) const
34 {
35 return TargetIndex == Other.TargetIndex &&
36 SpeakerState == Other.SpeakerState &&
37 Text.EqualTo(Other.Text) &&
38 bIncludeInAllOptionListIfUnsatisfied == Other.bIncludeInAllOptionListIfUnsatisfied &&
39 TextArguments == Other.TextArguments &&
40 Conditions == Other.Conditions;
41 }
42
43 bool operator!=(const FDlgEdge& Other) const
44 {
45 return !(*this == Other);
46 }
47
48 //
49 // Own methods
50 //
51
52 // Is the Text property visible on this edge, the edges comes from the ParentNode
53 static bool IsTextVisible(const UDlgNode& ParentNode);
54
55 // Updates the text value of the Edge Text from the default value and text remapping (if any)
56 void UpdateTextValueFromDefaultAndRemapping(
57 const UDlgDialogue& ParentDialogue, const UDlgNode& ParentNode, const UDlgSystemSettings& Settings, bool bUpdateFromRemapping
58 );
59
60 // Updates the namespace or keys depending on the settings
61 void UpdateTextsNamespacesAndKeys(const UObject* ParentObject, const UDlgSystemSettings& Settings);
62
63 // Rebuilds TextArguments
64 void RebuildTextArguments() { FDlgTextArgument::UpdateTextArgumentArray(Text, TextArguments); }
65 void RebuildTextArgumentsFromPreview(const FText& Preview) { FDlgTextArgument::UpdateTextArgumentArray(Preview, TextArguments); }
66
67 // Returns with true if every condition attached to the edge and every enter condition of the target node are satisfied //
68 bool Evaluate(const UDlgContext& Context, TSet<const UDlgNode*> AlreadyVisitedNodes) const;
69
70 // Constructs the ConstructedText.
71 void RebuildConstructedText(const UDlgContext& Context, FName FallbackParticipantName);
72
73 const TArray<FDlgTextArgument>& GetTextArguments() const { return TextArguments; }
74
75 // Sets the text and rebuilds the formatted constructed text
76 void SetText(const FText& NewText)
77 {
78 SetUnformattedText(NewText);
79 RebuildTextArguments();
80 }
81
82 // Sets the unformatted text, this is the text that includes the {identifier}
83 // NOTE: this is not call RebuildTextArguments(), use SetText for that
84 void SetUnformattedText(const FText& NewText)
85 {
86 Text = NewText;
87 }
88
90 const FText& GetText() const
91 {
92 if (TextArguments.Num() > 0 && !ConstructedText.IsEmpty())
93 {
94 return ConstructedText;
95 }
96 return Text;
97 }
98
99 // This always returns the unformatted text, if you want the formatted text use GetText()
100 const FText& GetUnformattedText() const { return Text; }
101 FText& GetMutableUnformattedText() { return Text; }
102
103 // Returns if the Edge is valid, has the TargetIndex non negative
104 bool IsValid() const { return TargetIndex > INDEX_NONE; }
105
106 static const FDlgEdge& GetInvalidEdge()
108 static FDlgEdge DlgEdge;
109 return DlgEdge;
110 }
111
112 // Helper functions to get the names of some properties. Used by the DlgSystemEditor module.
113 static FName GetMemberNameText() { return GET_MEMBER_NAME_CHECKED(FDlgEdge, Text); }
114 static FName GetMemberNameTextArguments() { return GET_MEMBER_NAME_CHECKED(FDlgEdge, TextArguments); }
115
116public:
117 // Index of the node in the Nodes TArray of the dialogue this edge is leading to
118 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge", Meta = (ClampMin = -1))
119 int32 TargetIndex = INDEX_NONE;
120
121 // Required but not sufficient conditions - target node's enter conditions are checked too
122 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge")
123 TArray<FDlgCondition> Conditions;
124
125 // Player emotion/state attached to this player choice
126 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge")
127 FName SpeakerState;
128
129 // Set this to false in order to skip this edge in the AllChildren array (which lists both satisfied and not satisfied player choices
130 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge")
131 bool bIncludeInAllOptionListIfUnsatisfied = true;
132
133protected:
134 // Some Variables are here to stop misuse
135
136 // Text associated with the child, can be used for user choices
137 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Dialogue|Edge", Meta = (MultiLine = true))
138 FText Text;
139
140 // If you want replaceable portions inside your Text nodes just add {identifier} inside it and set the value it should have at runtime.
141 UPROPERTY(EditAnywhere, BlueprintReadOnly, EditFixedSize, Category = "Dialogue|Edge")
142 TArray<FDlgTextArgument> TextArguments;
143
144 // Constructed at runtime from the original text and the arguments if there is any.
145 FText ConstructedText;
146};
147
148template<>
149struct TStructOpsTypeTraits<FDlgEdge> : public TStructOpsTypeTraitsBase2<FDlgEdge>
151 enum
152 {
153 WithIdenticalViaEquality = true
154 };
155};
UCLASS(BlueprintType)
Definition DlgContext.h:96
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))
USTRUCT(Blueprintable)
USTRUCT(BlueprintType)
Definition DlgEdge.h:25
void RebuildTextArgumentsFromPreview(const FText &Preview)
Definition DlgEdge.h:68
void RebuildTextArguments()
Definition DlgEdge.h:67
FText Text
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Dialogue|Edge", Meta = (MultiLine = true))
Definition DlgEdge.h:161
static const FDlgEdge & GetInvalidEdge()
Definition DlgEdge.h:109
TArray< FDlgCondition > Conditions
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge")
Definition DlgEdge.h:134
int32 TargetIndex
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge", Meta = (ClampMin = -1))
Definition DlgEdge.h:126
void SetText(const FText &NewText)
Definition DlgEdge.h:79
FDlgEdge(int32 InTargetIndex=INDEX_NONE)
Definition DlgEdge.h:30
static FName GetMemberNameTextArguments()
Definition DlgEdge.h:117
FText & GetMutableUnformattedText()
Definition DlgEdge.h:104
FText ConstructedText
Definition DlgEdge.h:173
const FText & GetText() const
Definition DlgEdge.h:93
GENERATED_USTRUCT_BODY()
void SetUnformattedText(const FText &NewText)
Definition DlgEdge.h:87
const FText & GetUnformattedText() const
Definition DlgEdge.h:103
FName SpeakerState
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Edge")
Definition DlgEdge.h:142
TArray< FDlgTextArgument > TextArguments
UPROPERTY(EditAnywhere, BlueprintReadOnly, EditFixedSize, Category = "Dialogue|Edge")
Definition DlgEdge.h:170
const TArray< FDlgTextArgument > & GetTextArguments() const
Definition DlgEdge.h:76
static FName GetMemberNameText()
Definition DlgEdge.h:116
bool operator==(const FDlgEdge &Other) const
Definition DlgEdge.h:36
bool operator!=(const FDlgEdge &Other) const
Definition DlgEdge.h:46
bool IsValid() const
Definition DlgEdge.h:107
USTRUCT(BlueprintType)
static void UpdateTextArgumentArray(const FText &Text, TArray< FDlgTextArgument > &InOutArgumentArray)