properly handle connecting to a box that already has a connection

This commit is contained in:
xxSeys1
2025-06-14 17:20:28 +02:00
parent 2e0c35e6e4
commit 92edb996f2
2 changed files with 12 additions and 13 deletions

View File

@@ -544,15 +544,13 @@ namespace FlaxEditor.Surface.Elements
public override void OnMouseLeave()
{
if (_originalTooltipText != null)
{
TooltipText = _originalTooltipText;
}
if (_isMouseDown)
{
_isMouseDown = false;
if (Surface.CanEdit)
{
if (Input.GetKey(KeyboardKeys.Control))
if (IsOutput && Input.GetKey(KeyboardKeys.Control))
{
List<Box> connectedBoxes = new List<Box>(Connections);
@@ -564,25 +562,21 @@ namespace FlaxEditor.Surface.Elements
}
else if (!IsOutput && HasSingleConnection)
{
var connectedBox = Connections[0];
var otherBox = Connections[0];
if (Surface.Undo != null && Surface.Undo.Enabled)
{
var action = new ConnectBoxesAction((InputBox)this, (OutputBox)connectedBox, false);
BreakConnection(connectedBox);
var action = new ConnectBoxesAction((InputBox)this, (OutputBox)otherBox, false);
BreakConnection(otherBox);
action.End();
Surface.AddBatchedUndoAction(action);
Surface.MarkAsEdited();
}
else
{
BreakConnection(connectedBox);
}
Surface.ConnectingStart(connectedBox);
BreakConnection(otherBox);
Surface.ConnectingStart(otherBox);
}
else
{
Surface.ConnectingStart(this);
}
}
}
base.OnMouseLeave();

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using FlaxEditor.Scripting;
using FlaxEditor.Surface.Elements;
using FlaxEngine;
namespace FlaxEditor.Surface
@@ -269,11 +270,15 @@ namespace FlaxEditor.Surface
List<IConnectionInstigator> instigators = new List<IConnectionInstigator>(_connectionInstigators);
for (int i = 0; i < instigators.Count; i++)
{
var start = _connectionInstigators[i];
var start = instigators[i];
// Check if boxes are different and end box is specified
if (start == end || end == null)
return;
// Properly handle connecting to a socket that already has a connection
if (end is Box e && !e.IsOutput && start is Box s && e.AreConnected(s))
e.BreakConnection(s);
// Connect them
if (start.CanConnectWith(end))