using System; using System.Collections.Generic; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.ViewVariables; namespace Robust.Client.GameObjects { [RegisterComponent, ComponentReference(typeof(SharedUserInterfaceComponent))] public sealed partial class ClientUserInterfaceComponent : SharedUserInterfaceComponent { [ViewVariables] internal readonly Dictionary _interfaces = new(); [ViewVariables] public readonly Dictionary OpenInterfaces = new(); } /// /// An abstract class to override to implement bound user interfaces. /// public abstract class BoundUserInterface : IDisposable { [Dependency] protected readonly IEntityManager EntMan = default!; protected readonly UserInterfaceSystem UiSystem = default!; 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 virtual void UpdateState(BoundUserInterfaceState state) { } /// /// Invoked when the server sends an arbitrary message. /// protected virtual void ReceiveMessage(BoundUserInterfaceMessage message) { } /// /// Invoked to close the UI. /// public void Close() { UiSystem.TryCloseUi(Owner, UiKey); } /// /// Sends a message to the server-side UI. /// public void SendMessage(BoundUserInterfaceMessage message) { UiSystem.SendUiMessage(this, message); } internal void InternalReceiveMessage(BoundUserInterfaceMessage message) { switch (message) { case UpdateBoundStateMessage updateBoundStateMessage: State = updateBoundStateMessage.State; UpdateState(State); break; default: ReceiveMessage(message); break; } } ~BoundUserInterface() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { } } }