A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueSearchManager.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 "Widgets/Docking/SDockTab.h"
6
8
9// The maximum amount of global Dialogue Search windows opened.
10static constexpr int32 MAX_GLOBAL_DIALOGUE_SEARCH_RESULTS = 4;
11
13class FAssetRegistryModule;
14
15class FWorkspaceItem;
18class UEdGraphNode_Comment;
19class IAssetRegistry;
20struct FAssetData;
21struct FDlgCondition;
22struct FDlgEvent;
23struct FDlgEdge;
24struct FDlgTextArgument;
25
27{
29 TWeakObjectPtr<UDlgDialogue> Dialogue;
30};
31
34{
35private:
37
38public:
39 static Self* Get();
40
43
49 const FDialogueSearchFilter& SearchFilter,
50 const FDlgTextArgument& InDlgTextArgument,
51 const TSharedPtr<FDialogueSearchResult>& OutParentNode,
52 int32 ArgumentIndex = INDEX_NONE
53 );
54
60 const FDialogueSearchFilter& SearchFilter,
61 const FDlgCondition& InDlgCondition,
62 const TSharedPtr<FDialogueSearchResult>& OutParentNode,
63 int32 ConditionIndex = INDEX_NONE,
64 FName ConditionMemberName = TEXT("Condition")
65 );
66
71 bool QueryDlgEvent(
72 const FDialogueSearchFilter& SearchFilter,
73 const FDlgEvent& InDlgEvent,
74 const TSharedPtr<FDialogueSearchResult>& OutParentNode,
75 int32 EventIndex = INDEX_NONE,
76 FName EventMemberName = TEXT("Event")
77 );
78
83 bool QueryDlgEdge(
84 const FDialogueSearchFilter& SearchFilter,
85 const FDlgEdge& InDlgEdge,
86 const TSharedPtr<FDialogueSearchResult>& OutParentNode
87 );
88
93 bool QueryGraphNode(
94 const FDialogueSearchFilter& SearchFilter,
95 const UDialogueGraphNode* InGraphNode,
96 const TSharedPtr<FDialogueSearchResult>& OutParentNode
97 );
98
103 bool QueryEdgeNode(
104 const FDialogueSearchFilter& SearchFilter,
105 const UDialogueGraphNode_Edge* InEdgeNode,
106 const TSharedPtr<FDialogueSearchResult>& OutParentNode
107 );
108
113 bool QueryCommentNode(
114 const FDialogueSearchFilter& SearchFilter,
115 const UEdGraphNode_Comment* InCommentNode,
116 const TSharedPtr<FDialogueSearchResult>& OutParentNode
117 );
118
124 const FDialogueSearchFilter& SearchFilter,
125 const UDlgDialogue* InDialogue,
126 TSharedPtr<FDialogueSearchResult>& OutParentNode
127 );
128
129 // Searches for InSearchString in all Dialogues. Adds the result as children of OutParentNode.
130 void QueryAllDialogues(const FDialogueSearchFilter& SearchFilter, TSharedPtr<FDialogueSearchResult>& OutParentNode);
131
132 // Determines the global find results tab label
134
135 // Close One of the global find results.
136 void CloseGlobalFindResults(const TSharedRef<SFindInDialogues>& FindResults);
137
138 // Find or create the global find results widget
139 TSharedPtr<SFindInDialogues> GetGlobalFindResults();
140
141 // Enables the global find results tab feature in the Windows Menu.
142 void EnableGlobalFindResults(TSharedPtr<FWorkspaceItem> ParentTabCategory = nullptr);
143
144 // Disables the global find results tab feature in the Windows Menu.
146
147 // Initializes the manager. Should only be called once in the FDlgSystemEditorModule::StartupModule()
148 void Initialize(TSharedPtr<FWorkspaceItem> ParentTabCategory = nullptr);
149
150 // Uninitializes the manager. Should only be called once in the FDlgSystemEditorModule::ShutdownModule()
151 void UnInitialize();
152
153private:
154 // Helper method to make a Text Node and add it as a child to ParentNode
155 TSharedPtr<FDialogueSearchResult> MakeChildTextNode(
156 const TSharedPtr<FDialogueSearchResult>& ParentNode,
157 const FText& DisplayName, const FText& Category,
158 const FString& CommentString
159 )
160 {
161 TSharedPtr<FDialogueSearchResult> TextNode = MakeShared<FDialogueSearchResult>(DisplayName, ParentNode);
162 TextNode->SetCategory(Category);
163 if (!CommentString.IsEmpty())
164 {
165 TextNode->SetCommentString(CommentString);
166 }
167 ParentNode->AddChild(TextNode);
168 return TextNode;
169 }
170
172 const TSharedPtr<FDialogueSearchResult>& ParentNode,
173 const FString& SearchString,
174 const FText& Text,
175 const FText& NamespaceCategory,
176 const FString& NamespaceCommentString,
177 const FText& KeyCategory,
178 const FString& KeyCommentString
179 )
180 {
181 static const FString DefaultValue = TEXT("");
182 bool bContainsSearchString = false;
183
184 const FString CurrentFullNamespace = FTextInspector::GetNamespace(Text).Get(DefaultValue);
185 const FString CurrentKey = FTextInspector::GetKey(Text).Get(DefaultValue);
186 if (CurrentFullNamespace.Contains(SearchString))
187 {
188 bContainsSearchString = true;
190 ParentNode,
191 FText::AsCultureInvariant(CurrentFullNamespace),
192 NamespaceCategory,
193 NamespaceCommentString
194 );
195 }
196 if (CurrentKey.Contains(SearchString))
197 {
198 bContainsSearchString = true;
200 ParentNode,
201 FText::AsCultureInvariant(CurrentKey),
202 KeyCategory,
203 KeyCommentString
204 );
205 }
206
207 return bContainsSearchString;
208 }
209
210 // Handler for a request to spawn a new global find results tab
211 TSharedRef<SDockTab> SpawnGlobalFindResultsTab(const FSpawnTabArgs& SpawnTabArgs, int32 TabIdx);
212
213 // Creates and opens a new global find results tab. The next one in the available list.
214 TSharedPtr<SFindInDialogues> OpenGlobalFindResultsTab();
215
216 // Builds the cache from all available Dialogues assets that the asset registry has discovered at the time of this function. Occurs on startup.
217 void BuildCache();
218
219 // Callback hook from the Asset Registry when an asset is added
220 void HandleOnAssetAdded(const FAssetData& InAssetData);
221
222 // Callback hook from the Asset Registry, marks the asset for deletion from the cache
223 void HandleOnAssetRemoved(const FAssetData& InAssetData);
224
225 // Callback hook from the Asset Registry, marks the asset for deletion from the cache
226 void HandleOnAssetRenamed(const FAssetData& InAssetData, const FString& InOldName);
227
228 // Callback hook from the Asset Registry when an asset is loaded
229 void HandleOnAssetLoaded(UObject* InAsset);
230
231 // Callback when the Asset Registry loads all its assets
233
234private:
235 static Self* Instance;
236
237 // Maps the Dialogue path => SearchData.
238 TMap<FName, FDialogueSearchData> SearchMap;
239
240 // Because we are unable to query for the module on another thread, cache it for use later
241 IAssetRegistry* AssetRegistry = nullptr;
242
243 // The tab identifier/instance name for global find results
245
246 // Array of open global find results widgets
247 TArray<TWeakPtr<SFindInDialogues>> GlobalFindResultsWidgets;
248
249 // Global Find Results workspace menu item
250 TSharedPtr<FWorkspaceItem> GlobalFindResultsMenuItem;
251
252 // Handlers
253 FDelegateHandle OnAssetAddedHandle;
254 FDelegateHandle OnAssetRemovedHandle;
255 FDelegateHandle OnAssetRenamedHandle;
256 FDelegateHandle OnFilesLoadedHandle;
257 FDelegateHandle OnAssetLoadedHandle;
258};
static constexpr int32 MAX_GLOBAL_DIALOGUE_SEARCH_RESULTS
bool QueryEdgeNode(const FDialogueSearchFilter &SearchFilter, const UDialogueGraphNode_Edge *InEdgeNode, const TSharedPtr< FDialogueSearchResult > &OutParentNode)
void HandleOnAssetAdded(const FAssetData &InAssetData)
bool SearchForTextLocalizationData(const TSharedPtr< FDialogueSearchResult > &ParentNode, const FString &SearchString, const FText &Text, const FText &NamespaceCategory, const FString &NamespaceCommentString, const FText &KeyCategory, const FString &KeyCommentString)
TMap< FName, FDialogueSearchData > SearchMap
TSharedPtr< FWorkspaceItem > GlobalFindResultsMenuItem
TSharedRef< SDockTab > SpawnGlobalFindResultsTab(const FSpawnTabArgs &SpawnTabArgs, int32 TabIdx)
TArray< TWeakPtr< SFindInDialogues > > GlobalFindResultsWidgets
TSharedPtr< SFindInDialogues > OpenGlobalFindResultsTab()
bool QueryDlgCondition(const FDialogueSearchFilter &SearchFilter, const FDlgCondition &InDlgCondition, const TSharedPtr< FDialogueSearchResult > &OutParentNode, int32 ConditionIndex=INDEX_NONE, FName ConditionMemberName=TEXT("Condition"))
bool QueryCommentNode(const FDialogueSearchFilter &SearchFilter, const UEdGraphNode_Comment *InCommentNode, const TSharedPtr< FDialogueSearchResult > &OutParentNode)
FText GetGlobalFindResultsTabLabel(int32 TabIdx)
void HandleOnAssetRemoved(const FAssetData &InAssetData)
bool QuerySingleDialogue(const FDialogueSearchFilter &SearchFilter, const UDlgDialogue *InDialogue, TSharedPtr< FDialogueSearchResult > &OutParentNode)
bool QueryGraphNode(const FDialogueSearchFilter &SearchFilter, const UDialogueGraphNode *InGraphNode, const TSharedPtr< FDialogueSearchResult > &OutParentNode)
FName GlobalFindResultsTabIDs[MAX_GLOBAL_DIALOGUE_SEARCH_RESULTS]
bool QueryDlgTextArgument(const FDialogueSearchFilter &SearchFilter, const FDlgTextArgument &InDlgTextArgument, const TSharedPtr< FDialogueSearchResult > &OutParentNode, int32 ArgumentIndex=INDEX_NONE)
void HandleOnAssetRenamed(const FAssetData &InAssetData, const FString &InOldName)
void QueryAllDialogues(const FDialogueSearchFilter &SearchFilter, TSharedPtr< FDialogueSearchResult > &OutParentNode)
bool QueryDlgEdge(const FDialogueSearchFilter &SearchFilter, const FDlgEdge &InDlgEdge, const TSharedPtr< FDialogueSearchResult > &OutParentNode)
void Initialize(TSharedPtr< FWorkspaceItem > ParentTabCategory=nullptr)
void HandleOnAssetLoaded(UObject *InAsset)
void EnableGlobalFindResults(TSharedPtr< FWorkspaceItem > ParentTabCategory=nullptr)
TSharedPtr< FDialogueSearchResult > MakeChildTextNode(const TSharedPtr< FDialogueSearchResult > &ParentNode, const FText &DisplayName, const FText &Category, const FString &CommentString)
bool QueryDlgEvent(const FDialogueSearchFilter &SearchFilter, const FDlgEvent &InDlgEvent, const TSharedPtr< FDialogueSearchResult > &OutParentNode, int32 EventIndex=INDEX_NONE, FName EventMemberName=TEXT("Event"))
FDialogueSearchManager Self
TSharedPtr< SFindInDialogues > GetGlobalFindResults()
void CloseGlobalFindResults(const TSharedRef< SFindInDialogues > &FindResults)
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
TWeakObjectPtr< UDlgDialogue > Dialogue
USTRUCT(Blueprintable)
USTRUCT(BlueprintType)
Definition DlgEdge.h:25
USTRUCT(BlueprintType)
Definition DlgEvent.h:59
USTRUCT(BlueprintType)