v1.4.4.1 (Blood in the Water Update)
This commit is contained in:
+70
-5
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
@@ -15,7 +16,17 @@ namespace Barotrauma
|
||||
/// </summary>
|
||||
internal sealed class CircuitBoxMouseDragSnapshotHandler
|
||||
{
|
||||
public IEnumerable<CircuitBoxNode> Nodes => circuitBoxUi.CircuitBox.Components.Union<CircuitBoxNode>(circuitBoxUi.CircuitBox.InputOutputNodes);
|
||||
public IEnumerable<CircuitBoxNode> Nodes
|
||||
{
|
||||
get
|
||||
{
|
||||
var cb = circuitBoxUi.CircuitBox;
|
||||
|
||||
foreach (var label in cb.Labels) { yield return label; }
|
||||
foreach (var component in cb.Components) { yield return component; }
|
||||
foreach (var node in cb.InputOutputNodes) { yield return node; }
|
||||
}
|
||||
}
|
||||
|
||||
private IReadOnlyList<CircuitBoxWire> Wires => circuitBoxUi.CircuitBox.Wires;
|
||||
|
||||
@@ -29,6 +40,8 @@ namespace Barotrauma
|
||||
// Nodes that should be moved when dragging
|
||||
moveAffectedComponents = ImmutableHashSet<CircuitBoxNode>.Empty;
|
||||
|
||||
public Option<(CircuitBoxResizeDirection, CircuitBoxNode)> LastResizeAffectedNode = Option.None;
|
||||
|
||||
public ImmutableHashSet<CircuitBoxNode> GetLastComponentsUnderCursor() => lastNodesUnderCursor;
|
||||
public ImmutableHashSet<CircuitBoxNode> GetMoveAffectedComponents() => moveAffectedComponents;
|
||||
|
||||
@@ -45,6 +58,11 @@ namespace Barotrauma
|
||||
/// </summary>
|
||||
public bool IsWiring { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// If the user grabbed a side of a node and is resizing a node
|
||||
/// </summary>
|
||||
public bool IsResizing { get; private set; }
|
||||
|
||||
private Vector2 startClick = Vector2.Zero;
|
||||
private readonly CircuitBoxUI circuitBoxUi;
|
||||
|
||||
@@ -147,6 +165,41 @@ namespace Barotrauma
|
||||
lastNodesUnderCursor = FindNodesUnderCursor(cursorPos);
|
||||
LastConnectorUnderCursor = FindConnectorUnderCursor(cursorPos);
|
||||
LastWireUnderCursor = FindWireUnderCursor(cursorPos);
|
||||
LastResizeAffectedNode = FindResizeBorderUnderCursor(lastNodesUnderCursor, cursorPos);
|
||||
}
|
||||
|
||||
private static Option<(CircuitBoxResizeDirection, CircuitBoxNode)> FindResizeBorderUnderCursor(ImmutableHashSet<CircuitBoxNode> nodes, Vector2 cursorPos)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (!node.IsResizable) { continue; }
|
||||
|
||||
const float borderSize = 32f;
|
||||
|
||||
var rect = node.Rect;
|
||||
RectangleF bottomBorder = new(rect.X, rect.Top, rect.Width, borderSize);
|
||||
RectangleF rightBorder = new(rect.Right - borderSize, rect.Y, borderSize, rect.Height);
|
||||
RectangleF leftBorder = new(rect.X, rect.Y, borderSize, rect.Height);
|
||||
|
||||
bool hoverBottom = bottomBorder.Contains(cursorPos),
|
||||
hoverRight = rightBorder.Contains(cursorPos),
|
||||
hoverLeft = leftBorder.Contains(cursorPos);
|
||||
|
||||
var dir = CircuitBoxResizeDirection.None;
|
||||
|
||||
if (hoverBottom) { dir |= CircuitBoxResizeDirection.Down; }
|
||||
if (hoverRight) { dir |= CircuitBoxResizeDirection.Right; }
|
||||
if (hoverLeft) { dir |= CircuitBoxResizeDirection.Left; }
|
||||
|
||||
if (dir is CircuitBoxResizeDirection.None)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return Option.Some((dir, node));
|
||||
}
|
||||
|
||||
return Option.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,6 +246,7 @@ namespace Barotrauma
|
||||
startClick = Vector2.Zero;
|
||||
IsDragging = false;
|
||||
IsWiring = false;
|
||||
IsResizing = false;
|
||||
lastNodesUnderCursor = ImmutableHashSet<CircuitBoxNode>.Empty;
|
||||
}
|
||||
|
||||
@@ -210,23 +264,34 @@ namespace Barotrauma
|
||||
IsDragging = false;
|
||||
}
|
||||
|
||||
if (LastResizeAffectedNode.IsNone())
|
||||
{
|
||||
IsResizing = false;
|
||||
}
|
||||
|
||||
// startClick is set to zero when the user releases the mouse button, so we should be neither dragging nor wiring in this state
|
||||
if (startClick == Vector2.Zero)
|
||||
{
|
||||
IsDragging = false;
|
||||
IsWiring = false;
|
||||
IsResizing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
bool isDragTresholdExceeded = Vector2.DistanceSquared(startClick, cursorPos) > dragTreshold * dragTreshold;
|
||||
if (circuitBoxUi.Locked) { return; }
|
||||
bool isDragThresholdExceeded = Vector2.DistanceSquared(startClick, cursorPos) > dragTreshold * dragTreshold;
|
||||
|
||||
if (LastConnectorUnderCursor.IsNone())
|
||||
if (LastResizeAffectedNode.IsSome())
|
||||
{
|
||||
IsDragging |= isDragTresholdExceeded;
|
||||
IsResizing |= isDragThresholdExceeded;
|
||||
}
|
||||
else if (LastConnectorUnderCursor.IsSome())
|
||||
{
|
||||
IsWiring |= isDragThresholdExceeded;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsWiring |= isDragTresholdExceeded;
|
||||
IsDragging |= isDragThresholdExceeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user