mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Extension helper function for registering BUI events filtered to UI key. Usages of events like BoundUIClosedEvent frequently did not check the UI key or do it improperly. This has, and will continue to cause, bugs. The new helper (accessible as Subs.BuiEvents() from an entity system) makes it easy to subscribe to BUI events while also filtering to the correct UI key. Also added missing SubscribeLocalEvent overloads with new handler types to EntitySystem.Subscriptions. * Sprinkle [ViewVariables] around BUI * Avoid buggy behavior if a Bound UI is closed inside the `BoundUIOpenedEvent` that's opening it.
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Shared.GameObjects;
|
|
|
|
/// <summary>
|
|
/// Represents an entity-bound interface that can be opened by multiple players at once.
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public sealed class PlayerBoundUserInterface
|
|
{
|
|
[ViewVariables]
|
|
public float InteractionRange;
|
|
|
|
[ViewVariables]
|
|
public float InteractionRangeSqrd => InteractionRange * InteractionRange;
|
|
|
|
[ViewVariables]
|
|
public Enum UiKey { get; }
|
|
[ViewVariables]
|
|
public EntityUid Owner { get; }
|
|
|
|
internal readonly HashSet<ICommonSession> _subscribedSessions = new();
|
|
[ViewVariables]
|
|
internal BoundUIWrapMessage? LastStateMsg;
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool RequireInputValidation;
|
|
|
|
[ViewVariables]
|
|
internal bool StateDirty;
|
|
|
|
[ViewVariables]
|
|
internal readonly Dictionary<ICommonSession, BoundUIWrapMessage> PlayerStateOverrides =
|
|
new();
|
|
|
|
/// <summary>
|
|
/// All of the sessions currently subscribed to this UserInterface.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public IReadOnlySet<ICommonSession> SubscribedSessions => _subscribedSessions;
|
|
|
|
public PlayerBoundUserInterface(PrototypeData data, EntityUid owner)
|
|
{
|
|
RequireInputValidation = data.RequireInputValidation;
|
|
UiKey = data.UiKey;
|
|
Owner = owner;
|
|
|
|
InteractionRange = data.InteractionRange;
|
|
}
|
|
}
|