- Renamed a bunch of ObjectProperty-related stuff (ObjectProperty -> SerializableProperty, IPropertyObject -> ISerializableEntity, the "SerializableProperty" attribute -> Serialize).
- Rectangle serialization. - Option to restrict numeric properties to a range of values. - WIP generic ISerializableEntity editor.
This commit is contained in:
@@ -33,7 +33,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
partial class ItemComponent : IPropertyObject
|
||||
partial class ItemComponent : ISerializableEntity
|
||||
{
|
||||
private Dictionary<ActionType, List<ItemSound>> sounds;
|
||||
|
||||
@@ -109,13 +109,13 @@ namespace Barotrauma.Items.Components
|
||||
if (sound == null) return 0.0f;
|
||||
if (sound.VolumeProperty == "") return 1.0f;
|
||||
|
||||
ObjectProperty op = null;
|
||||
if (properties.TryGetValue(sound.VolumeProperty.ToLowerInvariant(), out op))
|
||||
SerializableProperty property = null;
|
||||
if (properties.TryGetValue(sound.VolumeProperty.ToLowerInvariant(), out property))
|
||||
{
|
||||
float newVolume = 0.0f;
|
||||
try
|
||||
{
|
||||
newVolume = (float)op.GetValue();
|
||||
newVolume = (float)property.GetValue();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -128,12 +128,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
//public virtual void Draw(SpriteBatch spriteBatch, bool editing = false)
|
||||
//{
|
||||
// item.drawableComponents = Array.FindAll(item.drawableComponents, i => i != this);
|
||||
//}
|
||||
|
||||
|
||||
public virtual void DrawHUD(SpriteBatch spriteBatch, Character character) { }
|
||||
|
||||
public virtual void AddToGUIUpdateList() { }
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private Color textColor;
|
||||
|
||||
[SerializableProperty("", true), Editable(100)]
|
||||
[Serialize("", true), Editable(100)]
|
||||
public string Text
|
||||
{
|
||||
get { return textBlock.Text.Replace("\n", ""); }
|
||||
@@ -27,7 +27,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, SerializableProperty("0.0,0.0,0.0,1.0", true)]
|
||||
[Editable, Serialize("0.0,0.0,0.0,1.0", true)]
|
||||
public Color TextColor
|
||||
{
|
||||
get { return textColor; }
|
||||
@@ -37,7 +37,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
[Editable, SerializableProperty(1.0f, true)]
|
||||
[Editable, Serialize(1.0f, true)]
|
||||
public float TextScale
|
||||
{
|
||||
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class Item : MapEntity, IDamageable, IPropertyObject, IServerSerializable, IClientSerializable
|
||||
partial class Item : MapEntity, IDamageable, ISerializableEntity, IServerSerializable, IClientSerializable
|
||||
{
|
||||
public override Sprite Sprite
|
||||
{
|
||||
@@ -145,12 +145,12 @@ namespace Barotrauma
|
||||
|
||||
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
if (editingHUD != null) editingHUD.Draw(spriteBatch);
|
||||
if (editingHUD != null && editingHUD.UserData == this) editingHUD.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
private GUIComponent CreateEditingHUD(bool inGame = false)
|
||||
{
|
||||
List<ObjectProperty> editableProperties = inGame ? GetProperties<InGameEditable>() : GetProperties<Editable>();
|
||||
/*List<SerializableProperty> editableProperties = inGame ? GetProperties<InGameEditable>() : GetProperties<Editable>();
|
||||
|
||||
int requiredItemCount = 0;
|
||||
if (!inGame)
|
||||
@@ -159,27 +159,29 @@ namespace Barotrauma
|
||||
{
|
||||
requiredItemCount += ic.requiredItems.Count;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
int width = 450;
|
||||
int height = 80 + requiredItemCount * 20;
|
||||
int height = 150;
|
||||
int x = GameMain.GraphicsWidth / 2 - width / 2, y = 10;
|
||||
foreach (var objectProperty in editableProperties)
|
||||
/*foreach (var objectProperty in editableProperties)
|
||||
{
|
||||
var editable = objectProperty.Attributes.OfType<Editable>().FirstOrDefault();
|
||||
if (editable != null) height += (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f) + 5;
|
||||
}
|
||||
}*/
|
||||
|
||||
editingHUD = new GUIFrame(new Rectangle(x, y, width, height), "");
|
||||
editingHUD.Padding = new Vector4(10, 10, 0, 0);
|
||||
editingHUD = new GUIListBox(new Rectangle(x, y, width, height), "");
|
||||
//editingHUD.Padding = new Vector4(10, 10, 0, 0);
|
||||
editingHUD.UserData = this;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 0, 100, 20), prefab.Name, "",
|
||||
Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont);
|
||||
/*new GUITextBlock(new Rectangle(0, 0, 0, 20), prefab.Name, "",
|
||||
Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont);*/
|
||||
|
||||
y += 25;
|
||||
new SerializableEntityEditor(this, inGame, editingHUD);
|
||||
|
||||
if (!inGame)
|
||||
//y += 25;
|
||||
|
||||
/*if (!inGame)
|
||||
{
|
||||
if (prefab.IsLinkable)
|
||||
{
|
||||
@@ -198,7 +200,7 @@ namespace Barotrauma
|
||||
PropertyDescriptor property = properties.Find("JoinedNames", false);
|
||||
|
||||
namesBox.Text = relatedItem.JoinedNames;
|
||||
namesBox.UserData = new ObjectProperty(property, relatedItem);
|
||||
namesBox.UserData = new SerializableProperty(property, relatedItem);
|
||||
namesBox.OnEnterPressed = EnterProperty;
|
||||
namesBox.OnTextChanged = PropertyChanged;
|
||||
|
||||
@@ -206,9 +208,15 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
if (requiredItemCount > 0) y += 10;
|
||||
}*/
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
if (SerializableProperty.GetProperties<Editable>(ic).Count == 0) continue;
|
||||
new SerializableEntityEditor(ic, inGame, editingHUD);
|
||||
}
|
||||
|
||||
foreach (var objectProperty in editableProperties)
|
||||
/*foreach (var objectProperty in editableProperties)
|
||||
{
|
||||
int boxHeight = 18;
|
||||
var editable = objectProperty.Attributes.OfType<Editable>().FirstOrDefault();
|
||||
@@ -272,8 +280,7 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
y = y + boxHeight + 5;
|
||||
|
||||
}
|
||||
}*/
|
||||
return editingHUD;
|
||||
}
|
||||
|
||||
@@ -346,10 +353,10 @@ namespace Barotrauma
|
||||
|
||||
private bool EnterProperty(GUITickBox tickBox)
|
||||
{
|
||||
var objectProperty = tickBox.UserData as ObjectProperty;
|
||||
if (objectProperty == null) return false;
|
||||
var property = tickBox.UserData as SerializableProperty;
|
||||
if (property == null) return false;
|
||||
|
||||
objectProperty.TrySetValue(tickBox.Selected);
|
||||
property.TrySetValue(tickBox.Selected);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -358,24 +365,24 @@ namespace Barotrauma
|
||||
{
|
||||
textBox.Color = Color.DarkGreen;
|
||||
|
||||
var objectProperty = textBox.UserData as ObjectProperty;
|
||||
if (objectProperty == null) return false;
|
||||
var property = textBox.UserData as SerializableProperty;
|
||||
if (property == null) return false;
|
||||
|
||||
object prevValue = objectProperty.GetValue();
|
||||
object prevValue = property.GetValue();
|
||||
|
||||
textBox.Deselect();
|
||||
|
||||
if (objectProperty.TrySetValue(text))
|
||||
if (property.TrySetValue(text))
|
||||
{
|
||||
textBox.Text = text;
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, property });
|
||||
}
|
||||
else if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, objectProperty });
|
||||
GameMain.Client.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.ChangeProperty, property });
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user