From b3769b383a7e5398d29a828a733f3c9704681a86 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 13 Nov 2017 20:55:07 +0200 Subject: [PATCH] - Input field for rects. - Input fields for ItemComponent requiredItems. - Added tooltips to a bunch of editable ItemComponent properties. - Misc fixes. --- .../BarotraumaClient/Source/GUI/GUITextBox.cs | 5 +- .../BarotraumaClient/Source/GUI/GUITickBox.cs | 2 +- .../Source/Items/Components/ItemLabel.cs | 2 +- .../BarotraumaClient/Source/Items/Item.cs | 137 ++++-------------- .../Serialization/SerializableEntityEditor.cs | 129 +++++++++++++---- .../Source/Items/Components/Door.cs | 18 +-- .../Items/Components/Machines/Engine.cs | 15 +- .../Items/Components/Machines/MiniMap.cs | 6 +- .../Components/Machines/OxygenGenerator.cs | 19 +-- .../Items/Components/Machines/Reactor.cs | 6 +- .../Items/Components/Machines/Steering.cs | 3 +- .../Items/Components/Power/PowerContainer.cs | 8 +- .../Source/Items/Components/Power/Powered.cs | 12 +- .../Items/Components/Signal/LightComponent.cs | 5 +- .../Items/Components/Signal/WifiComponent.cs | 17 +-- .../Serialization/SerializableProperty.cs | 8 +- .../Source/Serialization/XMLExtensions.cs | 14 +- 17 files changed, 176 insertions(+), 230 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs index f9c02e9a9..b756bd809 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs @@ -120,7 +120,10 @@ namespace Barotrauma { base.Rect = value; - textBlock.Rect = value; + if (textBlock != null) + { + textBlock.Rect = value; + } } } diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs index 7e24f58ef..27dea057a 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUITickBox.cs @@ -51,7 +51,7 @@ namespace Barotrauma base.Rect = value; box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height); - text.Rect = new Rectangle(box.Rect.Right + 10, box.Rect.Y + 2, 20, box.Rect.Height); + text.Rect = new Rectangle(box.Rect.Right, box.Rect.Y + 2, 20, box.Rect.Height); } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs index 662b62f65..da578c595 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemLabel.cs @@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components } } - [Editable, Serialize(1.0f, true)] + [Editable(0.0f, 10.0f), Serialize(1.0f, true)] public float TextScale { get { return textBlock == null ? 1.0f : textBlock.TextScale; } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Item.cs b/Barotrauma/BarotraumaClient/Source/Items/Item.cs index 4054d6a42..d6b3cc93b 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Item.cs @@ -7,7 +7,6 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; namespace Barotrauma @@ -150,138 +149,54 @@ namespace Barotrauma private GUIComponent CreateEditingHUD(bool inGame = false) { - /*List editableProperties = inGame ? GetProperties() : GetProperties(); - - int requiredItemCount = 0; - if (!inGame) - { - foreach (ItemComponent ic in components) - { - requiredItemCount += ic.requiredItems.Count; - } - }*/ - int width = 450; int height = 150; int x = GameMain.GraphicsWidth / 2 - width / 2, y = 30; - /*foreach (var objectProperty in editableProperties) - { - var editable = objectProperty.Attributes.OfType().FirstOrDefault(); - if (editable != null) height += (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f) + 5; - }*/ editingHUD = new GUIListBox(new Rectangle(x, y, width, height), ""); + ((GUIListBox)editingHUD).Spacing = 5; editingHUD.UserData = this; - - /*new GUITextBlock(new Rectangle(0, 0, 0, 20), prefab.Name, "", - Alignment.TopLeft, Alignment.TopLeft, editingHUD, false, GUI.LargeFont);*/ - - new SerializableEntityEditor(this, inGame, editingHUD, true); - - //y += 25; - - /*if (!inGame) + + var itemEditor = new SerializableEntityEditor(this, inGame, editingHUD, true); + + if (!inGame && prefab.IsLinkable) { - if (prefab.IsLinkable) - { - new GUITextBlock(new Rectangle(0, 5, 0, 20), "Hold space to link to another item", - "", Alignment.TopRight, Alignment.TopRight, editingHUD).Font = GUI.SmallFont; - } - foreach (ItemComponent ic in components) - { - foreach (RelatedItem relatedItem in ic.requiredItems) - { - new GUITextBlock(new Rectangle(0, y, 100, 15), ic.Name + ": " + relatedItem.Type.ToString() + " required", "", Alignment.TopLeft, Alignment.CenterLeft, editingHUD, false, GUI.SmallFont); - GUITextBox namesBox = new GUITextBox(new Rectangle(-10, y, 160, 15), Alignment.Right, "", editingHUD); - namesBox.Font = GUI.SmallFont; - - PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(relatedItem); - PropertyDescriptor property = properties.Find("JoinedNames", false); - - namesBox.Text = relatedItem.JoinedNames; - namesBox.UserData = new SerializableProperty(property, relatedItem); - namesBox.OnEnterPressed = EnterProperty; - namesBox.OnTextChanged = PropertyChanged; - - y += 20; - } - } - if (requiredItemCount > 0) y += 10; - }*/ + itemEditor.AddCustomContent(new GUITextBlock(new Rectangle(0, 0, 0, 20), "Hold space to link to another item", "", null, GUI.SmallFont), 1); + } foreach (ItemComponent ic in components) { - if (SerializableProperty.GetProperties(ic).Count == 0) continue; - new SerializableEntityEditor(ic, inGame, editingHUD, false); - } - - /*foreach (var objectProperty in editableProperties) - { - int boxHeight = 18; - var editable = objectProperty.Attributes.OfType().FirstOrDefault(); - if (editable != null) boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f); + var componentEditor = new SerializableEntityEditor(ic, inGame, editingHUD, !inGame); - object value = objectProperty.GetValue(); + if (inGame) continue; - if (value is bool) + foreach (RelatedItem relatedItem in ic.requiredItems) { - GUITickBox propertyTickBox = new GUITickBox(new Rectangle(10, y, 18, boxHeight), objectProperty.Name, - Alignment.Left, editingHUD); - propertyTickBox.Font = GUI.SmallFont; + var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 20), relatedItem.Type.ToString() + " required", "", Alignment.TopLeft, Alignment.CenterLeft, null, false, GUI.SmallFont); + textBlock.Padding = Vector4.Zero; + componentEditor.AddCustomContent(textBlock, 1); - propertyTickBox.Selected = (bool)value; + GUITextBox namesBox = new GUITextBox(new Rectangle(0, 0, 180, 20), Alignment.Right, "", textBlock); + namesBox.Font = GUI.SmallFont; + namesBox.Text = relatedItem.JoinedNames; - propertyTickBox.UserData = objectProperty; - propertyTickBox.OnSelected = EnterProperty; - } - else if (value.GetType().IsEnum) - { - new GUITextBlock(new Rectangle(0, y, 100, 18), objectProperty.Name, "", Alignment.TopLeft, Alignment.Left, editingHUD, false, GUI.SmallFont); - GUIDropDown enumDropDown = new GUIDropDown(new Rectangle(180, y, 250, boxHeight), "", "", editingHUD); - foreach (object enumValue in Enum.GetValues(value.GetType())) + namesBox.OnDeselected += (textBox, key) => { - var enumTextBlock = new GUITextBlock(new Rectangle(0, 0, 200, 25), enumValue.ToString(), "", enumDropDown); - enumTextBlock.UserData = enumValue; - } + relatedItem.JoinedNames = textBox.Text; + textBox.Text = relatedItem.JoinedNames; + }; - enumDropDown.OnSelected += (selected, val) => + namesBox.OnEnterPressed += (textBox, text) => { - objectProperty.TrySetValue(val); + relatedItem.JoinedNames = text; + textBox.Text = relatedItem.JoinedNames; return true; }; - enumDropDown.SelectItem(value); + y += 20; } - else - { - new GUITextBlock(new Rectangle(0, y, 100, 18), objectProperty.Name, "", Alignment.TopLeft, Alignment.Left, editingHUD, false, GUI.SmallFont); - - GUITextBox propertyBox = new GUITextBox(new Rectangle(180, y, 250, boxHeight), "", editingHUD); - propertyBox.Font = GUI.SmallFont; - if (boxHeight > 18) propertyBox.Wrap = true; - - if (value != null) - { - if (value is float) - { - propertyBox.Text = ((float)value).ToString("G", System.Globalization.CultureInfo.InvariantCulture); - } - else - { - - propertyBox.Text = value.ToString(); - } - } - - propertyBox.UserData = objectProperty; - propertyBox.OnEnterPressed = EnterProperty; - propertyBox.OnTextChanged = PropertyChanged; - - } - y = y + boxHeight + 5; - }*/ - - + } + editingHUD.SetDimensions(new Point(editingHUD.Rect.Width, MathHelper.Clamp(editingHUD.children.Sum(c => c.Rect.Height), 50, editingHUD.Rect.Height))); return editingHUD; diff --git a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs index 159fea11f..7c845ab01 100644 --- a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs +++ b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs @@ -11,7 +11,7 @@ namespace Barotrauma { private static readonly string[] vectorComponentLabels = { "X", "Y", "Z", "W" }; - private static readonly string[] rectComponentLabels = { "X", "Y", "Width", "Height" }; + private static readonly string[] rectComponentLabels = { "X", "Y", "W", "H" }; private static readonly string[] colorComponentLabels = { "R", "G", "B", "A" }; //private GUIComponent editingHUD; @@ -22,35 +22,15 @@ namespace Barotrauma SerializableProperty.GetProperties(entity) : SerializableProperty.GetProperties(entity); - if (parent != null) - parent.AddChild(this); - - /*int requiredItemCount = 0; - if (!inGame) - { - foreach (ItemComponent ic in components) - { - requiredItemCount += ic.requiredItems.Count; - } - } + if (parent != null) parent.AddChild(this); - foreach (var objectProperty in editableProperties) - { - var editable = objectProperty.Attributes.OfType().FirstOrDefault(); - if (editable != null) height += (int)(Math.Ceiling(editable.MaxLength / 40.0f) * 18.0f) + 5; - } - - editingHUD = new GUIFrame(new Rectangle(0, 0, 0, 0), null, parent); - editingHUD.Padding = new Vector4(10, 0, 0, 10); - editingHUD.UserData = this;*/ - if (showName) { new GUITextBlock(new Rectangle(0, 0, 100, 20), entity.Name, "", Alignment.TopLeft, Alignment.TopLeft, this, false, GUI.Font); } - int y = 30, padding = 10; + int y = showName ? 30 : 10, padding = 10; foreach (var property in editableProperties) { //int boxHeight = 18; @@ -96,6 +76,10 @@ namespace Barotrauma { propertyField = CreateColorField(entity, property, (Color)value, y, this); } + else if (value is Rectangle) + { + propertyField = CreateRectangleField(entity, property, (Rectangle)value, y, this); + } if (propertyField != null) { @@ -106,6 +90,26 @@ namespace Barotrauma SetDimensions(new Point(Rect.Width, children.Last().Rect.Bottom - Rect.Y + 10), false); } + public void AddCustomContent(GUIComponent component, int childIndex) + { + childIndex = MathHelper.Clamp(childIndex, 0, children.Count); + + 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); + } + public override void Draw(SpriteBatch spriteBatch) { base.Draw(spriteBatch); @@ -134,7 +138,7 @@ namespace Barotrauma private GUIComponent CreateIntField(ISerializableEntity entity, SerializableProperty property, int value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; GUINumberInput numberInput = new GUINumberInput(new Rectangle(180, yPos, 0, 18), "", GUINumberInput.NumberType.Int, Alignment.Left, parent); numberInput.ToolTip = property.GetAttribute().ToolTip; @@ -159,7 +163,7 @@ namespace Barotrauma private GUIComponent CreateFloatField(ISerializableEntity entity, SerializableProperty property, float value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; GUINumberInput numberInput = new GUINumberInput(new Rectangle(180, yPos, 0, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent); numberInput.ToolTip = property.GetAttribute().ToolTip; @@ -184,7 +188,7 @@ namespace Barotrauma private GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; GUIDropDown enumDropDown = new GUIDropDown(new Rectangle(180, yPos, 0, 18), "", "", Alignment.TopLeft, parent); enumDropDown.ToolTip = property.GetAttribute().ToolTip; @@ -215,7 +219,7 @@ namespace Barotrauma var editable = property.GetAttribute(); boxHeight = (int)(Math.Ceiling(editable.MaxLength / 40.0f) * boxHeight); - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; GUITextBox propertyBox = new GUITextBox(new Rectangle(0, yPos, 250, boxHeight), Alignment.Right, "", parent); propertyBox.ToolTip = editable.ToolTip; @@ -236,7 +240,7 @@ namespace Barotrauma private GUIComponent CreateVector2Field(ISerializableEntity entity, SerializableProperty property, Vector2 value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; for (int i = 0; i < 2; i++) @@ -245,6 +249,11 @@ namespace Barotrauma GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent); numberInput.Font = GUI.SmallFont; + if (i == 0) + numberInput.FloatValue = value.X; + else + numberInput.FloatValue = value.Y; + int comp = i; numberInput.OnValueChanged += (numInput) => { @@ -266,7 +275,7 @@ namespace Barotrauma private GUIComponent CreateVector3Field(ISerializableEntity entity, SerializableProperty property, Vector3 value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; for (int i = 0; i < 3; i++) { @@ -274,6 +283,13 @@ namespace Barotrauma GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent); numberInput.Font = GUI.SmallFont; + if (i == 0) + numberInput.FloatValue = value.X; + else if (i == 1) + numberInput.FloatValue = value.Y; + else if (i == 2) + numberInput.FloatValue = value.Z; + int comp = i; numberInput.OnValueChanged += (numInput) => { @@ -297,7 +313,7 @@ namespace Barotrauma private GUIComponent CreateVector4Field(ISerializableEntity entity, SerializableProperty property, Vector4 value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; for (int i = 0; i < 4; i++) { @@ -305,6 +321,15 @@ namespace Barotrauma GUINumberInput numberInput = new GUINumberInput(new Rectangle(160 + i * 70, yPos, 45, 18), "", GUINumberInput.NumberType.Float, Alignment.Left, parent); numberInput.Font = GUI.SmallFont; + if (i == 0) + numberInput.FloatValue = value.X; + else if (i == 1) + numberInput.FloatValue = value.Y; + else if (i == 2) + numberInput.FloatValue = value.Z; + else + numberInput.FloatValue = value.W; + int comp = i; numberInput.OnValueChanged += (numInput) => { @@ -330,7 +355,7 @@ namespace Barotrauma private GUIComponent CreateColorField(ISerializableEntity entity, SerializableProperty property, Color value, int yPos, GUIComponent parent) { - var label = new GUITextBlock(new Rectangle(0, yPos, 100, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); + var label = new GUITextBlock(new Rectangle(0, yPos, 0, 18), property.Name, "", Alignment.TopLeft, Alignment.Left, parent, false, GUI.SmallFont); label.ToolTip = property.GetAttribute().ToolTip; var colorBoxBack = new GUIFrame(new Rectangle(110 - 1, yPos - 1, 25 + 2, 18 + 2), Color.Black, Alignment.TopLeft, null, parent); @@ -378,6 +403,48 @@ namespace Barotrauma return label; } + private GUIComponent CreateRectangleField(ISerializableEntity entity, SerializableProperty property, Rectangle 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().ToolTip; + for (int i = 0; i < 4; i++) + { + 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; + + if (i == 0) + numberInput.IntValue = value.X; + else if (i == 1) + numberInput.IntValue = value.Y; + else if (i == 2) + numberInput.IntValue = value.Width; + else + numberInput.IntValue = value.Height; + + int comp = i; + numberInput.OnValueChanged += (numInput) => + { + Rectangle newVal = (Rectangle)property.GetValue(); + if (comp == 0) + newVal.X = numInput.IntValue; + else if (comp == 1) + newVal.Y = numInput.IntValue; + else if (comp == 2) + newVal.Width = numInput.IntValue; + else + newVal.Height = numInput.IntValue; + + if (property.TrySetValue(newVal)) + { + TrySendNetworkUpdate(entity, property); + } + }; + } + + return label; + } + private void TrySendNetworkUpdate(ISerializableEntity entity, SerializableProperty property) { if (GameMain.Server != null) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs index dc3feecee..5cf96029e 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs @@ -112,24 +112,12 @@ namespace Barotrauma.Items.Components } [Serialize("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)); } - set - { - Vector4 vector = XMLExtensions.ParseVector4(value); - if (vector.Z != 0.0f || vector.W != 0.0f) - { - window = new Rectangle((int)vector.X, (int)vector.Y, (int)vector.Z, (int)vector.W); - } - } - } - - public Rectangle WindowRect + public Rectangle Window { get { return window; } + set { window = value; } } - + [Editable, Serialize(false, true)] public bool IsOpen { diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs index 1d368b612..32d68bc02 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs @@ -12,18 +12,9 @@ namespace Barotrauma.Items.Components private float targetForce; private float maxForce; - - //[Editable, HasDefaultValue(1.0f, true)] - //public float PowerPerForce - //{ - // get { return powerPerForce; } - // set - // { - // powerPerForce = Math.Max(0.0f, value); - // } - //} - - [Editable, Serialize(2000.0f, true)] + + [Editable(0.0f, 10000000.0f, ToolTip = "The amount of force exerted on the submarine when the engine is operating at full power."), + Serialize(2000.0f, true)] public float MaxForce { get { return maxForce; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs index a32940bb9..ba6a0c55c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/MiniMap.cs @@ -16,21 +16,21 @@ namespace Barotrauma.Items.Components bool hasPower; - [Editable, Serialize(false, true)] + [Editable(ToolTip = "Does the machine require inputs from water detectors in order to show the water levels inside rooms."), Serialize(false, true)] public bool RequireWaterDetectors { get; set; } - [Editable, Serialize(true, true)] + [Editable(ToolTip = "Does the machine require inputs from oxygen detectors in order to show the oxygen levels inside rooms."), Serialize(true, true)] public bool RequireOxygenDetectors { get; set; } - [Editable, Serialize(false, true)] + [Editable(ToolTip = "Should damaged walls be displayed by the machine."), Serialize(false, true)] public bool ShowHullIntegrity { get; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs index 8bbeb187a..a7cb87a53 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/OxygenGenerator.cs @@ -8,28 +8,23 @@ namespace Barotrauma.Items.Components { class OxygenGenerator : Powered { - float powerDownTimer; + private float powerDownTimer; - bool running; + private bool running; private float generatedAmount; - List ventList; + private List ventList; private float totalHullVolume; - - public bool IsRunning() - { - return (running && item.Condition>0.0f); - } - + public float CurrFlow { get; private set; } - [Editable, Serialize(100.0f, true)] + [Editable(ToolTip = "How much oxygen the machine generates when operating at full power."), Serialize(100.0f, true)] public float GeneratedAmount { get { return generatedAmount; } @@ -40,8 +35,6 @@ namespace Barotrauma.Items.Components : base(item, element) { IsActive = true; - - //item.linkedTo.CollectionChanged += delegate { GetVents(); }; } public override void Update(float deltaTime, Camera cam) @@ -66,7 +59,7 @@ namespace Barotrauma.Items.Components running = true; - CurrFlow = Math.Min(voltage, 1.0f) * generatedAmount*100.0f; + CurrFlow = Math.Min(voltage, 1.0f) * generatedAmount * 100.0f; //item.CurrentHull.Oxygen += CurrFlow * deltaTime; UpdateVents(CurrFlow); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs index ca6d2a605..b47b69d5a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Reactor.cs @@ -54,7 +54,7 @@ namespace Barotrauma.Items.Components private float? nextServerLogWriteTime; private float lastServerLogWriteTime; - [Editable, Serialize(9500.0f, true)] + [Editable(ToolTip = "The temperature at which the reactor melts down."), Serialize(9500.0f, true)] public float MeltDownTemp { get { return meltDownTemp; } @@ -64,7 +64,7 @@ namespace Barotrauma.Items.Components } } - [Editable, Serialize(9000.0f, true)] + [Editable(ToolTip = "The temperature at which the reactor catches fire."), Serialize(9000.0f, true)] public float FireTemp { get { return fireTemp; } @@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components } } - [Editable, Serialize(1.0f, true)] + [Editable(0.0f, float.MaxValue, ToolTip = "How much power (kW) the reactor generates relative to it's operating temperature (kW per one degree Celsius)."), Serialize(1.0f, true)] public float PowerPerTemp { get { return powerPerTemp; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs index 544eb2b04..b648347cc 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Steering.cs @@ -67,7 +67,8 @@ namespace Barotrauma.Items.Components } } - [Editable, Serialize(0.5f, true)] + [Editable(0.0f, 1.0f, ToolTip = "How full the ballast tanks should be when the submarine is not being steered upwards/downwards." + +" Can be used to compensate if the ballast tanks are too large/small relative to the size of the submarine."), Serialize(0.5f, true)] public float NeutralBallastLevel { get { return neutralBallastLevel; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs index 2e1dc6ab3..be46a3539 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs @@ -32,14 +32,15 @@ namespace Barotrauma.Items.Components private set; } - [Editable, Serialize(10.0f, true)] + [Editable(ToolTip = "Maximum output of the device when fully charged (kW)."), Serialize(10.0f, true)] public float MaxOutPut { set { maxOutput = value; } get { return maxOutput; } } - [Serialize(10.0f, true), Editable] + [Serialize(10.0f, true), Editable(ToolTip = "The maximum capacity of the device (kW * min). "+ + "For example, a value of 1000 means the device can output 100 kilowatts of power for 10 minutes, or 1000 kilowatts for 1 minute.")] public float Capacity { get { return capacity; } @@ -75,7 +76,8 @@ namespace Barotrauma.Items.Components } } - [Serialize(10.0f, false), Editable] + [Serialize(10.0f, false), Editable(ToolTip = "How fast the device can be recharged. "+ + "For example, a recharge speed of 100 kW and a capacity of 1000 kW*min would mean it takes 10 minutes to fully charge the device.")] public float MaxRechargeSpeed { get { return maxRechargeSpeed; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs index c053ce9fe..3f17757a3 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Power/Powered.cs @@ -18,14 +18,16 @@ namespace Barotrauma.Items.Components //the maximum amount of power the item can draw from connected items protected float powerConsumption; - [Editable, Serialize(0.5f, true)] + [Serialize(0.5f, true), Editable(ToolTip = "The minimum voltage required for the device to function. "+ + "The voltage is calculated as power / powerconsumption, meaning that a device "+ + "with a power consumption of 1000 kW would need at least 500 kW of power to work if the minimum voltage is set to 0.5.")] public float MinVoltage { get { return minVoltage; } set { minVoltage = value; } } - [Editable, Serialize(0.0f, true)] + [Editable(ToolTip = "How much power the device draws (or attempts to draw) from the electrical grid."), Serialize(0.0f, true)] public float PowerConsumption { get { return powerConsumption; } @@ -33,12 +35,12 @@ namespace Barotrauma.Items.Components } - [Serialize(false,true)] + [Serialize(false, true)] public override bool IsActive { get { return base.IsActive; } - set - { + set + { base.IsActive = value; if (!value) currPowerConsumption = 0.0f; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs index a530a369b..99797afd9 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs @@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components private bool castShadows; - [Editable, Serialize(100.0f, true)] + [Editable(0.0f, 2048.0f), Serialize(100.0f, true)] public float Range { get { return range; } @@ -31,7 +31,8 @@ namespace Barotrauma.Items.Components } } - [Editable, Serialize(true, true)] + [Editable(ToolTip = "Should structures cast shadows when light from this light source hits them. "+ + "Disabling shadows increases the performance of the game, and is recommended for lights with a short range."), Serialize(true, true)] public bool CastShadows { get { return castShadows; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs index b4cf4904a..e3ee5ff30 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/WifiComponent.cs @@ -31,7 +31,7 @@ namespace Barotrauma.Items.Components } } - [Editable, Serialize(false, false)] + [Editable(ToolTip = "If enabled, any signals received by the item are displayed as chat messages in the chatbox of the player holding the item."), Serialize(false, false)] public bool LinkToChat { get; @@ -49,20 +49,7 @@ namespace Barotrauma.Items.Components { return HasRequiredContainedItems(true); } - - /*public void Transmit(string signal) - { - if (!CanTransmit()) return; - - var receivers = GetReceiversInRange(); - foreach (WifiComponent w in receivers) - { - var connections = w.item.Connections; - - w.ReceiveSignal(1, signal, connections == null ? null : connections.Find(c => c.Name == "signal_in"), item, null); - } - }*/ - + private List GetReceiversInRange() { return list.FindAll(w => w != this && w.CanReceive(this)); diff --git a/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs b/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs index 558fc1958..2918f2fa1 100644 --- a/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs +++ b/Barotrauma/BarotraumaShared/Source/Serialization/SerializableProperty.cs @@ -15,8 +15,8 @@ namespace Barotrauma { public int MaxLength; - public int? MinValueInt, MaxValueInt; - public float? MinValueFloat, MaxValueFloat; + public int MinValueInt = int.MinValue, MaxValueInt = int.MaxValue; + public float MinValueFloat = float.MinValue, MaxValueFloat = float.MaxValue; public string ToolTip; @@ -25,13 +25,13 @@ namespace Barotrauma MaxLength = maxLength; } - public Editable(int? minValue, int? maxValue) + public Editable(int minValue, int maxValue) { MinValueInt = minValue; MaxValueInt = maxValue; } - public Editable(float? minValue, float? maxValue) + public Editable(float minValue, float maxValue) { MinValueFloat = minValue; MaxValueFloat = maxValue; diff --git a/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs b/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs index ebb6ccdd7..fba3131c8 100644 --- a/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs +++ b/Barotrauma/BarotraumaShared/Source/Serialization/XMLExtensions.cs @@ -338,26 +338,22 @@ namespace Barotrauma return new Color(components[0], components[1], components[2], components[3]); } - public static Color ParseRect(string stringColor, bool errorMessages = true) + public static Rectangle ParseRect(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; + return new Rectangle(0, 0, 0, 0); } - float[] components = new float[4] { 1.0f, 1.0f, 1.0f, 1.0f }; - + int[] components = new int[4] { 0, 0, 0, 0 }; for (int i = 0; i < 4 && i < strComponents.Length; i++) { - float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]); + int.TryParse(strComponents[i], out components[i]); } - return new Color(components[0], components[1], components[2], components[3]); + return new Rectangle(components[0], components[1], components[2], components[3]); } public static float[] ParseFloatArray(string[] stringArray)