1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Context menu limited to graph background and node headers

This commit is contained in:
Thor Brigsted 2017-11-19 22:38:05 +01:00
parent 1ddfdeb1d3
commit dabd55cf49
2 changed files with 25 additions and 17 deletions

View File

@ -103,7 +103,13 @@ namespace XNodeEditor {
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
} }
} else if (e.button == 1) { } else if (e.button == 1) {
if (!isPanning) ShowContextMenu(); if (!isPanning) {
if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
ShowNodeContextMenu(hoveredNode);
} else if (!IsHoveringNode) {
ShowGraphContextMenu();
}
}
isPanning = false; isPanning = false;
} }
break; break;

View File

@ -71,15 +71,18 @@ namespace XNodeEditor {
return GUILayout.Button(name, EditorStyles.toolbarDropDown, GUILayout.Width(width)); return GUILayout.Button(name, EditorStyles.toolbarDropDown, GUILayout.Width(width));
} }
/// <summary> Show right-click context menu </summary> /// <summary> Show right-click context menu for a node </summary>
public void ShowContextMenu() { public void ShowNodeContextMenu(Node node) {
GenericMenu contextMenu = new GenericMenu(); GenericMenu contextMenu = new GenericMenu();
Vector2 pos = WindowToGridPosition(Event.current.mousePosition); Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
if (hoveredNode != null) {
Node node = hoveredNode;
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node)); contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node));
} else { contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
}
/// <summary> Show right-click context menu for current graph </summary>
void ShowGraphContextMenu() {
GenericMenu contextMenu = new GenericMenu();
Vector2 pos = WindowToGridPosition(Event.current.mousePosition);
for (int i = 0; i < nodeTypes.Length; i++) { for (int i = 0; i < nodeTypes.Length; i++) {
Type type = nodeTypes[i]; Type type = nodeTypes[i];
@ -92,7 +95,6 @@ namespace XNodeEditor {
CreateNode(type, pos); CreateNode(type, pos);
}); });
} }
}
contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
} }