Skip to content

Commit

Permalink
Avoid unnecessary UpdateState calls for BUIs (#5670)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Feb 12, 2025
1 parent 9e9ac56 commit a734bc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -43,6 +45,10 @@ protected BoundUserInterface(EntityUid owner, Enum uiKey)
/// </summary>
protected internal virtual void Open()
{
if (IsOpened)
return;

IsOpened = true;
}

/// <summary>
Expand Down Expand Up @@ -93,6 +99,10 @@ protected internal virtual void ReceiveMessage(BoundUserInterfaceMessage message
/// </summary>
public void Close()
{
if (!IsOpened)
return;

IsOpened = false;
UiSystem.CloseUi(Owner, UiKey, PlayerManager.LocalEntity, predicted: true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ private void OnUserInterfaceHandleState(Entity<UserInterfaceComponent> 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;
Expand Down

0 comments on commit a734bc5

Please sign in to comment.