Build 0.18.2.0
This commit is contained in:
+95
-34
@@ -45,7 +45,7 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
new GUITextBlock(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform),
|
||||
TextManager.Get(ciElement.Label).Fallback(ciElement.Label));
|
||||
if (!ciElement.IsIntegerInput)
|
||||
if (!ciElement.IsNumberInput)
|
||||
{
|
||||
var textBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), ciElement.Signal, style: "GUITextBoxNoIcon")
|
||||
{
|
||||
@@ -77,29 +77,71 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
int.TryParse(ciElement.Signal, out int signal);
|
||||
var numberInput = new GUINumberInput(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), GUINumberInput.NumberType.Int)
|
||||
GUINumberInput numberInput = null;
|
||||
if (ciElement.NumberType == NumberType.Float)
|
||||
{
|
||||
UserData = ciElement,
|
||||
MinValueInt = ciElement.NumberInputMin,
|
||||
MaxValueInt = ciElement.NumberInputMax,
|
||||
IntValue = Math.Clamp(signal, ciElement.NumberInputMin, ciElement.NumberInputMax)
|
||||
};
|
||||
//reset size restrictions set by the Style to make sure the elements can fit the interface
|
||||
numberInput.RectTransform.MinSize = numberInput.LayoutGroup.RectTransform.MinSize = new Point(0, 0);
|
||||
numberInput.RectTransform.MaxSize = numberInput.LayoutGroup.RectTransform.MaxSize = new Point(int.MaxValue, int.MaxValue);
|
||||
numberInput.OnValueChanged += (ni) =>
|
||||
TryParseFloatInvariantCulture(ciElement.Signal, out float floatSignal);
|
||||
TryParseFloatInvariantCulture(ciElement.NumberInputMin, out float numberInputMin);
|
||||
TryParseFloatInvariantCulture(ciElement.NumberInputMax, out float numberInputMax);
|
||||
TryParseFloatInvariantCulture(ciElement.NumberInputStep, out float numberInputStep);
|
||||
numberInput = new GUINumberInput(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), NumberType.Float)
|
||||
{
|
||||
UserData = ciElement,
|
||||
MinValueFloat = numberInputMin,
|
||||
MaxValueFloat = numberInputMax,
|
||||
FloatValue = Math.Clamp(floatSignal, numberInputMin, numberInputMax),
|
||||
DecimalsToDisplay = ciElement.NumberInputDecimalPlaces,
|
||||
valueStep = numberInputStep,
|
||||
OnValueChanged = (ni) =>
|
||||
{
|
||||
if (GameMain.Client == null)
|
||||
{
|
||||
ValueChanged(ni.UserData as CustomInterfaceElement, ni.FloatValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (ciElement.NumberType == NumberType.Int)
|
||||
{
|
||||
if (GameMain.Client == null)
|
||||
int.TryParse(ciElement.Signal, out int intSignal);
|
||||
int.TryParse(ciElement.NumberInputMin, out int numberInputMin);
|
||||
int.TryParse(ciElement.NumberInputMax, out int numberInputMax);
|
||||
TryParseFloatInvariantCulture(ciElement.NumberInputStep, out float numberInputStep);
|
||||
numberInput = new GUINumberInput(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), NumberType.Int)
|
||||
{
|
||||
ValueChanged(ni.UserData as CustomInterfaceElement, ni.IntValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
}
|
||||
};
|
||||
uiElements.Add(numberInput);
|
||||
UserData = ciElement,
|
||||
MinValueInt = numberInputMin,
|
||||
MaxValueInt = numberInputMax,
|
||||
IntValue = Math.Clamp(intSignal, numberInputMin, numberInputMax),
|
||||
valueStep = numberInputStep,
|
||||
OnValueChanged = (ni) =>
|
||||
{
|
||||
if (GameMain.Client == null)
|
||||
{
|
||||
ValueChanged(ni.UserData as CustomInterfaceElement, ni.IntValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.CreateClientEvent(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ShowError($"Error creating a CustomInterface component: unexpected NumberType \"{(ciElement.NumberType.HasValue ? ciElement.NumberType.Value.ToString() : "none")}\"");
|
||||
}
|
||||
if (numberInput != null)
|
||||
{
|
||||
//reset size restrictions set by the Style to make sure the elements can fit the interface
|
||||
numberInput.RectTransform.MinSize = numberInput.LayoutGroup.RectTransform.MinSize = new Point(0, 0);
|
||||
numberInput.RectTransform.MaxSize = numberInput.LayoutGroup.RectTransform.MaxSize = new Point(int.MaxValue, int.MaxValue);
|
||||
uiElements.Add(numberInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ciElement.ContinuousSignal)
|
||||
@@ -293,7 +335,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else if (uiElements[i] is GUINumberInput ni)
|
||||
{
|
||||
if (ni.InputType == GUINumberInput.NumberType.Int)
|
||||
if (ni.InputType == NumberType.Int)
|
||||
{
|
||||
int.TryParse(customInterfaceElementList[i].Signal, out int value);
|
||||
ni.IntValue = value;
|
||||
@@ -307,18 +349,28 @@ namespace Barotrauma.Items.Components
|
||||
//extradata contains an array of buttons clicked by the player (or nothing if the player didn't click anything)
|
||||
for (int i = 0; i < customInterfaceElementList.Count; i++)
|
||||
{
|
||||
if (customInterfaceElementList[i].HasPropertyName)
|
||||
var element = customInterfaceElementList[i];
|
||||
if (element.HasPropertyName)
|
||||
{
|
||||
if (!customInterfaceElementList[i].IsIntegerInput)
|
||||
if (!element.IsNumberInput)
|
||||
{
|
||||
msg.Write(((GUITextBox)uiElements[i]).Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(((GUINumberInput)uiElements[i]).IntValue.ToString());
|
||||
switch (element.NumberType)
|
||||
{
|
||||
case NumberType.Float:
|
||||
msg.Write(((GUINumberInput)uiElements[i]).FloatValue.ToString());
|
||||
break;
|
||||
case NumberType.Int:
|
||||
default:
|
||||
msg.Write(((GUINumberInput)uiElements[i]).IntValue.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (customInterfaceElementList[i].ContinuousSignal)
|
||||
else if (element.ContinuousSignal)
|
||||
{
|
||||
msg.Write(((GUITickBox)uiElements[i]).Selected);
|
||||
}
|
||||
@@ -333,29 +385,38 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
for (int i = 0; i < customInterfaceElementList.Count; i++)
|
||||
{
|
||||
if (customInterfaceElementList[i].HasPropertyName)
|
||||
var element = customInterfaceElementList[i];
|
||||
if (element.HasPropertyName)
|
||||
{
|
||||
if (!customInterfaceElementList[i].IsIntegerInput)
|
||||
string newValue = msg.ReadString();
|
||||
if (!element.IsNumberInput)
|
||||
{
|
||||
TextChanged(customInterfaceElementList[i], msg.ReadString());
|
||||
TextChanged(element, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
int.TryParse(msg.ReadString(), out int value);
|
||||
ValueChanged(customInterfaceElementList[i], value);
|
||||
switch (element.NumberType)
|
||||
{
|
||||
case NumberType.Int when int.TryParse(newValue, out int value):
|
||||
ValueChanged(element, value);
|
||||
break;
|
||||
case NumberType.Float when TryParseFloatInvariantCulture(newValue, out float value):
|
||||
ValueChanged(element, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool elementState = msg.ReadBoolean();
|
||||
if (customInterfaceElementList[i].ContinuousSignal)
|
||||
if (element.ContinuousSignal)
|
||||
{
|
||||
((GUITickBox)uiElements[i]).Selected = elementState;
|
||||
TickBoxToggled(customInterfaceElementList[i], elementState);
|
||||
TickBoxToggled(element, elementState);
|
||||
}
|
||||
else if (elementState)
|
||||
{
|
||||
ButtonClicked(customInterfaceElementList[i]);
|
||||
ButtonClicked(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user