(667564ff6) Fixed item scale not being saved and item rect not being scaled according to the item's scale. Closes #1547
This commit is contained in:
@@ -70,7 +70,9 @@ namespace Barotrauma
|
||||
|
||||
private Inventory parentInventory;
|
||||
private Inventory ownInventory;
|
||||
|
||||
|
||||
private Rectangle defaultRect;
|
||||
|
||||
private Dictionary<string, Connection> connections;
|
||||
|
||||
private List<Repairable> 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<IDrawableComponent>();
|
||||
tags = new HashSet<string>();
|
||||
repairables = new List<Repairable>();
|
||||
|
||||
|
||||
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<string, SerializableProperty> property in SerializableProperties)
|
||||
{
|
||||
if (!property.Value.Attributes.OfType<Editable>().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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user