1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 09:16:01 +08:00

Fix auto-connection menu opening on invalid connections where a target node is present

This commit is contained in:
Lumos 2019-12-22 15:43:25 +01:00
parent 5005b5e4f9
commit 23e369d38f

View File

@ -58,10 +58,9 @@ namespace XNodeEditor {
case EventType.MouseDrag: case EventType.MouseDrag:
if (e.button == 0) { if (e.button == 0) {
if (IsDraggingPort) { if (IsDraggingPort) {
if (IsHoveringPort && hoveredPort.IsInput && draggedOutput.CanConnectTo(hoveredPort)) { // Set target even if we can't connect, so as to prevent auto-conn menu from opening erroneously
if (!draggedOutput.IsConnectedTo(hoveredPort)) { if (IsHoveringPort && hoveredPort.IsInput && !draggedOutput.IsConnectedTo(hoveredPort)) {
draggedOutputTarget = hoveredPort; draggedOutputTarget = hoveredPort;
}
} else { } else {
draggedOutputTarget = null; draggedOutputTarget = null;
} }
@ -205,8 +204,8 @@ namespace XNodeEditor {
if (e.button == 0) { if (e.button == 0) {
//Port drag release //Port drag release
if (IsDraggingPort) { if (IsDraggingPort) {
//If connection is valid, save it // If connection is valid, save it
if (draggedOutputTarget != null) { if (draggedOutputTarget != null && draggedOutput.CanConnectTo(draggedOutputTarget)) {
XNode.Node node = draggedOutputTarget.node; XNode.Node node = draggedOutputTarget.node;
if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget); if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget);
@ -218,8 +217,8 @@ namespace XNodeEditor {
EditorUtility.SetDirty(graph); EditorUtility.SetDirty(graph);
} }
} }
// Open context menu for auto-connection // Open context menu for auto-connection if there is no target node
else if (NodeEditorPreferences.GetSettings().dragToCreate && autoConnectOutput != null) { else if (draggedOutputTarget == null && NodeEditorPreferences.GetSettings().dragToCreate && autoConnectOutput != null) {
GenericMenu menu = new GenericMenu(); GenericMenu menu = new GenericMenu();
graphEditor.AddContextMenuItems(menu); graphEditor.AddContextMenuItems(menu);
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));