Adding new menu options to node editor

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Swing Wren
Posts: 26
Joined: Fri Apr 10, 2020 2:30 am

Adding new menu options to node editor

Post by Swing Wren »

Hi, I'm trying to add more options to the node Editor to make iterations faster for our game.

I managed to do the change required by modifying the DialogueEditorWindowConversationNodeEditor.cs file and adding a empty method so I can get an error if an update overrides my changes.

Code: Select all

           ....
	   AddCustomOptionsFromExternalProject(contextMenu, entry);

            AddCanvasContextMenuGotoItems(contextMenu);

            contextMenu.AddSeparator(string.Empty);
            contextMenu.AddItem(new GUIContent("Play From Here..."), false, PlayConversationFromEntry, currentEntry.id);

            contextMenu.ShowAsContext();
            contextMenuPosition = Event.current.mousePosition;

            EditorZoomArea.Begin(_zoom, _zoomArea);
        }
        
          private const string InterrogationActionId = "InterrogationActionId";
        private const string InterrogationPressValue = "0";
        private const string CustomFieldType_InterrogationActionId = "CustomFieldType_InterrogationActionId";

        private void AddCustomOptionsFromExternalProject(GenericMenu contextMenu, DialogueEntry entry) {
            contextMenu.AddSeparator(string.Empty);
            
            void MarkAsInterrogationPress(object o) {
                DialogueEntry entryToMark = o as DialogueEntry;
                if (entryToMark == null) {
                    return;
                }
                Field foundField = null;
                foreach (Field field in entry.fields) {
                    if (field.title != InterrogationActionId) {
                        continue;
                    }
                    foundField = field;
                    break;
                }
                if (foundField != null) {
                    foundField.value = "0";
                    return;
                }
                entry.fields.Add(new Field(InterrogationActionId, InterrogationPressValue, FieldType.Number, CustomFieldType_InterrogationActionId));
            }
            
            contextMenu.AddItem(new GUIContent("Mark as Interrogation Press Node"), false, MarkAsInterrogationPress, entry);
            contextMenu.AddSeparator(string.Empty);
        }
        
                
        public static void EnsureCustomChangesAreThere() {
            
        }
My question is: Is there a cleaner way to achieve what I'm trying to do or any recommendation for custom changes?
(I discarded the idea of adding the field in a template as I don't want for each node to have a field that is not used often)
User avatar
Tony Li
Posts: 20651
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding new menu options to node editor

Post by Tony Li »

Hi,

Can you use the C# hooks (see Customizing the Editor) instead of directly modifying the Dialogue System's source code?
Swing Wren
Posts: 26
Joined: Fri Apr 10, 2020 2:30 am

Re: Adding new menu options to node editor

Post by Swing Wren »

I was not aware of those hooks, sadly are not in the places I need. (I want to add them to the context menu of a dialogue entry node). But that is much better for modifying the source code, I'll just add more hooks to the DialogueEditorWindowDelegates file

thanks!
User avatar
Tony Li
Posts: 20651
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding new menu options to node editor

Post by Tony Li »

Let me know what you'll add, and I'll add the same to the original Dialogue System files so you won't lose your customizations when you update.
Post Reply