diff --git a/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs b/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs
index 0e0688ce988..d1a4d829669 100644
--- a/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs
+++ b/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs
@@ -34,21 +34,10 @@ public abstract partial class SharedUserInterfaceSystem : EntitySystem
private ActorRangeCheckJob _rangeJob;
- /// Update type to apply
- private enum QueuedUpdate
- {
- /// Upen a UI
- Open,
- /// Apply new state to the UI
- ApplyState,
- /// Close the UI
- Close
- };
-
///
/// Defer BUIs during state handling so client doesn't spam a BUI constantly during prediction.
///
- private readonly List<(BoundUserInterface bui, QueuedUpdate updateType, BoundUserInterfaceState? state)> _queuedBuis = new();
+ private readonly List<(BoundUserInterface Bui, bool value)> _queuedBuis = new();
public override void Initialize()
{
@@ -91,22 +80,9 @@ public override void Initialize()
SubscribeLocalEvent(OnActorShutdown);
}
- ///
- /// Enqueues a BUI command to be processed in the next Update call,
- /// getting the last available state for the given UserInterfaceComponent at the last state.
- ///
- private void AddQueued(BoundUserInterface bui, QueuedUpdate type, Entity ent, Enum key)
- {
- var state = ent.Comp.States.GetValueOrDefault(key);
- _queuedBuis.Add((bui, type, state));
- }
-
- ///
- /// Enqueues a BUI command to be processed in the next Update call.
- ///
- private void AddQueued(BoundUserInterface bui, QueuedUpdate type, BoundUserInterfaceState? state = null)
+ private void AddQueued(BoundUserInterface bui, bool value)
{
- _queuedBuis.Add((bui, type, state));
+ _queuedBuis.Add((bui, value));
}
///
@@ -263,7 +239,7 @@ private void CloseUiInternal(Entity ent, Enum key, Enti
if (ent.Comp.ClientOpenInterfaces.TryGetValue(key, out var cBui))
{
- AddQueued(cBui, QueuedUpdate.Close);
+ AddQueued(cBui, false);
}
if (ent.Comp.Actors.Count == 0)
@@ -305,7 +281,7 @@ private void OnUserInterfaceStartup(Entity ent, ref Comp
// PlayerAttachedEvent will catch some of these.
foreach (var (key, bui) in ent.Comp.ClientOpenInterfaces)
{
- AddQueued(bui, QueuedUpdate.Open, ent, key);
+ AddQueued(bui, true);
}
}
@@ -325,7 +301,7 @@ protected void OnUserInterfaceShutdown(Entity ent, ref C
DebugTools.Assert(!ent.Comp.Actors.ContainsKey(key));
}
- DebugTools.Assert(ent.Comp.ClientOpenInterfaces.Values.All(x => _queuedBuis.Contains((x, QueuedUpdate.Close, null))));
+ DebugTools.Assert(ent.Comp.ClientOpenInterfaces.Values.All(x => _queuedBuis.Contains((x, false))));
}
private void OnUserInterfaceGetState(Entity ent, ref ComponentGetState args)
@@ -486,7 +462,7 @@ private void OnUserInterfaceHandleState(Entity ent, ref
}
var bui = ent.Comp.ClientOpenInterfaces[key];
- AddQueued(bui, QueuedUpdate.Close);
+ AddQueued(bui, false);
}
}
@@ -513,7 +489,9 @@ private void OnUserInterfaceHandleState(Entity ent, ref
if (!ent.Comp.ClientOpenInterfaces.TryGetValue(key, out var cBui) || !cBui.IsOpened)
continue;
- AddQueued(cBui, QueuedUpdate.ApplyState, buiState);
+ cBui.State = buiState;
+ cBui.UpdateState(buiState);
+ cBui.Update();
}
}
@@ -541,7 +519,7 @@ private void EnsureClientBui(Entity entity, Enum key, In
// Existing BUI just keep it.
if (entity.Comp.ClientOpenInterfaces.TryGetValue(key, out var existing))
{
- _queuedBuis.Remove((existing, QueuedUpdate.Close, null));
+ _queuedBuis.Remove((existing, false));
return;
}
@@ -566,7 +544,7 @@ private void EnsureClientBui(Entity entity, Enum key, In
if (!open)
return;
- AddQueued(boundUserInterface, QueuedUpdate.Open, entity, key);
+ AddQueued(boundUserInterface, true);
}
///
@@ -777,7 +755,11 @@ public void SetUiState(Entity entity, Enum key, BoundUs
// Predict the change on client
if (state != null && _netManager.IsClient && entity.Comp.ClientOpenInterfaces.TryGetValue(key, out var bui))
{
- AddQueued(bui, QueuedUpdate.ApplyState, state);
+ if (bui.State?.Equals(state) != true)
+ {
+ bui.UpdateState(state);
+ bui.Update();
+ }
}
DirtyField(entity, nameof(UserInterfaceComponent.States));
@@ -1119,36 +1101,36 @@ public override void Update(float frameTime)
{
if (_timing.IsFirstTimePredicted)
{
- foreach (var (bui, updateType, state) in _queuedBuis)
+ foreach (var (bui, open) in _queuedBuis)
{
- if (updateType == QueuedUpdate.Open || updateType == QueuedUpdate.ApplyState)
+ if (open)
{
#if EXCEPTION_TOLERANCE
try
{
#endif
- if (updateType == QueuedUpdate.Open)
- {
- bui.Open();
- }
+ bui.Open();
- if (state != null)
+ if (UIQuery.TryComp(bui.Owner, out var uiComp))
{
- bui.State = state;
- bui.UpdateState(state);
- bui.Update();
+ if (uiComp.States.TryGetValue(bui.UiKey, out var buiState))
+ {
+ bui.State = buiState;
+ bui.UpdateState(buiState);
+ bui.Update();
+ }
}
#if EXCEPTION_TOLERANCE
}
catch (Exception e)
{
- var operationType = updateType == QueuedUpdate.Open ? "create" : "update";
Log.Error(
- $"Caught exception while attempting to {operationType} a BUI {bui.UiKey} with type {bui.GetType()} on entity {ToPrettyString(bui.Owner)}. Exception: {e}");
+ $"Caught exception while attempting to create a BUI {bui.UiKey} with type {bui.GetType()} on entity {ToPrettyString(bui.Owner)}. Exception: {e}");
}
#endif
}
- else // Close BUI
+ // Close BUI
+ else
{
if (UIQuery.TryComp(bui.Owner, out var uiComp))
{