- fixed light components throwing errors when receiving an invalid color value to the "set_color" input

- fixed it being possible to connect wires to more than two items by selecting another item while dragging the wire
- relay components break if too much power is directed through them
- relay components are active by default and the can be toggled on/off in the editor
- bool properties show as checkboxes in the editor
This commit is contained in:
Regalis
2016-03-17 19:16:21 +02:00
parent d6a57f9533
commit 20d61b0647
6 changed files with 120 additions and 60 deletions

View File

@@ -333,30 +333,16 @@ namespace Barotrauma.Items.Components
int index = FindWireIndex(null);
Wire wireComponent = draggingConnected.GetComponent<Wire>();
if (index>-1 && wireComponent!=null && !Wires.Contains(wireComponent))
if (index > -1 && wireComponent != null && !Wires.Contains(wireComponent))
{
bool alreadyConnected = wireComponent.IsConnectedTo(item);
wireComponent.RemoveConnection(item);
Wires[index] = wireComponent;
wireComponent.Connect(this, !alreadyConnected);
if (wireComponent.Connect(this, !alreadyConnected)) Wires[index] = wireComponent;
}
}
//far away -> disconnect if the wire is linked to this connector
else
{
//int index = FindWireIndex(draggingConnected);
//if (index>-1)
//{
// Wires[index].RemoveConnection(this);
// //Wires[index].Item.SetTransform(item.SimPosition, 0.0f);
// //Wires[index].Item.Drop();
// //Wires[index].Item.body.Enabled = true;
// Wires[index] = null;
//}
}
}
}
int screwIndex = (position.Y % 60 < 30) ? 0 : 1;

View File

@@ -27,6 +27,16 @@ namespace Barotrauma.Items.Components
range = MathHelper.Clamp(value, 0.0f, 2048.0f);
}
}
[Editable, HasDefaultValue(false, true)]
public bool IsOn
{
get { return IsActive; }
set
{
IsActive = value;
}
}
[HasDefaultValue(0.0f, false)]
public float Flicker
@@ -41,10 +51,10 @@ namespace Barotrauma.Items.Components
[InGameEditable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
public string LightColor
{
get { return ToolBox.Vector4ToString(lightColor.ToVector4()); }
get { return ToolBox.Vector4ToString(lightColor.ToVector4(), "0.00"); }
set
{
Vector4 newColor = ToolBox.ParseToVector4(value);
Vector4 newColor = ToolBox.ParseToVector4(value, false);
newColor.X = MathHelper.Clamp(newColor.X, 0.0f, 1.0f);
newColor.Y = MathHelper.Clamp(newColor.Y, 0.0f, 1.0f);
newColor.Z = MathHelper.Clamp(newColor.Z, 0.0f, 1.0f);
@@ -69,7 +79,8 @@ namespace Barotrauma.Items.Components
{
if (base.IsActive == value) return;
base.IsActive = value;
light.Color = value ? lightColor : Color.Transparent;
light.Color = value ? lightColor : Color.Transparent;
if (!value) lightBrightness = 0.0f;
}
}
@@ -136,6 +147,14 @@ namespace Barotrauma.Items.Components
voltage = 0.0f;
}
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, bool editing = false)
{
if (light.LightSprite != null)
{
light.LightSprite.Draw(spriteBatch, new Vector2(item.WorldPosition.X, -item.WorldPosition.Y), lightColor * lightBrightness);
}
}
protected override void RemoveComponentSpecific()
{

View File

@@ -1,9 +1,32 @@
using System.Xml.Linq;
using System;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class RelayComponent : ItemComponent
{
private float maxPower;
[Editable, HasDefaultValue(1000.0f, true)]
public float MaxPower
{
get { return maxPower; }
set
{
maxPower = Math.Max(0.0f, value);
}
}
[Editable, HasDefaultValue(false, true)]
public bool IsOn
{
get { return IsActive; }
set
{
IsActive = value;
}
}
public RelayComponent(Item item, XElement element)
: base (item, element)
{
@@ -12,6 +35,10 @@ namespace Barotrauma.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
if (item.Condition <= 0.0f) return;
if (power > maxPower) item.Condition = 0.0f;
if (connection.Name.Contains("_in"))
{
if (!IsActive) return;

View File

@@ -86,13 +86,15 @@ namespace Barotrauma.Items.Components
if (connection == connections[1]) connections[1] = null;
}
public void Connect(Connection newConnection, bool addNode = true, bool loading = false)
public bool Connect(Connection newConnection, bool addNode = true, bool loading = false)
{
for (int i = 0; i < 2; i++)
{
if (connections[i] == newConnection) return;
if (connections[i] == newConnection) return false;
}
if (!connections.Any(c => c == null)) return false;
for (int i = 0; i < 2; i++)
{
if (connections[i] != null && connections[i].Item == newConnection.Item)
@@ -144,6 +146,8 @@ namespace Barotrauma.Items.Components
}
if (!loading) Item.NewComponentEvent(this, true, true);
return true;
}
public override void Equip(Character character)
@@ -163,8 +167,9 @@ namespace Barotrauma.Items.Components
public override void Drop(Character dropper)
{
ClearConnections();
IsActive = false;
IsActive = false;
}
public override void Update(float deltaTime, Camera cam)
@@ -329,6 +334,7 @@ namespace Barotrauma.Items.Components
}
if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode ) return;
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) return;
for (int i = 0; i < Nodes.Count; i++)
{