using System; using Robust.Shared.IoC; using Robust.Shared.Player; namespace Robust.Shared.GameObjects { /// /// An abstract class to override to implement bound user interfaces. /// public abstract class BoundUserInterface : IDisposable { [Dependency] protected readonly IEntityManager EntMan = default!; [Dependency] private readonly ISharedPlayerManager _playerManager = default!; protected readonly SharedUserInterfaceSystem UiSystem; public readonly Enum UiKey; public EntityUid Owner { get; } /// /// The last received state object sent from the server. /// protected BoundUserInterfaceState? State { get; private set; } protected BoundUserInterface(EntityUid owner, Enum uiKey) { IoCManager.InjectDependencies(this); UiSystem = EntMan.System(); Owner = owner; UiKey = uiKey; } /// /// Invoked when the UI is opened. /// Do all creation and opening of things like windows in here. /// protected internal virtual void Open() { } /// /// Invoked when the server uses SetState. /// protected internal virtual void UpdateState(BoundUserInterfaceState state) { } /// /// Invoked when the server sends an arbitrary message. /// protected internal virtual void ReceiveMessage(BoundUserInterfaceMessage message) { } /// /// Invoked to close the UI. /// public void Close() { UiSystem.CloseUi(Owner, UiKey, _playerManager.LocalEntity, predicted: true); } /// /// Sends a message to the server-side UI. /// public void SendMessage(BoundUserInterfaceMessage message) { UiSystem.ClientSendUiMessage(Owner, UiKey, message); } public void SendPredictedMessage(BoundUserInterfaceMessage message) { UiSystem.SendPredictedUiMessage(this, message); } ~BoundUserInterface() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { } } }