A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgManager.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3#include "Kismet/BlueprintFunctionLibrary.h"
4
5#include "DlgDialogue.h"
7#include "DlgMemory.h"
8
9#include "DlgManager.generated.h"
10
11class AActor;
12class UDlgContext;
13class UDlgDialogue;
14
15
16USTRUCT(BlueprintType)
17struct DLGSYSTEM_API FDlgObjectsArray
18{
19 GENERATED_USTRUCT_BODY()
21public:
22 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
23 TArray<UObject*> Array;
24};
25
29UCLASS()
30class DLGSYSTEM_API UDlgManager : public UBlueprintFunctionLibrary
31{
32 GENERATED_BODY()
33
34public:
35
47 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch", meta = (WorldContext = "WorldContextObject"))
48 static UDlgContext* StartDialogueWithDefaultParticipants(UObject* WorldContextObject, UDlgDialogue* Dialogue);
49
50 // Supplies where we called this from
51 static UDlgContext* StartDialogueWithContext(const FString& ContextString, UDlgDialogue* Dialogue, const TArray<UObject*>& Participants);
52
62 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
63 static UDlgContext* StartDialogue(UDlgDialogue* Dialogue, UPARAM(ref)const TArray<UObject*>& Participants)
64 {
65 return StartDialogueWithContext(TEXT("StartDialogue"), Dialogue, Participants);
66 }
67
73 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
74 static bool CanStartDialogue(UDlgDialogue* Dialogue, UPARAM(ref)const TArray<UObject*>& Participants);
75
96 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
97 static UDlgContext* ResumeDialogueFromNodeIndex(
99 UPARAM(ref)const TArray<UObject*>& Participants,
100 UPARAM(DisplayName="Start Node Index") int32 StartIndex,
101 const TSet<int32>& AlreadyVisitedNodes,
102 bool bFireEnterEvents
103 );
104
123 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
124 static UDlgContext* ResumeDialogueFromNodeGUID(
126 UPARAM(ref)const TArray<UObject*>& Participants,
127 const FGuid& StartNodeGUID,
128 const TSet<FGuid>& AlreadyVisitedNodes,
129 bool bFireEnterEvents
130 );
131
132
133 //
134 // Helper methods, same as StartDialogue but with fixed amount of participant(s)
135 //
136
137 // Helper methods that allows you to start a Dialogue with only a participant
138 // For N Participants just use StartDialogue
139 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
140 static UDlgContext* StartMonologue(UDlgDialogue* Dialogue, UObject* Participant);
141
142 // Helper methods that allows you to start a Dialogue with 2 participants
143 // For N Participants just use StartDialogue
144 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
145 static UDlgContext* StartDialogue2(UDlgDialogue* Dialogue, UObject* Participant0, UObject* Participant1);
146
147 // Helper methods that allows you to start a Dialogue with 3 participants
148 // For N Participants just use StartDialogue
149 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
150 static UDlgContext* StartDialogue3(UDlgDialogue* Dialogue, UObject* Participant0, UObject* Participant1, UObject* Participant2);
151
152 // Helper methods that allows you to start a Dialogue with 4 participants
153 // For N Participants just use StartDialogue
154 UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
155 static UDlgContext* StartDialogue4(UDlgDialogue* Dialogue, UObject* Participant0, UObject* Participant1, UObject* Participant2, UObject* Participant3);
156
161 static int32 LoadAllDialoguesIntoMemory(bool bAsync = false);
162
163 // Gets all loaded dialogues from memory. LoadAllDialoguesIntoMemory must be called before this
164 static TArray<UDlgDialogue*> GetAllDialoguesFromMemory();
165
166 // Gets all the objects from the provided World that implement the Dialogue Participant Interface. Iterates through all objects, DO NOT CALL EACH FRAME
167 static TArray<TWeakObjectPtr<AActor>> GetAllWeakActorsWithDialogueParticipantInterface(UWorld* World);
168
169 // Gets all objects from the World that implement the Dialogue Participant Interface
170 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper", meta = (WorldContext = "WorldContextObject"))
171 static TArray<UObject*> GetAllObjectsWithDialogueParticipantInterface(UObject* WorldContextObject);
172
173 // Same as GetAllObjectsWithDialogueParticipantInterface but groups the Objects into a Map
174 // Where the Key is the Participant Name
175 // and the Value is the Participants Array
176 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper", meta = (WorldContext = "WorldContextObject"))
177 static TMap<FName, FDlgObjectsArray> GetAllObjectsMapWithDialogueParticipantInterface(UObject* WorldContextObject);
178
179 // Gets all the dialogues that have a duplicate GUID, should not happen, like ever.
180 static TArray<UDlgDialogue*> GetDialoguesWithDuplicateGUIDs();
181
182 // Helper methods that gets all the dialogues in a map by guid.
183 static TMap<FGuid, UDlgDialogue*> GetAllDialoguesGUIDsMap();
184
185 // Gets all the loaded dialogues from memory that have the ParticipantName included inside them.
186 static TArray<UDlgDialogue*> GetAllDialoguesForParticipantName(FName ParticipantName);
187
188 // Sets the FDlgMemory Dialogue history.
189 UFUNCTION(BlueprintCallable, Category = "Dialogue|Memory")
190 static void SetDialogueHistory(const TMap<FGuid, FDlgHistory>& DlgHistory);
191
192 // Empties the FDlgMemory Dialogue history.
193 UFUNCTION(BlueprintCallable, Category = "Dialogue|Memory")
194 static void ClearDialogueHistory();
195
196 // Gets the Dialogue History from the FDlgMemory.
197 UFUNCTION(BlueprintPure, Category = "Dialogue|Memory")
198 static const TMap<FGuid, FDlgHistory>& GetDialogueHistory();
199
200 // Does the Object implement the Dialogue Participant Interface?
201 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper")
202 static bool DoesObjectImplementDialogueParticipantInterface(const UObject* Object);
203
204 // Is Object a UDlgEventCustom or a child from that
205 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper", DisplayName = "Is Object A Custom Event")
206 static bool IsObjectACustomEvent(const UObject* Object);
207
208 // Is Object a UDlgConditionCustom or a child from that
209 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper", DisplayName = "Is Object A Custom Condition")
210 static bool IsObjectACustomCondition(const UObject* Object);
211
212 // Is Object a UDlgTextArgumentCustom or a child from that
213 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper", DisplayName = "Is Object A Custom Text Argument")
214 static bool IsObjectACustomTextArgument(const UObject* Object);
215
216 // Is Object a UDlgNodeData or a child from that
217 UFUNCTION(BlueprintPure, Category = "Dialogue|Helper", DisplayName = "Is Object A Node Data")
218 static bool IsObjectANodeData(const UObject* Object);
219
220 // Gets all the unique participant names sorted alphabetically from all the Dialogues loaded into memory.
221 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
222 static void GetAllDialoguesParticipantNames(TArray<FName>& OutArray);
223
224 // Gets all the used speaker states sorted alphabetically from all the Dialogues loaded into memory.
225 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
226 static void GetAllDialoguesSpeakerStates(TArray<FName>& OutArray);
227
228 // Gets all the unique int variable names sorted alphabetically for the specified ParticipantName from the loaded Dialogues
229 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
230 static void GetAllDialoguesIntNames(FName ParticipantName, TArray<FName>& OutArray);
231
232 // Gets all the unique float variable names sorted alphabetically for the specified ParticipantName from the loaded Dialogues
233 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
234 static void GetAllDialoguesFloatNames(FName ParticipantName, TArray<FName>& OutArray);
235
236 // Gets all the unique bool variable names sorted alphabetically for the specified ParticipantName from the loaded Dialogues
237 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
238 static void GetAllDialoguesBoolNames(FName ParticipantName, TArray<FName>& OutArray);
239
240 // Gets all the unique name variable names sorted alphabetically for the specified ParticipantName from the loaded Dialogues
241 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
242 static void GetAllDialoguesNameNames(FName ParticipantName, TArray<FName>& OutArray);
243
244 // Gets all the unique condition names sorted alphabetically for the specified ParticipantName from the loaded Dialogues
245 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
246 static void GetAllDialoguesConditionNames(FName ParticipantName, TArray<FName>& OutArray);
247
248 // Gets all the unique event names sorted alphabetically for the specified ParticipantName from the loaded Dialogues
249 UFUNCTION(BlueprintPure, Category = "Dialogue|Data")
250 static void GetAllDialoguesEventNames(FName ParticipantName, TArray<FName>& OutArray);
251
252 // Registers all the DlgSystem Module console commands.
253 // To set the custom reference WorldContextObjectPtr, set it with SetDialoguePersistentWorldContextObject
254 // @return true on success, false otherwise
255 UFUNCTION(BlueprintCallable, Category = "Dialogue|Console")
256 static bool RegisterDialogueConsoleCommands();
257
258 // Unregister all the DlgSystem Module console commands.
259 // @return true on success, false otherwise
260 UFUNCTION(BlueprintCallable, Category = "Dialogue|Console")
261 static bool UnregisterDialogueConsoleCommands();
262
263
264 // This tries to get the source world for the dialogues
265 // In the following order (the first one that is valid, returns that):
266 // 1. The user set one UserWorldContextObjectPtr (if it is set):
267 // - Set with SetDialoguePersistentWorldContextObject
268 // - Clear with ClearDialoguePersistentWorldContextObject
269 // 2. The first PIE world
270 // 3. The first Game World
271 UFUNCTION(BlueprintCallable, Category = "Dialogue|Persistence")
272 static UWorld* GetDialogueWorld();
273
274 // If the user wants to set the world context object manually
275 // Otherwise just use GetDialogueWorld
276 UFUNCTION(BlueprintCallable, Category = "Dialogue|Persistence")
277 static void SetDialoguePersistentWorldContextObject(const UObject* WorldContextObject)
278 {
279 UserWorldContextObjectPtr = WorldContextObject;
280 }
281
282 UFUNCTION(BlueprintCallable, Category = "Dialogue|Persistence")
283 static void ClearDialoguePersistentWorldContextObject()
284 {
285 UserWorldContextObjectPtr.Reset();
286 }
287
288private:
289 static void GatherParticipantsRecursive(UObject* Object, TArray<UObject*>& Array, TSet<UObject*>& AlreadyVisited);
290
291 // Set by the user, we will default to automagically resolve the world
292 static TWeakObjectPtr<const UObject> UserWorldContextObjectPtr;
293
294 static bool bCalledLoadAllDialoguesIntoMemory;
295};
UCLASS(BlueprintType)
Definition DlgContext.h:96
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
UCLASS()
Definition DlgManager.h:40
static UDlgContext * StartDialogue(UDlgDialogue *Dialogue, UPARAM(ref) const TArray< UObject * > &Participants)
UFUNCTION(BlueprintCallable, Category = "Dialogue|Launch")
Definition DlgManager.h:78
static TWeakObjectPtr< const UObject > UserWorldContextObjectPtr
Definition DlgManager.h:397
static void ClearDialoguePersistentWorldContextObject()
UFUNCTION(BlueprintCallable, Category = "Dialogue|Persistence")
Definition DlgManager.h:388
static bool bCalledLoadAllDialoguesIntoMemory
Definition DlgManager.h:399
static void SetDialoguePersistentWorldContextObject(const UObject *WorldContextObject)
UFUNCTION(BlueprintCallable, Category = "Dialogue|Persistence")
Definition DlgManager.h:379
USTRUCT(BlueprintType)
Definition DlgManager.h:21
TArray< UObject * > Array
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
Definition DlgManager.h:30