Page 1 of 1

Adding new menu options to node editor

Posted: Wed Apr 17, 2024 12:40 pm
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)

Re: Adding new menu options to node editor

Posted: Wed Apr 17, 2024 2:41 pm
by Tony Li
Hi,

Can you use the C# hooks (see Customizing the Editor) instead of directly modifying the Dialogue System's source code?

Re: Adding new menu options to node editor

Posted: Thu Apr 18, 2024 3:25 am
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!

Re: Adding new menu options to node editor

Posted: Thu Apr 18, 2024 8:35 am
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.

Re: Adding new menu options to node editor

Posted: Sun Aug 11, 2024 3:57 am
by Swing Wren
Sorry for the huge delay,

I only ended up doing this:

Code: Select all

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

   if (customSetupDialogueEntryNodeContextMenu != null) customSetupDialogueEntryNodeContextMenu(contextMenu,entry);
            
   contextMenu.ShowAsContext();
   contextMenuPosition = Event.current.mousePosition;
Either way I don't mind doing the changes every time, I already have a few modifications on the dialogue system and one more is no trouble :)

Re: Adding new menu options to node editor

Posted: Sun Aug 11, 2024 8:53 am
by Tony Li
I've just added a similar hook to version 2.2.48:

customNodeContextMenuSetup(DialogueDatabase database, DialogueEntry entry, GenericMenu contextMenu)

When you update to 2.2.48+, you can use this delegate instead of directly modifying DialogueEditorWindowConversationNodeEditor.cs.