add support to move visject socket connections

This commit is contained in:
xxSeys1
2025-06-13 22:05:57 +02:00
parent eee4e55cf0
commit f40c67ddf0
7 changed files with 77 additions and 55 deletions

View File

@@ -552,7 +552,17 @@ namespace FlaxEditor.Surface.Elements
_isMouseDown = false;
if (Surface.CanEdit)
{
if (!IsOutput && HasSingleConnection)
if (Input.GetKey(KeyboardKeys.Control))
{
List<Box> connectedBoxes = new List<Box>(Connections);
for (int i = 0; i < connectedBoxes.Count; i++)
{
BreakConnection(connectedBoxes[i]);
Surface.ConnectingStart(connectedBoxes[i], true);
}
}
else if (!IsOutput && HasSingleConnection)
{
var connectedBox = Connections[0];
if (Surface.Undo != null && Surface.Undo.Enabled)

View File

@@ -1,5 +1,6 @@
// Copyright (c) Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using FlaxEditor.Scripting;
using FlaxEngine;
@@ -233,11 +234,15 @@ namespace FlaxEditor.Surface
/// Begins connecting surface objects action.
/// </summary>
/// <param name="instigator">The connection instigator (eg. start box).</param>
public void ConnectingStart(IConnectionInstigator instigator)
/// <param name="additive">If the instigator should be added to the list of instigators.</param>
public void ConnectingStart(IConnectionInstigator instigator, bool additive = false)
{
if (instigator != null && instigator != _connectionInstigator)
{
_connectionInstigator = instigator;
if (!additive)
_connectionInstigator.Clear();
_connectionInstigator.Add(instigator);
StartMouseCapture();
}
}
@@ -257,22 +262,26 @@ namespace FlaxEditor.Surface
/// <param name="end">The end object (eg. end box).</param>
public void ConnectingEnd(IConnectionInstigator end)
{
// Ensure that there was a proper start box
if (_connectionInstigator == null)
// Ensure that there is at least one connection instigator
if (_connectionInstigator.Count == 0)
return;
var start = _connectionInstigator;
_connectionInstigator = null;
// Check if boxes are different and end box is specified
if (start == end || end == null)
return;
// Connect them
if (start.CanConnectWith(end))
List<IConnectionInstigator> instigators = new List<IConnectionInstigator>(_connectionInstigator);
for (int i = 0; i < instigators.Count; i++)
{
start.Connect(end);
var start = _connectionInstigator[i];
// Check if boxes are different and end box is specified
if (start == end || end == null)
return;
// Connect them
if (start.CanConnectWith(end))
start.Connect(end);
}
// Reset instigator list
_connectionInstigator.Clear();
}
}
}

View File

@@ -290,7 +290,7 @@ namespace FlaxEditor.Surface
_cmStartPos = location;
// Offset added in case the user doesn't like the box and wants to quickly get rid of it by clicking
OnShowPrimaryMenu(_activeVisjectCM, _cmStartPos + ContextMenuOffset, _connectionInstigator as Box);
OnShowPrimaryMenu(_activeVisjectCM, _cmStartPos + ContextMenuOffset, _connectionInstigator[0] as Box);
if (!string.IsNullOrEmpty(input))
{
@@ -475,9 +475,7 @@ namespace FlaxEditor.Surface
private void OnPrimaryMenuVisibleChanged(Control primaryMenu)
{
if (!primaryMenu.Visible)
{
_connectionInstigator = null;
}
_connectionInstigator.Clear();
}
/// <summary>
@@ -555,8 +553,7 @@ namespace FlaxEditor.Surface
}
// If the user is patiently waiting for his box to get connected to the newly created one fulfill his wish!
_connectionInstigator = startBox;
_connectionInstigator[0] = startBox;
if (!IsConnecting)
{

View File

@@ -1,5 +1,6 @@
// Copyright (c) Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using FlaxEditor.Surface.Elements;
using FlaxEngine;
@@ -126,40 +127,45 @@ namespace FlaxEditor.Surface
/// <remarks>Called only when user is connecting nodes.</remarks>
protected virtual void DrawConnectingLine()
{
// Get start position
var startPos = _connectionInstigator.ConnectionOrigin;
// Check if mouse is over any of box
var cmVisible = _activeVisjectCM != null && _activeVisjectCM.Visible;
var endPos = cmVisible ? _rootControl.PointFromParent(ref _cmStartPos) : _rootControl.PointFromParent(ref _mousePos);
Color lineColor = Style.Colors.Connecting;
if (_lastInstigatorUnderMouse != null && !cmVisible)
{
// Check if can connect objects
bool canConnect = _connectionInstigator.CanConnectWith(_lastInstigatorUnderMouse);
lineColor = canConnect ? Style.Colors.ConnectingValid : Style.Colors.ConnectingInvalid;
endPos = _lastInstigatorUnderMouse.ConnectionOrigin;
}
Float2 actualStartPos = startPos;
Float2 actualEndPos = endPos;
if (_connectionInstigator is Archetypes.Tools.RerouteNode)
List<IConnectionInstigator> instigators = new List<IConnectionInstigator>(_connectionInstigator);
for (int i = 0; i < instigators.Count; i++)
{
if (endPos.X < startPos.X && _lastInstigatorUnderMouse is null or Box { IsOutput: true })
IConnectionInstigator currentInstigator = instigators[i];
Float2 currentStartPosition = currentInstigator.ConnectionOrigin;
// Check if mouse is over any of box
if (_lastInstigatorUnderMouse != null && !cmVisible)
{
// Check if can connect objects
bool canConnect = currentInstigator.CanConnectWith(_lastInstigatorUnderMouse);
lineColor = canConnect ? Style.Colors.ConnectingValid : Style.Colors.ConnectingInvalid;
endPos = _lastInstigatorUnderMouse.ConnectionOrigin;
}
Float2 actualStartPos = currentStartPosition;
Float2 actualEndPos = endPos;
if (currentInstigator is Archetypes.Tools.RerouteNode)
{
if (endPos.X < currentStartPosition.X && _lastInstigatorUnderMouse is null or Box { IsOutput: true })
{
actualStartPos = endPos;
actualEndPos = currentStartPosition;
}
}
else if (currentInstigator is Box { IsOutput: false })
{
actualStartPos = endPos;
actualEndPos = startPos;
actualEndPos = currentStartPosition;
}
}
else if (_connectionInstigator is Box { IsOutput: false })
{
actualStartPos = endPos;
actualEndPos = startPos;
}
// Draw connection
_connectionInstigator.DrawConnectingLine(ref actualStartPos, ref actualEndPos, ref lineColor);
// Draw connection
currentInstigator.DrawConnectingLine(ref actualStartPos, ref actualEndPos, ref lineColor);
}
}
/// <summary>

View File

@@ -268,7 +268,7 @@ namespace FlaxEditor.Surface
if (_leftMouseDown)
{
// Connecting
if (_connectionInstigator != null)
if (_connectionInstigator.Count > 0)
{
}
// Moving
@@ -438,7 +438,7 @@ namespace FlaxEditor.Surface
public override bool OnMouseDown(Float2 location, MouseButton button)
{
// Check if user is connecting boxes
if (_connectionInstigator != null)
if (_connectionInstigator.Count > 0)
return true;
// Base
@@ -560,7 +560,7 @@ namespace FlaxEditor.Surface
_movingNodesDelta = Float2.Zero;
}
// Connecting
else if (_connectionInstigator != null)
else if (_connectionInstigator.Count > 0)
{
}
// Selecting
@@ -632,7 +632,7 @@ namespace FlaxEditor.Surface
ShowPrimaryMenu(_cmStartPos);
}
// Letting go of a connection or right clicking while creating a connection
else if (!_isMovingSelection && _connectionInstigator != null && !IsPrimaryMenuOpened)
else if (!_isMovingSelection && _connectionInstigator.Count > 0 && !IsPrimaryMenuOpened)
{
_cmStartPos = location;
Cursor = CursorType.Default;

View File

@@ -33,7 +33,7 @@ namespace FlaxEditor.Surface
Enabled = false;
// Clean data
_connectionInstigator = null;
_connectionInstigator.Clear();
_lastInstigatorUnderMouse = null;
var failed = RootContext.Load();

View File

@@ -121,7 +121,7 @@ namespace FlaxEditor.Surface
/// <summary>
/// The connection start.
/// </summary>
protected IConnectionInstigator _connectionInstigator;
protected List<IConnectionInstigator> _connectionInstigator = new List<IConnectionInstigator>();
/// <summary>
/// The last connection instigator under mouse.
@@ -234,17 +234,17 @@ namespace FlaxEditor.Surface
/// <summary>
/// Gets a value indicating whether user is selecting nodes.
/// </summary>
public bool IsSelecting => _leftMouseDown && !_isMovingSelection && _connectionInstigator == null;
public bool IsSelecting => _leftMouseDown && !_isMovingSelection && _connectionInstigator.Count == 0;
/// <summary>
/// Gets a value indicating whether user is moving selected nodes.
/// </summary>
public bool IsMovingSelection => _leftMouseDown && _isMovingSelection && _connectionInstigator == null;
public bool IsMovingSelection => _leftMouseDown && _isMovingSelection && _connectionInstigator.Count == 0;
/// <summary>
/// Gets a value indicating whether user is connecting nodes.
/// </summary>
public bool IsConnecting => _connectionInstigator != null;
public bool IsConnecting => _connectionInstigator.Count > 0;
/// <summary>
/// Gets a value indicating whether the left mouse button is down.