v1.5.7.0 (Summer Update)
This commit is contained in:
@@ -71,9 +71,9 @@ namespace Barotrauma
|
||||
|
||||
private Vector2 position;
|
||||
|
||||
public List<CircuitBoxConnection> ExternallyConnectedFrom = new();
|
||||
public readonly List<CircuitBoxConnection> ExternallyConnectedFrom = new();
|
||||
|
||||
public static float Size = CircuitBoxSizes.ConnectorSize;
|
||||
public static readonly float Size = CircuitBoxSizes.ConnectorSize;
|
||||
|
||||
public Vector2 Position
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
@@ -8,7 +8,7 @@ using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
internal sealed class CircuitBoxInputOutputNode : CircuitBoxNode
|
||||
internal sealed partial class CircuitBoxInputOutputNode : CircuitBoxNode
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
@@ -17,22 +17,104 @@ namespace Barotrauma
|
||||
Output
|
||||
}
|
||||
|
||||
public Type NodeType;
|
||||
public readonly Type NodeType;
|
||||
|
||||
private const int MaxConnectionLabelLength = 32;
|
||||
private const string ConnectionLabelOverrideElementName = "ConnectionLabelOverride";
|
||||
|
||||
public Dictionary<string, string> ConnectionLabelOverrides = new();
|
||||
|
||||
public CircuitBoxInputOutputNode(IReadOnlyList<CircuitBoxConnection> conns, Vector2 initialPosition, Type type, CircuitBox circuitBox): base(circuitBox)
|
||||
{
|
||||
Size = CalculateSize(conns);
|
||||
InitSize(conns);
|
||||
Connectors = conns.ToImmutableArray();
|
||||
Position = initialPosition;
|
||||
NodeType = type;
|
||||
UpdatePositions();
|
||||
}
|
||||
|
||||
public XElement Save() => new XElement($"{NodeType}Node", new XAttribute("pos", XMLExtensions.Vector2ToString(Position)));
|
||||
public void ReplaceAllConnectionLabelOverrides(Dictionary<string, string> replace)
|
||||
{
|
||||
foreach (var (_, value) in replace)
|
||||
{
|
||||
if (value.Length > MaxConnectionLabelLength)
|
||||
{
|
||||
DebugConsole.ThrowError($"Label override value \"{value}\" is too long (max {MaxConnectionLabelLength} characters)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (name, value) in replace)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
ConnectionLabelOverrides.Remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectionLabelOverrides[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
InitSize(Connectors);
|
||||
UpdatePositions();
|
||||
}
|
||||
|
||||
private void InitSize(IReadOnlyList<CircuitBoxConnection> conns)
|
||||
{
|
||||
#if CLIENT
|
||||
foreach (CircuitBoxConnection conn in conns)
|
||||
{
|
||||
if (ConnectionLabelOverrides.TryGetValue(conn.Name, out string? value))
|
||||
{
|
||||
LocalizedString newLabel =
|
||||
string.IsNullOrWhiteSpace(value)
|
||||
? conn.Connection.DisplayName
|
||||
: TextManager.Get(value).Fallback(value);
|
||||
|
||||
conn.SetLabel(newLabel, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
conn.SetLabel(conn.Connection.DisplayName, this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Size = CalculateSize(conns);
|
||||
}
|
||||
|
||||
public XElement Save()
|
||||
{
|
||||
XElement element = new XElement($"{NodeType}Node", new XAttribute("pos", XMLExtensions.Vector2ToString(Position)));
|
||||
|
||||
foreach (var (name, value) in ConnectionLabelOverrides)
|
||||
{
|
||||
element.Add(new XElement(ConnectionLabelOverrideElementName,
|
||||
new XAttribute("name", name),
|
||||
new XAttribute("value", value)));
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void Load(ContentXElement element)
|
||||
{
|
||||
Position = element.GetAttributeVector2("pos", Vector2.Zero);
|
||||
|
||||
Dictionary<string, string> loadedOverrides = new();
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name != ConnectionLabelOverrideElementName) { continue; }
|
||||
|
||||
string name = subElement.GetAttributeString("name", string.Empty);
|
||||
string value = subElement.GetAttributeString("value", string.Empty);
|
||||
|
||||
loadedOverrides[name] = value;
|
||||
}
|
||||
|
||||
ConnectionLabelOverrides = loadedOverrides;
|
||||
InitSize(Connectors);
|
||||
UpdatePositions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ namespace Barotrauma
|
||||
AddLabel,
|
||||
RemoveLabel,
|
||||
ResizeLabel,
|
||||
RenameConnections,
|
||||
ServerInitialize
|
||||
}
|
||||
|
||||
@@ -156,6 +157,10 @@ namespace Barotrauma
|
||||
[NetworkSerialize]
|
||||
internal readonly record struct CircuitBoxRenameLabelEvent(ushort LabelId, Color Color, NetLimitedString NewHeader, NetLimitedString NewBody) : INetSerializableStruct;
|
||||
|
||||
[NetworkSerialize]
|
||||
internal readonly record struct CircuitBoxRenameConnectionLabelsEvent(CircuitBoxInputOutputNode.Type Type, NetDictionary<string, string> Override) : INetSerializableStruct;
|
||||
|
||||
|
||||
[NetworkSerialize]
|
||||
internal readonly record struct CircuitBoxErrorEvent(string Message) : INetSerializableStruct;
|
||||
|
||||
@@ -164,6 +169,7 @@ namespace Barotrauma
|
||||
ImmutableArray<CircuitBoxServerCreateComponentEvent> Components,
|
||||
ImmutableArray<CircuitBoxServerCreateWireEvent> Wires,
|
||||
ImmutableArray<CircuitBoxServerAddLabelEvent> Labels,
|
||||
ImmutableArray<CircuitBoxRenameConnectionLabelsEvent> LabelOverrides,
|
||||
Vector2 InputPos,
|
||||
Vector2 OutputPos) : INetSerializableStruct;
|
||||
|
||||
@@ -198,6 +204,8 @@ namespace Barotrauma
|
||||
=> CircuitBoxOpcode.RemoveLabel,
|
||||
CircuitBoxResizeLabelEvent
|
||||
=> CircuitBoxOpcode.ResizeLabel,
|
||||
CircuitBoxRenameConnectionLabelsEvent
|
||||
=> CircuitBoxOpcode.RenameConnections,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(Data))
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user