A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueEditorUtilities.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3
4#include "ConnectionDrawingPolicy.h"
5#include "PropertyHandle.h"
6#include "Toolkits/AssetEditorManager.h"
7#include "EdGraphNode_Comment.h"
8
10#include "Nodes/DlgNode.h"
11
13{
14 None = 0,
16 Event
17};
18
20// FDialogueEditorUtilities
21
22class UDlgDialogue;
23class UEdGraphSchema;
24class UDlgNode;
25class UEdGraph;
26class FSlateRect;
27class UK2Node_Event;
28
30{
31public:
33 template <typename GraphNodeType>
34 static GraphNodeType* SpawnGraphNodeFromTemplate(UEdGraph* ParentGraph, const FIntPoint& Location, bool bSelectNewNode = true)
35 {
36 FGraphNodeCreator<GraphNodeType> NodeCreator(*ParentGraph);
37 GraphNodeType* GraphNode = NodeCreator.CreateUserInvokedNode(bSelectNewNode);
38 NodeCreator.Finalize(); // Calls on the node: CreateNewGuid, PostPlacedNewNode, AllocateDefaultPins
39 GraphNode->NodePosX = Location.X;
40 GraphNode->NodePosY = Location.Y;
41 GraphNode->SetFlags(RF_Transactional);
42
43 return GraphNode;
44 }
45
46 // Loads all dialogues into memory and checks the GUIDs for duplicates
48
50 static const TSet<UObject*> GetSelectedNodes(const UEdGraph* Graph);
51
60 static bool GetBoundsForSelectedNodes(const UEdGraph* Graph, FSlateRect& Rect, float Padding = 0.0f);
61
63 static void RefreshDetailsView(const UEdGraph* Graph, bool bRestorePreviousSelection);
64
65 // Refresh the viewport and property/details pane
66 static void Refresh(const UEdGraph* Graph, bool bRestorePreviousSelection);
67
70 static void SetLastTargetGraphEdgeBeforeDrag(const UEdGraph* Graph, UDialogueGraphNode_Edge* InEdge);
71
73 static bool RemoveNode(UEdGraphNode* NodeToRemove);
74
85 UObject* ParentScope,
86 FName GraphName,
87 TSubclassOf<UEdGraph> GraphClass,
88 TSubclassOf<UEdGraphSchema> SchemaClass
89 );
90
92 static bool CheckAndTryToFixDialogue(UDlgDialogue* Dialogue, bool bDisplayWarning = true);
93
100 static void TryToCreateDefaultGraph(UDlgDialogue* Dialogue, bool bPrompt = true);
101
104
105 // Tries to get the closest UDlgNode for a UEdGraphNode
107
110 {
111 return CastChecked<UDialogueGraph>(Graph)->GetDialogue();
112 }
113
123 static void AutoPositionGraphNodes(
124 UDialogueGraphNode* RootNode,
125 const TArray<UDialogueGraphNode*>& GraphNodes,
126 int32 OffsetBetweenColumnsX,
127 int32 OffsetBetweenRowsY,
128 bool bIsDirectionVertical
129 );
130
141 const TSet<UObject*>& SelectedNodes,
142 TArray<UDialogueGraphNode*>& OutSelectedGraphNodes
143 );
144
145 static bool CanConvertSpeechNodesToSpeechSequence(const TSet<UObject*>& SelectedNodes)
146 {
147 TArray<UDialogueGraphNode*> OutSelectedGraphNodes;
148 return CanConvertSpeechNodesToSpeechSequence(SelectedNodes, OutSelectedGraphNodes);
149 }
150
157 static bool CanConvertSpeechSequenceNodeToSpeechNodes(const TSet<UObject*>& SelectedNodes);
158
160 static void CloseOtherEditors(UObject* Asset, IAssetEditorInstance* OnlyEditor);
161
166 static bool OpenEditorForAsset(const UObject* Asset);
167
171 static IAssetEditorInstance* FindEditorForAsset(UObject* Asset, bool bFocusIfOpen);
172
177 static bool OpenEditorAndJumpToGraphNode(const UEdGraphNode* GraphNode, bool bFocusIfOpen = false);
178
179 // Just jumps to that graph node without trying to open any Dialogue Editor
180 // If you want that just call OpenEditorAndJumpToGraphNode
181 static bool JumpToGraphNode(const UEdGraphNode* GraphNode);
182 static bool JumpToGraphNodeIndex(const UDlgDialogue* Dialogue, int32 NodeIndex);
183
190 static void CopyNodeChildren(const UDialogueGraphNode* FromNode, UDialogueGraphNode* ToNode);
191
199 static void ReplaceParentConnectionsToNode(const UDialogueGraphNode* OldNode, const UDialogueGraphNode* NewNode);
200
201 // Wrapper over standard message box that that also logs to the console
202 static EAppReturnType::Type ShowMessageBox(EAppMsgType::Type MsgType, const FString& Text, const FString& Caption);
203
204 // Returns true if the TestPoint is inside the Geometry.
205 static bool IsPointInsideGeometry(const FVector2D& TestPoint, const FGeometry& Geometry)
206 {
207 TArray<FVector2D> GeometryPoints;
208 FGeometryHelper::ConvertToPoints(Geometry, GeometryPoints);
209 return FBox2D(GeometryPoints).IsInside(TestPoint);
210 }
211
221 const TArray<UDialogueGraphNode*>& GraphNodes,
222 const TMap<int32, int32>& OldToNewIndexMap
223 );
224
225 // Gets the Dialogue for the provided UEdGraphNode
226 static UDlgDialogue* GetDialogueFromGraphNode(const UEdGraphNode* GraphNode);
227
228 // Save all the dialogues.
229 // @return True on success or false on failure.
230 static bool SaveAllDialogues();
231
232 // Deletes all teh dialogues text files
233 // @return True on success or false on failure.
234 static bool DeleteAllDialoguesTextFiles();
235
236 /***
237 * Pops up a class picker dialog to choose the class that is a child of the Classprovided.
238 *
239 * @param TitleText The title of the class picker dialog
240 * @param OutChosenClass The class chosen (if this function returns false, this will be null) by the the user
241 * @param Class The children of this class we are displaying and prompting the user to choose from.
242 *
243 * @return true if OK was pressed, false otherwise
244 */
245 static bool PickChildrenOfClass(const FText& TitleText, UClass*& OutChosenClass, UClass* Class);
246
247 // Opens the specified Blueprint at the last edited graph by default
248 // or if the OpenType is set to Function or Event it opens that with the FunctionNameToOpen
249 static bool OpenBlueprintEditor(
250 UBlueprint* Blueprint,
252 FName FunctionNameToOpen = NAME_None,
253 bool bForceFullEditor = true,
254 bool bAddBlueprintFunctionIfItDoesNotExist = false
255 );
256
257 // Adds the function if it does not exist
258 // Return the Function Graph of the existing function or the newly created one
259 static UEdGraph* BlueprintGetOrAddFunction(UBlueprint* Blueprint, FName FunctionName, UClass* FunctionClassSignature);
260
261 // Same as BlueprintGetOrAddFunction but does not add it
262 static UEdGraph* BlueprintGetFunction(UBlueprint* Blueprint, FName FunctionName, UClass* FunctionClassSignature);
263
264 // Same as BlueprintGetOrAddFunction but only for an overriden event
265 static UK2Node_Event* BlueprintGetOrAddEvent(UBlueprint* Blueprint, FName EventName, UClass* EventClassSignature);
266
267 // Same as BlueprintGetOrAddEvent but does not add it
268 static UK2Node_Event* BlueprintGetEvent(UBlueprint* Blueprint, FName EventName, UClass* EventClassSignature);
269
270 // Adds a comment to the Blueprint
271 static UEdGraphNode_Comment* BlueprintAddComment(UBlueprint* Blueprint, const FString& CommentString, FVector2D Location = FVector2D::ZeroVector);
272
273private:
274 // Get the DialogueEditor for given object, if it exists
275 static TSharedPtr<class IDialogueEditor> GetDialogueEditorForGraph(const UEdGraph* Graph);
276
278};
EDialogueBlueprintOpenType
static bool OpenEditorAndJumpToGraphNode(const UEdGraphNode *GraphNode, bool bFocusIfOpen=false)
static void CopyNodeChildren(const UDialogueGraphNode *FromNode, UDialogueGraphNode *ToNode)
static IAssetEditorInstance * FindEditorForAsset(UObject *Asset, bool bFocusIfOpen)
static void RemapOldIndicesWithNewAndUpdateGUID(const TArray< UDialogueGraphNode * > &GraphNodes, const TMap< int32, int32 > &OldToNewIndexMap)
static bool AreDialogueNodesInSyncWithGraphNodes(const UDlgDialogue *Dialogue)
static bool JumpToGraphNodeIndex(const UDlgDialogue *Dialogue, int32 NodeIndex)
static UDialogueGraphNode_Edge * GetLastTargetGraphEdgeBeforeDrag(const UEdGraph *Graph)
static UK2Node_Event * BlueprintGetOrAddEvent(UBlueprint *Blueprint, FName EventName, UClass *EventClassSignature)
static GraphNodeType * SpawnGraphNodeFromTemplate(UEdGraph *ParentGraph, const FIntPoint &Location, bool bSelectNewNode=true)
static UEdGraph * BlueprintGetFunction(UBlueprint *Blueprint, FName FunctionName, UClass *FunctionClassSignature)
static void TryToCreateDefaultGraph(UDlgDialogue *Dialogue, bool bPrompt=true)
static bool PickChildrenOfClass(const FText &TitleText, UClass *&OutChosenClass, UClass *Class)
static UDlgDialogue * GetDialogueFromGraphNode(const UEdGraphNode *GraphNode)
static UEdGraph * CreateNewGraph(UObject *ParentScope, FName GraphName, TSubclassOf< UEdGraph > GraphClass, TSubclassOf< UEdGraphSchema > SchemaClass)
static TSharedPtr< class IDialogueEditor > GetDialogueEditorForGraph(const UEdGraph *Graph)
static void SetLastTargetGraphEdgeBeforeDrag(const UEdGraph *Graph, UDialogueGraphNode_Edge *InEdge)
static void CloseOtherEditors(UObject *Asset, IAssetEditorInstance *OnlyEditor)
static bool CanConvertSpeechNodesToSpeechSequence(const TSet< UObject * > &SelectedNodes, TArray< UDialogueGraphNode * > &OutSelectedGraphNodes)
static void ReplaceParentConnectionsToNode(const UDialogueGraphNode *OldNode, const UDialogueGraphNode *NewNode)
static bool CheckAndTryToFixDialogue(UDlgDialogue *Dialogue, bool bDisplayWarning=true)
static UEdGraphNode_Comment * BlueprintAddComment(UBlueprint *Blueprint, const FString &CommentString, FVector2D Location=FVector2D::ZeroVector)
static bool OpenBlueprintEditor(UBlueprint *Blueprint, EDialogueBlueprintOpenType OpenType=EDialogueBlueprintOpenType::None, FName FunctionNameToOpen=NAME_None, bool bForceFullEditor=true, bool bAddBlueprintFunctionIfItDoesNotExist=false)
static UK2Node_Event * BlueprintGetEvent(UBlueprint *Blueprint, FName EventName, UClass *EventClassSignature)
static bool CanConvertSpeechNodesToSpeechSequence(const TSet< UObject * > &SelectedNodes)
static bool OpenEditorForAsset(const UObject *Asset)
static void AutoPositionGraphNodes(UDialogueGraphNode *RootNode, const TArray< UDialogueGraphNode * > &GraphNodes, int32 OffsetBetweenColumnsX, int32 OffsetBetweenRowsY, bool bIsDirectionVertical)
static bool GetBoundsForSelectedNodes(const UEdGraph *Graph, FSlateRect &Rect, float Padding=0.0f)
static bool RemoveNode(UEdGraphNode *NodeToRemove)
static const TSet< UObject * > GetSelectedNodes(const UEdGraph *Graph)
static bool CanConvertSpeechSequenceNodeToSpeechNodes(const TSet< UObject * > &SelectedNodes)
static bool IsPointInsideGeometry(const FVector2D &TestPoint, const FGeometry &Geometry)
static EAppReturnType::Type ShowMessageBox(EAppMsgType::Type MsgType, const FString &Text, const FString &Caption)
static void Refresh(const UEdGraph *Graph, bool bRestorePreviousSelection)
static UEdGraph * BlueprintGetOrAddFunction(UBlueprint *Blueprint, FName FunctionName, UClass *FunctionClassSignature)
static UDlgDialogue * GetDialogueForGraph(const UEdGraph *Graph)
static UDlgNode * GetClosestNodeFromGraphNode(UEdGraphNode *GraphNode)
static void RefreshDetailsView(const UEdGraph *Graph, bool bRestorePreviousSelection)
static bool JumpToGraphNode(const UEdGraphNode *GraphNode)
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
UCLASS(BlueprintType, Abstract, EditInlineNew, ClassGroup = "Dialogue")
Definition DlgNode.h:40