(f0d812055) v0.9.9.0

This commit is contained in:
Joonas Rikkonen
2020-04-23 19:19:37 +03:00
parent b647059b93
commit ac37a3b0e4
391 changed files with 15054 additions and 5420 deletions

View File

@@ -399,7 +399,7 @@ namespace Barotrauma
ToolTip = toolTip,
OnSelected = (tickBox) =>
{
if (property.TrySetValue(entity, tickBox.Selected))
if (SetPropertyValue(property, entity, tickBox.Selected))
{
TrySendNetworkUpdate(entity, property);
}
@@ -440,7 +440,7 @@ namespace Barotrauma
numberInput.IntValue = value;
numberInput.OnValueChanged += (numInput) =>
{
if (property.TrySetValue(entity, numInput.IntValue))
if (SetPropertyValue(property, entity, numInput.IntValue))
{
TrySendNetworkUpdate(entity, property);
}
@@ -474,7 +474,7 @@ namespace Barotrauma
numberInput.OnValueChanged += (numInput) =>
{
if (property.TrySetValue(entity, numInput.FloatValue))
if (SetPropertyValue(property, entity, numInput.FloatValue))
{
// This causes stack overflow. What's the purpose of it?
//numInput.FloatValue = (float)property.GetValue(entity);
@@ -504,7 +504,7 @@ namespace Barotrauma
enumDropDown.SelectItem(value);
enumDropDown.OnSelected += (selected, val) =>
{
if (property.TrySetValue(entity, val))
if (SetPropertyValue(property, entity, val))
{
TrySendNetworkUpdate(entity, property);
}
@@ -536,7 +536,7 @@ namespace Barotrauma
}
enumDropDown.OnSelected += (selected, val) =>
{
if (property.TrySetValue(entity, string.Join(", ", enumDropDown.SelectedDataMultiple.Select(d => d.ToString()))))
if (SetPropertyValue(property, entity, string.Join(", ", enumDropDown.SelectedDataMultiple.Select(d => d.ToString()))))
{
TrySendNetworkUpdate(entity, property);
}
@@ -568,16 +568,23 @@ namespace Barotrauma
ToolTip = toolTip,
Font = GUI.SmallFont,
Text = value,
OverflowClip = true,
OverflowClip = true
};
propertyBox.OnDeselected += (textBox, keys) =>
propertyBox.OnDeselected += (textBox, keys) => OnApply(textBox);
propertyBox.OnEnterPressed += (box, text) => OnApply(box);
bool OnApply(GUITextBox textBox)
{
if (property.TrySetValue(entity, textBox.Text))
if (SetPropertyValue(property, entity, textBox.Text))
{
TrySendNetworkUpdate(entity, property);
textBox.Text = (string)property.GetValue(entity);
textBox.Text = (string) property.GetValue(entity);
textBox.Flash(GUI.Style.Green, flashDuration: 1f);
}
};
return true;
}
if (translationTextTag != null)
{
new GUIButton(new RectTransform(new Vector2(browseButtonWidth, 1), frame.RectTransform, Anchor.TopRight), "...", style: "GUIButtonSmall")
@@ -647,7 +654,7 @@ namespace Barotrauma
else
newVal.Y = numInput.IntValue;
if (property.TrySetValue(entity, newVal))
if (SetPropertyValue(property, entity, newVal))
{
TrySendNetworkUpdate(entity, property);
}
@@ -702,7 +709,7 @@ namespace Barotrauma
else
newVal.Y = numInput.FloatValue;
if (property.TrySetValue(entity, newVal))
if (SetPropertyValue(property, entity, newVal))
{
TrySendNetworkUpdate(entity, property);
}
@@ -761,7 +768,7 @@ namespace Barotrauma
else
newVal.Z = numInput.FloatValue;
if (property.TrySetValue(entity, newVal))
if (SetPropertyValue(property, entity, newVal))
{
TrySendNetworkUpdate(entity, property);
}
@@ -824,7 +831,7 @@ namespace Barotrauma
else
newVal.W = numInput.FloatValue;
if (property.TrySetValue(entity, newVal))
if (SetPropertyValue(property, entity, newVal))
{
TrySendNetworkUpdate(entity, property);
}
@@ -894,7 +901,7 @@ namespace Barotrauma
else
newVal.A = (byte)(numInput.IntValue);
if (property.TrySetValue(entity, newVal))
if (SetPropertyValue(property, entity, newVal))
{
TrySendNetworkUpdate(entity, property);
colorBox.Color = newVal;
@@ -958,7 +965,7 @@ namespace Barotrauma
else
newVal.Height = numInput.IntValue;
if (property.TrySetValue(entity, newVal))
if (SetPropertyValue(property, entity, newVal))
{
TrySendNetworkUpdate(entity, property);
}
@@ -980,7 +987,7 @@ namespace Barotrauma
{
string text = userData as string ?? "";
if (property.TrySetValue(entity, text))
if (SetPropertyValue(property, entity, text))
{
TrySendNetworkUpdate(entity, property);
textBox.Text = (string)property.GetValue(entity);
@@ -1019,6 +1026,61 @@ namespace Barotrauma
}
}
}
}
private bool SetPropertyValue(SerializableProperty property, object entity, object value)
{
MultiSetProperties(property, entity, value);
return property.TrySetValue(entity, value);
}
/// <summary>
/// Sets common shared properties to all selected map entities in sub editor.
/// Only works client side while in the sub editor and when parentObject is ItemComponent, Item or Structure.
/// </summary>
/// <param name="property"></param>
/// <param name="parentObject"></param>
/// <param name="value"></param>
/// <remarks>The function has the same parameters as <see cref="SetValue"/></remarks>
private void MultiSetProperties(SerializableProperty property, object parentObject, object value)
{
if (!(Screen.Selected is SubEditorScreen) || MapEntity.SelectedList.Count <= 1) { return; }
if (!(parentObject is ItemComponent || parentObject is Item || parentObject is Structure)) { return; }
foreach (var entity in MapEntity.SelectedList.Where(entity => entity != parentObject))
{
switch (parentObject)
{
case Structure _:
case Item _:
{
if (entity.GetType() == parentObject.GetType())
{
property.PropertyInfo.SetValue(entity, value);
}
else if (entity is ISerializableEntity sEntity && sEntity.SerializableProperties != null)
{
var props = sEntity.SerializableProperties;
if (props.TryGetValue(property.NameToLowerInvariant, out SerializableProperty foundProp))
{
foundProp.PropertyInfo.SetValue(entity, value);
}
}
break;
}
case ItemComponent _ when entity is Item item:
{
foreach (var component in item.Components)
{
if (component.GetType() == parentObject.GetType() && component != parentObject)
{
property.PropertyInfo.SetValue(component, value);
}
}
break;
}
}
}
}
}
}