a0d606ef5f
- Add support for some of the most common types (vectors, colors, rects) so there's no need to parse the values in the setters of the serializable properties (see Holdable.HoldPos for example). - Make a generic version of the item editing HUD that can be used on any IPropertyObject. Should make it easier to implement things like the character editor, editing structure properties, particle editor, etc. - Improve the interface of the editing HUD. Instead of having to type in a string value into a textbox, there should be number input fields for numeric properties, sliders for properties that only accept a range of values, a color picker, etc. And tooltips.
116 lines
3.3 KiB
C#
116 lines
3.3 KiB
C#
using System;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
partial class Powered : ItemComponent
|
|
{
|
|
//the amount of power CURRENTLY consumed by the item
|
|
//negative values mean that the item is providing power to connected items
|
|
protected float currPowerConsumption;
|
|
|
|
//current voltage of the item (load / power)
|
|
protected float voltage;
|
|
|
|
//the minimum voltage required for the item to work
|
|
protected float minVoltage;
|
|
|
|
//the maximum amount of power the item can draw from connected items
|
|
protected float powerConsumption;
|
|
|
|
[Editable, SerializableProperty(0.5f, true)]
|
|
public float MinVoltage
|
|
{
|
|
get { return minVoltage; }
|
|
set { minVoltage = value; }
|
|
}
|
|
|
|
[Editable, SerializableProperty(0.0f, true)]
|
|
public float PowerConsumption
|
|
{
|
|
get { return powerConsumption; }
|
|
set { powerConsumption = value; }
|
|
}
|
|
|
|
|
|
[SerializableProperty(false,true)]
|
|
public override bool IsActive
|
|
{
|
|
get { return base.IsActive; }
|
|
set
|
|
{
|
|
base.IsActive = value;
|
|
if (!value) currPowerConsumption = 0.0f;
|
|
}
|
|
}
|
|
|
|
[SerializableProperty(0.0f, true)]
|
|
public float CurrPowerConsumption
|
|
{
|
|
get {return currPowerConsumption; }
|
|
set { currPowerConsumption = value; }
|
|
}
|
|
|
|
[SerializableProperty(0.0f, true)]
|
|
public float Voltage
|
|
{
|
|
get { return voltage; }
|
|
set { voltage = Math.Max(0.0f, value); }
|
|
}
|
|
|
|
public Powered(Item item, XElement element)
|
|
: base(item, element)
|
|
{
|
|
#if CLIENT
|
|
if (powerOnSound == null)
|
|
{
|
|
powerOnSound = Sound.Load("Content/Items/Electricity/powerOn.ogg", false);
|
|
}
|
|
|
|
if (sparkSounds == null)
|
|
{
|
|
sparkSounds = new Sound[4];
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
sparkSounds[i] = Sound.Load("Content/Items/Electricity/zap" + (i + 1) + ".ogg", false);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0)
|
|
{
|
|
if (currPowerConsumption == 0.0f) voltage = 0.0f;
|
|
if (connection.IsPower) voltage = power;
|
|
}
|
|
|
|
public override void Update(float deltaTime, Camera cam)
|
|
{
|
|
if (currPowerConsumption == 0.0f) return;
|
|
|
|
#if CLIENT
|
|
if (voltage > minVoltage)
|
|
{
|
|
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
|
if (!powerOnSoundPlayed)
|
|
{
|
|
powerOnSound.Play(1.0f, 600.0f, item.WorldPosition);
|
|
powerOnSoundPlayed = true;
|
|
}
|
|
}
|
|
else if (voltage < 0.1f)
|
|
{
|
|
powerOnSoundPlayed = false;
|
|
}
|
|
#else
|
|
if (voltage > minVoltage)
|
|
{
|
|
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
}
|
|
}
|