diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs index 683c7eebd..16094d621 100644 --- a/Source/Editor/Surface/Elements/OutputBox.cs +++ b/Source/Editor/Surface/Elements/OutputBox.cs @@ -136,7 +136,7 @@ namespace FlaxEditor.Surface.Elements // TODO: Figure out how to only draw the topmost connection if (IntersectsConnection(ref startPos, ref endPos, ref mousePosition, mouseOverDistance)) { - highlight += 1; + highlight += 0.5f; } DrawConnection(ref startPos, ref endPos, ref color, highlight); @@ -151,7 +151,7 @@ namespace FlaxEditor.Surface.Elements // Draw all the connections var startPos = Parent.PointToParent(Center); Vector2 endPos = targetBox.Parent.PointToParent(targetBox.Center); - DrawConnection(ref startPos, ref endPos, ref _currentTypeColor, 2); + DrawConnection(ref startPos, ref endPos, ref _currentTypeColor, 2.5f); } /// diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index 3c544dbdd..9c6f55004 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -763,25 +763,29 @@ namespace FlaxEditor.Surface } } + } + + /// + /// Draws all selected connections between surface objects related to this node. + /// + /// The index of the currently selected connection. + public void DrawSelectedConnections(int selectedConnectionIndex) + { if (_isSelected) { - bool hasBoxesSelection = HasBoxesSelection; - for (int j = 0; j < Elements.Count; j++) + if (HasBoxesSelection) { - if (Elements[j] is Box box && box.HasAnyConnection && (!hasBoxesSelection || box.IsSelected)) + for (int j = 0; j < Elements.Count; j++) { - if (box is OutputBox ob) + if (Elements[j] is Box box && box.IsSelected && selectedConnectionIndex < box.Connections.Count) { - for (int i = 0; i < ob.Connections.Count; i++) + if (box is OutputBox ob) { - ob.DrawSelectedConnection(ob.Connections[i]); + ob.DrawSelectedConnection(ob.Connections[selectedConnectionIndex]); } - } - else - { - for (int i = 0; i < box.Connections.Count; i++) + else { - if (box.Connections[i] is OutputBox outputBox) + if (box.Connections[selectedConnectionIndex] is OutputBox outputBox) { outputBox.DrawSelectedConnection(box); } @@ -789,6 +793,32 @@ namespace FlaxEditor.Surface } } } + else + { + for (int j = 0; j < Elements.Count; j++) + { + if (Elements[j] is Box box) + { + if (box is OutputBox ob) + { + for (int i = 0; i < ob.Connections.Count; i++) + { + ob.DrawSelectedConnection(ob.Connections[i]); + } + } + else + { + for (int i = 0; i < box.Connections.Count; i++) + { + if (box.Connections[i] is OutputBox outputBox) + { + outputBox.DrawSelectedConnection(box); + } + } + } + } + } + } } } diff --git a/Source/Editor/Surface/VisjectSurface.Draw.cs b/Source/Editor/Surface/VisjectSurface.Draw.cs index 488324a0a..016e0083f 100644 --- a/Source/Editor/Surface/VisjectSurface.Draw.cs +++ b/Source/Editor/Surface/VisjectSurface.Draw.cs @@ -103,6 +103,7 @@ namespace FlaxEditor.Surface for (int i = 0; i < Nodes.Count; i++) { Nodes[i].DrawConnections(ref mousePosition); + Nodes[i].DrawSelectedConnections(_selectedConnectionIndex); } } diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs index dc3406e45..996f9d2e0 100644 --- a/Source/Editor/Surface/VisjectSurface.Input.cs +++ b/Source/Editor/Surface/VisjectSurface.Input.cs @@ -562,89 +562,69 @@ namespace FlaxEditor.Surface } return true; } - - if (key == KeyboardKeys.ArrowUp) + if (key == KeyboardKeys.ArrowUp || key == KeyboardKeys.ArrowDown) { Box selectedBox = GetSelectedBox(SelectedNodes); - Box toSelect = selectedBox?.ParentNode.GetPreviousBox(selectedBox); + if (selectedBox == null) return true; - if (toSelect != null) + Box toSelect = (key == KeyboardKeys.ArrowUp) ? + selectedBox?.ParentNode.GetPreviousBox(selectedBox) : + selectedBox?.ParentNode.GetNextBox(selectedBox); + + if (toSelect != null && toSelect.IsOutput == selectedBox.IsOutput) { - if (toSelect.Connections.Count > 1) - { - // Box has multiple connections - } - - if (toSelect.IsOutput != selectedBox.IsOutput) - { - // Jump up (nodes) - } - else - { - Select(toSelect.ParentNode); - toSelect.ParentNode.SelectBox(toSelect); - } + Select(toSelect.ParentNode); + toSelect.ParentNode.SelectBox(toSelect); } - - return true; } - if (key == KeyboardKeys.ArrowDown) + + if (key == KeyboardKeys.Tab) { Box selectedBox = GetSelectedBox(SelectedNodes); - Box toSelect = selectedBox?.ParentNode.GetNextBox(selectedBox); + if (selectedBox == null) return true; - if (toSelect != null) + int connectionCount = selectedBox.Connections.Count; + if (connectionCount == 0) return true; + + if (Root.GetKey(KeyboardKeys.Shift)) { - if (toSelect.Connections.Count > 1) - { - // Box has multiple connections - } - - if (toSelect.IsOutput != selectedBox.IsOutput) - { - // Jump down (nodes) - } - else - { - Select(toSelect.ParentNode); - toSelect.ParentNode.SelectBox(toSelect); - } + _selectedConnectionIndex = ((_selectedConnectionIndex - 1) % connectionCount + connectionCount) % connectionCount; + } + else + { + _selectedConnectionIndex = (_selectedConnectionIndex + 1) % connectionCount; } - - return true; } + if (key == KeyboardKeys.ArrowRight || key == KeyboardKeys.ArrowLeft) { Box selectedBox = GetSelectedBox(SelectedNodes); - if (selectedBox == null) return false; + if (selectedBox == null) return true; Box toSelect = null; - if (key == KeyboardKeys.ArrowRight && selectedBox.IsOutput || key == KeyboardKeys.ArrowLeft && !selectedBox.IsOutput) + if ((key == KeyboardKeys.ArrowRight && selectedBox.IsOutput) || (key == KeyboardKeys.ArrowLeft && !selectedBox.IsOutput)) { - if (selectedBox.Connections.Count > 1) + if (_selectedConnectionIndex < 0 || _selectedConnectionIndex >= selectedBox.Connections.Count) { - // Box has multiple connections - } - else if (selectedBox.Connections.Count == 1) - { - toSelect = selectedBox.Connections[0]; + _selectedConnectionIndex = 0; } + toSelect = selectedBox.Connections[_selectedConnectionIndex]; } else { // Use the node with the closest Y-level // Since there are cases like 3 nodes on one side and only 1 node on the other side - var elements = selectedBox?.ParentNode.Elements; - float distance = float.PositiveInfinity; + var elements = selectedBox.ParentNode.Elements; + float minDistance = float.PositiveInfinity; for (int i = 0; i < elements.Count; i++) { - if (elements[i] is Box box && box.IsOutput != selectedBox.IsOutput && Mathf.Abs(box.Y - selectedBox.Y) < distance) + if (elements[i] is Box box && box.IsOutput != selectedBox.IsOutput && Mathf.Abs(box.Y - selectedBox.Y) < minDistance) { toSelect = box; - distance = Mathf.Abs(box.Y - selectedBox.Y); + minDistance = Mathf.Abs(box.Y - selectedBox.Y); } } } diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index d98e2c421..c4b14ee5c 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -39,6 +39,7 @@ namespace FlaxEditor.Surface private GroupArchetype _customNodesGroup; private List _customNodes; private Action _onSave; + private int _selectedConnectionIndex; internal int _isUpdatingBoxTypes; @@ -362,6 +363,8 @@ namespace FlaxEditor.Surface Context.ControlSpawned += OnSurfaceControlSpawned; Context.ControlDeleted += OnSurfaceControlDeleted; + SelectionChanged += () => { _selectedConnectionIndex = 0; }; + // Init drag handlers DragHandlers.Add(_dragAssets = new DragAssets(ValidateDragItem)); DragHandlers.Add(_dragParameters = new DragNames(SurfaceParameter.DragPrefix, ValidateDragParameter));