A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueEditor.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3
4#include "GraphEditor.h"
5#include "EditorUndoClient.h"
6#include "Toolkits/AssetEditorToolkit.h"
7#include "IDetailsView.h"
8#include "Misc/NotifyHook.h"
9
13#include "DlgDialogue.h"
14#include "DlgSystemSettings.h"
15#include "NYReflectionTypes.h"
16
17class IDetailsView;
18class UDlgDialogue;
21class FTabManager;
22
24// FDialogueEditor
26{
28
29public:
31 SLATE_END_ARGS()
32
34 virtual ~FDialogueEditor();
35
36 //
37 // IToolkit interface
38 //
39
40 void RegisterTabSpawners(const TSharedRef<FTabManager>& TabManager) override;
41 void UnregisterTabSpawners(const TSharedRef<FTabManager>& TabManager) override;
42 FText GetBaseToolkitName() const override;
43 FText GetToolkitName() const override;
44 FName GetToolkitFName() const override { return FName(TEXT("DialogueEditor")); }
45 FText GetToolkitToolTipText() const override { return GetToolTipTextForObject(Cast<UObject>(DialogueBeingEdited)); }
46 FLinearColor GetWorldCentricTabColorScale() const override { return FLinearColor::White; }
47 FString GetWorldCentricTabPrefix() const override { return FString(TEXT("DialogueEditor")); }
48
49 //
50 // FAssetEditorToolkit interface
51 //
52
54 FString GetDocumentationLink() const override { return FString(TEXT("Plugins/DlgSystem/DialogueEditor")); }
55
56 bool CanSaveAsset() const override { return true; }
57 bool CanSaveAssetAs() const override { return true; }
58 void SaveAsset_Execute() override;
59 void SaveAssetAs_Execute() override;
60
61 //
62 // IAssetEditorInstance interface
63 //
64
65 void FocusWindow(UObject* ObjectToFocusOn = nullptr) override;
66
67 //
68 // FEditorUndoClient interface
69 //
70
71 // Signal that client should run any PostUndo code
72 // @param bSuccess If true than undo succeeded, false if undo failed
73 void PostUndo(bool bSuccess) override;
74
75 // Signal that client should run any PostRedo code
76 // @param bSuccess If true than redo succeeded, false if redo failed
77 void PostRedo(bool bSuccess) override;
78
79 //
80 // FSerializableObject interface, FGCObject
81 //
82
83 void AddReferencedObjects(FReferenceCollector& Collector) override
84 {
85 Collector.AddReferencedObject(DialogueBeingEdited);
86 }
87
88 //
89 // IDialogueEditor interface
90 //
91
92 // Get the currently selected set of nodes
93 TSet<UObject*> GetSelectedNodes() const override
94 {
95 check(GraphEditorView.IsValid());
96 return GraphEditorView->GetSelectedNodes();
97 }
98
107 bool GetBoundsForSelectedNodes(class FSlateRect& Rect, float Padding) const override
108 {
109 return GraphEditorView->GetBoundsForSelectedNodes(Rect, Padding);
110 }
111
112 // Clears the viewport selection set
114 {
115 if (GraphEditorView.IsValid())
116 {
117 GraphEditorView->ClearSelectionSet();
118 }
119 }
120
121 // Refreshes the graph viewport.
122 void RefreshViewport() const
123 {
124 if (GraphEditorView.IsValid())
125 {
126 GraphEditorView->NotifyGraphChanged();
127 }
128 }
129
130 // Refreshes the details panel with the Dialogue
131 void RefreshDetailsView(bool bRestorePreviousSelection) override;
132 void Refresh(bool bRestorePreviousSelection) override;
133 void JumpToObject(const UObject* Object) override;
134
135 //
136 // Own methods
137 //
138
139 // Summons The Search UI
140 void SummonSearchUI(bool bSetFindWithinDialogue, FString NewSearchTerms = FString(), bool bSelectFirstResult = false);
141
142 // Edits the specified Dialogue. This is called from the TypeActions object.
144 EToolkitMode::Type Mode,
145 const TSharedPtr<IToolkitHost>& InitToolkitHost,
146 UDlgDialogue* InitDialogue
147 );
148
149 // Helper method to get directly the Dialogue Graph
150 UDialogueGraph* GetDialogueGraph() const { return CastChecked<UDialogueGraph>(DialogueBeingEdited->GetGraph()); }
151
152 // Performs checks on all the nodes in the Dialogue
153 void CheckAll() const;
154
155 // Gets/Sets the dialogue being edited
161 void SetDialogueBeingEdited(UDlgDialogue* NewDialogue);
162
163 // Used only on drag/drop operations of edges.
166
167private:
168 //
169 // FNotifyHook interface
170 //
171 void NotifyPostChange(const FPropertyChangedEvent& PropertyChangedEvent, FNYProperty* PropertyThatChanged) override;
172
173 //
174 // Own methods
175 //
176
177 // Creates all internal widgets for the tabs to point at
179
180 // Create new graph editor widget
181 TSharedRef<SGraphEditor> CreateGraphEditorWidget();
182
183 // Bind the commands from the editor. See GraphEditorCommands for more details.
184 void BindEditorCommands();
185
186 // Generates the submenu fo the primary/secondary button
187 TSharedRef<SWidget> GeneratePrimarySecondaryEdgesMenu() const;
188 TSharedRef<SWidget> GenerateExternalURLsMenu() const;
189
190 // Extend the Menus of the editor
191 void ExtendMenu();
192
193 // Extends the Top Toolbar
194 void ExtendToolbar();
195
196 //
197 // Functions to spawn each tab type.
198 //
199
200 // Spawn the details tab where we can see the internal structure of the dialogue.
201 TSharedRef<SDockTab> SpawnTab_Details(const FSpawnTabArgs& Args) const;
202
203 // Spawn the main graph canvas where all the nodes live. */
204 TSharedRef<SDockTab> SpawnTab_GraphCanvas(const FSpawnTabArgs& Args) const;
205
206 // Spawn the pallete tab view where you can see all the nodes available for the graph.
207 TSharedRef<SDockTab> SpawnTab_Palette(const FSpawnTabArgs& Args) const;
208
209 // Spawn the find in Dialogue tab view.
210 TSharedRef<SDockTab> SpawnTab_FindInDialogue(const FSpawnTabArgs& Args) const;
211
212 //
213 // Graph editor commands
214 //
215
216 // Called to undo the last action
217 void OnCommandUndoGraphAction() const;
218
219 // Called to redo the last undone action
220 void OnCommandRedoGraphAction() const;
221
222 //
223 // Edit Node commands
224 //
225
226 // Converts a speech sequence node to a list of speech node.
228
229 // Converts a list of speech nodes to a speech sequence node
231
232 // Remove the currently selected nodes from editor view
233 void OnCommandDeleteSelectedNodes() const;
234
235 // Whether we are able to remove the currently selected nodes
236 bool CanDeleteNodes() const;
237
238 // Copy the currently selected nodes to the text buffer.
239 void OnCommandCopySelectedNodes() const;
240
241 // Whether we are able to copy the currently selected nodes.
242 bool CanCopyNodes() const;
243
244 // Paste the nodes at the current location
245 void OnCommandPasteNodes();
246
247 // Paste the nodes at the specified Location.
248 void PasteNodesHere(const FVector2D& Location);
249
250 // Whether we are able to paste from the clipboard
251 bool CanPasteNodes() const;
252
253 // Hide the selected nodes.
255
256 // Unhide all nodes.
258
259 //
260 // Toolbar commands
261 //
262
263 // Reloads the Dialogue from the file
264 void OnCommandDialogueReload() const;
265
266 //
267 // Graph events
268 //
269
270 // Called when the selection changes in the GraphEditor
271 void OnSelectedNodesChanged(const TSet<UObject*>& NewSelection);
272
273 // Called to create context menu when right-clicking on graph
274 FActionMenuContent OnCreateGraphActionMenu(UEdGraph* InGraph,
275 const FVector2D& InNodePosition,
276 const TArray<UEdGraphPin*>& InDraggedPins,
277 bool bAutoExpand,
278 SGraphEditor::FActionMenuClosed InOnMenuClosed);
279
280 // Called from graph context menus when they close to tell the editor why they closed
281 void OnGraphActionMenuClosed(bool bActionExecuted, bool bGraphPinContext);
282
290 void OnNodeTitleCommitted(const FText& NewText, ETextCommit::Type CommitInfo, UEdGraphNode* NodeBeingChanged) const;
291
293// void OnPreviewTextChanged(const FString& Text);
294//
295// /** Called when the selection changes in the GraphEditor */
296// void OnSelectedNodesChanged(const TSet<class UObject*>& NewSelection);
297
298 const UDlgSystemSettings& GetSettings() const { return *Settings; }
299
300private:
301 // The dialogue we are currently editing
303
304 // The dialogue system settings
306
307 // Graph Editor
308 TSharedPtr<SGraphEditor> GraphEditorView;
309
310 // The custom details view used
311 TSharedPtr<IDetailsView> DetailsView;
312
313 // Palette view of dialogue nodes types
314 TSharedPtr<SDialoguePalette> PaletteView;
315
317 TSharedPtr<SFindInDialogues> FindResultsView;
318
319 // Command list for this editor. Synced with FDlgEditorCommands. Aka list of shortcuts supported.
320 TSharedPtr<FUICommandList> GraphEditorCommands;
321
324
325 // Keep track of the previous selected objects so that we can reverse selection
326 TArray<TWeakObjectPtr<UObject>> PreviousSelectedNodeObjects;
327
329 static const FName DetailsTabID;
330 static const FName GraphCanvasTabID;
331 static const FName PaletteTabId;
332 static const FName FindInDialogueTabId;
333};
UProperty FNYProperty
bool CanPasteNodes() const
void InitDialogueEditor(EToolkitMode::Type Mode, const TSharedPtr< IToolkitHost > &InitToolkitHost, UDlgDialogue *InitDialogue)
void OnCommandDeleteSelectedNodes() const
UDlgSystemSettings * Settings
void OnCommandHideSelectedNodes()
TSharedPtr< IDetailsView > DetailsView
void PasteNodesHere(const FVector2D &Location)
void PostRedo(bool bSuccess) override
static const FName PaletteTabId
void SetDialogueBeingEdited(UDlgDialogue *NewDialogue)
void CheckAll() const
TSharedRef< SGraphEditor > CreateGraphEditorWidget()
TSharedPtr< SGraphEditor > GraphEditorView
TArray< TWeakObjectPtr< UObject > > PreviousSelectedNodeObjects
void NotifyPostChange(const FPropertyChangedEvent &PropertyChangedEvent, FNYProperty *PropertyThatChanged) override
void SummonSearchUI(bool bSetFindWithinDialogue, FString NewSearchTerms=FString(), bool bSelectFirstResult=false)
static const FName GraphCanvasTabID
void SaveAssetAs_Execute() override
bool CanDeleteNodes() const
FText GetBaseToolkitName() const override
bool CanCopyNodes() const
bool GetBoundsForSelectedNodes(class FSlateRect &Rect, float Padding) const override
void JumpToObject(const UObject *Object) override
UDialogueGraphNode_Edge * GetLastTargetGraphEdgeBeforeDrag() const override
void OnCommandUndoGraphAction() const
void SetLastTargetGraphEdgeBeforeDrag(UDialogueGraphNode_Edge *InEdge) override
void OnCommandRedoGraphAction() const
static const FName DetailsTabID
void PostUndo(bool bSuccess) override
TSet< UObject * > GetSelectedNodes() const override
FDialogueEditor Self
void RegisterTabSpawners(const TSharedRef< FTabManager > &TabManager) override
void OnCommandConvertSpeechNodesToSpeechSequence() const
TSharedRef< SDockTab > SpawnTab_Palette(const FSpawnTabArgs &Args) const
UDialogueGraph * GetDialogueGraph() const
void SaveAsset_Execute() override
TSharedPtr< SDialoguePalette > PaletteView
const UDlgSystemSettings & GetSettings() const
void ClearViewportSelection() const
UDialogueGraphNode_Edge * LastTargetGraphEdgeBeforeDrag
void OnGraphActionMenuClosed(bool bActionExecuted, bool bGraphPinContext)
FLinearColor GetWorldCentricTabColorScale() const override
void OnSelectedNodesChanged(const TSet< UObject * > &NewSelection)
void AddReferencedObjects(FReferenceCollector &Collector) override
void RefreshViewport() const
FString GetWorldCentricTabPrefix() const override
void RefreshDetailsView(bool bRestorePreviousSelection) override
bool CanSaveAsset() const override
TSharedRef< SDockTab > SpawnTab_FindInDialogue(const FSpawnTabArgs &Args) const
static const FName FindInDialogueTabId
FActionMenuContent OnCreateGraphActionMenu(UEdGraph *InGraph, const FVector2D &InNodePosition, const TArray< UEdGraphPin * > &InDraggedPins, bool bAutoExpand, SGraphEditor::FActionMenuClosed InOnMenuClosed)
TSharedPtr< SFindInDialogues > FindResultsView
FName GetToolkitFName() const override
FText GetToolkitName() const override
TSharedRef< SDockTab > SpawnTab_GraphCanvas(const FSpawnTabArgs &Args) const
TSharedRef< SWidget > GenerateExternalURLsMenu() const
TSharedRef< SDockTab > SpawnTab_Details(const FSpawnTabArgs &Args) const
FString GetDocumentationLink() const override
void OnCommandCopySelectedNodes() const
void UnregisterTabSpawners(const TSharedRef< FTabManager > &TabManager) override
bool CanSaveAssetAs() const override
UDlgDialogue * GetDialogueBeingEdited()
TSharedPtr< FUICommandList > GraphEditorCommands
void Refresh(bool bRestorePreviousSelection) override
UDlgDialogue * DialogueBeingEdited
void FocusWindow(UObject *ObjectToFocusOn=nullptr) override
FText GetToolkitToolTipText() const override
void OnCommandConvertSpeechSequenceNodeToSpeechNodes() const
void OnNodeTitleCommitted(const FText &NewText, ETextCommit::Type CommitInfo, UEdGraphNode *NodeBeingChanged) const
void OnCommandDialogueReload() const
TSharedRef< SWidget > GeneratePrimarySecondaryEdgesMenu() const
UCLASS(BlueprintType, Meta = (DisplayThumbnail = "true"))
Definition DlgDialogue.h:85
UCLASS(Config = Engine, DefaultConfig, meta = (DisplayName = "Dialogue System Settings"))