38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
@@ -3,166 +3,391 @@ using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
namespace Barotrauma
{
class SerializableEntityEditor : GUIComponent
{
private int elementHeight;
private GUILayoutGroup layoutGroup;
private static readonly string[] vectorComponentLabels = { "X", "Y", "Z", "W" };
private static readonly string[] rectComponentLabels = { "X", "Y", "W", "H" };
private static readonly string[] colorComponentLabels = { "R", "G", "B", "A" };
//private GUIComponent editingHUD;
public SerializableEntityEditor(ISerializableEntity entity, bool inGame, GUIComponent parent, bool showName) : base("")
public int ContentHeight
{
get
{
if (layoutGroup.NeedsToRecalculate) layoutGroup.Recalculate();
int spacing = layoutGroup.CountChildren == 0 ? 0 : ((layoutGroup.CountChildren - 1) * layoutGroup.AbsoluteSpacing);
return spacing + layoutGroup.Children.Sum(c => c.RectTransform.NonScaledSize.Y);
}
}
public int ContentCount
{
get { return layoutGroup.CountChildren; }
}
/// <summary>
/// Holds the references to the input fields.
/// </summary>
public Dictionary<string, GUIComponent[]> Fields { get; private set; } = new Dictionary<string, GUIComponent[]>();
public void UpdateValue(SerializableProperty property, object newValue, bool flash = true)
{
if (!Fields.TryGetValue(property.Name, out GUIComponent[] fields))
{
DebugConsole.ThrowError($"No field for {property.Name} found!");
return;
}
if (newValue is float f)
{
foreach (var field in fields)
{
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Float)
{
numInput.FloatValue = f;
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
else if (newValue is int integer)
{
foreach (var field in fields)
{
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Int)
{
numInput.IntValue = integer;
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
else if (newValue is bool b)
{
if (fields[0] is GUITickBox tickBox)
{
tickBox.Selected = b;
if (flash)
{
tickBox.Flash(Color.LightGreen);
}
}
}
else if (newValue is string s)
{
if (fields[0] is GUITextBox textBox)
{
textBox.Text = s;
if (flash)
{
textBox.Flash(Color.LightGreen);
}
}
}
else if (newValue.GetType().IsEnum)
{
if (fields[0] is GUIDropDown dropDown)
{
dropDown.Select((int)newValue);
if (flash)
{
dropDown.Flash(Color.LightGreen);
}
}
}
else if (newValue is Vector2 v2)
{
for (int i = 0; i < fields.Length; i++)
{
var field = fields[i];
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Float)
{
numInput.FloatValue = i == 0 ? v2.X : v2.Y;
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
else if (newValue is Vector3 v3)
{
for (int i = 0; i < fields.Length; i++)
{
var field = fields[i];
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Float)
{
switch (i)
{
case 0:
numInput.FloatValue = v3.X;
break;
case 1:
numInput.FloatValue = v3.Y;
break;
case 2:
numInput.FloatValue = v3.Z;
break;
}
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
else if (newValue is Vector4 v4)
{
for (int i = 0; i < fields.Length; i++)
{
var field = fields[i];
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Float)
{
switch (i)
{
case 0:
numInput.FloatValue = v4.X;
break;
case 1:
numInput.FloatValue = v4.Y;
break;
case 2:
numInput.FloatValue = v4.Z;
break;
case 3:
numInput.FloatValue = v4.W;
break;
}
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
else if (newValue is Color c)
{
for (int i = 0; i < fields.Length; i++)
{
var field = fields[i];
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Int)
{
switch (i)
{
case 0:
numInput.IntValue = c.R;
break;
case 1:
numInput.IntValue = c.G;
break;
case 2:
numInput.IntValue = c.B;
break;
case 3:
numInput.IntValue = c.A;
break;
}
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
else if (newValue is Rectangle r)
{
for (int i = 0; i < fields.Length; i++)
{
var field = fields[i];
if (field is GUINumberInput numInput)
{
if (numInput.InputType == GUINumberInput.NumberType.Int)
{
switch (i)
{
case 0:
numInput.IntValue = r.X;
break;
case 1:
numInput.IntValue = r.Y;
break;
case 2:
numInput.IntValue = r.Width;
break;
case 3:
numInput.IntValue = r.Height;
break;
}
if (flash)
{
numInput.Flash(Color.LightGreen);
}
}
}
}
}
}
public SerializableEntityEditor(RectTransform parent, ISerializableEntity entity, bool inGame, bool showName, string style = "", int elementHeight = 24) : base(style, new RectTransform(Vector2.One, parent))
{
this.elementHeight = elementHeight;
List<SerializableProperty> editableProperties = inGame ?
SerializableProperty.GetProperties<InGameEditable>(entity) :
SerializableProperty.GetProperties<Editable>(entity);
if (parent != null) parent.AddChild(this);
layoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, RectTransform)) { AbsoluteSpacing = 2 };
if (showName)
{
new GUITextBlock(new Rectangle(0, 0, 100, 20), entity.Name, "",
Alignment.TopLeft, Alignment.TopLeft, this, false, GUI.Font);
new GUITextBlock(new RectTransform(new Point(layoutGroup.Rect.Width, elementHeight), layoutGroup.RectTransform), entity.Name, font: GUI.Font);
}
editableProperties.ForEach(ep => CreateNewField(ep, entity));
int y = showName ? 30 : 10, padding = 10;
foreach (var property in editableProperties)
{
//int boxHeight = 18;
//var editable = property.Attributes.OfType<Editable>().FirstOrDefault();
//if (editable != null) boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f);
object value = property.GetValue();
GUIComponent propertyField = null;
if (value is bool)
{
propertyField = CreateBoolField(entity, property, (bool)value, y, this);
}
else if (value.GetType().IsEnum)
{
propertyField = CreateEnumField(entity, property, value, y, this);
}
else if (value is string)
{
propertyField = CreateStringField(entity, property, (string)value, y, this);
}
else if (value is int)
{
propertyField = CreateIntField(entity, property, (int)value, y, this);
}
else if (value is float)
{
propertyField = CreateFloatField(entity, property, (float)value, y, this);
}
else if (value is Vector2)
{
propertyField = CreateVector2Field(entity, property, (Vector2)value, y, this);
}
else if (value is Vector3)
{
propertyField = CreateVector3Field(entity, property, (Vector3)value, y, this);
}
else if (value is Vector4)
{
propertyField = CreateVector4Field(entity, property, (Vector4)value, y, this);
}
else if (value is Color)
{
propertyField = CreateColorField(entity, property, (Color)value, y, this);
}
else if (value is Rectangle)
{
propertyField = CreateRectangleField(entity, property, (Rectangle)value, y, this);
}
if (propertyField != null)
{
y += propertyField.Rect.Height + padding;
}
}
if (children.Count > 0)
{
SetDimensions(new Point(Rect.Width, children.Last().Rect.Bottom - Rect.Y + 10), false);
}
else
{
SetDimensions(new Point(Rect.Width, 0), false);
}
if (parent is GUIListBox)
{
((GUIListBox)parent).UpdateScrollBarSize();
}
//scale the size of this component and the layout group to fit the children
int contentHeight = ContentHeight;
RectTransform.NonScaledSize = new Point(RectTransform.NonScaledSize.X, contentHeight);
layoutGroup.RectTransform.NonScaledSize = new Point(layoutGroup.RectTransform.NonScaledSize.X, contentHeight);
}
public void AddCustomContent(GUIComponent component, int childIndex)
{
childIndex = MathHelper.Clamp(childIndex, 0, children.Count);
component.RectTransform.Parent = layoutGroup.RectTransform;
component.RectTransform.RepositionChildInHierarchy(childIndex);
AddChild(component);
children.Remove(component);
children.Insert(childIndex, component);
if (childIndex > 0 )
{
component.Rect = new Rectangle(component.Rect.X, children[childIndex - 1].Rect.Bottom, component.Rect.Width, component.Rect.Height);
}
for (int i = childIndex + 1; i < children.Count; i++)
{
children[i].Rect = new Rectangle(children[i].Rect.X, children[i].Rect.Y + component.Rect.Height, children[i].Rect.Width, children[i].Rect.Height);
}
SetDimensions(new Point(Rect.Width, children.Last().Rect.Bottom - Rect.Y + 10), false);
int contentHeight = ContentHeight;
RectTransform.NonScaledSize = new Point(RectTransform.NonScaledSize.X, contentHeight);
layoutGroup.RectTransform.NonScaledSize = new Point(layoutGroup.RectTransform.NonScaledSize.X, contentHeight);
}
public override void Draw(SpriteBatch spriteBatch)
private GUIComponent CreateNewField(SerializableProperty property, ISerializableEntity entity)
{
base.Draw(spriteBatch);
DrawChildren(spriteBatch);
}
private GUIComponent CreateBoolField(ISerializableEntity entity, SerializableProperty property, bool value, int yPos, GUIComponent parent)
{
GUITickBox propertyTickBox = new GUITickBox(new Rectangle(10, yPos, 18, 18), property.Name, Alignment.Left, parent);
propertyTickBox.Font = GUI.SmallFont;
propertyTickBox.Selected = value;
propertyTickBox.ToolTip = property.GetAttribute<Editable>().ToolTip;
propertyTickBox.OnSelected = (tickBox) =>
object value = property.GetValue();
if (property.PropertyType == typeof(string) && value == null)
{
if (property.TrySetValue(tickBox.Selected))
value = "";
}
string displayName = property.GetAttribute<Editable>().DisplayName;
if (displayName == null)
{
displayName = property.Name.FormatCamelCaseWithSpaces();
}
string toolTip = property.GetAttribute<Editable>().ToolTip;
GUIComponent propertyField = null;
if (value is bool)
{
propertyField = CreateBoolField(entity, property, (bool)value, displayName, toolTip);
}
else if (value is string)
{
propertyField = CreateStringField(entity, property, (string)value, displayName, toolTip);
}
else if (value.GetType().IsEnum)
{
if (value.GetType().IsDefined(typeof(FlagsAttribute), inherit: false))
{
TrySendNetworkUpdate(entity, property);
propertyField = CreateEnumFlagField(entity, property, value, displayName, toolTip);
}
return true;
};
else
{
propertyField = CreateEnumField(entity, property, value, displayName, toolTip);
}
}
else if (value is int i)
{
propertyField = CreateIntField(entity, property, i, displayName, toolTip);
}
else if (value is float f)
{
propertyField = CreateFloatField(entity, property, f, displayName, toolTip);
}
else if (value is Point p)
{
propertyField = CreatePointField(entity, property, p, displayName, toolTip);
}
else if (value is Vector2 v2)
{
propertyField = CreateVector2Field(entity, property, v2, displayName, toolTip);
}
else if (value is Vector3 v3)
{
propertyField = CreateVector3Field(entity, property, v3, displayName, toolTip);
}
else if (value is Vector4 v4)
{
propertyField = CreateVector4Field(entity, property, v4, displayName, toolTip);
}
else if (value is Color c)
{
propertyField = CreateColorField(entity, property, c, displayName, toolTip);
}
else if (value is Rectangle r)
{
propertyField = CreateRectangleField(entity, property, r, displayName, toolTip);
}
return propertyField;
}
private GUIComponent CreateBoolField(ISerializableEntity entity, SerializableProperty property, bool value, string displayName, string toolTip)
{
GUITickBox propertyTickBox = new GUITickBox(new RectTransform(new Point(Rect.Width, elementHeight), layoutGroup.RectTransform), displayName)
{
Font = GUI.SmallFont,
Selected = value,
ToolTip = toolTip,
OnSelected = (tickBox) =>
{
if (property.TrySetValue(tickBox.Selected))
{
TrySendNetworkUpdate(entity, property);
}
return true;
}
};
Fields.Add(property.Name, new GUIComponent[] { propertyTickBox });
return propertyTickBox;
}
private GUIComponent CreateIntField(ISerializableEntity entity, SerializableProperty property, int value, int yPos, GUIComponent parent)
private GUIComponent CreateIntField(ISerializableEntity entity, SerializableProperty property, int value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
GUINumberInput numberInput = new GUINumberInput(new Rectangle(180, yPos, 0, 18), "", GUINumberInput.NumberType.Int, Alignment.Left, parent);
numberInput.ToolTip = property.GetAttribute<Editable>().ToolTip;
numberInput.Font = GUI.SmallFont;
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
ToolTip = toolTip
};
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform,
Anchor.TopRight), GUINumberInput.NumberType.Int)
{
ToolTip = toolTip,
Font = GUI.SmallFont
};
var editableAttribute = property.GetAttribute<Editable>();
numberInput.MinValueInt = editableAttribute.MinValueInt;
numberInput.MaxValueInt = editableAttribute.MaxValueInt;
numberInput.IntValue = value;
numberInput.OnValueChanged += (numInput) =>
{
if (property.TrySetValue(numInput.IntValue))
@@ -170,24 +395,29 @@ namespace Barotrauma
TrySendNetworkUpdate(entity, property);
}
};
return numberInput;
Fields.Add(property.Name, new GUIComponent[] { numberInput });
return frame;
}
private GUIComponent CreateFloatField(ISerializableEntity entity, SerializableProperty property, float value, int yPos, GUIComponent parent)
private GUIComponent CreateFloatField(ISerializableEntity entity, SerializableProperty property, float value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
GUINumberInput numberInput = new GUINumberInput(new Rectangle(180, yPos, 0, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent);
numberInput.ToolTip = property.GetAttribute<Editable>().ToolTip;
numberInput.Font = GUI.SmallFont;
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
ToolTip = toolTip
};
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform,
Anchor.TopRight), GUINumberInput.NumberType.Float)
{
ToolTip = toolTip,
Font = GUI.SmallFont
};
var editableAttribute = property.GetAttribute<Editable>();
numberInput.MinValueFloat = editableAttribute.MinValueFloat;
numberInput.MaxValueFloat = editableAttribute.MaxValueFloat;
numberInput.DecimalsToDisplay = editableAttribute.DecimalCount;
numberInput.valueStep = editableAttribute.ValueStep;
numberInput.FloatValue = value;
numberInput.OnValueChanged += (numInput) =>
{
if (property.TrySetValue(numInput.FloatValue))
@@ -195,23 +425,26 @@ namespace Barotrauma
TrySendNetworkUpdate(entity, property);
}
};
return numberInput;
Fields.Add(property.Name, new GUIComponent[] { numberInput });
return frame;
}
private GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, int yPos, GUIComponent parent)
private GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
GUIDropDown enumDropDown = new GUIDropDown(new Rectangle(180, yPos, 0, 18), "", "", Alignment.TopLeft, parent);
enumDropDown.ToolTip = property.GetAttribute<Editable>().ToolTip;
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, elementHeight), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
ToolTip = toolTip
};
GUIDropDown enumDropDown = new GUIDropDown(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform, Anchor.TopRight),
elementCount: Enum.GetValues(value.GetType()).Length)
{
ToolTip = toolTip
};
foreach (object enumValue in Enum.GetValues(value.GetType()))
{
var enumTextBlock = new GUITextBlock(new Rectangle(0, 0, 200, 25), enumValue.ToString(), "", enumDropDown);
enumTextBlock.UserData = enumValue;
enumDropDown.AddItem(enumValue.ToString(), enumValue);
}
enumDropDown.OnSelected += (selected, val) =>
{
if (property.TrySetValue(val))
@@ -220,49 +453,151 @@ namespace Barotrauma
}
return true;
};
enumDropDown.SelectItem(value);
return enumDropDown;
Fields.Add(property.Name, new GUIComponent[] { enumDropDown });
return frame;
}
private GUIComponent CreateStringField(ISerializableEntity entity, SerializableProperty property, string value, int yPos, GUIComponent parent)
private GUIComponent CreateEnumFlagField(ISerializableEntity entity, SerializableProperty property, object value, string displayName, string toolTip)
{
int boxHeight = 18;
var editable = property.GetAttribute<Editable>();
boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * boxHeight);
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
GUITextBox propertyBox = new GUITextBox(new Rectangle(0, yPos, 250, boxHeight), Alignment.Right, "", parent);
propertyBox.ToolTip = editable.ToolTip;
propertyBox.Font = GUI.SmallFont;
propertyBox.Text = value;
propertyBox.OnEnterPressed = (textBox, text) =>
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, elementHeight), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
if (property.TrySetValue(text))
ToolTip = toolTip
};
GUIDropDown enumDropDown = new GUIDropDown(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform, Anchor.TopRight),
elementCount: Enum.GetValues(value.GetType()).Length, selectMultiple: true)
{
ToolTip = toolTip
};
foreach (object enumValue in Enum.GetValues(value.GetType()))
{
enumDropDown.AddItem(enumValue.ToString(), enumValue);
if (((int)enumValue != 0 || (int)value == 0) && ((Enum)value).HasFlag((Enum)enumValue))
{
enumDropDown.SelectItem(enumValue);
}
}
enumDropDown.OnSelected += (selected, val) =>
{
if (property.TrySetValue(string.Join(", ", enumDropDown.SelectedDataMultiple.Select(d => d.ToString()))))
{
TrySendNetworkUpdate(entity, property);
textBox.Text = (string)property.GetValue();
textBox.Deselect();
}
return true;
};
return propertyBox;
}
private GUIComponent CreateVector2Field(ISerializableEntity entity, SerializableProperty property, Vector2 value, int yPos, GUIComponent parent)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
for (int i = 0; i < 2; i++)
Fields.Add(property.Name, new GUIComponent[] { enumDropDown });
return frame;
}
private GUIComponent CreateStringField(ISerializableEntity entity, SerializableProperty property, string value, string displayName, string toolTip)
{
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, elementHeight), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform), displayName, font: GUI.SmallFont, textAlignment: Alignment.Left)
{
new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), vectorComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent);
numberInput.Font = GUI.SmallFont;
ToolTip = toolTip
};
GUITextBox propertyBox = new GUITextBox(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform, Anchor.TopRight))
{
ToolTip = toolTip,
Font = GUI.SmallFont,
Text = value,
OnEnterPressed = (textBox, text) =>
{
if (property.TrySetValue(text))
{
TrySendNetworkUpdate(entity, property);
textBox.Text = (string)property.GetValue();
textBox.Deselect();
}
return true;
}
};
Fields.Add(property.Name, new GUIComponent[] { propertyBox });
return frame;
}
private GUIComponent CreatePointField(ISerializableEntity entity, SerializableProperty property, Point value, string displayName, string toolTip)
{
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
ToolTip = toolTip
};
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform, Anchor.TopRight), isHorizontal: true, childAnchor: Anchor.CenterRight)
{
Stretch = true,
RelativeSpacing = 0.05f
};
var editableAttribute = property.GetAttribute<Editable>();
var fields = new GUIComponent[2];
for (int i = 1; i >= 0; i--)
{
var element = new GUIFrame(new RectTransform(new Vector2(0.45f, 1), inputArea.RectTransform), style: null);
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), GUI.vectorComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
GUINumberInput.NumberType.Int)
{
Font = GUI.SmallFont
};
if (i == 0)
numberInput.IntValue = value.X;
else
numberInput.IntValue = value.Y;
numberInput.MinValueInt = editableAttribute.MinValueInt;
numberInput.MaxValueInt = editableAttribute.MaxValueInt;
int comp = i;
numberInput.OnValueChanged += (numInput) =>
{
Point newVal = (Point)property.GetValue();
if (comp == 0)
newVal.X = numInput.IntValue;
else
newVal.Y = numInput.IntValue;
if (property.TrySetValue(newVal))
{
TrySendNetworkUpdate(entity, property);
}
};
fields[i] = numberInput;
}
Fields.Add(property.Name, fields);
return frame;
}
private GUIComponent CreateVector2Field(ISerializableEntity entity, SerializableProperty property, Vector2 value, string displayName, string toolTip)
{
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
ToolTip = toolTip
};
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform, Anchor.TopRight), isHorizontal: true, childAnchor: Anchor.CenterRight)
{
Stretch = true,
RelativeSpacing = 0.05f
};
var editableAttribute = property.GetAttribute<Editable>();
var fields = new GUIComponent[2];
for (int i = 1; i >= 0; i--)
{
var element = new GUIFrame(new RectTransform(new Vector2(0.45f, 1), inputArea.RectTransform), style: null);
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), GUI.vectorComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
GUINumberInput.NumberType.Float)
{
Font = GUI.SmallFont
};
numberInput.MinValueFloat = editableAttribute.MinValueFloat;
numberInput.MaxValueFloat = editableAttribute.MaxValueFloat;
numberInput.DecimalsToDisplay = editableAttribute.DecimalCount;
numberInput.valueStep = editableAttribute.ValueStep;
if (i == 0)
numberInput.FloatValue = value.X;
@@ -283,21 +618,40 @@ namespace Barotrauma
TrySendNetworkUpdate(entity, property);
}
};
fields[i] = numberInput;
}
return label;
Fields.Add(property.Name, fields);
return frame;
}
// TODO: DRY, auto positioning
private GUIComponent CreateVector3Field(ISerializableEntity entity, SerializableProperty property, Vector3 value, int yPos, GUIComponent parent)
private GUIComponent CreateVector3Field(ISerializableEntity entity, SerializableProperty property, Vector3 value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
for (int i = 0; i < 3; i++)
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), vectorComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent);
numberInput.Font = GUI.SmallFont;
ToolTip = toolTip
};
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.7f, 1), frame.RectTransform, Anchor.TopRight), isHorizontal: true, childAnchor: Anchor.CenterRight)
{
Stretch = true,
RelativeSpacing = 0.03f
};
var editableAttribute = property.GetAttribute<Editable>();
var fields = new GUIComponent[3];
for (int i = 2; i >= 0; i--)
{
var element = new GUIFrame(new RectTransform(new Vector2(0.33f, 1), inputArea.RectTransform), style: null);
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), GUI.vectorComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
GUINumberInput.NumberType.Float)
{
Font = GUI.SmallFont
};
numberInput.MinValueFloat = editableAttribute.MinValueFloat;
numberInput.MaxValueFloat = editableAttribute.MaxValueFloat;
numberInput.DecimalsToDisplay = editableAttribute.DecimalCount;
numberInput.valueStep = editableAttribute.ValueStep;
if (i == 0)
numberInput.FloatValue = value.X;
@@ -322,20 +676,40 @@ namespace Barotrauma
TrySendNetworkUpdate(entity, property);
}
};
fields[i] = numberInput;
}
return label;
Fields.Add(property.Name, fields);
return frame;
}
private GUIComponent CreateVector4Field(ISerializableEntity entity, SerializableProperty property, Vector4 value, int yPos, GUIComponent parent)
private GUIComponent CreateVector4Field(ISerializableEntity entity, SerializableProperty property, Vector4 value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
for (int i = 0; i < 4; i++)
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.2f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), vectorComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent);
numberInput.Font = GUI.SmallFont;
ToolTip = toolTip
};
var editableAttribute = property.GetAttribute<Editable>();
var fields = new GUIComponent[4];
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 1), frame.RectTransform, Anchor.TopRight), isHorizontal: true, childAnchor: Anchor.CenterRight)
{
Stretch = true,
RelativeSpacing = 0.01f
};
for (int i = 3; i >= 0; i--)
{
var element = new GUIFrame(new RectTransform(new Vector2(0.22f, 1), inputArea.RectTransform) { MinSize = new Point(50, 0), MaxSize = new Point(150, 50) }, style: null);
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), GUI.vectorComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
GUINumberInput.NumberType.Float)
{
Font = GUI.SmallFont
};
numberInput.MinValueFloat = editableAttribute.MinValueFloat;
numberInput.MaxValueFloat = editableAttribute.MaxValueFloat;
numberInput.DecimalsToDisplay = editableAttribute.DecimalCount;
numberInput.valueStep = editableAttribute.ValueStep;
if (i == 0)
numberInput.FloatValue = value.X;
@@ -364,23 +738,39 @@ namespace Barotrauma
TrySendNetworkUpdate(entity, property);
}
};
fields[i] = numberInput;
}
return label;
Fields.Add(property.Name, fields);
return frame;
}
private GUIComponent CreateColorField(ISerializableEntity entity, SerializableProperty property, Color value, int yPos, GUIComponent parent)
private GUIComponent CreateColorField(ISerializableEntity entity, SerializableProperty property, Color value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
var colorBoxBack = new GUIFrame(new Rectangle(110 - 1, yPos - 1, 25 + 2, 18 + 2), Color.Black, Alignment.TopLeft, null, parent);
var colorBox = new GUIFrame(new Rectangle(110, yPos , 25, 18), value, Alignment.TopLeft, null, parent);
for (int i = 0; i < 4; i++)
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.2f, 1), frame.RectTransform) { MinSize = new Point(80, 26)}, displayName, font: GUI.SmallFont)
{
new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), colorComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Int, Alignment.Left, parent);
ToolTip = toolTip
};
var colorBoxBack = new GUIFrame(new RectTransform(new Vector2(0.075f, 1), frame.RectTransform)
{
AbsoluteOffset = new Point(label.Rect.Width, 0)
}, color: Color.Black, style: null);
var colorBox = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), colorBoxBack.RectTransform, Anchor.Center), style: null);
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.7f, 1), frame.RectTransform, Anchor.TopRight), isHorizontal: true, childAnchor: Anchor.CenterRight)
{
Stretch = true,
RelativeSpacing = 0.01f
};
var fields = new GUIComponent[4];
for (int i = 3; i >= 0; i--)
{
var element = new GUIFrame(new RectTransform(new Vector2(0.2f, 1), inputArea.RectTransform) { MinSize = new Point(40, 0), MaxSize = new Point(100, 50) }, style: null);
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), GUI.colorComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
GUINumberInput.NumberType.Int)
{
Font = GUI.SmallFont
};
numberInput.MinValueInt = 0;
numberInput.MaxValueInt = 255;
@@ -414,20 +804,39 @@ namespace Barotrauma
colorBox.Color = newVal;
}
};
colorBox.Color = (Color)property.GetValue();
fields[i] = numberInput;
}
return label;
Fields.Add(property.Name, fields);
return frame;
}
private GUIComponent CreateRectangleField(ISerializableEntity entity, SerializableProperty property, Rectangle value, int yPos, GUIComponent parent)
private GUIComponent CreateRectangleField(ISerializableEntity entity, SerializableProperty property, Rectangle value, string displayName, string toolTip)
{
var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont);
label.ToolTip = property.GetAttribute<Editable>().ToolTip;
for (int i = 0; i < 4; i++)
var frame = new GUIFrame(new RectTransform(new Point(Rect.Width, Math.Max(elementHeight, 26)), layoutGroup.RectTransform), color: Color.Transparent);
var label = new GUITextBlock(new RectTransform(new Vector2(0.2f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
{
new GUITextBlock(new Rectangle(140 + i * 70, yPos, 100, 18), rectComponentLabels[i], "", Alignment.TopLeft, Alignment.CenterLeft, parent, false, GUI.SmallFont);
GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Int, Alignment.Left, parent);
numberInput.Font = GUI.SmallFont;
ToolTip = toolTip
};
var fields = new GUIComponent[4];
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 1), frame.RectTransform, Anchor.TopRight), isHorizontal: true, childAnchor: Anchor.CenterRight)
{
Stretch = true,
RelativeSpacing = 0.01f
};
for (int i = 3; i >= 0; i--)
{
var element = new GUIFrame(new RectTransform(new Vector2(0.22f, 1), inputArea.RectTransform) { MinSize = new Point(50, 0), MaxSize = new Point(150, 50) }, style: null);
new GUITextBlock(new RectTransform(new Vector2(0.3f, 1), element.RectTransform, Anchor.CenterLeft), GUI.rectComponentLabels[i], font: GUI.SmallFont, textAlignment: Alignment.CenterLeft);
GUINumberInput numberInput = new GUINumberInput(new RectTransform(new Vector2(0.7f, 1), element.RectTransform, Anchor.CenterRight),
GUINumberInput.NumberType.Int)
{
Font = GUI.SmallFont
};
// Not sure if the min value could in any case be negative.
numberInput.MinValueInt = 0;
// Just something reasonable to keep the value in the input rect.
numberInput.MaxValueInt = 9999;
if (i == 0)
numberInput.IntValue = value.X;
@@ -456,11 +865,12 @@ namespace Barotrauma
TrySendNetworkUpdate(entity, property);
}
};
fields[i] = numberInput;
}
return label;
Fields.Add(property.Name, fields);
return frame;
}
private void TrySendNetworkUpdate(ISerializableEntity entity, SerializableProperty property)
{
if (entity is ItemComponent e)