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:
@@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Color textColor;
|
||||
|
||||
[HasDefaultValue("", true), Editable(100)]
|
||||
[SerializableProperty("", true), Editable(100)]
|
||||
public string Text
|
||||
{
|
||||
get { return textBlock.Text.Replace("\n", ""); }
|
||||
@@ -27,18 +27,17 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
|
||||
public string TextColor
|
||||
[Editable, SerializableProperty("0.0,0.0,0.0,1.0", true)]
|
||||
public Color TextColor
|
||||
{
|
||||
get { return XMLExtensions.Vector4ToString(textColor.ToVector4()); }
|
||||
get { return textColor; }
|
||||
set
|
||||
{
|
||||
textColor = new Color(XMLExtensions.ParseToVector4(value));
|
||||
if (textBlock != null) textBlock.TextColor = textColor;
|
||||
if (textBlock != null) textBlock.TextColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(1.0f, true)]
|
||||
[Editable, SerializableProperty(1.0f, true)]
|
||||
public float TextScale
|
||||
{
|
||||
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
|
||||
|
||||
@@ -5,21 +5,21 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class ItemLabel : ItemComponent, IDrawableComponent
|
||||
{
|
||||
[HasDefaultValue("", true), Editable(100)]
|
||||
[SerializableProperty("", true), Editable(100)]
|
||||
public string Text
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
|
||||
public string TextColor
|
||||
[Editable, SerializableProperty("0.0,0.0,0.0,1.0", true)]
|
||||
public Color TextColor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(1.0f, true)]
|
||||
[Editable, SerializableProperty(1.0f, true)]
|
||||
public float TextScale
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -1381,7 +1381,6 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\GameSession.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSession\InfoTextManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\GameSettings.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\IPropertyObject.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Items\CharacterInventory.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Items\Components\DockingPort.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Items\Components\Door.cs" />
|
||||
@@ -1493,10 +1492,12 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Physics\Physics.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Physics\PhysicsBody.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\PlayerInput.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Properties.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Screens\GameScreen.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Screens\NetLobbyScreen.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Screens\Screen.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Serialization\IPropertyObject.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Serialization\Properties.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Serialization\XMLExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Sprite\Sprite.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Sprite\SpriteSheet.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Timing.cs" />
|
||||
@@ -1507,6 +1508,5 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\SaveUtil.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\ToolBox.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\UpdaterUtil.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Utils\XMLExtensions.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -47,21 +47,21 @@ namespace Barotrauma.Items.Components
|
||||
set { dockingDir = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue("32.0,32.0", false)]
|
||||
public string DistanceTolerance
|
||||
[SerializableProperty("32.0,32.0", false)]
|
||||
public Vector2 DistanceTolerance
|
||||
{
|
||||
get { return XMLExtensions.Vector2ToString(distanceTolerance); }
|
||||
set { distanceTolerance = XMLExtensions.ParseToVector2(value); }
|
||||
get { return distanceTolerance; }
|
||||
set { distanceTolerance = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(32.0f, false)]
|
||||
[SerializableProperty(32.0f, false)]
|
||||
public float DockedDistance
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, false)]
|
||||
[SerializableProperty(true, false)]
|
||||
public bool IsHorizontal
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,0.0,0.0,0.0", false)]
|
||||
[SerializableProperty("0.0,0.0,0.0,0.0", false)]
|
||||
public string Window
|
||||
{
|
||||
get { return XMLExtensions.Vector4ToString(new Vector4(window.X, window.Y, window.Width, window.Height)); }
|
||||
@@ -130,7 +130,7 @@ namespace Barotrauma.Items.Components
|
||||
get { return window; }
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(false, true)]
|
||||
[Editable, SerializableProperty(false, true)]
|
||||
public bool IsOpen
|
||||
{
|
||||
get { return isOpen; }
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private string msg;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
[SerializableProperty(0.0f, false)]
|
||||
public float PickingTime
|
||||
{
|
||||
get;
|
||||
@@ -103,21 +103,21 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool CanBePicked
|
||||
{
|
||||
get { return canBePicked; }
|
||||
set { canBePicked = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool DrawHudWhenEquipped
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool CanBeSelected
|
||||
{
|
||||
get { return canBeSelected; }
|
||||
@@ -136,7 +136,7 @@ namespace Barotrauma.Items.Components
|
||||
protected set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool DeleteOnUse
|
||||
{
|
||||
get;
|
||||
@@ -153,7 +153,7 @@ namespace Barotrauma.Items.Components
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
[HasDefaultValue("", false)]
|
||||
[SerializableProperty("", false)]
|
||||
public string Msg
|
||||
{
|
||||
get { return msg; }
|
||||
@@ -205,7 +205,7 @@ namespace Barotrauma.Items.Components
|
||||
DebugConsole.ThrowError("Invalid pick key in " + element + "!", e);
|
||||
}
|
||||
|
||||
properties = ObjectProperty.InitProperties(this, element);
|
||||
properties = ObjectProperty.DeserializeProperties(this, element);
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
@@ -586,7 +586,7 @@ namespace Barotrauma.Items.Components
|
||||
componentElement.Add(newElement);
|
||||
}
|
||||
|
||||
ObjectProperty.SaveProperties(this, componentElement);
|
||||
ObjectProperty.SerializeProperties(this, componentElement);
|
||||
|
||||
parentElement.Add(componentElement);
|
||||
return componentElement;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Barotrauma.Items.Components
|
||||
private ushort[] itemIds;
|
||||
|
||||
//how many items can be contained
|
||||
[HasDefaultValue(5, false)]
|
||||
[SerializableProperty(5, false)]
|
||||
public int Capacity
|
||||
{
|
||||
get { return capacity; }
|
||||
@@ -26,7 +26,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
private int capacity;
|
||||
|
||||
[HasDefaultValue(true, false)]
|
||||
[SerializableProperty(true, false)]
|
||||
public bool HideItems
|
||||
{
|
||||
get { return hideItems; }
|
||||
@@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
private bool hideItems;
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool DrawInventory
|
||||
{
|
||||
get { return drawInventory; }
|
||||
@@ -47,24 +47,24 @@ namespace Barotrauma.Items.Components
|
||||
private bool drawInventory;
|
||||
|
||||
//the position of the first item in the container
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string ItemPos
|
||||
[SerializableProperty("0.0,0.0", false)]
|
||||
public Vector2 ItemPos
|
||||
{
|
||||
get { return XMLExtensions.Vector2ToString(itemPos); }
|
||||
set { itemPos = XMLExtensions.ParseToVector2(value); }
|
||||
get { return itemPos; }
|
||||
set { itemPos = value; }
|
||||
}
|
||||
private Vector2 itemPos;
|
||||
|
||||
//item[i].Pos = itemPos + itemInterval*i
|
||||
[HasDefaultValue("0.0,0.0", false)]
|
||||
public string ItemInterval
|
||||
[SerializableProperty("0.0,0.0", false)]
|
||||
public Vector2 ItemInterval
|
||||
{
|
||||
get { return XMLExtensions.Vector2ToString(itemInterval); }
|
||||
set { itemInterval = XMLExtensions.ParseToVector2(value); }
|
||||
get { return itemInterval; }
|
||||
set { itemInterval = value; }
|
||||
}
|
||||
private Vector2 itemInterval;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
[SerializableProperty(0.0f, false)]
|
||||
public float ItemRotation
|
||||
{
|
||||
get { return MathHelper.ToDegrees(itemRotation); }
|
||||
@@ -73,19 +73,18 @@ namespace Barotrauma.Items.Components
|
||||
private float itemRotation;
|
||||
|
||||
|
||||
[HasDefaultValue("0.5,0.9", false)]
|
||||
public string HudPos
|
||||
[SerializableProperty("0.5,0.9", false)]
|
||||
public Vector2 HudPos
|
||||
{
|
||||
get { return XMLExtensions.Vector2ToString(hudPos); }
|
||||
get { return hudPos; }
|
||||
set
|
||||
{
|
||||
hudPos = XMLExtensions.ParseToVector2(value);
|
||||
//inventory.CenterPos = hudPos;
|
||||
hudPos = value;
|
||||
}
|
||||
}
|
||||
private Vector2 hudPos;
|
||||
|
||||
[HasDefaultValue(5, false)]
|
||||
[SerializableProperty(5, false)]
|
||||
public int SlotsPerRow
|
||||
{
|
||||
get { return slotsPerRow; }
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components
|
||||
// }
|
||||
//}
|
||||
|
||||
[Editable, HasDefaultValue(2000.0f, true)]
|
||||
[Editable, SerializableProperty(2000.0f, true)]
|
||||
public float MaxForce
|
||||
{
|
||||
get { return maxForce; }
|
||||
|
||||
@@ -16,21 +16,21 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
bool hasPower;
|
||||
|
||||
[Editable, HasDefaultValue(false, true)]
|
||||
[Editable, SerializableProperty(false, true)]
|
||||
public bool RequireWaterDetectors
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(true, true)]
|
||||
[Editable, SerializableProperty(true, true)]
|
||||
public bool RequireOxygenDetectors
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(false, true)]
|
||||
[Editable, SerializableProperty(false, true)]
|
||||
public bool ShowHullIntegrity
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Barotrauma.Items.Components
|
||||
private set;
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(100.0f, true)]
|
||||
[Editable, SerializableProperty(100.0f, true)]
|
||||
public float GeneratedAmount
|
||||
{
|
||||
get { return generatedAmount; }
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public Hull hull1;
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
[SerializableProperty(0.0f, true)]
|
||||
public float FlowPercentage
|
||||
{
|
||||
get { return flowPercentage; }
|
||||
@@ -27,7 +27,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(80.0f, false)]
|
||||
[SerializableProperty(80.0f, false)]
|
||||
public float MaxFlow
|
||||
{
|
||||
get { return maxFlow; }
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float displayBorderSize;
|
||||
|
||||
[HasDefaultValue(10000.0f, false)]
|
||||
[SerializableProperty(10000.0f, false)]
|
||||
public float Range
|
||||
{
|
||||
get { return range; }
|
||||
set { range = MathHelper.Clamp(value, 0.0f, 100000.0f); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool DetectSubmarineWalls
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components
|
||||
private float? nextServerLogWriteTime;
|
||||
private float lastServerLogWriteTime;
|
||||
|
||||
[Editable, HasDefaultValue(9500.0f, true)]
|
||||
[Editable, SerializableProperty(9500.0f, true)]
|
||||
public float MeltDownTemp
|
||||
{
|
||||
get { return meltDownTemp; }
|
||||
@@ -64,7 +64,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(9000.0f, true)]
|
||||
[Editable, SerializableProperty(9000.0f, true)]
|
||||
public float FireTemp
|
||||
{
|
||||
get { return fireTemp; }
|
||||
@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(1.0f, true)]
|
||||
[Editable, SerializableProperty(1.0f, true)]
|
||||
public float PowerPerTemp
|
||||
{
|
||||
get { return powerPerTemp; }
|
||||
@@ -84,7 +84,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
[SerializableProperty(0.0f, true)]
|
||||
public float FissionRate
|
||||
{
|
||||
get { return fissionRate; }
|
||||
@@ -95,7 +95,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
[SerializableProperty(0.0f, true)]
|
||||
public float CoolingRate
|
||||
{
|
||||
get { return coolingRate; }
|
||||
@@ -106,7 +106,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
[SerializableProperty(0.0f, true)]
|
||||
public float Temperature
|
||||
{
|
||||
get { return temperature; }
|
||||
@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
|
||||
return (temperature > 0.0f);
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, true)]
|
||||
[SerializableProperty(false, true)]
|
||||
public bool AutoTemp
|
||||
{
|
||||
get { return autoTemp; }
|
||||
@@ -139,7 +139,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public float AvailableFuel { get; set; }
|
||||
|
||||
[HasDefaultValue(500.0f, true)]
|
||||
[SerializableProperty(500.0f, true)]
|
||||
public float ShutDownTemp
|
||||
{
|
||||
get { return shutDownTemp; }
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(0.5f, true)]
|
||||
[Editable, SerializableProperty(0.5f, true)]
|
||||
public float NeutralBallastLevel
|
||||
{
|
||||
get { return neutralBallastLevel; }
|
||||
|
||||
@@ -32,21 +32,21 @@ namespace Barotrauma.Items.Components
|
||||
private set;
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(10.0f, true)]
|
||||
[Editable, SerializableProperty(10.0f, true)]
|
||||
public float MaxOutPut
|
||||
{
|
||||
set { maxOutput = value; }
|
||||
get { return maxOutput; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(10.0f, true), Editable]
|
||||
[SerializableProperty(10.0f, true), Editable]
|
||||
public float Capacity
|
||||
{
|
||||
get { return capacity; }
|
||||
set { capacity = Math.Max(value, 1.0f); }
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(0.0f, true)]
|
||||
[Editable, SerializableProperty(0.0f, true)]
|
||||
public float Charge
|
||||
{
|
||||
get { return charge; }
|
||||
@@ -63,7 +63,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(10.0f, true), Editable]
|
||||
[SerializableProperty(10.0f, true), Editable]
|
||||
public float RechargeSpeed
|
||||
{
|
||||
get { return rechargeSpeed; }
|
||||
@@ -75,7 +75,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(10.0f, false), Editable]
|
||||
[SerializableProperty(10.0f, false), Editable]
|
||||
public float MaxRechargeSpeed
|
||||
{
|
||||
get { return maxRechargeSpeed; }
|
||||
|
||||
@@ -18,14 +18,14 @@ namespace Barotrauma.Items.Components
|
||||
//the maximum amount of power the item can draw from connected items
|
||||
protected float powerConsumption;
|
||||
|
||||
[Editable, HasDefaultValue(0.5f, true)]
|
||||
[Editable, SerializableProperty(0.5f, true)]
|
||||
public float MinVoltage
|
||||
{
|
||||
get { return minVoltage; }
|
||||
set { minVoltage = value; }
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue(0.0f, true)]
|
||||
[Editable, SerializableProperty(0.0f, true)]
|
||||
public float PowerConsumption
|
||||
{
|
||||
get { return powerConsumption; }
|
||||
@@ -33,7 +33,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
|
||||
[HasDefaultValue(false,true)]
|
||||
[SerializableProperty(false,true)]
|
||||
public override bool IsActive
|
||||
{
|
||||
get { return base.IsActive; }
|
||||
@@ -44,14 +44,14 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
[SerializableProperty(0.0f, true)]
|
||||
public float CurrPowerConsumption
|
||||
{
|
||||
get {return currPowerConsumption; }
|
||||
set { currPowerConsumption = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, true)]
|
||||
[SerializableProperty(0.0f, true)]
|
||||
public float Voltage
|
||||
{
|
||||
get { return voltage; }
|
||||
|
||||
@@ -23,35 +23,35 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public Character User;
|
||||
|
||||
[HasDefaultValue(10.0f, false)]
|
||||
[SerializableProperty(10.0f, false)]
|
||||
public float LaunchImpulse
|
||||
{
|
||||
get { return launchImpulse; }
|
||||
set { launchImpulse = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool CharacterUsable
|
||||
{
|
||||
get { return characterUsable; }
|
||||
set { characterUsable = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool DoesStick
|
||||
{
|
||||
get { return doesStick; }
|
||||
set { doesStick = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool Hitscan
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(false, false)]
|
||||
[SerializableProperty(false, false)]
|
||||
public bool RemoveOnHit
|
||||
{
|
||||
get;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -26,49 +26,44 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Camera cam;
|
||||
|
||||
[HasDefaultValue("0,0", false)]
|
||||
public string BarrelPos
|
||||
[SerializableProperty("0,0", false)]
|
||||
public Vector2 BarrelPos
|
||||
{
|
||||
get
|
||||
{
|
||||
return XMLExtensions.Vector2ToString(barrelPos);
|
||||
return barrelPos;
|
||||
}
|
||||
set
|
||||
{
|
||||
barrelPos = XMLExtensions.ParseToVector2(value);
|
||||
barrelPos = value;
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
[SerializableProperty(0.0f, false)]
|
||||
public float LaunchImpulse
|
||||
{
|
||||
get { return launchImpulse; }
|
||||
set { launchImpulse = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(5.0f, false)]
|
||||
[SerializableProperty(5.0f, false)]
|
||||
public float Reload
|
||||
{
|
||||
get { return reloadTime; }
|
||||
set { reloadTime = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,0.0", true), Editable]
|
||||
public string RotationLimits
|
||||
[SerializableProperty("0.0,0.0", true), Editable]
|
||||
public Vector2 RotationLimits
|
||||
{
|
||||
get
|
||||
{
|
||||
Vector2 limits = new Vector2(minRotation, maxRotation);
|
||||
limits.X = MathHelper.ToDegrees(limits.X);
|
||||
limits.Y = MathHelper.ToDegrees(limits.Y);
|
||||
|
||||
return XMLExtensions.Vector2ToString(limits);
|
||||
return new Vector2(MathHelper.ToDegrees(minRotation), MathHelper.ToDegrees(maxRotation));
|
||||
}
|
||||
set
|
||||
{
|
||||
Vector2 vector = XMLExtensions.ParseToVector2(value);
|
||||
minRotation = MathHelper.ToRadians(vector.X);
|
||||
maxRotation = MathHelper.ToRadians(vector.Y);
|
||||
minRotation = MathHelper.ToRadians(value.X);
|
||||
maxRotation = MathHelper.ToRadians(value.Y);
|
||||
|
||||
rotation = (minRotation + maxRotation) / 2;
|
||||
}
|
||||
|
||||
@@ -35,22 +35,21 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Vector2 armorSector;
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
[SerializableProperty(0.0f, false)]
|
||||
public float ArmorValue
|
||||
{
|
||||
get { return armorValue; }
|
||||
set { armorValue = MathHelper.Clamp(value, 0.0f, 100.0f); }
|
||||
}
|
||||
|
||||
[HasDefaultValue("0.0,360.0", false)]
|
||||
public string ArmorSector
|
||||
[SerializableProperty("0.0,360.0", false)]
|
||||
public Vector2 ArmorSector
|
||||
{
|
||||
get { return XMLExtensions.Vector2ToString(armorSector); }
|
||||
get { return armorSector; }
|
||||
set
|
||||
{
|
||||
armorSector = XMLExtensions.ParseToVector2(value);
|
||||
armorSector.X = MathHelper.ToRadians(armorSector.X);
|
||||
armorSector.Y = MathHelper.ToRadians(armorSector.Y);
|
||||
armorSector.X = MathHelper.ToRadians(value.X);
|
||||
armorSector.Y = MathHelper.ToRadians(value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
protected Color spriteColor;
|
||||
[Editable, HasDefaultValue("1.0,1.0,1.0,1.0", true)]
|
||||
[Editable, SerializableProperty("1.0,1.0,1.0,1.0", true)]
|
||||
public string SpriteColor
|
||||
{
|
||||
get { return XMLExtensions.Vector4ToString(spriteColor.ToVector4()); }
|
||||
@@ -220,7 +220,7 @@ namespace Barotrauma
|
||||
get { return condition; }
|
||||
}
|
||||
|
||||
[Editable, HasDefaultValue("", true)]
|
||||
[Editable, SerializableProperty("", true)]
|
||||
public string Tags
|
||||
{
|
||||
get { return string.Join(",",tags); }
|
||||
@@ -359,7 +359,7 @@ namespace Barotrauma
|
||||
XElement element = prefab.ConfigElement;
|
||||
if (element == null) return;
|
||||
|
||||
properties = ObjectProperty.InitProperties(this, element);
|
||||
properties = ObjectProperty.DeserializeProperties(this, element);
|
||||
|
||||
if (submarine == null || !submarine.Loading) FindHull();
|
||||
|
||||
@@ -1400,7 +1400,7 @@ namespace Barotrauma
|
||||
|
||||
ObjectProperty objectProperty = allProperties[propertyIndex];
|
||||
|
||||
Type type = objectProperty.GetType();
|
||||
Type type = objectProperty.PropertyType;
|
||||
if (type == typeof(string))
|
||||
{
|
||||
objectProperty.TrySetValue(msg.ReadString());
|
||||
@@ -1643,7 +1643,7 @@ namespace Barotrauma
|
||||
|
||||
bool shouldBeLoaded = false;
|
||||
|
||||
foreach (var propertyAttribute in property.Attributes.OfType<HasDefaultValue>())
|
||||
foreach (var propertyAttribute in property.Attributes.OfType<SerializableProperty>())
|
||||
{
|
||||
if (propertyAttribute.isSaveable)
|
||||
{
|
||||
@@ -1713,7 +1713,7 @@ namespace Barotrauma
|
||||
element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
|
||||
}
|
||||
|
||||
ObjectProperty.SaveProperties(this, element);
|
||||
ObjectProperty.SerializeProperties(this, element);
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(90.0f, true)]
|
||||
[SerializableProperty(90.0f, true)]
|
||||
public float Oxygen
|
||||
{
|
||||
get { return oxygen; }
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Barotrauma
|
||||
set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(1000, false)]
|
||||
[SerializableProperty(1000, false)]
|
||||
public int BackgroundSpriteAmount
|
||||
{
|
||||
get;
|
||||
@@ -115,14 +115,14 @@ namespace Barotrauma
|
||||
set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(100000.0f, false)]
|
||||
[SerializableProperty(100000.0f, false)]
|
||||
public float Width
|
||||
{
|
||||
get { return width; }
|
||||
set { width = Math.Max(value, 2000.0f); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(50000.0f, false)]
|
||||
[SerializableProperty(50000.0f, false)]
|
||||
public float Height
|
||||
{
|
||||
get { return height; }
|
||||
@@ -160,7 +160,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(5, false)]
|
||||
[SerializableProperty(5, false)]
|
||||
public int SmallTunnelCount
|
||||
{
|
||||
get { return smallTunnelCount; }
|
||||
@@ -177,21 +177,21 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(-300000.0f, false)]
|
||||
[SerializableProperty(-300000.0f, false)]
|
||||
public float SeaFloorDepth
|
||||
{
|
||||
get { return seaFloorBaseDepth; }
|
||||
set { seaFloorBaseDepth = MathHelper.Clamp(value, Level.MaxEntityDepth, 0.0f); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(1000.0f, false)]
|
||||
[SerializableProperty(1000.0f, false)]
|
||||
public float SeaFloorVariance
|
||||
{
|
||||
get { return seaFloorVariance; }
|
||||
set { seaFloorVariance = value; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(0, false)]
|
||||
[SerializableProperty(0, false)]
|
||||
public int MountainCountMin
|
||||
{
|
||||
get { return mountainCountMin; }
|
||||
@@ -201,7 +201,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(0, false)]
|
||||
[SerializableProperty(0, false)]
|
||||
public int MountainCountMax
|
||||
{
|
||||
get { return mountainCountMax; }
|
||||
@@ -211,7 +211,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(1000.0f, false)]
|
||||
[SerializableProperty(1000.0f, false)]
|
||||
public float MountainHeightMin
|
||||
{
|
||||
get { return mountainHeightMin; }
|
||||
@@ -221,7 +221,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(5000.0f, false)]
|
||||
[SerializableProperty(5000.0f, false)]
|
||||
public float MountainHeightMax
|
||||
{
|
||||
get { return mountainHeightMax; }
|
||||
@@ -231,14 +231,14 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(1, false)]
|
||||
[SerializableProperty(1, false)]
|
||||
public int RuinCount
|
||||
{
|
||||
get { return ruinCount; }
|
||||
set { ruinCount = MathHelper.Clamp(value, 0, 10); }
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.4f, false)]
|
||||
[SerializableProperty(0.4f, false)]
|
||||
public float BottomHoleProbability
|
||||
{
|
||||
get { return bottomHoleProbability; }
|
||||
@@ -278,7 +278,7 @@ namespace Barotrauma
|
||||
private LevelGenerationParams(XElement element)
|
||||
{
|
||||
Name = element == null ? "default" : element.Name.ToString();
|
||||
ObjectProperties = ObjectProperty.InitProperties(this, element);
|
||||
ObjectProperties = ObjectProperty.DeserializeProperties(this, element);
|
||||
|
||||
Vector3 colorVector = element.GetAttributeVector3("BackgroundColor", new Vector3(50, 46, 20));
|
||||
BackgroundColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
private List<SavedClientPermission> clientPermissions = new List<SavedClientPermission>();
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool RandomizeSeed
|
||||
{
|
||||
get;
|
||||
@@ -94,21 +94,21 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
|
||||
[HasDefaultValue(300.0f, true)]
|
||||
[SerializableProperty(300.0f, true)]
|
||||
public float RespawnInterval
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(180.0f, true)]
|
||||
[SerializableProperty(180.0f, true)]
|
||||
public float MaxTransportTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.2f, true)]
|
||||
[SerializableProperty(0.2f, true)]
|
||||
public float MinRespawnRatio
|
||||
{
|
||||
get;
|
||||
@@ -116,42 +116,42 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
|
||||
[HasDefaultValue(60.0f, true)]
|
||||
[SerializableProperty(60.0f, true)]
|
||||
public float AutoRestartInterval
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool AllowSpectating
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool EndRoundAtLevelEnd
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool SaveServerLogs
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool AllowFileTransfers
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(800, true)]
|
||||
[SerializableProperty(800, true)]
|
||||
private int LinesPerLogFile
|
||||
{
|
||||
get
|
||||
@@ -175,7 +175,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool AllowRespawn
|
||||
{
|
||||
get;
|
||||
@@ -203,21 +203,21 @@ namespace Barotrauma.Networking
|
||||
get { return banList; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(true, true)]
|
||||
[SerializableProperty(true, true)]
|
||||
public bool AllowVoteKick
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.6f, true)]
|
||||
[SerializableProperty(0.6f, true)]
|
||||
public float EndVoteRequiredRatio
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.6f, true)]
|
||||
[SerializableProperty(0.6f, true)]
|
||||
public float KickVoteRequiredRatio
|
||||
{
|
||||
get;
|
||||
@@ -228,7 +228,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
XDocument doc = new XDocument(new XElement("serversettings"));
|
||||
|
||||
ObjectProperty.SaveProperties(this, doc.Root, true);
|
||||
ObjectProperty.SerializeProperties(this, doc.Root, true);
|
||||
|
||||
doc.Root.SetAttributeValue("name", name);
|
||||
doc.Root.SetAttributeValue("public", isPublic);
|
||||
@@ -279,7 +279,7 @@ namespace Barotrauma.Networking
|
||||
doc = new XDocument(new XElement("serversettings"));
|
||||
}
|
||||
|
||||
ObjectProperties = ObjectProperty.InitProperties(this, doc.Root);
|
||||
ObjectProperties = ObjectProperty.DeserializeProperties(this, doc.Root);
|
||||
|
||||
AutoRestart = doc.Root.GetAttributeBool("autorestart", false);
|
||||
#if CLIENT
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
@@ -27,12 +28,12 @@ namespace Barotrauma
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class HasDefaultValue : System.Attribute
|
||||
public class SerializableProperty : System.Attribute
|
||||
{
|
||||
public object defaultValue;
|
||||
public bool isSaveable;
|
||||
|
||||
public HasDefaultValue(object defaultValue, bool isSaveable)
|
||||
public SerializableProperty(object defaultValue, bool isSaveable)
|
||||
{
|
||||
this.defaultValue = defaultValue;
|
||||
this.isSaveable = isSaveable;
|
||||
@@ -41,36 +42,44 @@ namespace Barotrauma
|
||||
|
||||
class ObjectProperty
|
||||
{
|
||||
readonly PropertyDescriptor property;
|
||||
readonly PropertyInfo propertyInfo;
|
||||
readonly object obj;
|
||||
|
||||
private readonly PropertyDescriptor propertyDescriptor;
|
||||
private readonly PropertyInfo propertyInfo;
|
||||
private readonly object obj;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return property.Name; }
|
||||
get { return propertyDescriptor.Name; }
|
||||
}
|
||||
|
||||
public AttributeCollection Attributes
|
||||
{
|
||||
get { return property.Attributes; }
|
||||
get { return propertyDescriptor.Attributes; }
|
||||
}
|
||||
|
||||
public Type PropertyType
|
||||
{
|
||||
get
|
||||
{
|
||||
return propertyInfo.PropertyType;
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectProperty(PropertyDescriptor property, object obj)
|
||||
{
|
||||
this.property = property;
|
||||
this.propertyDescriptor = property;
|
||||
propertyInfo = property.ComponentType.GetProperty(property.Name);
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
|
||||
public bool TrySetValue(string value)
|
||||
{
|
||||
if (value == null) return false;
|
||||
|
||||
if (property.PropertyType == typeof(string))
|
||||
|
||||
if (propertyDescriptor.PropertyType == typeof(string))
|
||||
{
|
||||
propertyInfo.SetValue(obj, value, null);
|
||||
}
|
||||
else if (property.PropertyType == typeof(float))
|
||||
else if (propertyDescriptor.PropertyType == typeof(float))
|
||||
{
|
||||
float floatVal;
|
||||
if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out floatVal))
|
||||
@@ -78,11 +87,11 @@ namespace Barotrauma
|
||||
propertyInfo.SetValue(obj, floatVal, null);
|
||||
}
|
||||
}
|
||||
else if (property.PropertyType == typeof(bool))
|
||||
else if (propertyDescriptor.PropertyType == typeof(bool))
|
||||
{
|
||||
propertyInfo.SetValue(obj, value.ToLowerInvariant() == "true", null);
|
||||
propertyInfo.SetValue(obj, value.ToLowerInvariant() == "true", null);
|
||||
}
|
||||
else if (property.PropertyType == typeof(int))
|
||||
else if (propertyDescriptor.PropertyType == typeof(int))
|
||||
{
|
||||
int intVal;
|
||||
if (int.TryParse(value, out intVal))
|
||||
@@ -90,7 +99,23 @@ namespace Barotrauma
|
||||
propertyInfo.SetValue(obj, intVal, null);
|
||||
}
|
||||
}
|
||||
else if (property.PropertyType.IsEnum)
|
||||
else if (propertyDescriptor.PropertyType == typeof(Vector2))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToVector2(value));
|
||||
}
|
||||
else if (propertyDescriptor.PropertyType == typeof(Vector3))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToVector3(value));
|
||||
}
|
||||
else if (propertyDescriptor.PropertyType == typeof(Vector4))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToVector4(value));
|
||||
}
|
||||
else if (propertyDescriptor.PropertyType == typeof(Color))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToColor(value));
|
||||
}
|
||||
else if (propertyDescriptor.PropertyType.IsEnum)
|
||||
{
|
||||
object enumVal;
|
||||
try
|
||||
@@ -118,18 +143,36 @@ namespace Barotrauma
|
||||
public bool TrySetValue(object value)
|
||||
{
|
||||
if (value == null) return false;
|
||||
|
||||
if (property.PropertyType != value.GetType())
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to set the value of the property \"" + Name + "\" of \"" + obj.ToString() + "\" to " + value.ToString());
|
||||
|
||||
DebugConsole.ThrowError("(Non-matching type, should be " + property.PropertyType + " instead of " + value.GetType() + ")");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == null || property == null) return false;
|
||||
if (obj == null || propertyDescriptor == null) return false;
|
||||
try
|
||||
{
|
||||
if (value.GetType() == typeof(string) &&
|
||||
propertyDescriptor.PropertyType == typeof(Vector2))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToVector2(value.ToString()));
|
||||
}
|
||||
else if (value.GetType() == typeof(string) &&
|
||||
propertyDescriptor.PropertyType == typeof(Vector3))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToVector3(value.ToString()));
|
||||
}
|
||||
else if (value.GetType() == typeof(string) &&
|
||||
propertyDescriptor.PropertyType == typeof(Vector4))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToVector4(value.ToString()));
|
||||
}
|
||||
else if (value.GetType() == typeof(string) &&
|
||||
propertyDescriptor.PropertyType == typeof(Color))
|
||||
{
|
||||
propertyInfo.SetValue(obj, XMLExtensions.ParseToColor(value.ToString()));
|
||||
}
|
||||
else if (propertyDescriptor.PropertyType != value.GetType())
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to set the value of the property \"" + Name + "\" of \"" + obj.ToString() + "\" to " + value.ToString());
|
||||
DebugConsole.ThrowError("(Non-matching type, should be " + propertyDescriptor.PropertyType + " instead of " + value.GetType() + ")");
|
||||
return false;
|
||||
}
|
||||
|
||||
propertyInfo.SetValue(obj, value, null);
|
||||
}
|
||||
catch
|
||||
@@ -143,13 +186,13 @@ namespace Barotrauma
|
||||
{
|
||||
try
|
||||
{
|
||||
propertyInfo.SetValue(obj, value, null);
|
||||
propertyInfo.SetValue(obj, value, null);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -181,7 +224,7 @@ namespace Barotrauma
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
if (obj == null || property == null) return false;
|
||||
if (obj == null || propertyDescriptor == null) return false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -192,12 +235,7 @@ namespace Barotrauma
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Type GetType()
|
||||
{
|
||||
return propertyInfo.PropertyType;
|
||||
}
|
||||
|
||||
|
||||
public static List<ObjectProperty> GetProperties<T>(IPropertyObject obj)
|
||||
{
|
||||
List<ObjectProperty> editableProperties = new List<ObjectProperty>();
|
||||
@@ -210,7 +248,7 @@ namespace Barotrauma
|
||||
return editableProperties;
|
||||
}
|
||||
|
||||
public static Dictionary<string, ObjectProperty> GetProperties(IPropertyObject obj)
|
||||
public static Dictionary<string, ObjectProperty> GetProperties(IPropertyObject obj)
|
||||
{
|
||||
var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast<PropertyDescriptor>();
|
||||
|
||||
@@ -224,12 +262,17 @@ namespace Barotrauma
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
/*/// <summary>
|
||||
/// Sets all serializable properties to their default value
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, ObjectProperty> InitProperties(IPropertyObject obj)
|
||||
{
|
||||
return InitProperties(obj, null);
|
||||
}
|
||||
return DeserializeProperties(obj, null);
|
||||
}*/
|
||||
|
||||
public static Dictionary<string, ObjectProperty> InitProperties(IPropertyObject obj, XElement element)
|
||||
public static Dictionary<string, ObjectProperty> DeserializeProperties(IPropertyObject obj, XElement element)
|
||||
{
|
||||
var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast<PropertyDescriptor>();
|
||||
|
||||
@@ -241,14 +284,14 @@ namespace Barotrauma
|
||||
dictionary.Add(property.Name.ToLowerInvariant(), objProperty);
|
||||
|
||||
//set the value of the property to the default value if there is one
|
||||
foreach (var ini in property.Attributes.OfType<HasDefaultValue>())
|
||||
foreach (var ini in property.Attributes.OfType<SerializableProperty>())
|
||||
{
|
||||
objProperty.TrySetValue(ini.defaultValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (element!=null)
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
//go through all the attributes in the xml element
|
||||
//and set the value of the matching property if it is initializable
|
||||
@@ -256,47 +299,80 @@ namespace Barotrauma
|
||||
{
|
||||
ObjectProperty property = null;
|
||||
if (!dictionary.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out property)) continue;
|
||||
if (!property.Attributes.OfType<HasDefaultValue>().Any()) continue;
|
||||
if (!property.Attributes.OfType<SerializableProperty>().Any()) continue;
|
||||
property.TrySetValue(attribute.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static void SaveProperties(IPropertyObject obj, XElement element, bool saveIfDefault = false)
|
||||
|
||||
public static void SerializeProperties(IPropertyObject obj, XElement element, bool saveIfDefault = false)
|
||||
{
|
||||
var saveProperties = GetProperties<HasDefaultValue>(obj);
|
||||
var saveProperties = GetProperties<SerializableProperty>(obj);
|
||||
foreach (var property in saveProperties)
|
||||
{
|
||||
object value = property.GetValue();
|
||||
if (value == null) continue;
|
||||
|
||||
|
||||
if (!saveIfDefault)
|
||||
{
|
||||
//only save
|
||||
// - if the attribute is saveable and it's different from the default value
|
||||
// - or can be changed in-game or in the editor
|
||||
bool save = false;
|
||||
foreach (var attribute in property.Attributes.OfType<HasDefaultValue>())
|
||||
foreach (var attribute in property.Attributes.OfType<SerializableProperty>())
|
||||
{
|
||||
if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) ||
|
||||
if ((attribute.isSaveable && !attribute.defaultValue.Equals(value)) ||
|
||||
property.Attributes.OfType<Editable>().Any())
|
||||
{
|
||||
save = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!save) continue;
|
||||
}
|
||||
|
||||
string stringValue;
|
||||
if (value is float)
|
||||
if (value.GetType() == typeof(float))
|
||||
{
|
||||
//do this to make sure the decimal point isn't converted to a comma or anything like that
|
||||
//make sure the decimal point isn't converted to a comma or anything else
|
||||
stringValue = ((float)value).ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else if (value.GetType() == typeof(Vector2))
|
||||
{
|
||||
Vector2 vector = (Vector2)value;
|
||||
stringValue =
|
||||
vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Y.ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else if (value.GetType() == typeof(Vector3))
|
||||
{
|
||||
Vector3 vector = (Vector3)value;
|
||||
stringValue =
|
||||
vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Y.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Z.ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else if (value.GetType() == typeof(Vector4))
|
||||
{
|
||||
Vector4 vector = (Vector4)value;
|
||||
stringValue =
|
||||
vector.X.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Y.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.Z.ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
vector.W.ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else if (value.GetType() == typeof(Color))
|
||||
{
|
||||
Color color = (Color)value;
|
||||
stringValue =
|
||||
(color.R / 255.0f).ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
(color.G / 255.0f).ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
(color.B / 255.0f).ToString("G", CultureInfo.InvariantCulture) + "," +
|
||||
(color.A / 255.0f).ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringValue = value.ToString();
|
||||
@@ -289,6 +289,28 @@ namespace Barotrauma
|
||||
return vector;
|
||||
}
|
||||
|
||||
public static Color ParseToColor(string stringColor, bool errorMessages = true)
|
||||
{
|
||||
string[] strComponents = stringColor.Split(',');
|
||||
|
||||
Color color = Color.White;
|
||||
|
||||
if (strComponents.Length < 3)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
|
||||
return Color.White;
|
||||
}
|
||||
|
||||
float[] components = new float[4] { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
for (int i = 0; i < 4 && i < strComponents.Length; i++)
|
||||
{
|
||||
float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]);
|
||||
}
|
||||
|
||||
return new Color(components[0], components[1], components[2], components[3]);
|
||||
}
|
||||
|
||||
public static string Vector4ToString(Vector4 vector, string format = "G")
|
||||
{
|
||||
return vector.X.ToString(format, CultureInfo.InvariantCulture) + "," +
|
||||
Reference in New Issue
Block a user