- 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:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
return ParentInventory == null && (body == null || !body.Enabled);
|
||||
return ParentInventory == null && (body == null || body.Enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +327,8 @@ namespace Barotrauma
|
||||
|
||||
properties = ObjectProperty.InitProperties(this, element);
|
||||
|
||||
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLower())
|
||||
@@ -861,36 +863,51 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
foreach (var objectProperty in editableProperties)
|
||||
{
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 20), objectProperty.Name, Color.Transparent, Color.White, Alignment.Left, GUI.Style, editingHUD);
|
||||
|
||||
int height = 20;
|
||||
var editable = objectProperty.Attributes.OfType<Editable>().FirstOrDefault<Editable>();
|
||||
var editable = objectProperty.Attributes.OfType<Editable>().FirstOrDefault();
|
||||
if (editable != null) height = (int)(Math.Ceiling(editable.MaxLength / 20.0f) * 20.0f);
|
||||
|
||||
GUITextBox propertyBox = new GUITextBox(new Rectangle(180, y, 250, height), GUI.Style, editingHUD);
|
||||
if (height>20) propertyBox.Wrap = true;
|
||||
|
||||
object value = objectProperty.GetValue();
|
||||
if (value != null)
|
||||
|
||||
if (value is bool)
|
||||
{
|
||||
if (value is float)
|
||||
{
|
||||
propertyBox.Text = ((float)value).ToString("G", System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUITickBox propertyTickBox = new GUITickBox(new Rectangle(10, y, 20, 20), objectProperty.Name,
|
||||
Alignment.Left, editingHUD);
|
||||
|
||||
propertyBox.Text = value.ToString();
|
||||
}
|
||||
propertyTickBox.UserData = objectProperty;
|
||||
propertyTickBox.OnSelected = EnterProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
new GUITextBlock(new Rectangle(0, y, 100, 20), objectProperty.Name, Color.Transparent, Color.White, Alignment.Left, GUI.Style, editingHUD);
|
||||
|
||||
GUITextBox propertyBox = new GUITextBox(new Rectangle(180, y, 250, height), GUI.Style, editingHUD);
|
||||
if (height > 20) propertyBox.Wrap = true;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
if (value is float)
|
||||
{
|
||||
propertyBox.Text = ((float)value).ToString("G", System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
propertyBox.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
propertyBox.UserData = objectProperty;
|
||||
propertyBox.OnEnterPressed = EnterProperty;
|
||||
propertyBox.OnTextChanged = PropertyChanged;
|
||||
|
||||
}
|
||||
y = y + height + 10;
|
||||
|
||||
propertyBox.UserData = objectProperty;
|
||||
propertyBox.OnEnterPressed = EnterProperty;
|
||||
propertyBox.OnTextChanged = PropertyChanged;
|
||||
y = y + height+10;
|
||||
}
|
||||
return editingHUD;
|
||||
}
|
||||
@@ -998,6 +1015,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
if (item.prefab.PickDistance == 0.0f) continue;
|
||||
|
||||
if (Vector2.Distance(displayPos, item.WorldPosition) > item.prefab.PickDistance) continue;
|
||||
|
||||
if (!item.prefab.PickThroughWalls)
|
||||
@@ -1225,6 +1243,16 @@ namespace Barotrauma
|
||||
return editableProperties;
|
||||
}
|
||||
|
||||
private bool EnterProperty(GUITickBox tickBox)
|
||||
{
|
||||
var objectProperty = tickBox.UserData as ObjectProperty;
|
||||
if (objectProperty == null) return false;
|
||||
|
||||
objectProperty.TrySetValue(tickBox.Selected);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool EnterProperty(GUITextBox textBox, string text)
|
||||
{
|
||||
textBox.Color = Color.DarkGreen;
|
||||
@@ -1260,13 +1288,7 @@ namespace Barotrauma
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//private void Init()
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
|
||||
public override XElement Save(XDocument doc)
|
||||
{
|
||||
XElement element = new XElement("Item");
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace Barotrauma
|
||||
return vector.X.ToString("G", CultureInfo.InvariantCulture) + "," + vector.Y.ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static Vector4 ParseToVector4(string stringVector4)
|
||||
public static Vector4 ParseToVector4(string stringVector4, bool errorMessages = true)
|
||||
{
|
||||
string[] components = stringVector4.Split(',');
|
||||
|
||||
@@ -267,7 +267,7 @@ namespace Barotrauma
|
||||
|
||||
if (components.Length < 3)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to parse the string ''" + stringVector4 + "'' to Vector4");
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string ''" + stringVector4 + "'' to Vector4");
|
||||
return vector;
|
||||
}
|
||||
|
||||
@@ -280,12 +280,12 @@ namespace Barotrauma
|
||||
return vector;
|
||||
}
|
||||
|
||||
public static string Vector4ToString(Vector4 vector)
|
||||
public static string Vector4ToString(Vector4 vector, string format = "G")
|
||||
{
|
||||
return vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Y.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Z.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.W.ToString("G", CultureInfo.InvariantCulture);
|
||||
return vector.X.ToString(format, CultureInfo.InvariantCulture) + "," +
|
||||
vector.Y.ToString(format, CultureInfo.InvariantCulture) + "," +
|
||||
vector.Z.ToString(format, CultureInfo.InvariantCulture) + "," +
|
||||
vector.W.ToString(format, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static float[] ParseArrayToFloat(string[] stringArray)
|
||||
|
||||
Reference in New Issue
Block a user