diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 8a8725e0b..49400fd62 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -70,7 +70,9 @@ namespace Barotrauma private Inventory parentInventory; private Inventory ownInventory; - + + private Rectangle defaultRect; + private Dictionary connections; private List repairables; @@ -198,6 +200,26 @@ namespace Barotrauma } } + private float scale = 1.0f; + public override float Scale + { + get { return scale; } + set + { + if (scale == value) { return; } + scale = MathHelper.Clamp(value, 0.1f, 10.0f); + + float relativeScale = scale / prefab.Scale; + + if (!ResizeHorizontal || !ResizeVertical) + { + int newWidth = ResizeHorizontal ? rect.Width : (int)(defaultRect.Width * relativeScale); + int newHeight = ResizeVertical ? rect.Height : (int)(defaultRect.Height * relativeScale); + Rect = new Rectangle(rect.X, rect.Y, newWidth, newHeight); + } + } + } + public float PositionUpdateInterval { get; @@ -499,9 +521,10 @@ namespace Barotrauma drawableComponents = new List(); tags = new HashSet(); repairables = new List(); - + + defaultRect = newRect; rect = newRect; - + condition = itemPrefab.Health; lastSentCondition = condition; @@ -634,7 +657,10 @@ namespace Barotrauma public override MapEntity Clone() { - Item clone = new Item(rect, Prefab, Submarine, callOnItemLoaded: false); + Item clone = new Item(rect, Prefab, Submarine, callOnItemLoaded: false) + { + defaultRect = defaultRect + }; foreach (KeyValuePair property in SerializableProperties) { if (!property.Value.Attributes.OfType().Any()) continue; @@ -2052,11 +2078,11 @@ namespace Barotrauma System.Diagnostics.Debug.Assert(Submarine != null || rootContainer.ParentInventory?.Owner is Character); Vector2 subPosition = Submarine == null ? Vector2.Zero : Submarine.HiddenSubPosition; - + element.Add(new XAttribute("rect", (int)(rect.X - subPosition.X) + "," + (int)(rect.Y - subPosition.Y) + "," + - rect.Width + "," + rect.Height)); + defaultRect.Width + "," + defaultRect.Height)); if (linkedTo != null && linkedTo.Count > 0) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs index 84bcce6c5..83600423c 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs @@ -555,7 +555,7 @@ namespace Barotrauma } } - [Serialize(1f, false), Editable(0.1f, 10f, DecimalCount = 3, ValueStep = 0.1f)] + [Serialize(1f, true), Editable(0.1f, 10f, DecimalCount = 3, ValueStep = 0.1f)] public virtual float Scale { get; set; } = 1; #endregion }