From a734bc50fa15cc4967a38daf081e428af597904f Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Wed, 12 Feb 2025 12:50:33 +1100
Subject: [PATCH] Avoid unnecessary UpdateState calls for BUIs (#5670)
---
.../Components/UserInterface/BoundUserInterface.cs | 10 ++++++++++
.../GameObjects/Systems/SharedUserInterfaceSystem.cs | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs b/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs
index ea96e6f701a..f2cd0f1f06f 100644
--- a/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs
+++ b/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs
@@ -15,6 +15,8 @@ public abstract class BoundUserInterface : IDisposable
[Dependency] protected readonly ISharedPlayerManager PlayerManager = default!;
protected readonly SharedUserInterfaceSystem UiSystem;
+ public bool IsOpened { get; protected set; }
+
public readonly Enum UiKey;
public EntityUid Owner { get; }
@@ -43,6 +45,10 @@ protected BoundUserInterface(EntityUid owner, Enum uiKey)
///
protected internal virtual void Open()
{
+ if (IsOpened)
+ return;
+
+ IsOpened = true;
}
///
@@ -93,6 +99,10 @@ protected internal virtual void ReceiveMessage(BoundUserInterfaceMessage message
///
public void Close()
{
+ if (!IsOpened)
+ return;
+
+ IsOpened = false;
UiSystem.CloseUi(Owner, UiKey, PlayerManager.LocalEntity, predicted: true);
}
diff --git a/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs b/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs
index 70f2e077376..6c950f3fc30 100644
--- a/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs
+++ b/Robust.Shared/GameObjects/Systems/SharedUserInterfaceSystem.cs
@@ -487,7 +487,7 @@ private void OnUserInterfaceHandleState(Entity ent, ref
ent.Comp.States[key] = buiState;
- if (!ent.Comp.ClientOpenInterfaces.TryGetValue(key, out var cBui))
+ if (!ent.Comp.ClientOpenInterfaces.TryGetValue(key, out var cBui) || !cBui.IsOpened)
continue;
cBui.State = buiState;