Cherry-picked 869b725 from dev

This commit is contained in:
Joonas Rikkonen
2018-07-13 13:15:14 +03:00
parent 982f1ba6f1
commit e0455caaaa
3 changed files with 36 additions and 7 deletions

View File

@@ -81,6 +81,14 @@ namespace Barotrauma.Items.Components
if (IsActive && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
Submarine sub = null;
if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine;
if (connections[1] != null && connections[1].Item.Submarine != null) sub = connections[1].Item.Submarine;
if (sub != null)
{
drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
}
WireSection.Draw(
spriteBatch,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,

View File

@@ -1,4 +1,5 @@
using Barotrauma.Networking;
using FarseerPhysics;
using Lidgren.Network;
using System;
using System.Collections.Generic;

View File

@@ -35,6 +35,7 @@ namespace Barotrauma.Items.Components
private Connection[] connections;
private bool canPlaceNode;
private Vector2 newNodePos;
public bool Hidden, Locked;
@@ -158,13 +159,14 @@ namespace Barotrauma.Items.Components
ic.Drop(null);
}
if (item.Container != null) item.Container.RemoveContained(this.item);
if (item.body != null) item.body.Enabled = false;
IsActive = false;
CleanNodes();
}
if (item.body != null) item.Submarine = newConnection.Item.Submarine;
if (sendNetworkEvent)
{
@@ -211,13 +213,31 @@ namespace Barotrauma.Items.Components
if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine;
if (connections[1] != null && connections[1].Item.Submarine != null) sub = connections[1].Item.Submarine;
if ((item.Submarine != sub || sub == null) && Screen.Selected != GameMain.SubEditorScreen)
if (Screen.Selected != GameMain.SubEditorScreen)
{
ClearConnections();
return;
}
//cannot run wires from sub to another
if (sub == null || (item.Submarine != sub && sub != null && item.Submarine != null))
{
ClearConnections();
return;
}
newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition;
if (item.CurrentHull == null)
{
newNodePos = item.WorldPosition - sub.Position - sub.HiddenSubPosition;
canPlaceNode = false;
}
else
{
newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition;
canPlaceNode = true;
}
}
else
{
newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition;
canPlaceNode = true;
}
}
public override bool Use(float deltaTime, Character character = null)
@@ -225,7 +245,7 @@ namespace Barotrauma.Items.Components
if (character == null) return false;
if (character == Character.Controlled && character.SelectedConstruction != null) return false;
if (newNodePos != Vector2.Zero && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
if (newNodePos != Vector2.Zero && canPlaceNode && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
nodes.Add(newNodePos);
UpdateSections();