Merge branch 'master' into new-netcode
Conflicts: Subsurface/Properties/AssemblyInfo.cs Subsurface/Source/Items/Components/DockingPort.cs Subsurface/Source/Items/Components/Signal/Wire.cs Subsurface/Source/Items/Item.cs
This commit is contained in:
@@ -44,6 +44,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private bool docked;
|
||||
|
||||
public int DockingDir
|
||||
{
|
||||
get { return dockingDir; }
|
||||
set { dockingDir = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue("32.0,32.0", false)]
|
||||
public string DistanceTolerance
|
||||
{
|
||||
@@ -150,7 +156,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (target.item.Submarine == item.Submarine)
|
||||
{
|
||||
DebugConsole.ThrowError("Error - tried to a submarine to itself");
|
||||
DebugConsole.ThrowError("Error - tried to dock a submarine to itself");
|
||||
dockingTarget = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -176,8 +183,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
dockingDir = IsHorizontal ?
|
||||
Math.Sign(dockingTarget.item.WorldPosition.X - item.WorldPosition.X) :
|
||||
Math.Sign(item.WorldPosition.Y - dockingTarget.item.WorldPosition.Y);
|
||||
Math.Sign(dockingTarget.item.WorldPosition.Y - item.WorldPosition.Y);
|
||||
dockingTarget.dockingDir = -dockingDir;
|
||||
|
||||
|
||||
foreach (WayPoint wp in WayPoint.WayPointList)
|
||||
{
|
||||
@@ -199,12 +207,46 @@ namespace Barotrauma.Items.Components
|
||||
CreateJoint(false);
|
||||
}
|
||||
|
||||
public void Lock()
|
||||
{
|
||||
if (dockingTarget==null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error - attempted to lock a docking port that's not connected to anything");
|
||||
return;
|
||||
}
|
||||
else if (joint is WeldJoint)
|
||||
{
|
||||
DebugConsole.ThrowError("Error - attempted to lock a docking port that's already locked");
|
||||
return;
|
||||
}
|
||||
|
||||
dockingDir = IsHorizontal ?
|
||||
Math.Sign(dockingTarget.item.WorldPosition.X - item.WorldPosition.X) :
|
||||
Math.Sign(dockingTarget.item.WorldPosition.Y - item.WorldPosition.Y);
|
||||
dockingTarget.dockingDir = -dockingDir;
|
||||
|
||||
GameMain.World.RemoveJoint(joint);
|
||||
|
||||
PlaySound(ActionType.OnSecondaryUse, item.WorldPosition);
|
||||
|
||||
ConnectWireBetweenPorts();
|
||||
|
||||
CreateJoint(true);
|
||||
|
||||
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
|
||||
{
|
||||
CreateHull();
|
||||
|
||||
//item.NewComponentEvent(this, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void CreateJoint(bool useWeldJoint)
|
||||
{
|
||||
Vector2 offset = (IsHorizontal ?
|
||||
Vector2.UnitX * Math.Sign(dockingTarget.item.WorldPosition.X - item.WorldPosition.X) :
|
||||
Vector2.UnitY * Math.Sign(dockingTarget.item.WorldPosition.Y - item.WorldPosition.Y));
|
||||
Vector2.UnitX * dockingDir :
|
||||
Vector2.UnitY * dockingDir);
|
||||
offset *= DockedDistance * 0.5f;
|
||||
|
||||
Vector2 pos1 = item.WorldPosition + offset;
|
||||
@@ -491,28 +533,18 @@ namespace Barotrauma.Items.Components
|
||||
if (!docked)
|
||||
{
|
||||
Dock(dockingTarget);
|
||||
if (dockingTarget == null) return;
|
||||
}
|
||||
|
||||
if (joint is DistanceJoint)
|
||||
{
|
||||
item.SendSignal(0, "0", "state_out");
|
||||
dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f);
|
||||
|
||||
if (Vector2.Distance(joint.WorldAnchorA, joint.WorldAnchorB) < 0.05f)
|
||||
{
|
||||
GameMain.World.RemoveJoint(joint);
|
||||
|
||||
PlaySound(ActionType.OnSecondaryUse, item.WorldPosition);
|
||||
|
||||
ConnectWireBetweenPorts();
|
||||
|
||||
CreateJoint(true);
|
||||
|
||||
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
|
||||
{
|
||||
CreateHull();
|
||||
}
|
||||
Lock();
|
||||
}
|
||||
dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -606,12 +638,14 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (!item.linkedTo.Any()) return;
|
||||
|
||||
foreach (MapEntity entity in item.linkedTo)
|
||||
List<MapEntity> linked = new List<MapEntity>(item.linkedTo);
|
||||
foreach (MapEntity entity in linked)
|
||||
{
|
||||
var hull = entity as Hull;
|
||||
if (hull != null)
|
||||
{
|
||||
hull.Remove();
|
||||
item.linkedTo.Remove(hull);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -619,6 +653,7 @@ namespace Barotrauma.Items.Components
|
||||
if (gap != null)
|
||||
{
|
||||
gap.Remove();
|
||||
gap.linkedTo.Remove(hull);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -626,10 +661,11 @@ namespace Barotrauma.Items.Components
|
||||
if (linkedItem == null) continue;
|
||||
|
||||
var dockingPort = linkedItem.GetComponent<DockingPort>();
|
||||
if (dockingPort != null) dockingTarget = dockingPort;
|
||||
if (dockingPort != null)
|
||||
{
|
||||
Dock(dockingPort);
|
||||
}
|
||||
}
|
||||
|
||||
item.linkedTo.Clear();
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power = 0.0f)
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Barotrauma.Items.Components
|
||||
Item targetItem;
|
||||
if ((targetStructure = (targetBody.UserData as Structure)) != null)
|
||||
{
|
||||
if (!fixableEntities.Contains(targetStructure.Name)) return;
|
||||
if (!fixableEntities.Contains("structure") && !fixableEntities.Contains(targetStructure.Name)) return;
|
||||
if (targetStructure.IsPlatform) return;
|
||||
|
||||
int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition));
|
||||
@@ -195,7 +195,7 @@ namespace Barotrauma.Items.Components
|
||||
1.0f - targetStructure.SectionDamage(sectionIndex) / targetStructure.Health,
|
||||
Color.Red, Color.Green);
|
||||
|
||||
progressBar.Size = new Vector2(60.0f, 20.0f);
|
||||
if (progressBar != null) progressBar.Size = new Vector2(60.0f, 20.0f);
|
||||
|
||||
targetStructure.AddDamage(sectionIndex, -StructureFixAmount * degreeOfSuccess);
|
||||
|
||||
|
||||
@@ -544,11 +544,28 @@ namespace Barotrauma.Items.Components
|
||||
RemoveComponentSpecific();
|
||||
}
|
||||
|
||||
protected virtual void RemoveComponentSpecific()
|
||||
/// <summary>
|
||||
/// Remove the component so that it doesn't appear to exist in the game world (stop sounds, remove bodies etc)
|
||||
/// but don't reset anything that's required for cloning the item
|
||||
/// </summary>
|
||||
public void ShallowRemove()
|
||||
{
|
||||
if (loopingSound != null)
|
||||
{
|
||||
Sounds.SoundManager.Stop(loopingSoundIndex);
|
||||
}
|
||||
|
||||
ShallowRemoveComponentSpecific();
|
||||
}
|
||||
|
||||
protected virtual void ShallowRemoveComponentSpecific()
|
||||
{
|
||||
RemoveComponentSpecific();
|
||||
}
|
||||
|
||||
protected virtual void RemoveComponentSpecific()
|
||||
{ }
|
||||
|
||||
public bool HasRequiredSkills(Character character)
|
||||
{
|
||||
Skill temp;
|
||||
|
||||
@@ -26,15 +26,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Direction dir;
|
||||
|
||||
//the x-position where the user walks to when using the controller
|
||||
private float userPos;
|
||||
//the position where the user walks to when using the controller
|
||||
//(relative to the position of the item)
|
||||
private Vector2 userPos;
|
||||
|
||||
private Camera cam;
|
||||
|
||||
private Character character;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float UserPos
|
||||
public Vector2 UserPos
|
||||
{
|
||||
get { return userPos; }
|
||||
set { userPos = value; }
|
||||
@@ -45,13 +45,16 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
limbPositions = new List<LimbPos>();
|
||||
|
||||
dir = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "direction", "None"), true);
|
||||
userPos = ToolBox.GetAttributeVector2(element, "UserPos", Vector2.Zero);
|
||||
|
||||
Enum.TryParse<Direction>(ToolBox.GetAttributeString(element, "direction", "None"), out dir);
|
||||
|
||||
foreach (XElement el in element.Elements())
|
||||
{
|
||||
if (el.Name != "limbposition") continue;
|
||||
|
||||
LimbPos lp = new LimbPos();
|
||||
|
||||
try
|
||||
{
|
||||
lp.limbType = (LimbType)Enum.Parse(typeof(LimbType), el.Attribute("limb").Value, true);
|
||||
@@ -90,23 +93,34 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
character.AnimController.Anim = AnimController.Animation.UsingConstruction;
|
||||
|
||||
if (userPos != 0.0f)
|
||||
if (userPos != Vector2.Zero)
|
||||
{
|
||||
float torsoX = character.Position.X;
|
||||
|
||||
Vector2 diff = new Vector2(item.Rect.X + UserPos - torsoX, 0.0f);
|
||||
Vector2 diff = (item.WorldPosition + userPos) - character.WorldPosition;
|
||||
|
||||
if (diff!= Vector2.Zero && diff.Length() > 10.0f)
|
||||
if (character.AnimController.InWater)
|
||||
{
|
||||
//character.AnimController.Anim = AnimController.Animation.None;
|
||||
|
||||
character.AnimController.TargetMovement = new Vector2(Math.Sign(diff.X), 0.0f);
|
||||
character.AnimController.TargetDir = (Math.Sign(diff.X) == 1) ? Direction.Right : Direction.Left;
|
||||
return;
|
||||
if (diff.Length() > 30.0f)
|
||||
{
|
||||
character.AnimController.TargetMovement = Vector2.Clamp(diff*0.01f, -Vector2.One, Vector2.One);
|
||||
character.AnimController.TargetDir = diff.X > 0.0f ? Direction.Right : Direction.Left;
|
||||
}
|
||||
else
|
||||
{
|
||||
character.AnimController.TargetMovement = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
character.AnimController.TargetMovement = Vector2.Zero;
|
||||
diff.Y = 0.0f;
|
||||
if (diff != Vector2.Zero && diff.Length() > 10.0f)
|
||||
{
|
||||
character.AnimController.TargetMovement = Vector2.Normalize(diff);
|
||||
character.AnimController.TargetDir = diff.X > 0.0f ? Direction.Right : Direction.Left;
|
||||
return;
|
||||
}
|
||||
character.AnimController.TargetMovement = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +129,7 @@ namespace Barotrauma.Items.Components
|
||||
if (limbPositions.Count == 0) return;
|
||||
|
||||
character.AnimController.Anim = AnimController.Animation.UsingConstruction;
|
||||
|
||||
character.AnimController.ResetPullJoints();
|
||||
|
||||
if (dir != 0) character.AnimController.TargetDir = dir;
|
||||
@@ -256,10 +271,10 @@ namespace Barotrauma.Items.Components
|
||||
dir = dir == Direction.Left ? Direction.Right : Direction.Left;
|
||||
}
|
||||
|
||||
if (userPos != 0.0f)
|
||||
if (userPos.X != 0.0f)
|
||||
{
|
||||
float diff = (item.Rect.X + UserPos) - item.Rect.Center.X;
|
||||
userPos = item.Rect.Center.X - diff - item.Rect.X;
|
||||
float diff = (item.Rect.X + UserPos.X) - item.Rect.Center.X;
|
||||
userPos.X = item.Rect.Center.X - diff - item.Rect.X;
|
||||
}
|
||||
|
||||
for (int i = 0; i < limbPositions.Count; i++)
|
||||
|
||||
@@ -125,6 +125,8 @@ namespace Barotrauma.Items.Components
|
||||
Item it = recipient.Item;
|
||||
if (it == null) continue;
|
||||
|
||||
if (it.Condition <= 0.0f) continue;
|
||||
|
||||
Powered powered = it.GetComponent<Powered>();
|
||||
if (powered == null || !powered.IsActive) continue;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public Wire[] Wires;
|
||||
|
||||
private Item item;
|
||||
private Item item;
|
||||
|
||||
public readonly bool IsOutput;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components
|
||||
private List<StatusEffect> effects;
|
||||
|
||||
public readonly ushort[] wireId;
|
||||
|
||||
|
||||
public bool IsPower
|
||||
{
|
||||
get;
|
||||
@@ -64,17 +64,17 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
panelTexture = Sprite.LoadTexture("Content/Items/connectionpanel.png");
|
||||
|
||||
connector = new Sprite(panelTexture, new Rectangle(470, 102, 19,43), Vector2.Zero, 0.0f);
|
||||
connector = new Sprite(panelTexture, new Rectangle(470, 102, 19, 43), Vector2.Zero, 0.0f);
|
||||
connector.Origin = new Vector2(9.5f, 10.0f);
|
||||
|
||||
wireVertical = new Sprite(panelTexture, new Rectangle(408, 1, 11, 102), Vector2.Zero, 0.0f);
|
||||
wireVertical = new Sprite(panelTexture, new Rectangle(408, 1, 11, 102), Vector2.Zero, 0.0f);
|
||||
}
|
||||
|
||||
this.item = item;
|
||||
|
||||
//recipient = new Connection[MaxLinked];
|
||||
Wires = new Wire[MaxLinked];
|
||||
|
||||
|
||||
IsOutput = (element.Name.ToString() == "output");
|
||||
Name = ToolBox.GetAttributeString(element, "name", (IsOutput) ? "output" : "input");
|
||||
|
||||
@@ -92,12 +92,12 @@ namespace Barotrauma.Items.Components
|
||||
int index = -1;
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (wireId[i]<1) index = i;
|
||||
if (wireId[i] < 1) index = i;
|
||||
}
|
||||
if (index == -1) break;
|
||||
|
||||
int id = ToolBox.GetAttributeInt(subElement, "w", 0);
|
||||
if (id<0) id = 0;
|
||||
if (id < 0) id = 0;
|
||||
wireId[index] = (ushort)id;
|
||||
|
||||
break;
|
||||
@@ -113,7 +113,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i]==null) return i;
|
||||
if (Wires[i] == null) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddLink(int index, Wire wire)
|
||||
{
|
||||
Wires[index] = wire;
|
||||
@@ -164,9 +164,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void SendSignal(int stepsTaken, string signal, Item sender, float power)
|
||||
{
|
||||
for (int i = 0; i<MaxLinked; i++)
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i]==null) continue;
|
||||
if (Wires[i] == null) continue;
|
||||
|
||||
Connection recipient = Wires[i].OtherConnection(this);
|
||||
if (recipient == null) continue;
|
||||
@@ -188,13 +188,13 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void ClearConnections()
|
||||
{
|
||||
for (int i = 0; i<MaxLinked; i++)
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i] == null) continue;
|
||||
|
||||
Wires[i].RemoveConnection(this);
|
||||
Wires[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -235,12 +235,12 @@ namespace Barotrauma.Items.Components
|
||||
Vector2 rightPos = new Vector2(x + width - 130, y + 50);
|
||||
Vector2 leftPos = new Vector2(x + 130, y + 50);
|
||||
|
||||
Vector2 rightWirePos = new Vector2(x + width-5, y + 30);
|
||||
Vector2 rightWirePos = new Vector2(x + width - 5, y + 30);
|
||||
|
||||
Vector2 leftWirePos = new Vector2(x+5, y + 30);
|
||||
Vector2 leftWirePos = new Vector2(x + 5, y + 30);
|
||||
|
||||
int wireInterval = (height - 20) / Math.Max(totalWireCount, 1);
|
||||
|
||||
int wireInterval = (height - 20) / Math.Max(totalWireCount,1);
|
||||
|
||||
foreach (Connection c in panel.Connections)
|
||||
{
|
||||
//if dragging a wire, let the Inventory know so that the wire can be
|
||||
@@ -248,7 +248,7 @@ namespace Barotrauma.Items.Components
|
||||
if (draggingConnected != null)
|
||||
{
|
||||
int linkIndex = c.FindWireIndex(draggingConnected.Item);
|
||||
if (linkIndex>-1)
|
||||
if (linkIndex > -1)
|
||||
{
|
||||
Inventory.draggingItem = c.Wires[linkIndex].Item;
|
||||
}
|
||||
@@ -257,21 +257,21 @@ namespace Barotrauma.Items.Components
|
||||
//outputs are drawn at the right side of the panel, inputs at the left
|
||||
if (c.IsOutput)
|
||||
{
|
||||
c.Draw(spriteBatch, panel.Item, rightPos,
|
||||
new Vector2(rightPos.X - GUI.SmallFont.MeasureString(c.Name).X - 20, rightPos.Y+3),
|
||||
rightWirePos,
|
||||
mouseInRect, equippedWire != null,
|
||||
c.Draw(spriteBatch, panel.Item, rightPos,
|
||||
new Vector2(rightPos.X - GUI.SmallFont.MeasureString(c.Name).X - 20, rightPos.Y + 3),
|
||||
rightWirePos,
|
||||
mouseInRect, equippedWire,
|
||||
wireInterval);
|
||||
|
||||
rightPos.Y += 30;
|
||||
rightWirePos.Y += c.Wires.Count(w => w!=null) * wireInterval;
|
||||
rightWirePos.Y += c.Wires.Count(w => w != null) * wireInterval;
|
||||
}
|
||||
else
|
||||
{
|
||||
c.Draw(spriteBatch, panel.Item, leftPos,
|
||||
new Vector2(leftPos.X + 20, leftPos.Y-12),
|
||||
leftWirePos,
|
||||
mouseInRect, equippedWire != null,
|
||||
new Vector2(leftPos.X + 20, leftPos.Y - 12),
|
||||
leftWirePos,
|
||||
mouseInRect, equippedWire,
|
||||
wireInterval);
|
||||
|
||||
leftPos.Y += 30;
|
||||
@@ -279,14 +279,14 @@ namespace Barotrauma.Items.Components
|
||||
//leftWireX -= wireInterval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (draggingConnected != null)
|
||||
{
|
||||
DrawWire(spriteBatch, draggingConnected, draggingConnected.Item, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, false);
|
||||
DrawWire(spriteBatch, draggingConnected, draggingConnected.Item, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, null);
|
||||
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
//panel.Item.CreateServerEvent(panel, true, true);
|
||||
//panel.Item.NewComponentEvent(panel, true, true);
|
||||
//draggingConnected.Drop(Character);
|
||||
draggingConnected = null;
|
||||
}
|
||||
@@ -294,61 +294,49 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
//if the Character using the panel has a wire item equipped
|
||||
//and the wire hasn't been connected yet, draw it on the panel
|
||||
if (equippedWire!=null)
|
||||
if (equippedWire != null)
|
||||
{
|
||||
if (panel.Connections.Find(c => c.Wires.Contains(equippedWire)) == null)
|
||||
{
|
||||
DrawWire(spriteBatch, equippedWire, equippedWire.Item,
|
||||
new Vector2(x + width / 2, y + height - 100),
|
||||
new Vector2(x + width / 2, y + height), mouseInRect, false);
|
||||
new Vector2(x + width / 2, y + height), mouseInRect, null);
|
||||
|
||||
if (draggingConnected == equippedWire) Inventory.draggingItem = equippedWire.Item;
|
||||
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
//stop dragging a wire item if cursor is outside the panel
|
||||
if (mouseInRect) Inventory.draggingItem = null;
|
||||
|
||||
if (draggingConnected != null)
|
||||
{
|
||||
DrawWire(spriteBatch, draggingConnected, draggingConnected.Item, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, false);
|
||||
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
//draggingConnected.Drop(Character);
|
||||
draggingConnected = null;
|
||||
}
|
||||
}
|
||||
|
||||
spriteBatch.Draw(panelTexture, panelRect, new Rectangle(0, 0, width, height), Color.White);
|
||||
|
||||
}
|
||||
|
||||
private void Draw(SpriteBatch spriteBatch, Item item, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, bool wireEquipped, float wireInterval)
|
||||
private void Draw(SpriteBatch spriteBatch, Item item, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval)
|
||||
{
|
||||
//spriteBatch.DrawString(GUI.SmallFont, Name, new Vector2(labelPos.X, labelPos.Y-10), Color.White);
|
||||
GUI.DrawString(spriteBatch, labelPos, Name, IsPower ? Color.Red : Color.White, Color.Black,0, GUI.SmallFont);
|
||||
GUI.DrawString(spriteBatch, labelPos, Name, IsPower ? Color.Red : Color.White, Color.Black, 0, GUI.SmallFont);
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)position.X-10, (int)position.Y-10, 20, 20), Color.White);
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle((int)position.X - 10, (int)position.Y - 10, 20, 20), Color.White);
|
||||
spriteBatch.Draw(panelTexture, position - new Vector2(16.0f, 16.0f), new Rectangle(64, 256, 32, 32), Color.White);
|
||||
|
||||
for (int i = 0; i<MaxLinked; i++)
|
||||
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i]==null || Wires[i].Hidden || draggingConnected == Wires[i]) continue;
|
||||
if (Wires[i] == null || Wires[i].Hidden || draggingConnected == Wires[i]) continue;
|
||||
|
||||
Connection recipient = Wires[i].OtherConnection(this);
|
||||
|
||||
DrawWire(spriteBatch, Wires[i], (recipient == null) ? Wires[i].Item : recipient.item, position, wirePosition, mouseIn, wireEquipped);
|
||||
DrawWire(spriteBatch, Wires[i], (recipient == null) ? Wires[i].Item : recipient.item, position, wirePosition, mouseIn, equippedWire);
|
||||
|
||||
wirePosition.Y += wireInterval;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (draggingConnected != null && Vector2.Distance(position, PlayerInput.MousePosition) < 13.0f)
|
||||
{
|
||||
spriteBatch.Draw(panelTexture, position - new Vector2(21.5f, 21.5f), new Rectangle(106, 250, 43, 43), Color.White);
|
||||
|
||||
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
//find an empty cell for the new connection
|
||||
@@ -369,18 +357,18 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (Wires.Any(w => w != null && w != draggingConnected))
|
||||
{
|
||||
spriteBatch.Draw(panelTexture, position - new Vector2(16.0f, 16.0f), new Rectangle(screwIndex*32, 256, 32, 32), Color.White);
|
||||
spriteBatch.Draw(panelTexture, position - new Vector2(16.0f, 16.0f), new Rectangle(screwIndex * 32, 256, 32, 32), Color.White);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Item item, Vector2 end, Vector2 start, bool mouseIn, bool wireEquipped)
|
||||
private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Item item, Vector2 end, Vector2 start, bool mouseIn, Wire equippedWire)
|
||||
{
|
||||
if (draggingConnected == wire)
|
||||
{
|
||||
if (!mouseIn) return;
|
||||
end = PlayerInput.MousePosition;
|
||||
start.X = (start.X+end.X)/2.0f;
|
||||
start.X = (start.X + end.X) / 2.0f;
|
||||
}
|
||||
|
||||
int textX = (int)start.X;
|
||||
@@ -389,28 +377,30 @@ namespace Barotrauma.Items.Components
|
||||
else
|
||||
textX += 10;
|
||||
|
||||
float alpha = wireEquipped ? 0.5f : 1.0f;
|
||||
bool canDrag = equippedWire == null || equippedWire == wire;
|
||||
|
||||
bool mouseOn =
|
||||
!wireEquipped &&
|
||||
float alpha = canDrag ? 1.0f : 0.5f;
|
||||
|
||||
bool mouseOn =
|
||||
canDrag &&
|
||||
((PlayerInput.MousePosition.X > Math.Min(start.X, end.X) &&
|
||||
PlayerInput.MousePosition.X < Math.Max(start.X, end.X) &&
|
||||
MathUtils.LineToPointDistance(start, end, PlayerInput.MousePosition) < 6) ||
|
||||
Vector2.Distance(end, PlayerInput.MousePosition)<20.0f ||
|
||||
new Rectangle((start.X < end.X) ? textX-100 : textX, (int)start.Y-5, 100, 14).Contains(PlayerInput.MousePosition));
|
||||
Vector2.Distance(end, PlayerInput.MousePosition) < 20.0f ||
|
||||
new Rectangle((start.X < end.X) ? textX - 100 : textX, (int)start.Y - 5, 100, 14).Contains(PlayerInput.MousePosition));
|
||||
|
||||
string label = wire.Locked ? item.Name +"\n(Locked)" : item.Name;
|
||||
string label = wire.Locked ? item.Name + "\n(Locked)" : item.Name;
|
||||
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2(start.X < end.X ? textX-GUI.SmallFont.MeasureString(label).X : textX,start.Y -5.0f),
|
||||
label,
|
||||
(mouseOn ? Color.Gold : Color.White) * (wire.Locked ? 0.6f : 1.0f), Color.Black * 0.8f,
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2(start.X < end.X ? textX - GUI.SmallFont.MeasureString(label).X : textX, start.Y - 5.0f),
|
||||
label,
|
||||
(mouseOn ? Color.Gold : Color.White) * (wire.Locked ? 0.6f : 1.0f), Color.Black * 0.8f,
|
||||
3, GUI.SmallFont);
|
||||
|
||||
var wireEnd = end + Vector2.Normalize(start - end) * 30.0f;
|
||||
|
||||
float dist = Vector2.Distance(start, wireEnd);
|
||||
|
||||
|
||||
if (mouseOn)
|
||||
{
|
||||
spriteBatch.Draw(wireVertical.Texture, new Rectangle(wireEnd.ToPoint(), new Point(18, (int)dist)), wireVertical.SourceRect,
|
||||
@@ -427,9 +417,9 @@ namespace Barotrauma.Items.Components
|
||||
SpriteEffects.None,
|
||||
0.0f);
|
||||
|
||||
connector.Draw(spriteBatch, end, Color.White, new Vector2(10.0f, 10.0f), MathUtils.VectorToAngle(end - start)+MathHelper.PiOver2);
|
||||
connector.Draw(spriteBatch, end, Color.White, new Vector2(10.0f, 10.0f), MathUtils.VectorToAngle(end - start) + MathHelper.PiOver2);
|
||||
|
||||
if (draggingConnected == null && !wireEquipped)
|
||||
if (draggingConnected == null && canDrag)
|
||||
{
|
||||
if (mouseOn)
|
||||
{
|
||||
@@ -438,9 +428,8 @@ namespace Barotrauma.Items.Components
|
||||
if (!wire.Locked)
|
||||
{
|
||||
//start dragging the wire
|
||||
if (PlayerInput.LeftButtonHeld()) draggingConnected = wire;
|
||||
if (PlayerInput.LeftButtonHeld()) draggingConnected = wire;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,25 +438,25 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
XElement newElement = new XElement(IsOutput ? "output" : "input", new XAttribute("name", Name));
|
||||
|
||||
Array.Sort(Wires, delegate(Wire wire1, Wire wire2)
|
||||
Array.Sort(Wires, delegate(Wire wire1, Wire wire2)
|
||||
{
|
||||
if (wire1 == null) return 1;
|
||||
if (wire2 == null) return -1;
|
||||
return wire1.Item.ID.CompareTo(wire2.Item.ID);
|
||||
return wire1.Item.ID.CompareTo(wire2.Item.ID);
|
||||
});
|
||||
|
||||
for (int i = 0; i < MaxLinked; i++ )
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i] == null) continue;
|
||||
|
||||
|
||||
//Connection recipient = wires[i].OtherConnection(this);
|
||||
|
||||
//int connectionIndex = recipient.item.Connections.FindIndex(x => x == recipient);
|
||||
newElement.Add(new XElement("link",
|
||||
new XAttribute("w", Wires[i].Item.ID.ToString())));
|
||||
newElement.Add(new XElement("link",
|
||||
new XAttribute("w", Wires[i].Item.ID.ToString())));
|
||||
}
|
||||
|
||||
parentElement.Add(newElement);
|
||||
|
||||
parentElement.Add(newElement);
|
||||
}
|
||||
|
||||
|
||||
@@ -486,7 +475,7 @@ namespace Barotrauma.Items.Components
|
||||
if (wireItem == null) continue;
|
||||
Wires[i] = wireItem.GetComponent<Wire>();
|
||||
|
||||
if (Wires[i]!=null)
|
||||
if (Wires[i] != null)
|
||||
{
|
||||
if (Wires[i].Item.body != null) Wires[i].Item.body.Enabled = false;
|
||||
Wires[i].Connect(this, false, true);
|
||||
@@ -499,4 +488,4 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,10 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ShallowRemoveComponentSpecific()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -63,8 +64,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Vector2 newNodePos;
|
||||
|
||||
|
||||
|
||||
private static Wire draggingWire;
|
||||
private static int? selectedNodeIndex;
|
||||
private static int? highlightedNodeIndex;
|
||||
|
||||
public bool Hidden, Locked;
|
||||
|
||||
@@ -89,7 +93,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
|
||||
public Connection OtherConnection(Connection connection)
|
||||
{
|
||||
if (connection == null) return null;
|
||||
@@ -191,7 +195,14 @@ namespace Barotrauma.Items.Components
|
||||
CleanNodes();
|
||||
}
|
||||
|
||||
Drawable = nodes.Any();
|
||||
if (!loading)
|
||||
{
|
||||
//Item.NewComponentEvent(this, true, true);
|
||||
//the wire is active if only one end has been connected
|
||||
IsActive = connections[0] == null ^ connections[1] == null;
|
||||
}
|
||||
|
||||
Drawable = IsActive || nodes.Any();
|
||||
|
||||
UpdateSections();
|
||||
return true;
|
||||
@@ -202,7 +213,6 @@ namespace Barotrauma.Items.Components
|
||||
ClearConnections();
|
||||
|
||||
IsActive = true;
|
||||
//Drawable = true;
|
||||
}
|
||||
|
||||
public override void Unequip(Character character)
|
||||
@@ -227,7 +237,7 @@ 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 && Screen.Selected != GameMain.EditMapScreen)
|
||||
if ((item.Submarine != sub || sub == null) && Screen.Selected != GameMain.EditMapScreen)
|
||||
{
|
||||
ClearConnections();
|
||||
return;
|
||||
@@ -260,7 +270,7 @@ namespace Barotrauma.Items.Components
|
||||
UpdateSections();
|
||||
}
|
||||
|
||||
Drawable = sections.Count > 0;
|
||||
Drawable = IsActive || sections.Count > 0;
|
||||
}
|
||||
|
||||
public override bool Pick(Character picker)
|
||||
@@ -303,7 +313,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
sections.Add(new WireSection(nodes[i], nodes[i + 1]));
|
||||
}
|
||||
Drawable = sections.Count > 0;
|
||||
Drawable = IsActive || sections.Count > 0;
|
||||
}
|
||||
|
||||
private void ClearConnections()
|
||||
@@ -384,7 +394,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (sections.Count == 0)
|
||||
if (sections.Count == 0 && !IsActive)
|
||||
{
|
||||
Drawable = false;
|
||||
return;
|
||||
@@ -396,7 +406,7 @@ namespace Barotrauma.Items.Components
|
||||
drawOffset = item.Submarine.DrawPosition + item.Submarine.HiddenSubPosition;
|
||||
}
|
||||
|
||||
float depth = wireSprite.Depth + ((item.ID % 100) * 0.00001f);
|
||||
float depth = item.IsSelected ? 0.0f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);
|
||||
|
||||
if (item.IsHighlighted)
|
||||
{
|
||||
@@ -417,8 +427,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
section.Draw(spriteBatch, item.Color, drawOffset, depth, 0.3f);
|
||||
}
|
||||
|
||||
if (IsActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
|
||||
|
||||
if (IsActive && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
|
||||
{
|
||||
WireSection.Draw(
|
||||
spriteBatch,
|
||||
@@ -428,78 +438,198 @@ namespace Barotrauma.Items.Components
|
||||
depth,
|
||||
0.3f);
|
||||
}
|
||||
|
||||
if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode) return;
|
||||
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) return;
|
||||
|
||||
if (!editing || !GameMain.EditMapScreen.WiringMode) return;
|
||||
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
{
|
||||
Vector2 worldPos = nodes[i];
|
||||
if (item.Submarine != null) worldPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
|
||||
worldPos.Y = -worldPos.Y;
|
||||
Vector2 drawPos = nodes[i];
|
||||
if (item.Submarine != null) drawPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
|
||||
drawPos.Y = -drawPos.Y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, worldPos + new Vector2(-3, -3), new Vector2(6, 6), item.Color, true, 0.0f);
|
||||
|
||||
if (IsActive) continue;
|
||||
|
||||
if (GUIComponent.MouseOn != null ||
|
||||
Vector2.Distance(GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), new Vector2(worldPos.X, -worldPos.Y)) > 10.0f)
|
||||
if (item.IsSelected)
|
||||
{
|
||||
continue;
|
||||
GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-5, -5), new Vector2(10, 10), item.Color, true, 0.0f);
|
||||
|
||||
if (highlightedNodeIndex == i)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, worldPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
|
||||
|
||||
if (selectedNodeIndex == null && draggingWire == null)// && !MapEntity.SelectedAny)
|
||||
else
|
||||
{
|
||||
if (PlayerInput.LeftButtonDown())
|
||||
{
|
||||
MapEntity.DisableSelect = true;
|
||||
MapEntity.SelectEntity(item);
|
||||
draggingWire = this;
|
||||
selectedNodeIndex = i;
|
||||
break;
|
||||
}
|
||||
else if (PlayerInput.RightButtonClicked())
|
||||
{
|
||||
nodes.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-3, -3), new Vector2(6, 6), item.Color, true, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
public static void UpdateEditing(List<Wire> wires)
|
||||
{
|
||||
//dragging a node of some wire
|
||||
if (draggingWire != null)
|
||||
{
|
||||
if (selectedNodeIndex != null && draggingWire == this)
|
||||
//cancel dragging
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
draggingWire = null;
|
||||
selectedNodeIndex = null;
|
||||
}
|
||||
//update dragging
|
||||
else
|
||||
{
|
||||
MapEntity.DisableSelect = true;
|
||||
//Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition)-Submarine.HiddenSubPosition+Submarine.Loaded.Position;
|
||||
|
||||
|
||||
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 (draggingWire.connections[0] != null && draggingWire.connections[0].Item.Submarine != null) sub = draggingWire.connections[0].Item.Submarine;
|
||||
if (draggingWire.connections[1] != null && draggingWire.connections[1].Item.Submarine != null) sub = draggingWire.connections[1].Item.Submarine;
|
||||
|
||||
Vector2 nodeWorldPos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition) - sub.HiddenSubPosition - sub.Position;// Nodes[(int)selectedNodeIndex];
|
||||
|
||||
nodeWorldPos.X = MathUtils.Round(nodeWorldPos.X, Submarine.GridSize.X / 2.0f);
|
||||
nodeWorldPos.Y = MathUtils.Round(nodeWorldPos.Y, Submarine.GridSize.Y / 2.0f);
|
||||
|
||||
//if (item.Submarine != null) nodeWorldPos += item.Submarine.Position;
|
||||
draggingWire.nodes[(int)selectedNodeIndex] = nodeWorldPos;
|
||||
draggingWire.UpdateSections();
|
||||
|
||||
nodes[(int)selectedNodeIndex] = nodeWorldPos;
|
||||
UpdateSections();
|
||||
MapEntity.SelectEntity(draggingWire.item);
|
||||
}
|
||||
|
||||
MapEntity.SelectEntity(item);
|
||||
return;
|
||||
}
|
||||
|
||||
//a wire has been selected -> check if we should start dragging one of the nodes
|
||||
float nodeSelectDist = 10, sectionSelectDist = 5;
|
||||
highlightedNodeIndex = null;
|
||||
if (MapEntity.SelectedList.Count == 1 && MapEntity.SelectedList[0] is Item)
|
||||
{
|
||||
Wire selectedWire = ((Item)MapEntity.SelectedList[0]).GetComponent<Wire>();
|
||||
|
||||
if (selectedWire != null)
|
||||
{
|
||||
Vector2 mousePos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
if (selectedWire.item.Submarine != null) mousePos -= (selectedWire.item.Submarine.Position + selectedWire.item.Submarine.HiddenSubPosition);
|
||||
|
||||
//left click while holding ctrl -> check if the cursor is on a wire section,
|
||||
//and add a new node if it is
|
||||
if (PlayerInput.KeyDown(Keys.RightControl) || PlayerInput.KeyDown(Keys.LeftControl))
|
||||
{
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
float temp = 0.0f;
|
||||
int closestSectionIndex = selectedWire.GetClosestSectionIndex(mousePos, sectionSelectDist, out temp);
|
||||
|
||||
if (closestSectionIndex > -1)
|
||||
{
|
||||
selectedWire.nodes.Insert(closestSectionIndex + 1, mousePos);
|
||||
selectedWire.UpdateSections();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//check if close enough to a node
|
||||
float temp = 0.0f;
|
||||
int closestIndex = selectedWire.GetClosestNodeIndex(mousePos, nodeSelectDist, out temp);
|
||||
if (closestIndex > -1)
|
||||
{
|
||||
highlightedNodeIndex = closestIndex;
|
||||
//start dragging the node
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
draggingWire = selectedWire;
|
||||
selectedNodeIndex = closestIndex;
|
||||
}
|
||||
//remove the node
|
||||
else if (PlayerInput.RightButtonClicked() && closestIndex > 0 && closestIndex < selectedWire.nodes.Count - 1)
|
||||
{
|
||||
selectedWire.nodes.RemoveAt(closestIndex);
|
||||
selectedWire.UpdateSections();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
//check which wire is highlighted with the cursor
|
||||
Wire highlighted = null;
|
||||
float closestDist = 0.0f;
|
||||
foreach (Wire w in wires)
|
||||
{
|
||||
selectedNodeIndex = null;
|
||||
draggingWire = null;
|
||||
Vector2 mousePos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
if (w.item.Submarine != null) mousePos -= (w.item.Submarine.Position + w.item.Submarine.HiddenSubPosition);
|
||||
|
||||
float dist = 0.0f;
|
||||
if (w.GetClosestNodeIndex(mousePos, highlighted == null ? nodeSelectDist : closestDist, out dist) > -1)
|
||||
{
|
||||
highlighted = w;
|
||||
closestDist = dist;
|
||||
}
|
||||
|
||||
if (w.GetClosestSectionIndex(mousePos, highlighted == null ? sectionSelectDist : closestDist, out dist) > -1)
|
||||
{
|
||||
highlighted = w;
|
||||
closestDist = dist;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (highlighted != null)
|
||||
{
|
||||
highlighted.item.IsHighlighted = true;
|
||||
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
MapEntity.DisableSelect = true;
|
||||
MapEntity.SelectEntity(highlighted.item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int GetClosestNodeIndex(Vector2 pos, float maxDist, out float closestDist)
|
||||
{
|
||||
closestDist = 0.0f;
|
||||
int closestIndex = -1;
|
||||
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
{
|
||||
float dist = Vector2.Distance(nodes[i], pos);
|
||||
if (dist > maxDist) continue;
|
||||
|
||||
if (closestIndex == -1 || dist < closestDist)
|
||||
{
|
||||
closestIndex = i;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return closestIndex;
|
||||
}
|
||||
|
||||
private int GetClosestSectionIndex(Vector2 mousePos, float maxDist, out float closestDist)
|
||||
{
|
||||
closestDist = 0.0f;
|
||||
int closestIndex = -1;
|
||||
|
||||
for (int i = 0; i < nodes.Count-1; i++)
|
||||
{
|
||||
if ((Math.Abs(nodes[i].X - nodes[i + 1].X)<5 || Math.Sign(mousePos.X - nodes[i].X) != Math.Sign(mousePos.X - nodes[i + 1].X)) &&
|
||||
(Math.Abs(nodes[i].Y - nodes[i + 1].Y)<5 || Math.Sign(mousePos.Y - nodes[i].Y) != Math.Sign(mousePos.Y - nodes[i + 1].Y)))
|
||||
{
|
||||
float dist = MathUtils.LineToPointDistance(nodes[i], nodes[i + 1], mousePos);
|
||||
if (dist > maxDist) continue;
|
||||
|
||||
if (closestIndex == -1 || dist < closestDist)
|
||||
{
|
||||
closestIndex = i;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closestIndex;
|
||||
}
|
||||
|
||||
public override void FlipX()
|
||||
{
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
@@ -555,7 +685,20 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
Drawable = nodes.Any();
|
||||
}
|
||||
|
||||
protected override void ShallowRemoveComponentSpecific()
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (connections[i] == null) continue;
|
||||
int wireIndex = connections[i].FindWireIndex(item);
|
||||
|
||||
if (wireIndex > -1)
|
||||
{
|
||||
connections[i].AddLink(wireIndex, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RemoveComponentSpecific()
|
||||
|
||||
Reference in New Issue
Block a user