v1.7.7.0 (Winter Update 2024)

This commit is contained in:
Regalis11
2024-12-11 13:26:13 +02:00
parent 7d5b7a310a
commit f6349b2175
256 changed files with 4794 additions and 1653 deletions
@@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components
private readonly List<GUIComponent> uiElements = new List<GUIComponent>();
private GUILayoutGroup uiElementContainer;
private bool readingNetworkEvent;
private bool suppressNetworkEvents;
private GUIComponent insufficientPowerWarning;
@@ -70,7 +70,7 @@ namespace Barotrauma.Items.Components
}
else
{
item.CreateClientEvent(this);
CreateClientEventWithCorrectionDelay();
}
};
@@ -100,13 +100,10 @@ namespace Barotrauma.Items.Components
ValueStep = numberInputStep,
OnValueChanged = (ni) =>
{
if (GameMain.Client == null)
ValueChanged(ni.UserData as CustomInterfaceElement, ni.FloatValue);
if (!suppressNetworkEvents && GameMain.Client != null)
{
ValueChanged(ni.UserData as CustomInterfaceElement, ni.FloatValue);
}
else if (!readingNetworkEvent)
{
item.CreateClientEvent(this);
CreateClientEventWithCorrectionDelay();
}
}
};
@@ -126,13 +123,10 @@ namespace Barotrauma.Items.Components
ValueStep = numberInputStep,
OnValueChanged = (ni) =>
{
if (GameMain.Client == null)
ValueChanged(ni.UserData as CustomInterfaceElement, ni.IntValue);
if (!suppressNetworkEvents && GameMain.Client != null)
{
ValueChanged(ni.UserData as CustomInterfaceElement, ni.IntValue);
}
else if (!readingNetworkEvent)
{
item.CreateClientEvent(this);
CreateClientEventWithCorrectionDelay();
}
}
};
@@ -162,13 +156,10 @@ namespace Barotrauma.Items.Components
};
tickBox.OnSelected += (tBox) =>
{
if (GameMain.Client == null)
TickBoxToggled(tBox.UserData as CustomInterfaceElement, tBox.Selected);
if (!suppressNetworkEvents && GameMain.Client != null)
{
TickBoxToggled(tBox.UserData as CustomInterfaceElement, tBox.Selected);
}
else if (!readingNetworkEvent)
{
item.CreateClientEvent(this);
CreateClientEventWithCorrectionDelay();
}
return true;
};
@@ -191,8 +182,10 @@ namespace Barotrauma.Items.Components
{
ButtonClicked(btnElement);
}
else if (!readingNetworkEvent)
else if (!suppressNetworkEvents && GameMain.Client != null)
{
//don't use CreateClientEventWithCorrectionDelay here, because buttons have no state,
//which means we don't need to worry about server updates interfering with client-side changes to the values in the interface
item.CreateClientEvent(this, new EventData(btnElement));
}
return true;
@@ -215,6 +208,12 @@ namespace Barotrauma.Items.Components
Visible = false
};
}
void CreateClientEventWithCorrectionDelay()
{
item.CreateClientEvent(this);
correctionTimer = CorrectionDelay;
}
}
public override void CreateEditingHUD(SerializableEntityEditor editor)
@@ -268,7 +267,7 @@ namespace Barotrauma.Items.Components
if (visible)
{
visibleElementCount++;
if (element.GetValueInterval > 0.0f)
if (element.GetValueInterval > 0.0f && correctionTimer <= 0.0f)
{
element.GetValueTimer -= deltaTime;
if (element.GetValueTimer <= 0.0f)
@@ -330,7 +329,7 @@ namespace Barotrauma.Items.Components
LocalizedString CreateLabelText(int elementIndex)
{
var label = customInterfaceElementList[elementIndex].Label;
string label = customInterfaceElementList[elementIndex].Label;
return string.IsNullOrWhiteSpace(label) ?
TextManager.GetWithVariable("connection.signaloutx", "[num]", (elementIndex + 1).ToString()) :
TextManager.Get(label).Fallback(label);
@@ -373,6 +372,9 @@ namespace Barotrauma.Items.Components
private void UpdateSignalProjSpecific(GUIComponent uiElement)
{
if (uiElement.UserData is not CustomInterfaceElement element) { return; }
suppressNetworkEvents = true;
string signal = element.Signal;
if (uiElement is GUITextBox tb)
{
@@ -384,14 +386,22 @@ namespace Barotrauma.Items.Components
{
if (ni.InputType == NumberType.Int)
{
int.TryParse(signal, out int value);
ni.IntValue = value;
if (int.TryParse(signal, out int value))
{
ni.IntValue = value;
}
else if (float.TryParse(signal, out float floatValue))
{
ni.IntValue = (int)MathF.Round(floatValue);
}
}
}
else if (uiElement is GUITickBox tickBox)
{
tickBox.Selected = signal.Equals("true", StringComparison.OrdinalIgnoreCase);
}
suppressNetworkEvents = false;
}
public void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData = null)
@@ -429,38 +439,62 @@ namespace Barotrauma.Items.Components
public void ClientEventRead(IReadMessage msg, float sendingTime)
{
readingNetworkEvent = true;
int msgStartPos = msg.BitPosition;
suppressNetworkEvents = true;
try
{
string[] stringValues = new string[customInterfaceElementList.Count];
bool[] boolValues = new bool[customInterfaceElementList.Count];
for (int i = 0; i < customInterfaceElementList.Count; i++)
{
var element = customInterfaceElementList[i];
switch (element.InputType)
{
case CustomInterfaceElement.InputTypeOption.Number:
case CustomInterfaceElement.InputTypeOption.Text:
stringValues[i] = msg.ReadString();
break;
case CustomInterfaceElement.InputTypeOption.TickBox:
case CustomInterfaceElement.InputTypeOption.Button:
boolValues[i] = msg.ReadBoolean();
break;
}
}
if (correctionTimer > 0.0f)
{
int msgLength = msg.BitPosition - msgStartPos;
msg.BitPosition = msgStartPos;
StartDelayedCorrection(msg.ExtractBits(msgLength), sendingTime);
return;
}
for (int i = 0; i < customInterfaceElementList.Count; i++)
{
var element = customInterfaceElementList[i];
switch (element.InputType)
{
case CustomInterfaceElement.InputTypeOption.Number:
string newValue = msg.ReadString();
switch (element.NumberType)
{
case NumberType.Int when int.TryParse(newValue, out int value):
case NumberType.Int when int.TryParse(stringValues[i], out int value):
ValueChanged(element, value);
break;
case NumberType.Float when TryParseFloatInvariantCulture(newValue, out float value):
case NumberType.Float when TryParseFloatInvariantCulture(stringValues[i], out float value):
ValueChanged(element, value);
break;
}
break;
case CustomInterfaceElement.InputTypeOption.Text:
string newTextValue = msg.ReadString();
TextChanged(element, newTextValue);
TextChanged(element, stringValues[i]);
break;
case CustomInterfaceElement.InputTypeOption.TickBox:
bool tickBoxState = msg.ReadBoolean();
bool tickBoxState = boolValues[i];
((GUITickBox)uiElements[i]).Selected = tickBoxState;
TickBoxToggled(element, tickBoxState);
break;
case CustomInterfaceElement.InputTypeOption.Button:
bool buttonState = msg.ReadBoolean();
if (buttonState)
if (boolValues[i])
{
ButtonClicked(element);
}
@@ -472,7 +506,7 @@ namespace Barotrauma.Items.Components
}
finally
{
readingNetworkEvent = false;
suppressNetworkEvents = false;
}
}
}