using Robust.Server.GameObjects; using Robust.Server.Player; using Robust.Shared.Reflection; using Robust.Shared.Serialization; namespace Content.Server.UserInterface { [RegisterComponent] public sealed class ActivatableUIComponent : Component, ISerializationHooks { [ViewVariables] public Enum? Key { get; set; } [ViewVariables] public BoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null; [ViewVariables(VVAccess.ReadWrite)] [DataField("inHandsOnly")] public bool InHandsOnly { get; set; } = false; [DataField("singleUser")] public bool SingleUser { get; set; } = false; [ViewVariables(VVAccess.ReadWrite)] [DataField("adminOnly")] public bool AdminOnly { get; set; } = false; [DataField("key", readOnly: true, required: true)] private string _keyRaw = default!; [DataField("verbText")] public string VerbText = "ui-verb-toggle-open"; /// /// Whether you need a hand to operate this UI. The hand does not need to be free, you just need to have one. /// /// /// This should probably be true for most machines & computers, but there will still be UIs that represent a /// more generic interaction / configuration that might not require hands. /// [ViewVariables(VVAccess.ReadWrite)] [DataField("requireHands")] public bool RequireHands = true; /// /// Whether spectators (non-admin ghosts) should be allowed to view this UI. /// [ViewVariables(VVAccess.ReadWrite)] [DataField("allowSpectator")] public bool AllowSpectator = true; /// /// Whether the UI should close when the item is deselected due to a hand swap or drop /// [ViewVariables(VVAccess.ReadWrite)] [DataField("closeOnHandDeselect")] public bool CloseOnHandDeselect = true; /// /// The client channel currently using the object, or null if there's none/not single user. /// NOTE: DO NOT DIRECTLY SET, USE ActivatableUISystem.SetCurrentSingleUser /// [ViewVariables] public IPlayerSession? CurrentSingleUser; void ISerializationHooks.AfterDeserialization() { var reflectionManager = IoCManager.Resolve(); if (reflectionManager.TryParseEnumReference(_keyRaw, out var key)) Key = key; } } }