Working on improving the serialization system and ObjectProperty/IPropertyObject (TODO: come up with better names). The plan is to:

- 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.
This commit is contained in:
Joonas Rikkonen
2017-11-03 19:41:21 +02:00
parent 8b9be55135
commit a0d606ef5f
41 changed files with 345 additions and 263 deletions
@@ -13,7 +13,7 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame;
[InGameEditable, HasDefaultValue(0.0f, true)]
[InGameEditable, SerializableProperty(0.0f, true)]
public float TimeFrame
{
get { return timeFrame; }
@@ -23,14 +23,14 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, HasDefaultValue("1", true)]
[InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, HasDefaultValue("", true)]
[InGameEditable, SerializableProperty("", true)]
public string FalseOutput
{
get { return falseOutput; }
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
private Queue<Tuple<string, DateTime>> signalQueue;
[InGameEditable, HasDefaultValue(1.0f, true)]
[InGameEditable, SerializableProperty(1.0f, true)]
public float Delay
{
get { return (float)delay.TotalSeconds; }
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
private bool castShadows;
[Editable, HasDefaultValue(100.0f, true)]
[Editable, SerializableProperty(100.0f, true)]
public float Range
{
get { return range; }
@@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, HasDefaultValue(true, true)]
[Editable, SerializableProperty(true, true)]
public bool CastShadows
{
get { return castShadows; }
@@ -44,7 +44,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, HasDefaultValue(false, true)]
[Editable, SerializableProperty(false, true)]
public bool IsOn
{
get { return IsActive; }
@@ -57,7 +57,7 @@ namespace Barotrauma.Items.Components
}
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float Flicker
{
get { return flicker; }
@@ -67,19 +67,11 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
public string LightColor
[InGameEditable, SerializableProperty("1.0,1.0,1.0,1.0", true)]
public Color LightColor
{
get { return XMLExtensions.Vector4ToString(lightColor.ToVector4(), "0.00"); }
set
{
Vector4 newColor = XMLExtensions.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);
newColor.W = MathHelper.Clamp(newColor.W, 0.0f, 1.0f);
lightColor = new Color(newColor);
}
get { return lightColor; }
set { lightColor = value; }
}
public override void Move(Vector2 amount)
@@ -215,7 +207,7 @@ namespace Barotrauma.Items.Components
IsActive = (signal != "0");
break;
case "set_color":
LightColor = signal;
LightColor = XMLExtensions.ParseToColor(signal, false);
break;
}
}
@@ -17,7 +17,7 @@ namespace Barotrauma.Items.Components
private float updateTimer;
[InGameEditable, HasDefaultValue(0.0f, true)]
[InGameEditable, SerializableProperty(0.0f, true)]
public float Range
{
get { return range; }
@@ -27,14 +27,14 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, HasDefaultValue("1", true)]
[InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, HasDefaultValue("", true)]
[InGameEditable, SerializableProperty("", true)]
public string FalseOutput
{
get { return falseOutput; }
@@ -20,14 +20,14 @@ namespace Barotrauma.Items.Components
private float phase;
[InGameEditable, HasDefaultValue(WaveType.Pulse, true)]
[InGameEditable, SerializableProperty(WaveType.Pulse, true)]
public WaveType OutputType
{
get;
set;
}
[InGameEditable, HasDefaultValue(1.0f, true)]
[InGameEditable, SerializableProperty(1.0f, true)]
public float Frequency
{
get { return frequency; }
@@ -16,14 +16,14 @@ namespace Barotrauma.Items.Components
private Regex regex;
[InGameEditable, HasDefaultValue("1", true)]
[InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, HasDefaultValue("", true)]
[InGameEditable, SerializableProperty("", true)]
public string Expression
{
get { return expression; }
@@ -11,7 +11,7 @@ namespace Barotrauma.Items.Components
private bool isOn;
[Editable, HasDefaultValue(1000.0f, true)]
[Editable, SerializableProperty(1000.0f, true)]
public float MaxPower
{
get { return maxPower; }
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, HasDefaultValue(false, true)]
[Editable, SerializableProperty(false, true)]
public bool IsOn
{
get
@@ -8,20 +8,20 @@ namespace Barotrauma.Items.Components
private string targetSignal;
[InGameEditable, HasDefaultValue("1", true)]
[InGameEditable, SerializableProperty("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, HasDefaultValue("0", true)]
[InGameEditable, SerializableProperty("0", true)]
public string FalseOutput
{
get { return falseOutput; }
set { falseOutput = value; }
}
[InGameEditable, HasDefaultValue("", true)]
[InGameEditable, SerializableProperty("", true)]
public string TargetSignal
{
get { return targetSignal; }
@@ -14,14 +14,14 @@ namespace Barotrauma.Items.Components
private int channel;
[HasDefaultValue(20000.0f, false)]
[SerializableProperty(20000.0f, false)]
public float Range
{
get { return range; }
set { range = Math.Max(value, 0.0f); }
}
[InGameEditable, HasDefaultValue(1, true)]
[InGameEditable, SerializableProperty(1, true)]
public int Channel
{
get { return channel; }
@@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, HasDefaultValue(false, false)]
[Editable, SerializableProperty(false, false)]
public bool LinkToChat
{
get;