Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into unstable
This commit is contained in:
+11
-2
@@ -48,6 +48,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (value == null) { return; }
|
||||
output = value;
|
||||
//reactivate (we may not have been previously sending a signal, but might now)
|
||||
IsActive = true;
|
||||
if (output.Length > MaxOutputLength && (item.Submarine == null || !item.Submarine.Loading))
|
||||
{
|
||||
output = output.Substring(0, MaxOutputLength);
|
||||
@@ -63,6 +65,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (value == null) { return; }
|
||||
falseOutput = value;
|
||||
//reactivate (we may not have been previously sending a signal, but might now)
|
||||
IsActive = true;
|
||||
if (falseOutput.Length > MaxOutputLength && (item.Submarine == null || !item.Submarine.Loading))
|
||||
{
|
||||
falseOutput = falseOutput.Substring(0, MaxOutputLength);
|
||||
@@ -82,9 +86,14 @@ namespace Barotrauma.Items.Components
|
||||
public sealed override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
int receivedInputs = 0;
|
||||
bool allInputsTimedOut = true;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] <= timeFrame) { receivedInputs += 1; }
|
||||
if (timeSinceReceived[i] <= timeFrame)
|
||||
{
|
||||
allInputsTimedOut = false;
|
||||
receivedInputs += 1;
|
||||
}
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
|
||||
@@ -93,7 +102,7 @@ namespace Barotrauma.Items.Components
|
||||
if (string.IsNullOrEmpty(signalOut))
|
||||
{
|
||||
//deactivate the component if state is false and there's no false output (will be woken up by non-zero signals in ReceiveSignal)
|
||||
if (!state) { IsActive = false; }
|
||||
if (!state && allInputsTimedOut) { IsActive = false; }
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ namespace Barotrauma.Items.Components
|
||||
private readonly HashSet<Wire> wires;
|
||||
public IReadOnlyCollection<Wire> Wires => wires;
|
||||
|
||||
private bool enumeratingWires;
|
||||
private readonly HashSet<Wire> removedWires = new HashSet<Wire>();
|
||||
|
||||
private readonly Item item;
|
||||
|
||||
public readonly bool IsOutput;
|
||||
@@ -239,7 +242,14 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
prevOtherConnection.recipientsDirty = true;
|
||||
}
|
||||
wires.Remove(wire);
|
||||
if (enumeratingWires)
|
||||
{
|
||||
removedWires.Add(wire);
|
||||
}
|
||||
else
|
||||
{
|
||||
wires.Remove(wire);
|
||||
}
|
||||
recipientsDirty = true;
|
||||
}
|
||||
|
||||
@@ -278,6 +288,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void SendSignal(Signal signal)
|
||||
{
|
||||
enumeratingWires = true;
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
Connection recipient = wire.OtherConnection(this);
|
||||
@@ -305,6 +316,12 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
enumeratingWires = false;
|
||||
foreach (var removedWire in removedWires)
|
||||
{
|
||||
wires.Remove(removedWire);
|
||||
}
|
||||
removedWires.Clear();
|
||||
}
|
||||
|
||||
public void ClearConnections()
|
||||
@@ -317,13 +334,23 @@ namespace Barotrauma.Items.Components
|
||||
Powered.ChangedConnections.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
wire.RemoveConnection(this);
|
||||
recipientsDirty = true;
|
||||
}
|
||||
wires.Clear();
|
||||
|
||||
if (enumeratingWires)
|
||||
{
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
removedWires.Add(wire);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wires.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeFromLoaded()
|
||||
|
||||
+15
-6
@@ -179,7 +179,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
UpdateProjSpecific(deltaTime);
|
||||
|
||||
if (user == null || user.SelectedConstruction != item)
|
||||
if (user == null || user.SelectedItem != item)
|
||||
{
|
||||
#if SERVER
|
||||
if (user != null) { item.CreateServerEvent(this); }
|
||||
@@ -196,7 +196,7 @@ namespace Barotrauma.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
user.AnimController.UpdateUseItem(true, item.WorldPosition + new Vector2(0.0f, 100.0f) * (((float)Timing.TotalTime / 10.0f) % 0.1f));
|
||||
user.AnimController.UpdateUseItem(!user.IsClimbing, item.WorldPosition + new Vector2(0.0f, 100.0f) * (((float)Timing.TotalTime / 10.0f) % 0.1f));
|
||||
}
|
||||
|
||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||
@@ -206,7 +206,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial void UpdateProjSpecific(float deltaTime);
|
||||
|
||||
public override bool Select(Character picker)
|
||||
public bool CanRewire()
|
||||
{
|
||||
//attaching wires to items with a body is not allowed
|
||||
//(signal items remove their bodies when attached to a wall)
|
||||
@@ -214,6 +214,15 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Select(Character picker)
|
||||
{
|
||||
if (!CanRewire())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
user = picker;
|
||||
#if SERVER
|
||||
@@ -392,14 +401,14 @@ namespace Barotrauma.Items.Components
|
||||
msg.WriteVariableUInt32((uint)connection.Wires.Count);
|
||||
foreach (Wire wire in connection.Wires)
|
||||
{
|
||||
msg.Write(wire?.Item == null ? (ushort)0 : wire.Item.ID);
|
||||
msg.WriteUInt16(wire?.Item == null ? (ushort)0 : wire.Item.ID);
|
||||
}
|
||||
}
|
||||
|
||||
msg.Write((ushort)DisconnectedWires.Count);
|
||||
msg.WriteUInt16((ushort)DisconnectedWires.Count);
|
||||
foreach (Wire disconnectedWire in DisconnectedWires)
|
||||
{
|
||||
msg.Write(disconnectedWire.Item.ID);
|
||||
msg.WriteUInt16(disconnectedWire.Item.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-2
@@ -155,7 +155,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
//use semicolon as a separator because comma may be needed in the signals (for color or vector values for example)
|
||||
//kind of hacky, we should probably add support for (string) arrays to SerializableEntityEditor so this wouldn't be needed
|
||||
get { return signals == null ? "" : string.Join(";", signals); }
|
||||
get { return signals == null ? string.Empty : string.Join(";", signals); }
|
||||
set
|
||||
{
|
||||
if (value == null) { return; }
|
||||
@@ -167,7 +167,31 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public override bool RecreateGUIOnResolutionChange => true;
|
||||
private bool[] elementStates;
|
||||
[Serialize("", IsPropertySaveable.Yes, description: "", alwaysUseInstanceValues: true)]
|
||||
public string ElementStates
|
||||
{
|
||||
get { return elementStates == null ? string.Empty : string.Join(",", elementStates); }
|
||||
set
|
||||
{
|
||||
if (value == null) { return; }
|
||||
if (customInterfaceElementList.Count > 0)
|
||||
{
|
||||
string[] splitValues = value == "" ? Array.Empty<string>() : value.Split(',');
|
||||
for (int i = 0; i < customInterfaceElementList.Count && i < splitValues.Length; i++)
|
||||
{
|
||||
if (!bool.TryParse(splitValues[i], out bool val)) { continue; }
|
||||
customInterfaceElementList[i].State = val;
|
||||
#if CLIENT
|
||||
if (uiElements != null && i < uiElements.Count && uiElements[i] is GUITickBox tickBox)
|
||||
{
|
||||
tickBox.Selected = val;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<CustomInterfaceElement> customInterfaceElementList = new List<CustomInterfaceElement>();
|
||||
|
||||
@@ -207,8 +231,10 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
IsActive = true;
|
||||
InitProjSpecific();
|
||||
//load these here to ensure the UI elements (created in InitProjSpecific) are up-to-date
|
||||
Labels = element.GetAttributeString("labels", "");
|
||||
Signals = element.GetAttributeString("signals", "");
|
||||
ElementStates = element.GetAttributeString("elementstates", "");
|
||||
}
|
||||
|
||||
private void UpdateLabels(string[] newLabels)
|
||||
@@ -386,6 +412,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
labels = customInterfaceElementList.Select(ci => ci.Label).ToArray();
|
||||
signals = customInterfaceElementList.Select(ci => ci.Signal).ToArray();
|
||||
elementStates = customInterfaceElementList.Select(ci => ci.State).ToArray();
|
||||
return base.Save(parentElement);
|
||||
}
|
||||
|
||||
|
||||
@@ -248,8 +248,19 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void OnMapLoaded()
|
||||
{
|
||||
if (item.body == null && powerConsumption <= 0.0f && Parent == null && turret == null && IsOn &&
|
||||
(statusEffectLists == null || !statusEffectLists.ContainsKey(ActionType.OnActive)) &&
|
||||
CheckIfNeedsUpdate();
|
||||
}
|
||||
|
||||
public void CheckIfNeedsUpdate()
|
||||
{
|
||||
if (!IsOn)
|
||||
{
|
||||
base.IsActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.body == null && powerConsumption <= 0.0f && Parent == null && turret == null &&
|
||||
(statusEffectLists == null || !statusEffectLists.ContainsKey(ActionType.OnActive)) &&
|
||||
(IsActiveConditionals == null || IsActiveConditionals.Count == 0))
|
||||
{
|
||||
lightBrightness = 1.0f;
|
||||
@@ -261,6 +272,10 @@ namespace Barotrauma.Items.Components
|
||||
Light.ParentSub = item.Submarine;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
base.IsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace Barotrauma.Items.Components
|
||||
Human = 1,
|
||||
Monster = 2,
|
||||
Wall = 4,
|
||||
Any = Human | Monster | Wall,
|
||||
Pet = 8,
|
||||
Any = Human | Monster | Wall | Pet,
|
||||
}
|
||||
|
||||
[Serialize(false, IsPropertySaveable.No, description: "Has the item currently detected movement. Intended to be used by StatusEffect conditionals (setting this value in XML has no effect).")]
|
||||
@@ -253,7 +254,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (Target.HasFlag(TargetType.Human) || Target.HasFlag(TargetType.Monster))
|
||||
if (Target.HasFlag(TargetType.Human) || Target.HasFlag(TargetType.Pet) || Target.HasFlag(TargetType.Monster))
|
||||
{
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
@@ -267,7 +268,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (!Target.HasFlag(TargetType.Human)) { continue; }
|
||||
}
|
||||
else if (!c.IsPet)
|
||||
else if (c.IsPet)
|
||||
{
|
||||
if (!Target.HasFlag(TargetType.Pet)) { continue; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Target.HasFlag(TargetType.Monster)) { continue; }
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void ServerEventWrite(IWriteMessage msg, Client c, NetEntityEvent.IData extraData = null)
|
||||
{
|
||||
msg.Write(isOn);
|
||||
msg.WriteBoolean(isOn);
|
||||
}
|
||||
|
||||
public void ClientEventRead(IReadMessage msg, float sendingTime)
|
||||
|
||||
@@ -106,11 +106,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
case "set_text":
|
||||
case "signal_in":
|
||||
if (string.IsNullOrEmpty(signal.value)) { return; }
|
||||
if (signal.value.Length > MaxMessageLength)
|
||||
{
|
||||
signal.value = signal.value.Substring(0, MaxMessageLength);
|
||||
}
|
||||
|
||||
string inputSignal = signal.value.Replace("\\n", "\n");
|
||||
ShowOnDisplay(inputSignal, addToHistory: true, TextColor);
|
||||
break;
|
||||
|
||||
@@ -58,6 +58,9 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public bool WaterDetected => isInWater;
|
||||
public int WaterPercentage => GetWaterPercentage(item.CurrentHull);
|
||||
|
||||
public WaterDetector(Item item, ContentXElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
|
||||
@@ -309,7 +309,7 @@ namespace Barotrauma.Items.Components
|
||||
if (nodes.Count == 0) { return; }
|
||||
|
||||
Character user = item.ParentInventory?.Owner as Character;
|
||||
editNodeDelay = (user?.SelectedConstruction == null) ? editNodeDelay - deltaTime : 0.5f;
|
||||
editNodeDelay = (user?.SelectedItem == null) ? editNodeDelay - deltaTime : 0.5f;
|
||||
|
||||
Submarine sub = item.Submarine;
|
||||
if (connections[0] != null && connections[0].Item.Submarine != null) { sub = connections[0].Item.Submarine; }
|
||||
@@ -369,7 +369,7 @@ namespace Barotrauma.Items.Components
|
||||
user.AnimController.Collider.ApplyForce(forceDir * user.Mass * 50.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity * 0.5f);
|
||||
if (diff.LengthSquared() > 50.0f * 50.0f)
|
||||
{
|
||||
user.AnimController.UpdateUseItem(true, user.WorldPosition + pullBackDir * Math.Min(150.0f, diff.Length()));
|
||||
user.AnimController.UpdateUseItem(!user.IsClimbing, user.WorldPosition + pullBackDir * Math.Min(150.0f, diff.Length()));
|
||||
}
|
||||
|
||||
if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer)
|
||||
@@ -428,7 +428,7 @@ namespace Barotrauma.Items.Components
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (character == null || character != Character.Controlled) { return false; }
|
||||
if (character.SelectedConstruction != null) { return false; }
|
||||
if (character.HasSelectedAnyItem) { return false; }
|
||||
#if CLIENT
|
||||
if (Screen.Selected == GameMain.SubEditorScreen && !PlayerInput.PrimaryMouseButtonClicked())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user