From bcb65a17888338f0ddda33f28689134c057bd9d3 Mon Sep 17 00:00:00 2001 From: Kailey Joanette Date: Mon, 27 Apr 2020 18:18:43 -0400 Subject: [PATCH] Selected Node on top --- Scripts/Editor/NodeEditorGUI.cs | 12 +++++++++++- Scripts/Editor/NodeEditorWindow.cs | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 7c82a12..7f36e3f 100755 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -11,6 +11,7 @@ namespace XNodeEditor { public NodeGraphEditor graphEditor; private List selectionCache; private List culledNodes; + private List orderedNodeIndices = new List(); /// 19 if docked, 22 if not private int topPadding { get { return isDocked() ? 19 : 22; } } /// Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run. @@ -24,6 +25,14 @@ namespace XNodeEditor { ValidateGraphEditor(); Controls(); + // Ensure we have all node indices covered + while (orderedNodeIndices.Count < graph.nodes.Count) + orderedNodeIndices.Add(orderedNodeIndices.Count); + while (orderedNodeIndices.Count > graph.nodes.Count) { + int removeIndex = orderedNodeIndices.IndexOf( orderedNodeIndices.Count - 1 ); + orderedNodeIndices.RemoveAt( removeIndex ); + } + DrawGrid(position, zoom, panOffset); DrawConnections(); DrawDraggedConnection(); @@ -412,7 +421,8 @@ namespace XNodeEditor { List removeEntries = new List(); if (e.type == EventType.Layout) culledNodes = new List(); - for (int n = 0; n < graph.nodes.Count; n++) { + //for (int n = 0; n < graph.nodes.Count; n++) { + foreach (int n in orderedNodeIndices) { // Skip null nodes. The user could be in the process of renaming scripts, so removing them at this point is not advisable. if (graph.nodes[n] == null) continue; if (n >= graph.nodes.Count) return; diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs index a751722..6499bd7 100644 --- a/Scripts/Editor/NodeEditorWindow.cs +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -175,6 +175,11 @@ namespace XNodeEditor { selection.Add(node); Selection.objects = selection.ToArray(); } else Selection.objects = new Object[] { node }; + + int nodeIndex = graph.nodes.IndexOf( node ); + int indexToMove = orderedNodeIndices.IndexOf( nodeIndex ); + orderedNodeIndices.RemoveAt( indexToMove ); + orderedNodeIndices.Insert( orderedNodeIndices.Count, nodeIndex ); } public void DeselectNode(XNode.Node node) {