v1.4.4.1 (Blood in the Water Update)

This commit is contained in:
Regalis11
2024-04-24 18:09:05 +03:00
parent 89b91d1c3e
commit ff1b8951a7
397 changed files with 15250 additions and 6479 deletions
@@ -0,0 +1,83 @@
#nullable enable
using System.Xml.Linq;
using Barotrauma.Items.Components;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
internal sealed partial class CircuitBoxLabelNode : CircuitBoxNode, ICircuitBoxIdentifiable
{
public Color Color;
public ushort ID { get; }
public override bool IsResizable => true;
public static NetLimitedString DefaultHeaderText => new("label");
public NetLimitedString BodyText = NetLimitedString.Empty;
public NetLimitedString HeaderText = DefaultHeaderText;
public static Vector2 MinSize = new(128, 8);
public CircuitBoxLabelNode(ushort id, Color color, Vector2 pos, CircuitBox circuitBox) : base(circuitBox)
{
Size = new Vector2(256);
Position = pos;
ID = id;
Color = color;
UpdatePositions();
#if CLIENT
bodyLabel = new GUITextBlock(new RectTransform(Point.Zero), text: string.Empty, font: GUIStyle.Font, textAlignment: Alignment.TopLeft, wrap: true);
headerLabel = new CircuitBoxLabel(HeaderText.Value, GUIStyle.LargeFont);
UpdateDrawRects();
UpdateTextSizes(DrawRect);
#endif
}
public void EditText(NetLimitedString header, NetLimitedString body)
{
HeaderText = header;
BodyText = body;
#if CLIENT
UpdateTextSizes(DrawRect);
#endif
}
public XElement Save()
{
var element = new XElement("Label",
new XAttribute("id", ID),
new XAttribute("color", Color.ToStringHex()),
new XAttribute("position", XMLExtensions.Vector2ToString(Position)),
new XAttribute("size", XMLExtensions.Vector2ToString(Size)),
new XAttribute("header", HeaderText),
new XAttribute("body", BodyText));
return element;
}
public static CircuitBoxLabelNode LoadFromXML(ContentXElement element, CircuitBox circuitBox)
{
ushort id = element.GetAttributeUInt16("id", ICircuitBoxIdentifiable.NullComponentID);
Vector2 position = element.GetAttributeVector2("position", Vector2.Zero);
Vector2 size = element.GetAttributeVector2("size", Vector2.Zero);
Color color = element.GetAttributeColor("color", Color.White);
string header = element.GetAttributeString("header", string.Empty);
string body = element.GetAttributeString("body", string.Empty);
var labelNode = new CircuitBoxLabelNode(id, color, position, circuitBox)
{
Size = size,
HeaderText = new NetLimitedString(header),
BodyText = new NetLimitedString(body)
};
// proc a edit to force the sizes to be updated
labelNode.EditText(new NetLimitedString(header), new NetLimitedString(body));
labelNode.UpdatePositions();
#if CLIENT
labelNode.UpdateTextSizes(labelNode.Rect);
#endif
return labelNode;
}
}
}
@@ -8,6 +8,19 @@ using Microsoft.Xna.Framework;
namespace Barotrauma
{
[Flags]
internal enum CircuitBoxResizeDirection
{
None = 0,
Down = 1,
Right = 2,
Left = 4
}
// TODO this needs to be refactored at some point for reasons:
// 1. We need to send 4 different ImmutableArray<short> for some network packets
// 2. We have 3 identical remove events that are identical in signature
// 3. We have 3 different events for selecting. nodes, wires, and server broadcast
public enum CircuitBoxOpcode
{
Error,
@@ -20,6 +33,10 @@ namespace Barotrauma
SelectWires,
UpdateSelection,
DeleteComponent,
RenameLabel,
AddLabel,
RemoveLabel,
ResizeLabel,
ServerInitialize
}
@@ -88,6 +105,18 @@ namespace Barotrauma
=> $"{{Name: {SignalConnection}, ID: {(TargetId.TryUnwrap(out var value) ? value.ToString() : "N/A")}}}";
}
[NetworkSerialize]
internal readonly record struct CircuitBoxAddLabelEvent(Vector2 Position, Color Color, NetLimitedString Header, NetLimitedString Body) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxServerAddLabelEvent(ushort ID, Vector2 Position, Vector2 Size, Color Color, NetLimitedString Header, NetLimitedString Body) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxResizeLabelEvent(ushort ID, Vector2 Position, Vector2 Size) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxRemoveLabelEvent(ImmutableArray<ushort> TargetIDs) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxAddComponentEvent(UInt32 PrefabIdentifier, Vector2 Position) : INetSerializableStruct;
@@ -98,13 +127,13 @@ namespace Barotrauma
internal readonly record struct CircuitBoxRemoveComponentEvent(ImmutableArray<ushort> TargetIDs) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxMoveComponentEvent(ImmutableArray<ushort> TargetIDs, ImmutableArray<CircuitBoxInputOutputNode.Type> IOs, Vector2 MoveAmount) : INetSerializableStruct;
internal readonly record struct CircuitBoxMoveComponentEvent(ImmutableArray<ushort> TargetIDs, ImmutableArray<CircuitBoxInputOutputNode.Type> IOs, ImmutableArray<ushort> LabelIDs, Vector2 MoveAmount) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxSelectNodesEvent(ImmutableArray<ushort> TargetIDs, ImmutableArray<CircuitBoxInputOutputNode.Type> IOs, bool Overwrite, ushort CharacterID) : INetSerializableStruct;
internal readonly record struct CircuitBoxSelectNodesEvent(ImmutableArray<ushort> TargetIDs, ImmutableArray<CircuitBoxInputOutputNode.Type> IOs, ImmutableArray<ushort> LabelIDs, bool Overwrite, ushort CharacterID) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxServerUpdateSelection(ImmutableArray<CircuitBoxIdSelectionPair> ComponentIds, ImmutableArray<CircuitBoxIdSelectionPair> WireIds, ImmutableArray<CircuitBoxTypeSelectionPair> InputOutputs) : INetSerializableStruct;
internal readonly record struct CircuitBoxServerUpdateSelection(ImmutableArray<CircuitBoxIdSelectionPair> ComponentIds, ImmutableArray<CircuitBoxIdSelectionPair> WireIds, ImmutableArray<CircuitBoxTypeSelectionPair> InputOutputs, ImmutableArray<CircuitBoxIdSelectionPair> LabelIds) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxIdSelectionPair(ushort ID, Option<ushort> SelectedBy) : INetSerializableStruct;
@@ -124,6 +153,9 @@ namespace Barotrauma
[NetworkSerialize]
internal readonly record struct CircuitBoxRemoveWireEvent(ImmutableArray<ushort> TargetIDs) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxRenameLabelEvent(ushort LabelId, Color Color, NetLimitedString NewHeader, NetLimitedString NewBody) : INetSerializableStruct;
[NetworkSerialize]
internal readonly record struct CircuitBoxErrorEvent(string Message) : INetSerializableStruct;
@@ -131,6 +163,7 @@ namespace Barotrauma
internal readonly record struct CircuitBoxInitializeStateFromServerEvent(
ImmutableArray<CircuitBoxServerCreateComponentEvent> Components,
ImmutableArray<CircuitBoxServerCreateWireEvent> Wires,
ImmutableArray<CircuitBoxServerAddLabelEvent> Labels,
Vector2 InputPos,
Vector2 OutputPos) : INetSerializableStruct;
@@ -157,6 +190,14 @@ namespace Barotrauma
=> CircuitBoxOpcode.RemoveWire,
CircuitBoxInitializeStateFromServerEvent
=> CircuitBoxOpcode.ServerInitialize,
CircuitBoxRenameLabelEvent
=> CircuitBoxOpcode.RenameLabel,
(CircuitBoxAddLabelEvent or CircuitBoxServerAddLabelEvent)
=> CircuitBoxOpcode.AddLabel,
CircuitBoxRemoveLabelEvent
=> CircuitBoxOpcode.RemoveLabel,
CircuitBoxResizeLabelEvent
=> CircuitBoxOpcode.ResizeLabel,
_ => throw new ArgumentOutOfRangeException(nameof(Data))
};
}
@@ -14,6 +14,8 @@ namespace Barotrauma
public RectangleF Rect;
private Vector2 position;
public virtual bool IsResizable => false;
public Vector2 Position
{
get => position;
@@ -22,12 +24,12 @@ namespace Barotrauma
const float clampSize = CircuitBoxSizes.PlayableAreaSize / 2f;
position = new Vector2(Math.Clamp(value.X, -clampSize, clampSize),
Math.Clamp(value.Y, -clampSize, clampSize));
Math.Clamp(value.Y, -clampSize, clampSize));
UpdatePositions();
}
}
public ImmutableArray<CircuitBoxConnection> Connectors;
public ImmutableArray<CircuitBoxConnection> Connectors = ImmutableArray<CircuitBoxConnection>.Empty;
public static float Opacity = 0.8f;
@@ -38,6 +40,47 @@ namespace Barotrauma
CircuitBox = circuitBox;
}
public (Vector2 Size, Vector2 Pos) ResizeBy(CircuitBoxResizeDirection directions, Vector2 amount)
{
Vector2 newSize = Size;
Vector2 newPos = Position;
amount.Y = -amount.Y;
if (directions.HasFlag(CircuitBoxResizeDirection.Down))
{
newSize.Y += amount.Y;
newSize.Y = Math.Max(newSize.Y, CircuitBoxLabelNode.MinSize.Y);
newPos = new Vector2(newPos.X, newPos.Y - (newSize.Y - Size.Y) / 2f);
}
if (directions.HasFlag(CircuitBoxResizeDirection.Right))
{
newSize.X += amount.X;
newSize.X = Math.Max(newSize.X, CircuitBoxLabelNode.MinSize.X);
newPos = new Vector2(newPos.X + (newSize.X - Size.X) / 2f, newPos.Y);
}
if (directions.HasFlag(CircuitBoxResizeDirection.Left))
{
newSize.X -= amount.X;
newSize.X = Math.Max(newSize.X, CircuitBoxLabelNode.MinSize.X);
newPos = new Vector2(newPos.X + (Size.X - newSize.X) / 2f, newPos.Y);
}
return (newSize, newPos);
}
public void ApplyResize(Vector2 newSize, Vector2 newPos)
{
if (!MathUtils.IsValid(newSize)) { return; }
Size = newSize;
Position = newPos;
UpdatePositions();
#if CLIENT
OnResized(DrawRect);
#endif
}
public static Vector2 CalculateSize(IReadOnlyList<CircuitBoxConnection> conns)
{
Vector2 leftSize = Vector2.Zero,
@@ -11,6 +11,7 @@ namespace Barotrauma
public const int WireWidth = 10;
public const int WireKnobLength = 16;
public const int NodeHeaderTextPadding = 8;
public const int NodeBodyTextPadding = 8;
public const float PlayableAreaSize = 8192f;
}
@@ -148,8 +148,14 @@ namespace Barotrauma
}
case CircuitBoxNodeConnection node when two is CircuitBoxInputConnection input:
{
if (node.ExternallyConnectedFrom.Contains(input)) { break; }
node.ExternallyConnectedFrom.Add(input);
if (!node.Connection.CircuitBoxConnections.Contains(input))
{
node.Connection.CircuitBoxConnections.Add(input);
}
if (!node.ExternallyConnectedFrom.Contains(input))
{
node.ExternallyConnectedFrom.Add(input);
}
break;
}
}