Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests
This commit is contained in:
@@ -17,7 +17,7 @@ namespace Barotrauma.Items.Components
|
||||
public readonly int MaxWires = 5;
|
||||
|
||||
public readonly string Name;
|
||||
public readonly string DisplayName;
|
||||
public readonly LocalizedString DisplayName;
|
||||
|
||||
private readonly Wire[] wires;
|
||||
public IEnumerable<Wire> Wires
|
||||
@@ -33,6 +33,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public readonly ushort[] wireId;
|
||||
|
||||
//The grid the connection is a part of
|
||||
public GridInfo Grid;
|
||||
|
||||
//Priority in which power output will be handled - load is unaffected
|
||||
public PowerPriority Priority = PowerPriority.Default;
|
||||
|
||||
public bool IsPower
|
||||
{
|
||||
get;
|
||||
@@ -40,7 +46,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
private bool recipientsDirty = true;
|
||||
private List<Connection> recipients = new List<Connection>();
|
||||
private readonly List<Connection> recipients = new List<Connection>();
|
||||
public List<Connection> Recipients
|
||||
{
|
||||
get
|
||||
@@ -66,17 +72,17 @@ namespace Barotrauma.Items.Components
|
||||
return "Connection (" + item.Name + ", " + Name + ")";
|
||||
}
|
||||
|
||||
public Connection(XElement element, ConnectionPanel connectionPanel, IdRemap idRemap)
|
||||
public Connection(ContentXElement element, ConnectionPanel connectionPanel, IdRemap idRemap)
|
||||
{
|
||||
|
||||
#if CLIENT
|
||||
if (connector == null)
|
||||
{
|
||||
connector = GUI.Style.GetComponentStyle("ConnectionPanelConnector").GetDefaultSprite();
|
||||
wireVertical = GUI.Style.GetComponentStyle("ConnectionPanelWire").GetDefaultSprite();
|
||||
connectionSprite = GUI.Style.GetComponentStyle("ConnectionPanelConnection").GetDefaultSprite();
|
||||
connectionSpriteHighlight = GUI.Style.GetComponentStyle("ConnectionPanelConnection").GetSprite(GUIComponent.ComponentState.Hover);
|
||||
screwSprites = GUI.Style.GetComponentStyle("ConnectionPanelScrew").Sprites[GUIComponent.ComponentState.None].Select(s => s.Sprite).ToList();
|
||||
connector = GUIStyle.GetComponentStyle("ConnectionPanelConnector").GetDefaultSprite();
|
||||
wireVertical = GUIStyle.GetComponentStyle("ConnectionPanelWire").GetDefaultSprite();
|
||||
connectionSprite = GUIStyle.GetComponentStyle("ConnectionPanelConnection").GetDefaultSprite();
|
||||
connectionSpriteHighlight = GUIStyle.GetComponentStyle("ConnectionPanelConnection").GetSprite(GUIComponent.ComponentState.Hover);
|
||||
screwSprites = GUIStyle.GetComponentStyle("ConnectionPanelScrew").Sprites[GUIComponent.ComponentState.None].Select(s => s.Sprite).ToList();
|
||||
}
|
||||
#endif
|
||||
ConnectionPanel = connectionPanel;
|
||||
@@ -93,9 +99,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
string displayNameTag = "", fallbackTag = "";
|
||||
//if displayname is not present, attempt to find it from the prefab
|
||||
if (element.Attribute("displayname") == null)
|
||||
if (element.GetAttribute("displayname") == null)
|
||||
{
|
||||
foreach (XElement subElement in item.Prefab.ConfigElement.Elements())
|
||||
foreach (var subElement in item.Prefab.ConfigElement.Elements())
|
||||
{
|
||||
if (!subElement.Name.ToString().Equals("connectionpanel", StringComparison.OrdinalIgnoreCase)) { continue; }
|
||||
|
||||
@@ -132,7 +138,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(DisplayName))
|
||||
if (DisplayName.IsNullOrEmpty())
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Missing display name in connection " + item.Name + ": " + Name);
|
||||
@@ -145,7 +151,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
wireId = new ushort[MaxWires];
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
@@ -236,6 +242,34 @@ namespace Barotrauma.Items.Components
|
||||
var otherConnection = previousWire.OtherConnection(this);
|
||||
if (otherConnection != null)
|
||||
{
|
||||
//Change the connection grids or flag them for updating
|
||||
if (IsPower && otherConnection.IsPower && Grid != null)
|
||||
{
|
||||
//Check if both connections belong to a larger grid
|
||||
if (otherConnection.recipients.Count > 1 && recipients.Count > 1)
|
||||
{
|
||||
Powered.ChangedConnections.Add(otherConnection);
|
||||
Powered.ChangedConnections.Add(this);
|
||||
}
|
||||
else if (recipients.Count > 1)
|
||||
{
|
||||
//This wire was the only one at the other grid
|
||||
otherConnection.Grid?.RemoveConnection(otherConnection);
|
||||
otherConnection.Grid = null;
|
||||
}
|
||||
else if (otherConnection.recipients.Count > 1)
|
||||
{
|
||||
Grid?.RemoveConnection(this);
|
||||
Grid = null;
|
||||
}
|
||||
else if (Grid.Connections.Count == 2)
|
||||
{
|
||||
//Delete the grid as these were the only 2 devices
|
||||
Powered.Grids.Remove(Grid.ID);
|
||||
Grid = null;
|
||||
otherConnection.Grid = null;
|
||||
}
|
||||
}
|
||||
otherConnection.recipientsDirty = true;
|
||||
}
|
||||
}
|
||||
@@ -244,10 +278,32 @@ namespace Barotrauma.Items.Components
|
||||
recipientsDirty = true;
|
||||
if (wire != null)
|
||||
{
|
||||
|
||||
ConnectionPanel.DisconnectedWires.Remove(wire);
|
||||
var otherConnection = wire.OtherConnection(this);
|
||||
if (otherConnection != null)
|
||||
{
|
||||
//Set the other connection grid if a grid exists already
|
||||
if (Powered.ValidPowerConnection(this, otherConnection))
|
||||
{
|
||||
if (Grid == null && otherConnection.Grid != null)
|
||||
{
|
||||
otherConnection.Grid.AddConnection(this);
|
||||
Grid = otherConnection.Grid;
|
||||
}
|
||||
else if (Grid != null && otherConnection.Grid == null)
|
||||
{
|
||||
Grid.AddConnection(otherConnection);
|
||||
otherConnection.Grid = Grid;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Flag change so that proper grids can be formed
|
||||
Powered.ChangedConnections.Add(this);
|
||||
Powered.ChangedConnections.Add(otherConnection);
|
||||
}
|
||||
}
|
||||
|
||||
otherConnection.recipientsDirty = true;
|
||||
}
|
||||
}
|
||||
@@ -286,20 +342,17 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void SendPowerProbeSignal(Item source, float power)
|
||||
{
|
||||
for (int i = 0; i < MaxWires; i++)
|
||||
{
|
||||
if (wires[i] == null) { continue; }
|
||||
|
||||
Connection recipient = wires[i].OtherConnection(this);
|
||||
if (recipient == null || !recipient.IsPower) { continue; }
|
||||
|
||||
recipient.item.GetComponent<Powered>()?.ReceivePowerProbeSignal(recipient, source, power);
|
||||
}
|
||||
}
|
||||
public void ClearConnections()
|
||||
{
|
||||
if (IsPower && Grid != null)
|
||||
{
|
||||
Powered.ChangedConnections.Add(this);
|
||||
foreach (Connection c in recipients)
|
||||
{
|
||||
Powered.ChangedConnections.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MaxWires; i++)
|
||||
{
|
||||
if (wires[i] == null) continue;
|
||||
|
||||
Reference in New Issue
Block a user