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
@@ -29,49 +29,49 @@ namespace Barotrauma.Items.Components
//the angle in which the Character holds the item
protected float holdAngle;
[HasDefaultValue(false, true)]
[SerializableProperty(false, true)]
public bool Attached
{
get { return attached && item.ParentInventory == null; }
set { attached = value; }
}
[HasDefaultValue(false, false)]
[SerializableProperty(false, false)]
public bool ControlPose
{
get;
set;
}
[HasDefaultValue(false, false)]
[SerializableProperty(false, false)]
public bool Attachable
{
get { return attachable; }
set { attachable = value; }
}
[HasDefaultValue(false, false)]
[SerializableProperty(false, false)]
public bool AttachedByDefault
{
get { return attachedByDefault; }
set { attachedByDefault = value; }
}
[HasDefaultValue("0.0,0.0", false)]
public string HoldPos
[SerializableProperty("0.0,0.0", false)]
public Vector2 HoldPos
{
get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(holdPos)); }
set { holdPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
get { return ConvertUnits.ToDisplayUnits(holdPos); }
set { holdPos = ConvertUnits.ToSimUnits(value); }
}
[HasDefaultValue("0.0,0.0", false)]
public string AimPos
[SerializableProperty("0.0,0.0", false)]
public Vector2 AimPos
{
get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(aimPos)); }
set { aimPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
get { return ConvertUnits.ToDisplayUnits(aimPos); }
set { aimPos = ConvertUnits.ToSimUnits(value); }
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float HoldAngle
{
get { return MathHelper.ToDegrees(holdAngle); }
@@ -24,14 +24,14 @@ namespace Barotrauma.Items.Components
private float reloadTimer;
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float Range
{
get { return ConvertUnits.ToDisplayUnits(range); }
set { range = ConvertUnits.ToSimUnits(value); }
}
[HasDefaultValue(0.5f, false)]
[SerializableProperty(0.5f, false)]
public float Reload
{
get { return reload; }
@@ -22,7 +22,7 @@ namespace Barotrauma.Items.Components
private UsableIn usableIn;
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float Force
{
get { return force; }
@@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components
}
#if CLIENT
[HasDefaultValue("", false)]
[SerializableProperty("", false)]
public string Particles
{
get { return particles; }
@@ -13,28 +13,28 @@ namespace Barotrauma.Items.Components
private Vector2 barrelPos;
[HasDefaultValue("0.0,0.0", false)]
[SerializableProperty("0.0,0.0", false)]
public string BarrelPos
{
get { return XMLExtensions.Vector2ToString(ConvertUnits.ToDisplayUnits(barrelPos)); }
set { barrelPos = ConvertUnits.ToSimUnits(XMLExtensions.ParseToVector2(value)); }
}
[HasDefaultValue(1.0f, false)]
[SerializableProperty(1.0f, false)]
public float Reload
{
get { return reload; }
set { reload = Math.Max(value, 0.0f); }
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float Spread
{
get;
set;
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float UnskilledSpread
{
get;
@@ -21,48 +21,48 @@ namespace Barotrauma.Items.Components
private float activeTimer;
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float Range
{
get { return range; }
set { range = value; }
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float StructureFixAmount
{
get; set;
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float LimbFixAmount
{
get; set;
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float ExtinquishAmount
{
get; set;
}
[HasDefaultValue("", false)]
[SerializableProperty("", false)]
public string Particles
{
get { return particles; }
set { particles = value; }
}
[HasDefaultValue(0.0f, false)]
[SerializableProperty(0.0f, false)]
public float ParticleSpeed
{
get; set;
}
[HasDefaultValue("0.0,0.0", false)]
public string BarrelPos
[SerializableProperty("0.0,0.0", false)]
public Vector2 BarrelPos
{
get { return XMLExtensions.Vector2ToString(barrelPos); }
set { barrelPos = XMLExtensions.ParseToVector2(value); }
get { return barrelPos; }
set { barrelPos = value; }
}
public Vector2 TransformedBarrelPos
@@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components
bool throwing;
[HasDefaultValue(1.0f, false)]
[SerializableProperty(1.0f, false)]
public float ThrowForce
{
get { return throwForce; }