Added a property for locking connection panels (better than the old hacky way of changing the required item to something else). Locked panels can still be rewired in the sub editor. Closes #679
This commit is contained in:
@@ -34,16 +34,19 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
Wire equippedWire = null;
|
Wire equippedWire = null;
|
||||||
|
|
||||||
//if the Character using the panel has a wire item equipped
|
if (!panel.Locked || Screen.Selected == GameMain.SubEditorScreen)
|
||||||
//and the wire hasn't been connected yet, draw it on the panel
|
|
||||||
for (int i = 0; i < character.SelectedItems.Length; i++)
|
|
||||||
{
|
{
|
||||||
Item selectedItem = character.SelectedItems[i];
|
//if the Character using the panel has a wire item equipped
|
||||||
|
//and the wire hasn't been connected yet, draw it on the panel
|
||||||
|
for (int i = 0; i < character.SelectedItems.Length; i++)
|
||||||
|
{
|
||||||
|
Item selectedItem = character.SelectedItems[i];
|
||||||
|
|
||||||
if (selectedItem == null) continue;
|
if (selectedItem == null) continue;
|
||||||
|
|
||||||
Wire wireComponent = selectedItem.GetComponent<Wire>();
|
Wire wireComponent = selectedItem.GetComponent<Wire>();
|
||||||
if (wireComponent != null) equippedWire = wireComponent;
|
if (wireComponent != null) equippedWire = wireComponent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 rightPos = new Vector2(x + width - 130, y + 50);
|
Vector2 rightPos = new Vector2(x + width - 130, y + 50);
|
||||||
@@ -71,7 +74,7 @@ namespace Barotrauma.Items.Components
|
|||||||
//outputs are drawn at the right side of the panel, inputs at the left
|
//outputs are drawn at the right side of the panel, inputs at the left
|
||||||
if (c.IsOutput)
|
if (c.IsOutput)
|
||||||
{
|
{
|
||||||
c.Draw(spriteBatch, panel.Item, rightPos,
|
c.Draw(spriteBatch, panel, rightPos,
|
||||||
new Vector2(rightPos.X - GUI.SmallFont.MeasureString(c.Name).X - 20, rightPos.Y + 3),
|
new Vector2(rightPos.X - GUI.SmallFont.MeasureString(c.Name).X - 20, rightPos.Y + 3),
|
||||||
rightWirePos,
|
rightWirePos,
|
||||||
mouseInRect, equippedWire,
|
mouseInRect, equippedWire,
|
||||||
@@ -82,7 +85,7 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c.Draw(spriteBatch, panel.Item, leftPos,
|
c.Draw(spriteBatch, panel, leftPos,
|
||||||
new Vector2(leftPos.X + 20, leftPos.Y - 12),
|
new Vector2(leftPos.X + 20, leftPos.Y - 12),
|
||||||
leftWirePos,
|
leftWirePos,
|
||||||
mouseInRect, equippedWire,
|
mouseInRect, equippedWire,
|
||||||
@@ -96,7 +99,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (draggingConnected != null)
|
if (draggingConnected != null)
|
||||||
{
|
{
|
||||||
DrawWire(spriteBatch, draggingConnected, draggingConnected.Item, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, null);
|
DrawWire(spriteBatch, draggingConnected, draggingConnected.Item, PlayerInput.MousePosition, new Vector2(x + width / 2, y + height), mouseInRect, null, panel);
|
||||||
|
|
||||||
if (!PlayerInput.LeftButtonHeld())
|
if (!PlayerInput.LeftButtonHeld())
|
||||||
{
|
{
|
||||||
@@ -121,7 +124,7 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
DrawWire(spriteBatch, equippedWire, equippedWire.Item,
|
DrawWire(spriteBatch, equippedWire, equippedWire.Item,
|
||||||
new Vector2(x + width / 2, y + height - 100),
|
new Vector2(x + width / 2, y + height - 100),
|
||||||
new Vector2(x + width / 2, y + height), mouseInRect, null);
|
new Vector2(x + width / 2, y + height), mouseInRect, null, panel);
|
||||||
|
|
||||||
if (draggingConnected == equippedWire) Inventory.draggingItem = equippedWire.Item;
|
if (draggingConnected == equippedWire) Inventory.draggingItem = equippedWire.Item;
|
||||||
}
|
}
|
||||||
@@ -135,7 +138,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw(SpriteBatch spriteBatch, Item item, Vector2 position, Vector2 labelPos, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval)
|
private void Draw(SpriteBatch spriteBatch, ConnectionPanel panel, 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);
|
//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);
|
||||||
@@ -149,7 +152,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
Connection recipient = Wires[i].OtherConnection(this);
|
Connection recipient = Wires[i].OtherConnection(this);
|
||||||
|
|
||||||
DrawWire(spriteBatch, Wires[i], (recipient == null) ? Wires[i].Item : recipient.item, position, wirePosition, mouseIn, equippedWire);
|
DrawWire(spriteBatch, Wires[i], (recipient == null) ? Wires[i].Item : recipient.item, position, wirePosition, mouseIn, equippedWire, panel);
|
||||||
|
|
||||||
wirePosition.Y += wireInterval;
|
wirePosition.Y += wireInterval;
|
||||||
}
|
}
|
||||||
@@ -165,9 +168,9 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (index > -1 && !Wires.Contains(draggingConnected))
|
if (index > -1 && !Wires.Contains(draggingConnected))
|
||||||
{
|
{
|
||||||
bool alreadyConnected = draggingConnected.IsConnectedTo(item);
|
bool alreadyConnected = draggingConnected.IsConnectedTo(panel.Item);
|
||||||
|
|
||||||
draggingConnected.RemoveConnection(item);
|
draggingConnected.RemoveConnection(panel.Item);
|
||||||
|
|
||||||
if (draggingConnected.Connect(this, !alreadyConnected, true))
|
if (draggingConnected.Connect(this, !alreadyConnected, true))
|
||||||
{
|
{
|
||||||
@@ -198,7 +201,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Item item, Vector2 end, Vector2 start, bool mouseIn, Wire equippedWire)
|
private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Item item, Vector2 end, Vector2 start, bool mouseIn, Wire equippedWire, ConnectionPanel panel)
|
||||||
{
|
{
|
||||||
if (draggingConnected == wire)
|
if (draggingConnected == wire)
|
||||||
{
|
{
|
||||||
@@ -225,7 +228,7 @@ namespace Barotrauma.Items.Components
|
|||||||
Vector2.Distance(end, PlayerInput.MousePosition) < 20.0f ||
|
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));
|
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" + TextManager.Get("ConnectionLocked") : item.Name;
|
string label = wire.Locked || panel.Locked ? item.Name + "\n" + TextManager.Get("ConnectionLocked") : item.Name;
|
||||||
|
|
||||||
GUI.DrawString(spriteBatch,
|
GUI.DrawString(spriteBatch,
|
||||||
new Vector2(start.X < end.X ? textX - GUI.SmallFont.MeasureString(label).X : textX, start.Y - 5.0f),
|
new Vector2(start.X < end.X ? textX - GUI.SmallFont.MeasureString(label).X : textX, start.Y - 5.0f),
|
||||||
@@ -261,7 +264,7 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
ConnectionPanel.HighlightedWire = wire;
|
ConnectionPanel.HighlightedWire = wire;
|
||||||
|
|
||||||
if (!wire.Locked)
|
if (!wire.Locked && (!panel.Locked || Screen.Selected == GameMain.SubEditorScreen))
|
||||||
{
|
{
|
||||||
//start dragging the wire
|
//start dragging the wire
|
||||||
if (PlayerInput.LeftButtonHeld()) draggingConnected = wire;
|
if (PlayerInput.LeftButtonHeld()) draggingConnected = wire;
|
||||||
|
|||||||
@@ -14,7 +14,14 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public List<Connection> Connections;
|
public List<Connection> Connections;
|
||||||
|
|
||||||
Character user;
|
private Character user;
|
||||||
|
|
||||||
|
[Serialize(false, true), Editable(ToolTip = "Locked connection panels cannot be rewired in-game.")]
|
||||||
|
public bool Locked
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
public ConnectionPanel(Item item, XElement element)
|
public ConnectionPanel(Item item, XElement element)
|
||||||
: base(item, element)
|
: base(item, element)
|
||||||
@@ -181,6 +188,9 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//don't allow rewiring locked panels
|
||||||
|
if (Locked) return;
|
||||||
|
|
||||||
item.CreateServerEvent(this);
|
item.CreateServerEvent(this);
|
||||||
|
|
||||||
//check if the character can access this connectionpanel
|
//check if the character can access this connectionpanel
|
||||||
|
|||||||
Reference in New Issue
Block a user