(ce8e185aa) Merge branch 'dev' of https://github.com/Regalis11/Barotrauma-development into dev
This commit is contained in:
@@ -277,13 +277,17 @@ namespace Barotrauma
|
||||
{
|
||||
component.RectTransform.Parent = layoutGroup.RectTransform;
|
||||
component.RectTransform.RepositionChildInHierarchy(childIndex);
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
public void Recalculate()
|
||||
{
|
||||
int contentHeight = ContentHeight;
|
||||
RectTransform.NonScaledSize = new Point(RectTransform.NonScaledSize.X, contentHeight);
|
||||
layoutGroup.RectTransform.NonScaledSize = new Point(layoutGroup.RectTransform.NonScaledSize.X, contentHeight);
|
||||
}
|
||||
|
||||
private GUIComponent CreateNewField(SerializableProperty property, ISerializableEntity entity)
|
||||
public GUIComponent CreateNewField(SerializableProperty property, ISerializableEntity entity)
|
||||
{
|
||||
object value = property.GetValue(entity);
|
||||
if (property.PropertyType == typeof(string) && value == null)
|
||||
@@ -351,7 +355,7 @@ namespace Barotrauma
|
||||
return propertyField;
|
||||
}
|
||||
|
||||
private GUIComponent CreateBoolField(ISerializableEntity entity, SerializableProperty property, bool value, string displayName, string toolTip)
|
||||
public 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)
|
||||
{
|
||||
@@ -367,11 +371,11 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Fields.Add(property.Name, new GUIComponent[] { propertyTickBox });
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, new GUIComponent[] { propertyTickBox }); }
|
||||
return propertyTickBox;
|
||||
}
|
||||
|
||||
private GUIComponent CreateIntField(ISerializableEntity entity, SerializableProperty property, int value, string displayName, string toolTip)
|
||||
public GUIComponent CreateIntField(ISerializableEntity entity, SerializableProperty property, int 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.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -395,11 +399,11 @@ namespace Barotrauma
|
||||
TrySendNetworkUpdate(entity, property);
|
||||
}
|
||||
};
|
||||
Fields.Add(property.Name, new GUIComponent[] { numberInput });
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, new GUIComponent[] { numberInput }); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateFloatField(ISerializableEntity entity, SerializableProperty property, float value, string displayName, string toolTip)
|
||||
public GUIComponent CreateFloatField(ISerializableEntity entity, SerializableProperty property, float 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.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -425,11 +429,11 @@ namespace Barotrauma
|
||||
TrySendNetworkUpdate(entity, property);
|
||||
}
|
||||
};
|
||||
Fields.Add(property.Name, new GUIComponent[] { numberInput });
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, new GUIComponent[] { numberInput }); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object value, string displayName, string toolTip)
|
||||
public GUIComponent CreateEnumField(ISerializableEntity entity, SerializableProperty property, object 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.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -454,11 +458,11 @@ namespace Barotrauma
|
||||
return true;
|
||||
};
|
||||
enumDropDown.SelectItem(value);
|
||||
Fields.Add(property.Name, new GUIComponent[] { enumDropDown });
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, new GUIComponent[] { enumDropDown }); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateEnumFlagField(ISerializableEntity entity, SerializableProperty property, object value, string displayName, string toolTip)
|
||||
public GUIComponent CreateEnumFlagField(ISerializableEntity entity, SerializableProperty property, object 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.6f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -487,18 +491,21 @@ namespace Barotrauma
|
||||
return true;
|
||||
};
|
||||
|
||||
Fields.Add(property.Name, new GUIComponent[] { enumDropDown });
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, new GUIComponent[] { enumDropDown }); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateStringField(ISerializableEntity entity, SerializableProperty property, string value, string displayName, string toolTip)
|
||||
public 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 frame = new GUILayoutGroup(new RectTransform(new Point(Rect.Width, elementHeight), layoutGroup.RectTransform), isHorizontal: true)
|
||||
{
|
||||
Stretch = true
|
||||
};
|
||||
var label = new GUITextBlock(new RectTransform(new Vector2(0.4f, 1), frame.RectTransform), displayName, font: GUI.SmallFont, textAlignment: Alignment.Left)
|
||||
{
|
||||
ToolTip = toolTip
|
||||
};
|
||||
GUITextBox propertyBox = new GUITextBox(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform, Anchor.TopRight))
|
||||
GUITextBox propertyBox = new GUITextBox(new RectTransform(new Vector2(0.6f, 1), frame.RectTransform))
|
||||
{
|
||||
ToolTip = toolTip,
|
||||
Font = GUI.SmallFont,
|
||||
@@ -514,11 +521,36 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Fields.Add(property.Name, new GUIComponent[] { propertyBox });
|
||||
string translationTextTag = property.GetAttribute<Serialize>()?.translationTextTag;
|
||||
if (translationTextTag != null)
|
||||
{
|
||||
new GUIButton(new RectTransform(new Vector2(0.1f, 1), frame.RectTransform, Anchor.TopRight), "...")
|
||||
{
|
||||
OnClicked = (bt, userData) => { CreateTextPicker(translationTextTag, entity, property, propertyBox); return true; }
|
||||
};
|
||||
propertyBox.OnTextChanged += (tb, text) =>
|
||||
{
|
||||
string translatedText = TextManager.Get(text, returnNull: true);
|
||||
if (translatedText == null)
|
||||
{
|
||||
propertyBox.TextColor = Color.Gray;
|
||||
propertyBox.ToolTip = TextManager.Get("StringPropertyCannotTranslate").Replace("[tag]", text ?? "");
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyBox.TextColor = Color.LightGreen;
|
||||
propertyBox.ToolTip = TextManager.Get("StringPropertyTranslate").Replace("[translation]", translatedText);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
propertyBox.Text = value;
|
||||
}
|
||||
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, new GUIComponent[] { propertyBox }); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreatePointField(ISerializableEntity entity, SerializableProperty property, Point value, string displayName, string toolTip)
|
||||
public 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)
|
||||
@@ -566,11 +598,11 @@ namespace Barotrauma
|
||||
};
|
||||
fields[i] = numberInput;
|
||||
}
|
||||
Fields.Add(property.Name, fields);
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, fields); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateVector2Field(ISerializableEntity entity, SerializableProperty property, Vector2 value, string displayName, string toolTip)
|
||||
public 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)
|
||||
@@ -620,11 +652,11 @@ namespace Barotrauma
|
||||
};
|
||||
fields[i] = numberInput;
|
||||
}
|
||||
Fields.Add(property.Name, fields);
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, fields); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateVector3Field(ISerializableEntity entity, SerializableProperty property, Vector3 value, string displayName, string toolTip)
|
||||
public GUIComponent CreateVector3Field(ISerializableEntity entity, SerializableProperty property, Vector3 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.3f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -678,11 +710,11 @@ namespace Barotrauma
|
||||
};
|
||||
fields[i] = numberInput;
|
||||
}
|
||||
Fields.Add(property.Name, fields);
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, fields); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateVector4Field(ISerializableEntity entity, SerializableProperty property, Vector4 value, string displayName, string toolTip)
|
||||
public GUIComponent CreateVector4Field(ISerializableEntity entity, SerializableProperty property, Vector4 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.2f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -740,14 +772,14 @@ namespace Barotrauma
|
||||
};
|
||||
fields[i] = numberInput;
|
||||
}
|
||||
Fields.Add(property.Name, fields);
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, fields); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateColorField(ISerializableEntity entity, SerializableProperty property, Color value, string displayName, string toolTip)
|
||||
public GUIComponent CreateColorField(ISerializableEntity entity, SerializableProperty property, Color 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.2f, 1), frame.RectTransform) { MinSize = new Point(80, 26)}, displayName, font: GUI.SmallFont)
|
||||
var label = new GUITextBlock(new RectTransform(new Vector2(0.2f, 1), frame.RectTransform) { MinSize = new Point(80, 26) }, displayName, font: GUI.SmallFont)
|
||||
{
|
||||
ToolTip = toolTip
|
||||
};
|
||||
@@ -807,11 +839,11 @@ namespace Barotrauma
|
||||
colorBox.Color = (Color)property.GetValue(entity);
|
||||
fields[i] = numberInput;
|
||||
}
|
||||
Fields.Add(property.Name, fields);
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, fields); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
private GUIComponent CreateRectangleField(ISerializableEntity entity, SerializableProperty property, Rectangle value, string displayName, string toolTip)
|
||||
public GUIComponent CreateRectangleField(ISerializableEntity entity, SerializableProperty property, Rectangle 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.2f, 1), frame.RectTransform), displayName, font: GUI.SmallFont)
|
||||
@@ -867,9 +899,43 @@ namespace Barotrauma
|
||||
};
|
||||
fields[i] = numberInput;
|
||||
}
|
||||
Fields.Add(property.Name, fields);
|
||||
if (!Fields.ContainsKey(property.Name)) { Fields.Add(property.Name, fields); }
|
||||
return frame;
|
||||
}
|
||||
|
||||
public void CreateTextPicker(string textTag, ISerializableEntity entity, SerializableProperty property, GUITextBox textBox)
|
||||
{
|
||||
var msgBox = new GUIMessageBox("", "", new string[] { TextManager.Get("Cancel") }, width: 300, height: 400);
|
||||
msgBox.Buttons[0].OnClicked = msgBox.Close;
|
||||
|
||||
var textList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.8f), msgBox.Content.RectTransform, Anchor.TopCenter))
|
||||
{
|
||||
OnSelected = (component, userData) =>
|
||||
{
|
||||
string text = userData as string ?? "";
|
||||
|
||||
if (property.TrySetValue(entity, text))
|
||||
{
|
||||
TrySendNetworkUpdate(entity, property);
|
||||
textBox.Text = (string)property.GetValue(entity);
|
||||
textBox.Deselect();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
textTag = textTag.ToLowerInvariant();
|
||||
var tagTextPairs = TextManager.GetAllTagTextPairs();
|
||||
foreach (KeyValuePair<string, string> tagTextPair in tagTextPairs)
|
||||
{
|
||||
if (!tagTextPair.Key.StartsWith(textTag)) { continue; }
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), textList.Content.RectTransform) { MinSize = new Point(0, 20) },
|
||||
ToolBox.LimitString(tagTextPair.Value, GUI.Font, textList.Content.Rect.Width))
|
||||
{
|
||||
UserData = tagTextPair.Key
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void TrySendNetworkUpdate(ISerializableEntity entity, SerializableProperty property)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user