diff --git a/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs b/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs index 058a501b03..1183e461b2 100644 --- a/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs @@ -4,6 +4,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.Access; using Content.Shared.GameObjects.Components.Access; using Content.Shared.Interfaces.GameObjects.Components; @@ -30,12 +31,7 @@ namespace Content.Server.GameObjects.Components.Access private ContainerSlot _privilegedIdContainer = default!; private ContainerSlot _targetIdContainer = default!; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(IdCardConsoleUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 511b26df1c..a8d61d1f41 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.Atmos; using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.EntitySystems; @@ -32,12 +33,7 @@ namespace Content.Server.GameObjects.Components.Atmos private bool _checkPlayer = false; // Check at the player pos or at some other tile? private GridCoordinates? _position; // The tile that we scanned - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(GasAnalyzerUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GasAnalyzerUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Body/BodyScannerComponent.cs b/Content.Server/GameObjects/Components/Body/BodyScannerComponent.cs index be4d6c99c9..dfc1cb5198 100644 --- a/Content.Server/GameObjects/Components/Body/BodyScannerComponent.cs +++ b/Content.Server/GameObjects/Components/Body/BodyScannerComponent.cs @@ -1,6 +1,7 @@ #nullable enable using System.Collections.Generic; using Content.Server.Body; +using Content.Server.Utility; using Content.Shared.Body.Scanner; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects.Components.UserInterface; @@ -17,12 +18,7 @@ namespace Content.Server.GameObjects.Components.Body { public sealed override string Name => "BodyScanner"; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(BodyScannerUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(BodyScannerUiKey.Key); void IActivate.Activate(ActivateEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Body/DroppedBodyPartComponent.cs b/Content.Server/GameObjects/Components/Body/DroppedBodyPartComponent.cs index cce6566879..f7fb29c6e7 100644 --- a/Content.Server/GameObjects/Components/Body/DroppedBodyPartComponent.cs +++ b/Content.Server/GameObjects/Components/Body/DroppedBodyPartComponent.cs @@ -4,6 +4,7 @@ using System.Linq; using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; using Content.Server.Body; +using Content.Server.Utility; using Content.Shared.Body.Surgery; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.UserInterface; @@ -34,12 +35,7 @@ namespace Content.Server.GameObjects.Components.Body [ViewVariables] public BodyPart ContainedBodyPart { get; private set; } = default!; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(GenericSurgeryUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GenericSurgeryUiKey.Key); void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Body/DroppedMechanismComponent.cs b/Content.Server/GameObjects/Components/Body/DroppedMechanismComponent.cs index 92af831132..939222ed2e 100644 --- a/Content.Server/GameObjects/Components/Body/DroppedMechanismComponent.cs +++ b/Content.Server/GameObjects/Components/Body/DroppedMechanismComponent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.Body; using Content.Server.Body.Mechanisms; +using Content.Server.Utility; using Content.Shared.Body.Mechanism; using Content.Shared.Body.Surgery; using Content.Shared.Interfaces; @@ -42,12 +43,7 @@ namespace Content.Server.GameObjects.Components.Body [ViewVariables] public Mechanism ContainedMechanism { get; private set; } = default!; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(GenericSurgeryUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GenericSurgeryUiKey.Key); void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Body/SurgeryToolComponent.cs b/Content.Server/GameObjects/Components/Body/SurgeryToolComponent.cs index 9f55f87a49..0c937b5a12 100644 --- a/Content.Server/GameObjects/Components/Body/SurgeryToolComponent.cs +++ b/Content.Server/GameObjects/Components/Body/SurgeryToolComponent.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Content.Server.Body; using Content.Server.Body.Mechanisms; using Content.Server.Body.Surgery; +using Content.Server.Utility; using Content.Shared.Body.Surgery; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Body; @@ -52,12 +53,7 @@ namespace Content.Server.GameObjects.Components.Body private SurgeryType _surgeryType; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(GenericSurgeryUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GenericSurgeryUiKey.Key); void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index e0149dc1c0..9f630edd1a 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -2,6 +2,7 @@ using Content.Server.Cargo; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Cargo; using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Prototypes.Cargo; @@ -59,12 +60,7 @@ namespace Content.Server.GameObjects.Components.Cargo private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; private CargoConsoleSystem _cargoConsoleSystem = default!; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(CargoConsoleUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(CargoConsoleUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs index 14a6413a4c..c3a7dc4764 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ChemMasterComponent.cs @@ -9,6 +9,7 @@ using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Chemistry.ChemMaster; using Content.Shared.GameObjects.EntitySystems; @@ -55,12 +56,7 @@ namespace Content.Server.GameObjects.Components.Chemistry private readonly SolutionComponent BufferSolution = new SolutionComponent(); - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(ChemMasterUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ChemMasterUiKey.Key); /// /// Shows the serializer how to save/load this components yaml prototype. diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs index f161403c82..3ec235caf7 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs @@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Chemistry.ReagentDispenser; using Content.Shared.GameObjects.EntitySystems; @@ -52,12 +53,7 @@ namespace Content.Server.GameObjects.Components.Chemistry private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(ReagentDispenserUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ReagentDispenserUiKey.Key); /// /// Shows the serializer how to save/load this components yaml prototype. diff --git a/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs b/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs index 4a26ee6a4a..09cd7c3137 100644 --- a/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs @@ -1,6 +1,7 @@ #nullable enable using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Command; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects.Components.UserInterface; @@ -23,12 +24,7 @@ namespace Content.Server.GameObjects.Components.Command private RoundEndSystem RoundEndSystem => _entitySystemManager.GetEntitySystem(); - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(CommunicationsConsoleUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalRouterComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalRouterComponent.cs index 9c85698e77..6cf6689e75 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalRouterComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalRouterComponent.cs @@ -17,6 +17,7 @@ using Robust.Shared.Maths; using Robust.Shared.ViewVariables; using System; using System.Collections.Generic; +using Content.Server.Utility; using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalRouterComponent; namespace Content.Server.GameObjects.Components.Disposal @@ -37,12 +38,7 @@ namespace Content.Server.GameObjects.Components.Disposal !Owner.TryGetComponent(out ICollidableComponent? collidable) || collidable.Anchored; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(DisposalRouterUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalRouterUiKey.Key); public override Direction NextDirection(DisposalHolderComponent holder) { diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTaggerComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTaggerComponent.cs index 34bb94e19b..76d913e2cf 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalTaggerComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalTaggerComponent.cs @@ -1,6 +1,7 @@ #nullable enable using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects.Components.UserInterface; @@ -35,12 +36,7 @@ namespace Content.Server.GameObjects.Components.Disposal !Owner.TryGetComponent(out CollidableComponent? collidable) || collidable.Anchored; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(DisposalTaggerUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalTaggerUiKey.Key); public override Direction NextDirection(DisposalHolderComponent holder) { diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 97e6bccf97..521615f4b9 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -9,6 +9,7 @@ using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Disposal; using Content.Shared.GameObjects.EntitySystems; @@ -112,15 +113,10 @@ namespace Content.Server.GameObjects.Components.Disposal } } - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(DisposalUnitUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(DisposalUnitUiKey.Key); private DisposalUnitBoundUserInterfaceState? _lastUiState; - + /// /// Store the translated state. /// @@ -296,7 +292,7 @@ namespace Content.Server.GameObjects.Components.Disposal private DisposalUnitBoundUserInterfaceState GetInterfaceState() { string stateString; - + if (_locState.State != State) { stateString = Loc.GetString($"{State}"); @@ -306,7 +302,7 @@ namespace Content.Server.GameObjects.Components.Disposal { stateString = _locState.Localized; } - + return new DisposalUnitBoundUserInterfaceState(Owner.Name, stateString, _pressure, Powered, Engaged); } diff --git a/Content.Server/GameObjects/Components/GUI/StrippableComponent.cs b/Content.Server/GameObjects/Components/GUI/StrippableComponent.cs index 484a60dd53..ec8ba05e42 100644 --- a/Content.Server/GameObjects/Components/GUI/StrippableComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/StrippableComponent.cs @@ -4,6 +4,7 @@ using System.Threading; using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.EntitySystems.DoAfter; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.GUI; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; @@ -27,12 +28,7 @@ namespace Content.Server.GameObjects.Components.GUI public const float StripDelay = 2f; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(StrippingUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(StrippingUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs index 7aa3a9df81..3a766f985a 100644 --- a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs @@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Damage; using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Gravity; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.EntitySystems; @@ -16,6 +17,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Gravity { @@ -59,11 +61,7 @@ namespace Content.Server.GameObjects.Components.Gravity public override string Name => "GravityGenerator"; - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(GravityGeneratorUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GravityGeneratorUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs b/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs index 833db0d87b..931b95288a 100644 --- a/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs +++ b/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs @@ -4,6 +4,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Mobs; using Content.Server.Interfaces; using Content.Server.Mobs; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Instruments; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; @@ -106,12 +107,7 @@ namespace Content.Server.GameObjects.Components.Instruments } } - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(InstrumentUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key); private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) { diff --git a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs index a3e049510c..21ef4a521a 100644 --- a/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/MicrowaveComponent.cs @@ -15,6 +15,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Power; using Content.Shared.Interfaces; @@ -73,12 +74,7 @@ namespace Content.Server.GameObjects.Components.Kitchen private AudioSystem _audioSystem = default!; private Container _storage = default!; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(MicrowaveUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MicrowaveUiKey.Key); public override void ExposeData(ObjectSerializer serializer) { diff --git a/Content.Server/GameObjects/Components/MagicMirrorComponent.cs b/Content.Server/GameObjects/Components/MagicMirrorComponent.cs index c03126cf9f..48aaadd613 100644 --- a/Content.Server/GameObjects/Components/MagicMirrorComponent.cs +++ b/Content.Server/GameObjects/Components/MagicMirrorComponent.cs @@ -1,5 +1,6 @@ #nullable enable using Content.Server.GameObjects.Components.Mobs; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; @@ -17,12 +18,7 @@ namespace Content.Server.GameObjects.Components [ComponentReference(typeof(IActivate))] public class MagicMirrorComponent : SharedMagicMirrorComponent, IActivate { - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(MagicMirrorUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MagicMirrorUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs index d16d821e78..cb2a11fb40 100644 --- a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Medical; using Content.Shared.GameObjects.EntitySystems; @@ -32,12 +33,7 @@ namespace Content.Server.GameObjects.Components.Medical [ViewVariables] private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(MedicalScannerUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MedicalScannerUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs index e3e4f810cf..fc87d0ddf5 100644 --- a/Content.Server/GameObjects/Components/PDA/PDAComponent.cs +++ b/Content.Server/GameObjects/Components/PDA/PDAComponent.cs @@ -9,6 +9,7 @@ using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.Interfaces; using Content.Server.Interfaces.PDA; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.PDA; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.Verbs; @@ -48,12 +49,7 @@ namespace Content.Server.GameObjects.Components.PDA [ViewVariables] private readonly PdaAccessSet _accessSet; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(PDAUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(PDAUiKey.Key); public PDAComponent() { diff --git a/Content.Server/GameObjects/Components/Paper/PaperComponent.cs b/Content.Server/GameObjects/Components/Paper/PaperComponent.cs index b3b9a8a459..ecae29f0a7 100644 --- a/Content.Server/GameObjects/Components/Paper/PaperComponent.cs +++ b/Content.Server/GameObjects/Components/Paper/PaperComponent.cs @@ -1,5 +1,6 @@ #nullable enable using System.Threading.Tasks; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; @@ -8,6 +9,7 @@ using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Utility; +using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Paper { @@ -17,11 +19,7 @@ namespace Content.Server.GameObjects.Components.Paper private string _content = ""; private PaperAction _mode; - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(PaperUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(PaperUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs index 7643db7112..fdb9d14133 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/ApcComponent.cs @@ -2,6 +2,7 @@ using System; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.Power.PowerNetComponents; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Power; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects; @@ -45,12 +46,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents private const int VisualsChangeDelay = 1; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(ApcUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ApcUiKey.Key); public BatteryComponent? Battery => Owner.TryGetComponent(out BatteryComponent? batteryComponent) ? batteryComponent : null; diff --git a/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarControlConsoleComponent.cs b/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarControlConsoleComponent.cs index 1670cb23dc..6eefdc32af 100644 --- a/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarControlConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerNetComponents/SolarControlConsoleComponent.cs @@ -1,6 +1,7 @@ #nullable enable using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Power; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects.Components.UserInterface; @@ -21,12 +22,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents private PowerSolarSystem _powerSolarSystem = default!; private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(SolarControlConsoleUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(SolarControlConsoleUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Research/LatheComponent.cs b/Content.Server/GameObjects/Components/Research/LatheComponent.cs index 987f6846c9..be55677be9 100644 --- a/Content.Server/GameObjects/Components/Research/LatheComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheComponent.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.Components.Stack; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Materials; using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Research; @@ -45,12 +46,7 @@ namespace Content.Server.GameObjects.Components.Research private static readonly TimeSpan InsertionTime = TimeSpan.FromSeconds(0.9f); - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(LatheUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(LatheUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs index fb5de72bd0..44a5069dcf 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs @@ -1,5 +1,6 @@ #nullable enable using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Research; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Server.GameObjects.Components.UserInterface; @@ -18,11 +19,7 @@ namespace Content.Server.GameObjects.Components.Research [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; // TODO: Create GUI for changing RD server. - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(ResearchClientUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ResearchClientUiKey.Key); public bool ConnectedToServer => Server != null; diff --git a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs index 4c7aa4a468..4a1adc57c1 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs @@ -1,5 +1,6 @@ #nullable enable using Content.Server.GameObjects.Components.Power.ApcNetComponents; +using Content.Server.Utility; using Content.Shared.Audio; using Content.Shared.GameObjects.Components.Research; using Content.Shared.Interfaces.GameObjects.Components; @@ -30,12 +31,7 @@ namespace Content.Server.GameObjects.Components.Research private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; - [ViewVariables] - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(ResearchConsoleUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ResearchConsoleUiKey.Key); public override void Initialize() { diff --git a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs index 2e1d47a898..3fd2c7177a 100644 --- a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using Content.Server.GameObjects.Components.Power.ApcNetComponents; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.VendingMachines; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; @@ -21,6 +22,7 @@ using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.Timers; using Robust.Shared.Utility; +using Robust.Shared.ViewVariables; using static Content.Shared.GameObjects.Components.SharedWiresComponent; namespace Content.Server.GameObjects.Components.VendingMachines @@ -42,11 +44,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines private string _soundVend = ""; - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(VendingMachineUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(VendingMachineUiKey.Key); public void Activate(ActivateEventArgs eventArgs) { diff --git a/Content.Server/GameObjects/Components/WiresComponent.cs b/Content.Server/GameObjects/Components/WiresComponent.cs index bd0276ab62..50ea153a2d 100644 --- a/Content.Server/GameObjects/Components/WiresComponent.cs +++ b/Content.Server/GameObjects/Components/WiresComponent.cs @@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.VendingMachines; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects.Components.Items; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.Components.Interactable; using Content.Shared.GameObjects.EntitySystems; @@ -140,11 +141,7 @@ namespace Content.Server.GameObjects.Components [ViewVariables] private string? _layoutId; - private BoundUserInterface? UserInterface => - Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) && - ui.TryGetBoundUserInterface(WiresUiKey.Key, out var boundUi) - ? boundUi - : null; + [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(WiresUiKey.Key); public override void Initialize() { diff --git a/Content.Server/Utility/UserInterfaceHelpers.cs b/Content.Server/Utility/UserInterfaceHelpers.cs new file mode 100644 index 0000000000..2c87ebdfc5 --- /dev/null +++ b/Content.Server/Utility/UserInterfaceHelpers.cs @@ -0,0 +1,14 @@ +#nullable enable +using Robust.Server.GameObjects.Components.UserInterface; +using Robust.Shared.Interfaces.GameObjects; + +namespace Content.Server.Utility +{ + public static class UserInterfaceHelpers + { + public static BoundUserInterface? GetUIOrNull(this IEntity entity, object uiKey) + { + return entity.GetComponentOrNull()?.GetBoundUserInterfaceOrNull(uiKey); + } + } +}