From 3ac4cf85db02c9db8196bf126ea9fc1c25a082b3 Mon Sep 17 00:00:00 2001 From: TemporalOroboros Date: Sat, 8 Jul 2023 09:02:17 -0700 Subject: [PATCH] Cleaner BoundUserInterfaces (#17736) --- .../UI/AgentIDCardBoundUserInterface.cs | 2 +- .../UI/IdCardConsoleBoundUserInterface.cs | 19 ++- .../UI/AirlockPainterBoundUserInterface.cs | 9 +- .../Ame/UI/AmeControllerBoundUserInterface.cs | 2 +- .../Ui/AnomalyGeneratorBoundUserInterface.cs | 6 +- .../Ui/AnomalyScannerBoundUserInterface.cs | 2 +- .../Arcade/UI/BlockGameBoundUserInterface.cs | 2 +- .../SpaceVillainArcadeBoundUserInterface.cs | 2 +- .../Monitor/UI/AirAlarmBoundUserInterface.cs | 4 +- .../Atmos/Monitor/UI/AirAlarmWindow.xaml.cs | 4 +- .../Atmos/UI/GasAnalyzerBoundUserInterface.cs | 7 +- .../Atmos/UI/GasCanisterBoundUserInterface.cs | 7 +- .../Atmos/UI/GasFilterBoundUserInterface.cs | 11 +- .../Atmos/UI/GasMixerBoundUserInteface.cs | 24 +-- .../UI/GasPressurePumpBoundUserInterface.cs | 16 +- .../UI/GasThermomachineBoundUserInterface.cs | 13 +- .../UI/GasVolumePumpBoundUserInterface.cs | 16 +- .../CargoBountyConsoleBoundUserInterface.cs | 3 +- .../CargoOrderConsoleBoundUserInterface.cs | 13 +- .../CargoPalletConsoleBoundUserInterface.cs | 5 +- .../CargoShuttleConsoleBoundUserInterface.cs | 5 +- .../CartridgeLoaderBoundUserInterface.cs | 14 +- .../UI/ChemMasterBoundUserInterface.cs | 13 +- .../UI/ReagentDispenserBoundUserInterface.cs | 16 +- .../UI/TransferAmountBoundUserInterface.cs | 9 +- .../UI/CloningConsoleBoundUserInterface.cs | 3 +- .../UI/ChameleonBoundUserInterface.cs | 7 +- ...CommunicationsConsoleBoundUserInterface.cs | 16 +- .../Computer/ComputerBoundUserInterface.cs | 21 ++- .../UI/ConfigurationBoundUserInterface.cs | 12 +- .../Crayon/UI/CrayonBoundUserInterface.cs | 9 +- .../UI/DisposalRouterBoundUserInterface.cs | 4 +- .../UI/DisposalTaggerBoundUserInterface.cs | 4 +- .../UI/DisposalUnitBoundUserInterface.cs | 9 +- Content.Client/Fax/UI/FaxBoundUi.cs | 3 +- .../ForensicScannerBoundUserInterface.cs | 4 +- .../UI/GravityGeneratorBoundUserInterface.cs | 6 +- .../Gravity/UI/GravityGeneratorWindow.xaml.cs | 6 +- .../UI/HealthAnalyzerBoundUserInterface.cs | 5 +- ...manoidMarkingModifierBoundUserInterface.cs | 7 +- .../UI/InstrumentBoundUserInterface.cs | 8 +- .../Inventory/StrippableBoundUserInterface.cs | 63 ++++---- .../Kitchen/UI/MicrowaveBoundUserInterface.cs | 32 ++-- .../UI/ReagentGrinderBoundUserInterface.cs | 41 ++++-- .../UI/HandLabelerBoundUserInterface.cs | 4 +- .../Lathe/UI/LatheBoundUserInterface.cs | 14 +- Content.Client/Lathe/UI/LatheMenu.xaml.cs | 14 +- .../SignalPortSelectorBoundUserInterface.cs | 9 +- .../UI/SignalTimerBoundUserInterface.cs | 3 +- .../MagicMirrorBoundUserInterface.cs | 7 +- .../Mech/Ui/MechBoundUserInterface.cs | 15 +- .../CrewMonitoringBoundUserInterface.cs | 11 +- .../NetworkConfiguratorBoundUserInterface.cs | 19 +-- Content.Client/Nuke/NukeBoundUserInterface.cs | 5 +- Content.Client/PDA/PdaBoundUserInterface.cs | 8 +- .../PDA/Ringer/RingerBoundUserInterface.cs | 4 +- .../Paper/UI/PaperBoundUserInterface.cs | 6 +- .../ParticleAcceleratorBoundUserInterface.cs | 3 +- .../UI/StationMapBoundUserInterface.cs | 8 +- .../Power/APC/ApcBoundUserInterface.cs | 15 +- Content.Client/Power/APC/UI/ApcMenu.xaml.cs | 4 +- .../Power/PowerMonitoringWindow.xaml.cs | 18 +-- .../Power/SolarControlWindow.xaml.cs | 34 +++-- .../UI/DiskConsoleBoundUserInterface.cs | 4 +- .../UI/ResearchClientBoundUserInterface.cs | 3 +- .../UI/ResearchConsoleBoundUserInterface.cs | 8 +- ...vageExpeditionConsoleBoundUserInterface.cs | 4 +- .../BUI/EmergencyConsoleBoundUserInterface.cs | 5 +- .../BUI/IFFConsoleBoundUserInterface.cs | 5 +- .../BUI/RadarConsoleBoundUserInterface.cs | 6 +- .../BUI/ShuttleConsoleBoundUserInterface.cs | 12 +- .../Shuttles/Systems/ShuttleConsoleSystem.cs | 6 +- ...lStationRecordConsoleBoundUserInterface.cs | 6 +- .../Storage/StorageBoundUserInterface.cs | 26 ++-- .../Store/Ui/StoreBoundUserInterface.cs | 5 +- Content.Client/Strip/StrippableSystem.cs | 2 +- .../UI/SurveillanceCameraMonitorBoundUi.cs | 17 ++- .../UI/SurveillanceCameraSetupBoundUi.cs | 11 +- .../GasTank/GasTankBoundUserInterface.cs | 16 +- .../VendingMachineBoundUserInterface.cs | 10 +- .../VoiceMask/VoiceMaskBoundUserInterface.cs | 7 +- .../Melee/UI/MeleeSpeechBoundUserInterface.cs | 11 +- .../Wires/UI/WiresBoundUserInterface.cs | 4 +- .../Ui/AnalysisConsoleBoundUserInterface.cs | 4 +- .../Interaction/InteractionTest.Helpers.cs | 12 +- .../Access/Systems/AgentIDCardSystem.cs | 6 +- .../AirlockPainter/AirlockPainterSystem.cs | 4 +- Content.Server/Alert/Click/StopPiloting.cs | 4 +- .../Ame/EntitySystems/AmeControllerSystem.cs | 2 +- .../Cargo/Systems/CargoSystem.Orders.cs | 132 +++++++++-------- .../Cargo/Systems/CargoSystem.Shuttle.cs | 37 +++-- .../Cargo/Systems/CargoSystem.Telepad.cs | 4 +- Content.Server/Cargo/Systems/CargoSystem.cs | 5 +- .../CartridgeLoader/CartridgeLoaderSystem.cs | 30 ++-- .../Cloning/CloningConsoleSystem.cs | 26 ++-- Content.Server/Cloning/CloningSystem.cs | 50 ++++--- .../CommunicationsConsoleSystem.cs | 55 +++---- .../Configurable/ConfigurationSystem.cs | 2 +- Content.Server/Crayon/CrayonSystem.cs | 15 +- .../Systems/SignalTimerSystem.cs | 8 +- .../Systems/NetworkConfiguratorSystem.cs | 49 +++--- .../Disposal/Mailing/MailingUnitSystem.cs | 3 +- .../Disposal/Tube/DisposalTubeSystem.cs | 6 +- .../Instruments/InstrumentSystem.cs | 8 +- .../Kitchen/EntitySystems/MicrowaveSystem.cs | 48 +++--- Content.Server/Lathe/LatheSystem.cs | 12 +- .../System/SignalLinkerSystem.cs | 139 ++++++++++-------- Content.Server/Mech/Systems/MechSystem.cs | 12 +- .../CrewMonitoringConsoleSystem.cs | 20 +-- .../Medical/MedicalScannerSystem.cs | 30 ++-- Content.Server/Nuke/NukeSystem.cs | 26 ++-- Content.Server/PDA/Ringer/RingerSystem.cs | 2 +- Content.Server/Paper/PaperSystem.cs | 18 ++- .../ParticleAcceleratorSystem.ControlBox.cs | 10 +- .../Physics/Controllers/MoverController.cs | 88 +++++------ .../PowerMonitoringConsoleSystem.cs | 16 +- .../Salvage/SalvageSystem.Expeditions.cs | 4 +- .../Components/ShuttleConsoleComponent.cs | 2 +- .../Systems/EmergencyShuttleSystem.Console.cs | 35 +++-- .../Shuttles/Systems/RadarConsoleSystem.cs | 24 +-- .../Shuttles/Systems/ShuttleConsoleSystem.cs | 44 +++--- .../PowerSolarControlConsoleSystem.cs | 9 +- .../StationEvents/Events/CargoGiftsRule.cs | 19 +-- .../GeneralStationRecordConsoleSystem.cs | 4 +- .../Storage/EntitySystems/StorageSystem.cs | 62 +++----- .../Store/Systems/StoreSystem.Ui.cs | 6 +- Content.Server/Store/Systems/StoreSystem.cs | 4 +- .../Systems/SurveillanceCameraRouterSystem.cs | 9 +- .../Systems/SurveillanceCameraSystem.cs | 9 +- .../UserInterface/ActivatableUISystem.cs | 10 +- .../UserInterface/IntrinsicUISystem.cs | 3 +- Content.Server/VoiceMask/VoiceMaskSystem.cs | 11 +- .../Systems/ArtifactAnalyzerSystem.cs | 18 +-- .../Shuttles/Components/PilotComponent.cs | 6 +- .../Components/RadarConsoleComponent.cs | 2 +- .../Systems/SharedRadarConsoleSystem.cs | 20 ++- .../Systems/SharedShuttleConsoleSystem.cs | 4 +- 137 files changed, 1069 insertions(+), 972 deletions(-) diff --git a/Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs b/Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs index 6b6ce1e565..a7c499c12e 100644 --- a/Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs +++ b/Content.Client/Access/UI/AgentIDCardBoundUserInterface.cs @@ -10,7 +10,7 @@ namespace Content.Client.Access.UI { private AgentIDCardWindow? _window; - public AgentIDCardBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public AgentIDCardBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs index d51e91401f..f1350a21b4 100644 --- a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs +++ b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs @@ -10,19 +10,21 @@ namespace Content.Client.Access.UI public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly IEntityManager _entityManager = default!; + private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!; - public IdCardConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) - { - } private IdCardConsoleWindow? _window; + public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + _idCardConsoleSystem = EntMan.System(); + } + protected override void Open() { base.Open(); List accessLevels; - if (_entityManager.TryGetComponent(Owner.Owner, out var idCard)) + if (EntMan.TryGetComponent(Owner, out var idCard)) { accessLevels = idCard.AccessLevels; accessLevels.Sort(); @@ -30,10 +32,13 @@ namespace Content.Client.Access.UI else { accessLevels = new List(); - Logger.ErrorS(SharedIdCardConsoleSystem.Sawmill, $"No IdCardConsole component found for {_entityManager.ToPrettyString(Owner.Owner)}!"); + _idCardConsoleSystem.Log.Error($"No IdCardConsole component found for {EntMan.ToPrettyString(Owner)}!"); } - _window = new IdCardConsoleWindow(this, _prototypeManager, accessLevels) {Title = _entityManager.GetComponent(Owner.Owner).EntityName}; + _window = new IdCardConsoleWindow(this, _prototypeManager, accessLevels) + { + Title = EntMan.GetComponent(Owner).EntityName + }; _window.CrewManifestButton.OnPressed += _ => SendMessage(new CrewManifestOpenUiMessage()); _window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId)); diff --git a/Content.Client/AirlockPainter/UI/AirlockPainterBoundUserInterface.cs b/Content.Client/AirlockPainter/UI/AirlockPainterBoundUserInterface.cs index 62ded3ecb3..019718c7b5 100644 --- a/Content.Client/AirlockPainter/UI/AirlockPainterBoundUserInterface.cs +++ b/Content.Client/AirlockPainter/UI/AirlockPainterBoundUserInterface.cs @@ -6,12 +6,13 @@ namespace Content.Client.AirlockPainter.UI { public sealed class AirlockPainterBoundUserInterface : BoundUserInterface { + [ViewVariables] private AirlockPainterWindow? _window; + + [ViewVariables] private AirlockPainterSystem? _painter; - [Dependency] private readonly IEntitySystemManager _entitySystems = default!; - - public AirlockPainterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public AirlockPainterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -21,7 +22,7 @@ namespace Content.Client.AirlockPainter.UI _window = new AirlockPainterWindow(); - _painter = _entitySystems.GetEntitySystem(); + _painter = EntMan.System(); _window.OpenCentered(); _window.OnClose += Close; diff --git a/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs b/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs index a99a69747f..3b4c9fa224 100644 --- a/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs +++ b/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs @@ -9,7 +9,7 @@ namespace Content.Client.Ame.UI { private AmeWindow? _window; - public AmeControllerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public AmeControllerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs b/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs index 9d8923a2e1..5764d0a097 100644 --- a/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs +++ b/Content.Client/Anomaly/Ui/AnomalyGeneratorBoundUserInterface.cs @@ -3,14 +3,14 @@ using Content.Shared.Gravity; using JetBrains.Annotations; using Robust.Client.GameObjects; -namespace Content.Client. Anomaly.Ui; +namespace Content.Client.Anomaly.Ui; [UsedImplicitly] public sealed class AnomalyGeneratorBoundUserInterface : BoundUserInterface { private AnomalyGeneratorWindow? _window; - public AnomalyGeneratorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base (owner, uiKey) + public AnomalyGeneratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -18,7 +18,7 @@ public sealed class AnomalyGeneratorBoundUserInterface : BoundUserInterface { base.Open(); - _window = new (Owner.Owner); + _window = new(Owner); _window.OpenCentered(); _window.OnClose += Close; diff --git a/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs b/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs index 64f66818eb..97bc0276e9 100644 --- a/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs +++ b/Content.Client/Anomaly/Ui/AnomalyScannerBoundUserInterface.cs @@ -9,7 +9,7 @@ public sealed class AnomalyScannerBoundUserInterface : BoundUserInterface { private AnomalyScannerMenu? _menu; - public AnomalyScannerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public AnomalyScannerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Arcade/UI/BlockGameBoundUserInterface.cs b/Content.Client/Arcade/UI/BlockGameBoundUserInterface.cs index 2abe9311fb..1a3422dec0 100644 --- a/Content.Client/Arcade/UI/BlockGameBoundUserInterface.cs +++ b/Content.Client/Arcade/UI/BlockGameBoundUserInterface.cs @@ -7,7 +7,7 @@ public sealed class BlockGameBoundUserInterface : BoundUserInterface { private BlockGameMenu? _menu; - public BlockGameBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public BlockGameBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Arcade/UI/SpaceVillainArcadeBoundUserInterface.cs b/Content.Client/Arcade/UI/SpaceVillainArcadeBoundUserInterface.cs index 2ecc8b46a8..40bbe8b2d8 100644 --- a/Content.Client/Arcade/UI/SpaceVillainArcadeBoundUserInterface.cs +++ b/Content.Client/Arcade/UI/SpaceVillainArcadeBoundUserInterface.cs @@ -11,7 +11,7 @@ public sealed class SpaceVillainArcadeBoundUserInterface : BoundUserInterface //public SharedSpaceVillainArcadeComponent SpaceVillainArcade; - public SpaceVillainArcadeBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public SpaceVillainArcadeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { SendAction(PlayerAction.RequestData); } diff --git a/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs b/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs index cf884dd509..0bd310c57c 100644 --- a/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs +++ b/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs @@ -12,7 +12,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface { private AirAlarmWindow? _window; - public AirAlarmBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public AirAlarmBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -20,7 +20,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface { base.Open(); - _window = new AirAlarmWindow(Owner); + _window = new AirAlarmWindow(this); if (State != null) { diff --git a/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs b/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs index 5b682e2620..bb3f0dcbfa 100644 --- a/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs +++ b/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs @@ -44,7 +44,7 @@ public sealed partial class AirAlarmWindow : FancyWindow private OptionButton _modes => CModeButton; - public AirAlarmWindow(ClientUserInterfaceComponent component) + public AirAlarmWindow(BoundUserInterface owner) { RobustXamlLoader.Load(this); @@ -88,7 +88,7 @@ public sealed partial class AirAlarmWindow : FancyWindow ResyncAllRequested!.Invoke(); }; - EntityView.Sprite = IoCManager.Resolve().GetComponent(component.Owner); + EntityView.SetEntity(owner.Owner); } public void UpdateState(AirAlarmUIState state) diff --git a/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs b/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs index 5aee69dd47..6e6fd17d42 100644 --- a/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasAnalyzerBoundUserInterface.cs @@ -5,12 +5,13 @@ namespace Content.Client.Atmos.UI { public sealed class GasAnalyzerBoundUserInterface : BoundUserInterface { - public GasAnalyzerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private GasAnalyzerWindow? _window; + + public GasAnalyzerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } - private GasAnalyzerWindow? _window; - protected override void Open() { base.Open(); diff --git a/Content.Client/Atmos/UI/GasCanisterBoundUserInterface.cs b/Content.Client/Atmos/UI/GasCanisterBoundUserInterface.cs index ba9c7037ed..a5e316a8de 100644 --- a/Content.Client/Atmos/UI/GasCanisterBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasCanisterBoundUserInterface.cs @@ -1,7 +1,6 @@ using Content.Shared.Atmos.Piping.Binary.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Atmos.UI { @@ -11,10 +10,10 @@ namespace Content.Client.Atmos.UI [UsedImplicitly] public sealed class GasCanisterBoundUserInterface : BoundUserInterface { - + [ViewVariables] private GasCanisterWindow? _window; - public GasCanisterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public GasCanisterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -24,7 +23,7 @@ namespace Content.Client.Atmos.UI _window = new GasCanisterWindow(); - if(State != null) + if (State != null) UpdateState(State); _window.OpenCentered(); diff --git a/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs b/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs index 6c16881224..1087efd51d 100644 --- a/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasFilterBoundUserInterface.cs @@ -12,10 +12,13 @@ namespace Content.Client.Atmos.UI [UsedImplicitly] public sealed class GasFilterBoundUserInterface : BoundUserInterface { + [ViewVariables] + private const float MaxTransferRate = Atmospherics.MaxTransferRate; + [ViewVariables] private GasFilterWindow? _window; - public GasFilterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public GasFilterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -23,11 +26,11 @@ namespace Content.Client.Atmos.UI { base.Open(); - var atmosSystem = IoCManager.Resolve().GetEntitySystem(); + var atmosSystem = EntMan.System(); _window = new GasFilterWindow(atmosSystem.Gases); - if(State != null) + if (State != null) UpdateState(State); _window.OpenCentered(); @@ -81,7 +84,7 @@ namespace Content.Client.Atmos.UI _window.SetTransferRate(cast.TransferRate); if (cast.FilteredGas is not null) { - var atmos = IoCManager.Resolve().GetEntitySystem(); + var atmos = EntMan.System(); var gas = atmos.GetGas((Gas) cast.FilteredGas); var gasName = Loc.GetString(gas.Name); _window.SetGasFiltered(gas.ID, gasName); diff --git a/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs b/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs index dc7a4dc903..cfec8c3495 100644 --- a/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs +++ b/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs @@ -1,11 +1,7 @@ -using System; -using Content.Client.Atmos.EntitySystems; using Content.Shared.Atmos; -using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Trinary.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Atmos.UI { @@ -15,11 +11,13 @@ namespace Content.Client.Atmos.UI [UsedImplicitly] public sealed class GasMixerBoundUserInterface : BoundUserInterface { - - private GasMixerWindow? _window; + [ViewVariables] private const float MaxPressure = Atmospherics.MaxOutputPressure; - public GasMixerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private GasMixerWindow? _window; + + public GasMixerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -29,7 +27,7 @@ namespace Content.Client.Atmos.UI _window = new GasMixerWindow(); - if(State != null) + if (State != null) UpdateState(State); _window.OpenCentered(); @@ -49,8 +47,9 @@ namespace Content.Client.Atmos.UI private void OnMixerOutputPressurePressed(string value) { - float pressure = float.TryParse(value, out var parsed) ? parsed : 0f; - if (pressure > MaxPressure) pressure = MaxPressure; + var pressure = float.TryParse(value, out var parsed) ? parsed : 0f; + if (pressure > MaxPressure) + pressure = MaxPressure; SendMessage(new GasMixerChangeOutputPressureMessage(pressure)); } @@ -58,11 +57,12 @@ namespace Content.Client.Atmos.UI private void OnMixerSetPercentagePressed(string value) { // We don't need to send both nodes because it's just 100.0f - node - float node = float.TryParse(value, out var parsed) ? parsed : 1.0f; + var node = float.TryParse(value, out var parsed) ? parsed : 1.0f; node = Math.Clamp(node, 0f, 100.0f); - if (_window is not null) node = _window.NodeOneLastEdited ? node : 100.0f - node; + if (_window is not null) + node = _window.NodeOneLastEdited ? node : 100.0f - node; SendMessage(new GasMixerChangeNodePercentageMessage(node)); } diff --git a/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs index 2c7302f056..69cd6cb587 100644 --- a/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs @@ -1,11 +1,7 @@ -using System; -using Content.Client.Atmos.EntitySystems; -using Content.Shared.Atmos; +using Content.Shared.Atmos; using Content.Shared.Atmos.Piping.Binary.Components; -using Content.Shared.Atmos.Piping.Trinary.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Atmos.UI { @@ -15,11 +11,13 @@ namespace Content.Client.Atmos.UI [UsedImplicitly] public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface { - - private GasPressurePumpWindow? _window; + [ViewVariables] private const float MaxPressure = Atmospherics.MaxOutputPressure; - public GasPressurePumpBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private GasPressurePumpWindow? _window; + + public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -29,7 +27,7 @@ namespace Content.Client.Atmos.UI _window = new GasPressurePumpWindow(); - if(State != null) + if (State != null) UpdateState(State); _window.OpenCentered(); diff --git a/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs b/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs index 5eee70808a..cda7f6836c 100644 --- a/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs @@ -1,9 +1,6 @@ -using Content.Shared.Atmos; -using Content.Shared.Atmos.Piping.Binary.Components; -using Content.Shared.Atmos.Piping.Unary.Components; +using Content.Shared.Atmos.Piping.Unary.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Atmos.UI { @@ -13,12 +10,16 @@ namespace Content.Client.Atmos.UI [UsedImplicitly] public sealed class GasThermomachineBoundUserInterface : BoundUserInterface { + [ViewVariables] private GasThermomachineWindow? _window; + [ViewVariables] private float _minTemp = 0.0f; + + [ViewVariables] private float _maxTemp = 0.0f; - public GasThermomachineBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public GasThermomachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -28,7 +29,7 @@ namespace Content.Client.Atmos.UI _window = new GasThermomachineWindow(); - if(State != null) + if (State != null) UpdateState(State); _window.OpenCentered(); diff --git a/Content.Client/Atmos/UI/GasVolumePumpBoundUserInterface.cs b/Content.Client/Atmos/UI/GasVolumePumpBoundUserInterface.cs index e211a58fed..5ccc79a410 100644 --- a/Content.Client/Atmos/UI/GasVolumePumpBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasVolumePumpBoundUserInterface.cs @@ -2,7 +2,6 @@ using Content.Shared.Atmos.Piping.Binary.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Atmos.UI { @@ -12,11 +11,13 @@ namespace Content.Client.Atmos.UI [UsedImplicitly] public sealed class GasVolumePumpBoundUserInterface : BoundUserInterface { - - private GasVolumePumpWindow? _window; + [ViewVariables] private const float MaxTransferRate = Atmospherics.MaxTransferRate; - public GasVolumePumpBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private GasVolumePumpWindow? _window; + + public GasVolumePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -26,7 +27,7 @@ namespace Content.Client.Atmos.UI _window = new GasVolumePumpWindow(); - if(State != null) + if (State != null) UpdateState(State); _window.OpenCentered(); @@ -45,8 +46,9 @@ namespace Content.Client.Atmos.UI private void OnPumpTransferRatePressed(string value) { - float rate = float.TryParse(value, out var parsed) ? parsed : 0f; - if (rate > MaxTransferRate) rate = MaxTransferRate; + var rate = float.TryParse(value, out var parsed) ? parsed : 0f; + if (rate > MaxTransferRate) + rate = MaxTransferRate; SendMessage(new GasVolumePumpChangeTransferRateMessage(rate)); } diff --git a/Content.Client/Cargo/BUI/CargoBountyConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoBountyConsoleBoundUserInterface.cs index 63587d9875..669f64fae4 100644 --- a/Content.Client/Cargo/BUI/CargoBountyConsoleBoundUserInterface.cs +++ b/Content.Client/Cargo/BUI/CargoBountyConsoleBoundUserInterface.cs @@ -11,9 +11,8 @@ public sealed class CargoBountyConsoleBoundUserInterface : BoundUserInterface [ViewVariables] private CargoBountyMenu? _menu; - public CargoBountyConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public CargoBountyConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } protected override void Open() diff --git a/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs index 54e1660af3..6c9af85a2c 100644 --- a/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs +++ b/Content.Client/Cargo/BUI/CargoOrderConsoleBoundUserInterface.cs @@ -38,9 +38,10 @@ namespace Content.Client.Cargo.BUI /// /// Currently selected product /// + [ViewVariables] private CargoProductPrototype? _product; - public CargoOrderConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public CargoOrderConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -48,17 +49,15 @@ namespace Content.Client.Cargo.BUI { base.Open(); - var entityManager = IoCManager.Resolve(); - var sysManager = entityManager.EntitySysManager; - var spriteSystem = sysManager.GetEntitySystem(); + var spriteSystem = EntMan.System(); _menu = new CargoConsoleMenu(IoCManager.Resolve(), spriteSystem); var localPlayer = IoCManager.Resolve()?.LocalPlayer?.ControlledEntity; var description = new FormattedMessage(); string orderRequester; - if (entityManager.TryGetComponent(localPlayer, out var metadata)) - orderRequester = Identity.Name(localPlayer.Value, entityManager); + if (EntMan.TryGetComponent(localPlayer, out var metadata)) + orderRequester = Identity.Name(localPlayer.Value, EntMan); else orderRequester = string.Empty; @@ -138,7 +137,7 @@ namespace Content.Client.Cargo.BUI private bool AddOrder() { - int orderAmt = _orderMenu?.Amount.Value ?? 0; + var orderAmt = _orderMenu?.Amount.Value ?? 0; if (orderAmt < 1 || orderAmt > OrderCapacity) { return false; diff --git a/Content.Client/Cargo/BUI/CargoPalletConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoPalletConsoleBoundUserInterface.cs index 3c7b7fe0c0..20c23a48a0 100644 --- a/Content.Client/Cargo/BUI/CargoPalletConsoleBoundUserInterface.cs +++ b/Content.Client/Cargo/BUI/CargoPalletConsoleBoundUserInterface.cs @@ -7,9 +7,12 @@ namespace Content.Client.Cargo.BUI; public sealed class CargoPalletConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private CargoPalletMenu? _menu; - public CargoPalletConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public CargoPalletConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { diff --git a/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs b/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs index f1f102985e..422d03707a 100644 --- a/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs +++ b/Content.Client/Cargo/BUI/CargoShuttleConsoleBoundUserInterface.cs @@ -9,9 +9,12 @@ namespace Content.Client.Cargo.BUI; [UsedImplicitly] public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private CargoShuttleMenu? _menu; - public CargoShuttleConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public CargoShuttleConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { diff --git a/Content.Client/CartridgeLoader/CartridgeLoaderBoundUserInterface.cs b/Content.Client/CartridgeLoader/CartridgeLoaderBoundUserInterface.cs index b7c3b7e22d..3ae61b182e 100644 --- a/Content.Client/CartridgeLoader/CartridgeLoaderBoundUserInterface.cs +++ b/Content.Client/CartridgeLoader/CartridgeLoaderBoundUserInterface.cs @@ -8,15 +8,17 @@ namespace Content.Client.CartridgeLoader; public abstract class CartridgeLoaderBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager? _entityManager = default!; - + [ViewVariables] private EntityUid? _activeProgram; + + [ViewVariables] private UIFragment? _activeCartridgeUI; + + [ViewVariables] private Control? _activeUiFragment; - protected CartridgeLoaderBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + protected CartridgeLoaderBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); } protected override void UpdateState(BoundUserInterfaceState state) @@ -119,7 +121,7 @@ public abstract class CartridgeLoaderBoundUserInterface : BoundUserInterface protected CartridgeComponent? RetrieveCartridgeComponent(EntityUid? cartridgeUid) { - return _entityManager?.GetComponentOrNull(cartridgeUid); + return EntMan.GetComponentOrNull(cartridgeUid); } private void SendCartridgeUiReadyEvent(EntityUid cartridgeUid) @@ -130,7 +132,7 @@ public abstract class CartridgeLoaderBoundUserInterface : BoundUserInterface private UIFragment? RetrieveCartridgeUI(EntityUid? cartridgeUid) { - var component = _entityManager?.GetComponentOrNull(cartridgeUid); + var component = EntMan.GetComponentOrNull(cartridgeUid); component?.Ui?.Setup(this, cartridgeUid); return component?.Ui; } diff --git a/Content.Client/Chemistry/UI/ChemMasterBoundUserInterface.cs b/Content.Client/Chemistry/UI/ChemMasterBoundUserInterface.cs index 0577aa1fcb..988fea7978 100644 --- a/Content.Client/Chemistry/UI/ChemMasterBoundUserInterface.cs +++ b/Content.Client/Chemistry/UI/ChemMasterBoundUserInterface.cs @@ -1,5 +1,4 @@ using Content.Shared.Chemistry; -using Content.Shared.Chemistry.Dispenser; using Content.Shared.Containers.ItemSlots; using JetBrains.Annotations; using Robust.Client.GameObjects; @@ -12,12 +11,11 @@ namespace Content.Client.Chemistry.UI [UsedImplicitly] public sealed class ChemMasterBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; + [ViewVariables] private ChemMasterWindow? _window; - public ChemMasterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ChemMasterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } /// @@ -31,7 +29,7 @@ namespace Content.Client.Chemistry.UI // Setup window layout/elements _window = new ChemMasterWindow { - Title = _entityManager.GetComponent(Owner.Owner).EntityName, + Title = EntMan.GetComponent(Owner).EntityName, }; _window.OpenCentered(); @@ -48,9 +46,10 @@ namespace Content.Client.Chemistry.UI new ChemMasterSetModeMessage(ChemMasterMode.Discard)); _window.CreatePillButton.OnPressed += _ => SendMessage( new ChemMasterCreatePillsMessage( - (uint)_window.PillDosage.Value, (uint)_window.PillNumber.Value, _window.LabelLine)); + (uint) _window.PillDosage.Value, (uint) _window.PillNumber.Value, _window.LabelLine)); _window.CreateBottleButton.OnPressed += _ => SendMessage( - new ChemMasterOutputToBottleMessage((uint)_window.BottleDosage.Value, _window.LabelLine)); + new ChemMasterOutputToBottleMessage( + (uint) _window.BottleDosage.Value, _window.LabelLine)); for (uint i = 0; i < _window.PillTypeButtons.Length; i++) { diff --git a/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs b/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs index c5417caf40..c94759a6c1 100644 --- a/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs +++ b/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs @@ -11,11 +11,13 @@ namespace Content.Client.Chemistry.UI [UsedImplicitly] public sealed class ReagentDispenserBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; + [ViewVariables] private ReagentDispenserWindow? _window; + + [ViewVariables] private ReagentDispenserBoundUserInterfaceState? _lastState; - public ReagentDispenserBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ReagentDispenserBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -31,7 +33,7 @@ namespace Content.Client.Chemistry.UI // Setup window layout/elements _window = new() { - Title = _entityManager.GetComponent(Owner.Owner).EntityName, + Title = EntMan.GetComponent(Owner).EntityName, }; _window.OpenCentered(); @@ -52,11 +54,13 @@ namespace Content.Client.Chemistry.UI // Setup reagent button actions. _window.OnDispenseReagentButtonPressed += (args, button) => SendMessage(new ReagentDispenserDispenseReagentMessage(button.ReagentId)); - _window.OnDispenseReagentButtonMouseEntered += (args, button) => { + _window.OnDispenseReagentButtonMouseEntered += (args, button) => + { if (_lastState is not null) _window.UpdateContainerInfo(_lastState, button.ReagentId); }; - _window.OnDispenseReagentButtonMouseExited += (args, button) => { + _window.OnDispenseReagentButtonMouseExited += (args, button) => + { if (_lastState is not null) _window.UpdateContainerInfo(_lastState); }; @@ -73,7 +77,7 @@ namespace Content.Client.Chemistry.UI { base.UpdateState(state); - var castState = (ReagentDispenserBoundUserInterfaceState)state; + var castState = (ReagentDispenserBoundUserInterfaceState) state; _lastState = castState; _window?.UpdateState(castState); //Update window state diff --git a/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs b/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs index cca7310efd..35df131312 100644 --- a/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs +++ b/Content.Client/Chemistry/UI/TransferAmountBoundUserInterface.cs @@ -8,8 +8,13 @@ namespace Content.Client.Chemistry.UI [UsedImplicitly] public sealed class TransferAmountBoundUserInterface : BoundUserInterface { + [ViewVariables] private TransferAmountWindow? _window; + public TransferAmountBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } + protected override void Open() { base.Open(); @@ -27,10 +32,6 @@ namespace Content.Client.Chemistry.UI _window.OpenCentered(); } - public TransferAmountBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) - { - } - protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs b/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs index 51ee9d7b4e..26f0994701 100644 --- a/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs +++ b/Content.Client/CloningConsole/UI/CloningConsoleBoundUserInterface.cs @@ -7,9 +7,10 @@ namespace Content.Client.CloningConsole.UI [UsedImplicitly] public sealed class CloningConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private CloningConsoleWindow? _window; - public CloningConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public CloningConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Clothing/UI/ChameleonBoundUserInterface.cs b/Content.Client/Clothing/UI/ChameleonBoundUserInterface.cs index 7ea6c6b90f..5b0d5fcf21 100644 --- a/Content.Client/Clothing/UI/ChameleonBoundUserInterface.cs +++ b/Content.Client/Clothing/UI/ChameleonBoundUserInterface.cs @@ -8,15 +8,14 @@ namespace Content.Client.Clothing.UI; [UsedImplicitly] public sealed class ChameleonBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; private readonly ChameleonClothingSystem _chameleon; + [ViewVariables] private ChameleonMenu? _menu; - public ChameleonBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ChameleonBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); - _chameleon = _entityManager.System(); + _chameleon = EntMan.System(); } protected override void Open() diff --git a/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs b/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs index 7428594be8..dc7448aab1 100644 --- a/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs +++ b/Content.Client/Communications/UI/CommunicationsConsoleBoundUserInterface.cs @@ -8,23 +8,31 @@ namespace Content.Client.Communications.UI { [Dependency] private readonly IGameTiming _gameTiming = default!; - [ViewVariables] private CommunicationsConsoleMenu? _menu; + [ViewVariables] + private CommunicationsConsoleMenu? _menu; + [ViewVariables] public bool CanAnnounce { get; private set; } + + [ViewVariables] public bool CanCall { get; private set; } + [ViewVariables] public bool CountdownStarted { get; private set; } + [ViewVariables] public bool AlertLevelSelectable { get; private set; } + [ViewVariables] public string CurrentLevel { get; private set; } = default!; - public int Countdown => _expectedCountdownTime == null ? 0 : Math.Max((int)_expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0); + [ViewVariables] private TimeSpan? _expectedCountdownTime; - public CommunicationsConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) - { + public int Countdown => _expectedCountdownTime == null ? 0 : Math.Max((int) _expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0); + public CommunicationsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { } protected override void Open() diff --git a/Content.Client/Computer/ComputerBoundUserInterface.cs b/Content.Client/Computer/ComputerBoundUserInterface.cs index 1a65c168c9..58820245ae 100644 --- a/Content.Client/Computer/ComputerBoundUserInterface.cs +++ b/Content.Client/Computer/ComputerBoundUserInterface.cs @@ -1,7 +1,5 @@ using Robust.Client.GameObjects; using Robust.Client.UserInterface.CustomControls; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; namespace Content.Client.Computer { @@ -13,6 +11,8 @@ namespace Content.Client.Computer public class ComputerBoundUserInterface : ComputerBoundUserInterfaceBase where TWindow : BaseWindow, IComputerWindow, new() where TState : BoundUserInterfaceState { [Dependency] private readonly IDynamicTypeFactory _dynamicTypeFactory = default!; + + [ViewVariables] private TWindow? _window; protected override void Open() @@ -26,7 +26,9 @@ namespace Content.Client.Computer } // Alas, this constructor has to be copied to the subclass. :( - public ComputerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public ComputerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void UpdateState(BoundUserInterfaceState state) { @@ -58,7 +60,9 @@ namespace Content.Client.Computer [Virtual] public class ComputerBoundUserInterfaceBase : BoundUserInterface { - public ComputerBoundUserInterfaceBase(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public ComputerBoundUserInterfaceBase(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } public new void SendMessage(BoundUserInterfaceMessage msg) { @@ -68,8 +72,13 @@ namespace Content.Client.Computer public interface IComputerWindow { - void SetupComputerWindow(ComputerBoundUserInterfaceBase cb) {} - void UpdateState(TState state) {} + void SetupComputerWindow(ComputerBoundUserInterfaceBase cb) + { + } + + void UpdateState(TState state) + { + } } } diff --git a/Content.Client/Configurable/UI/ConfigurationBoundUserInterface.cs b/Content.Client/Configurable/UI/ConfigurationBoundUserInterface.cs index f114f0cc11..4fea44f225 100644 --- a/Content.Client/Configurable/UI/ConfigurationBoundUserInterface.cs +++ b/Content.Client/Configurable/UI/ConfigurationBoundUserInterface.cs @@ -1,21 +1,21 @@ -using System.Collections.Generic; -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; using static Content.Shared.Configurable.ConfigurationComponent; namespace Content.Client.Configurable.UI { public sealed class ConfigurationBoundUserInterface : BoundUserInterface { + [ViewVariables] + private ConfigurationMenu? _menu; + + [ViewVariables] public Regex? Validation { get; internal set; } - public ConfigurationBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } - private ConfigurationMenu? _menu; - protected override void Open() { base.Open(); diff --git a/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs b/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs index b6634ca813..3bb3b5eeaf 100644 --- a/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs +++ b/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs @@ -2,20 +2,19 @@ using Content.Shared.Crayon; using Content.Shared.Decals; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Prototypes; namespace Content.Client.Crayon.UI { public sealed class CrayonBoundUserInterface : BoundUserInterface { - public CrayonBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private CrayonWindow? _menu; + + public CrayonBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } - private CrayonWindow? _menu; - protected override void Open() { base.Open(); diff --git a/Content.Client/Disposal/UI/DisposalRouterBoundUserInterface.cs b/Content.Client/Disposal/UI/DisposalRouterBoundUserInterface.cs index f883fe42d1..e8e77217ea 100644 --- a/Content.Client/Disposal/UI/DisposalRouterBoundUserInterface.cs +++ b/Content.Client/Disposal/UI/DisposalRouterBoundUserInterface.cs @@ -1,6 +1,5 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent; namespace Content.Client.Disposal.UI @@ -11,9 +10,10 @@ namespace Content.Client.Disposal.UI [UsedImplicitly] public sealed class DisposalRouterBoundUserInterface : BoundUserInterface { + [ViewVariables] private DisposalRouterWindow? _window; - public DisposalRouterBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public DisposalRouterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Disposal/UI/DisposalTaggerBoundUserInterface.cs b/Content.Client/Disposal/UI/DisposalTaggerBoundUserInterface.cs index 6c2da1e4ff..3aeed8dc80 100644 --- a/Content.Client/Disposal/UI/DisposalTaggerBoundUserInterface.cs +++ b/Content.Client/Disposal/UI/DisposalTaggerBoundUserInterface.cs @@ -1,6 +1,5 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent; namespace Content.Client.Disposal.UI @@ -11,9 +10,10 @@ namespace Content.Client.Disposal.UI [UsedImplicitly] public sealed class DisposalTaggerBoundUserInterface : BoundUserInterface { + [ViewVariables] private DisposalTaggerWindow? _window; - public DisposalTaggerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public DisposalTaggerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Disposal/UI/DisposalUnitBoundUserInterface.cs b/Content.Client/Disposal/UI/DisposalUnitBoundUserInterface.cs index a01515035e..d2bec6e94f 100644 --- a/Content.Client/Disposal/UI/DisposalUnitBoundUserInterface.cs +++ b/Content.Client/Disposal/UI/DisposalUnitBoundUserInterface.cs @@ -14,16 +14,15 @@ namespace Content.Client.Disposal.UI [UsedImplicitly] public sealed class DisposalUnitBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; - // What are you doing here + [ViewVariables] public MailingUnitWindow? MailingUnitWindow; + [ViewVariables] public DisposalUnitWindow? DisposalUnitWindow; - public DisposalUnitBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public DisposalUnitBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); } private void ButtonPressed(UiButton button) @@ -56,7 +55,7 @@ namespace Content.Client.Disposal.UI MailingUnitWindow.TargetListContainer.OnItemSelected += TargetSelected; } - else if(UiKey is DisposalUnitUiKey) + else if (UiKey is DisposalUnitUiKey) { DisposalUnitWindow = new DisposalUnitWindow(); diff --git a/Content.Client/Fax/UI/FaxBoundUi.cs b/Content.Client/Fax/UI/FaxBoundUi.cs index 19a48a3a34..ab6f170639 100644 --- a/Content.Client/Fax/UI/FaxBoundUi.cs +++ b/Content.Client/Fax/UI/FaxBoundUi.cs @@ -7,9 +7,10 @@ namespace Content.Client.Fax.UI; [UsedImplicitly] public sealed class FaxBoundUi : BoundUserInterface { + [ViewVariables] private FaxWindow? _window; - public FaxBoundUi(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public FaxBoundUi(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Forensics/ForensicScannerBoundUserInterface.cs b/Content.Client/Forensics/ForensicScannerBoundUserInterface.cs index 88dc06c2af..ba49f11ea0 100644 --- a/Content.Client/Forensics/ForensicScannerBoundUserInterface.cs +++ b/Content.Client/Forensics/ForensicScannerBoundUserInterface.cs @@ -8,11 +8,13 @@ namespace Content.Client.Forensics { [Dependency] private readonly IGameTiming _gameTiming = default!; + [ViewVariables] private ForensicScannerMenu? _window; + [ViewVariables] private TimeSpan _printCooldown; - public ForensicScannerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ForensicScannerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs b/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs index cac4e31b62..d72da3e812 100644 --- a/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs +++ b/Content.Client/Gravity/UI/GravityGeneratorBoundUserInterface.cs @@ -1,16 +1,16 @@ using Content.Shared.Gravity; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Gravity.UI { [UsedImplicitly] public sealed class GravityGeneratorBoundUserInterface : BoundUserInterface { + [ViewVariables] private GravityGeneratorWindow? _window; - public GravityGeneratorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base (owner, uiKey) + public GravityGeneratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -18,7 +18,7 @@ namespace Content.Client.Gravity.UI { base.Open(); - _window = new GravityGeneratorWindow(this, Owner); + _window = new GravityGeneratorWindow(this); /* _window.Switch.OnPressed += _ => diff --git a/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs b/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs index 99b41954a1..75f8eb479b 100644 --- a/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs +++ b/Content.Client/Gravity/UI/GravityGeneratorWindow.xaml.cs @@ -14,12 +14,12 @@ namespace Content.Client.Gravity.UI private readonly GravityGeneratorBoundUserInterface _owner; - public GravityGeneratorWindow(GravityGeneratorBoundUserInterface ui, ClientUserInterfaceComponent component) + public GravityGeneratorWindow(GravityGeneratorBoundUserInterface owner) { RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); - _owner = ui; + _owner = owner; OnButton.Group = _buttonGroup; OffButton.Group = _buttonGroup; @@ -27,7 +27,7 @@ namespace Content.Client.Gravity.UI OnButton.OnPressed += _ => _owner.SetPowerSwitch(true); OffButton.OnPressed += _ => _owner.SetPowerSwitch(false); - EntityView.Sprite = IoCManager.Resolve().GetComponent(component.Owner); + EntityView.SetEntity(owner.Owner); } public void UpdateState(SharedGravityGeneratorComponent.GeneratorState state) diff --git a/Content.Client/HealthAnalyzer/UI/HealthAnalyzerBoundUserInterface.cs b/Content.Client/HealthAnalyzer/UI/HealthAnalyzerBoundUserInterface.cs index 052726de3a..dc0a3e9fcc 100644 --- a/Content.Client/HealthAnalyzer/UI/HealthAnalyzerBoundUserInterface.cs +++ b/Content.Client/HealthAnalyzer/UI/HealthAnalyzerBoundUserInterface.cs @@ -7,9 +7,10 @@ namespace Content.Client.HealthAnalyzer.UI [UsedImplicitly] public sealed class HealthAnalyzerBoundUserInterface : BoundUserInterface { + [ViewVariables] private HealthAnalyzerWindow? _window; - public HealthAnalyzerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public HealthAnalyzerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -18,7 +19,7 @@ namespace Content.Client.HealthAnalyzer.UI base.Open(); _window = new HealthAnalyzerWindow { - Title = IoCManager.Resolve().GetComponent(Owner.Owner).EntityName, + Title = EntMan.GetComponent(Owner).EntityName, }; _window.OnClose += Close; _window.OpenCentered(); diff --git a/Content.Client/Humanoid/HumanoidMarkingModifierBoundUserInterface.cs b/Content.Client/Humanoid/HumanoidMarkingModifierBoundUserInterface.cs index c493b46a38..286965f8b2 100644 --- a/Content.Client/Humanoid/HumanoidMarkingModifierBoundUserInterface.cs +++ b/Content.Client/Humanoid/HumanoidMarkingModifierBoundUserInterface.cs @@ -11,12 +11,13 @@ namespace Content.Client.Humanoid; public sealed class HumanoidMarkingModifierBoundUserInterface : BoundUserInterface { - public HumanoidMarkingModifierBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private HumanoidMarkingModifierWindow? _window; + + public HumanoidMarkingModifierBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } - private HumanoidMarkingModifierWindow? _window; - protected override void Open() { base.Open(); diff --git a/Content.Client/Instruments/UI/InstrumentBoundUserInterface.cs b/Content.Client/Instruments/UI/InstrumentBoundUserInterface.cs index 2279e3e09d..630345418e 100644 --- a/Content.Client/Instruments/UI/InstrumentBoundUserInterface.cs +++ b/Content.Client/Instruments/UI/InstrumentBoundUserInterface.cs @@ -1,7 +1,4 @@ using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.ViewVariables; namespace Content.Client.Instruments.UI { @@ -10,15 +7,16 @@ namespace Content.Client.Instruments.UI [ViewVariables] private InstrumentMenu? _instrumentMenu; + [ViewVariables] public InstrumentComponent? Instrument { get; set; } - public InstrumentBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public InstrumentBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } protected override void Open() { - if (!IoCManager.Resolve().TryGetComponent(Owner.Owner, out var instrument)) return; + if (!EntMan.TryGetComponent(Owner, out var instrument)) return; Instrument = instrument; _instrumentMenu = new InstrumentMenu(this); diff --git a/Content.Client/Inventory/StrippableBoundUserInterface.cs b/Content.Client/Inventory/StrippableBoundUserInterface.cs index 8e8d7b1875..6dbb8f3c22 100644 --- a/Content.Client/Inventory/StrippableBoundUserInterface.cs +++ b/Content.Client/Inventory/StrippableBoundUserInterface.cs @@ -29,31 +29,34 @@ namespace Content.Client.Inventory [UsedImplicitly] public sealed class StrippableBoundUserInterface : BoundUserInterface { - private const int ButtonSeparation = 4; - [Dependency] private readonly IPrototypeManager _protoMan = default!; - [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IUserInterfaceManager _ui = default!; - private ExamineSystem _examine = default!; - private InventorySystem _inv = default!; + private readonly ExamineSystem _examine = default!; + private readonly InventorySystem _inv = default!; private readonly SharedCuffableSystem _cuffable; [ViewVariables] - private StrippingMenu? _strippingMenu; + private const int ButtonSeparation = 4; + [ViewVariables] public const string HiddenPocketEntityId = "StrippingHiddenEntity"; - private EntityUid _virtualHiddenEntity; - public StrippableBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private readonly StrippingMenu? _strippingMenu; + + [ViewVariables] + private readonly EntityUid _virtualHiddenEntity; + + public StrippableBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); - _examine = _entMan.EntitySysManager.GetEntitySystem(); - _inv = _entMan.EntitySysManager.GetEntitySystem(); - _cuffable = _entMan.System(); - var title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner.Owner, _entMan))); + _examine = EntMan.System(); + _inv = EntMan.System(); + _cuffable = EntMan.System(); + + var title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner, EntMan))); _strippingMenu = new StrippingMenu(title, this); _strippingMenu.OnClose += Close; - _virtualHiddenEntity = _entMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace); + _virtualHiddenEntity = EntMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace); } protected override void Open() @@ -66,7 +69,7 @@ namespace Content.Client.Inventory { base.Dispose(disposing); - _entMan.DeleteEntity(_virtualHiddenEntity); + EntMan.DeleteEntity(_virtualHiddenEntity); if (!disposing) return; @@ -87,15 +90,15 @@ namespace Content.Client.Inventory _strippingMenu.ClearButtons(); - if (_entMan.TryGetComponent(Owner.Owner, out InventoryComponent? inv) && _protoMan.TryIndex(inv.TemplateId, out var template)) + if (EntMan.TryGetComponent(Owner, out var inv) && _protoMan.TryIndex(inv.TemplateId, out var template)) { foreach (var slot in template.Slots) { - AddInventoryButton(slot.Name, template, inv); + AddInventoryButton(Owner, slot.Name, template, inv); } } - if (_entMan.TryGetComponent(Owner.Owner, out HandsComponent? handsComp)) + if (EntMan.TryGetComponent(Owner, out var handsComp)) { // good ol hands shit code. there is a GuiHands comparer that does the same thing... but these are hands // and not gui hands... which are different... @@ -125,7 +128,7 @@ namespace Content.Client.Inventory } // snare-removal button. This is just the old button before the change to item slots. It is pretty out of place. - if (_entMan.TryGetComponent(Owner.Owner, out EnsnareableComponent? snare) && snare.IsEnsnared) + if (EntMan.TryGetComponent(Owner, out var snare) && snare.IsEnsnared) { var button = new Button() { @@ -156,10 +159,10 @@ namespace Content.Client.Inventory button.Pressed += SlotPressed; - if (_entMan.TryGetComponent(hand.HeldEntity, out HandVirtualItemComponent? virt)) + if (EntMan.TryGetComponent(hand.HeldEntity, out var virt)) { button.Blocked = true; - if (_entMan.TryGetComponent(Owner.Owner, out CuffableComponent? cuff) && _cuffable.GetAllCuffs(cuff).Contains(virt.BlockingEntity)) + if (EntMan.TryGetComponent(Owner, out var cuff) && _cuffable.GetAllCuffs(cuff).Contains(virt.BlockingEntity)) button.BlockedRect.MouseFilter = MouseFilterMode.Ignore; } @@ -187,9 +190,9 @@ namespace Content.Client.Inventory _ui.GetUIController().OpenVerbMenu(slot.Entity.Value); } - private void AddInventoryButton(string slotId, InventoryTemplatePrototype template, InventoryComponent inv) + private void AddInventoryButton(EntityUid invUid, string slotId, InventoryTemplatePrototype _, InventoryComponent inv) { - if (!_inv.TryGetSlotContainer(inv.Owner, slotId, out var container, out var slotDef, inv)) + if (!_inv.TryGetSlotContainer(invUid, slotId, out var container, out var slotDef, inv)) return; var entity = container.ContainedEntity; @@ -216,17 +219,19 @@ namespace Content.Client.Inventory if (entity == null) { - button.SpriteView.Sprite = null; + button.SpriteView.SetEntity(null); return; } - SpriteComponent? sprite; - if (_entMan.TryGetComponent(entity, out HandVirtualItemComponent? virt)) - _entMan.TryGetComponent(virt.BlockingEntity, out sprite); - else if (!_entMan.TryGetComponent(entity, out sprite)) + EntityUid? viewEnt; + if (EntMan.TryGetComponent(entity, out var virt)) + viewEnt = EntMan.HasComponent(virt.BlockingEntity) ? virt.BlockingEntity : null; + else if (EntMan.HasComponent(entity)) + viewEnt = entity; + else return; - button.SpriteView.Sprite = sprite; + button.SpriteView.SetEntity(viewEnt); } } } diff --git a/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs b/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs index dcfdf2cec3..87f77e24f7 100644 --- a/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs +++ b/Content.Client/Kitchen/UI/MicrowaveBoundUserInterface.cs @@ -1,29 +1,25 @@ -using System.Collections.Generic; using Content.Shared.Chemistry.Components; -using Content.Shared.Chemistry.Reagent; using Content.Shared.Kitchen.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.UserInterface.Controls; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Prototypes; namespace Content.Client.Kitchen.UI { [UsedImplicitly] public sealed class MicrowaveBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; - + [ViewVariables] private MicrowaveMenu? _menu; + [ViewVariables] private readonly Dictionary _solids = new(); - private readonly Dictionary _reagents =new(); - public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner,uiKey) + [ViewVariables] + private readonly Dictionary _reagents = new(); + + public MicrowaveBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -40,10 +36,10 @@ namespace Content.Client.Kitchen.UI SendMessage(new MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex])); }; - _menu.OnCookTimeSelected += (args,buttonIndex) => + _menu.OnCookTimeSelected += (args, buttonIndex) => { - var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button ; - SendMessage(new MicrowaveSelectCookTimeMessage(buttonIndex,actualButton.CookTime)); + var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button; + SendMessage(new MicrowaveSelectCookTimeMessage(buttonIndex, actualButton.CookTime)); }; } @@ -93,7 +89,7 @@ namespace Content.Client.Kitchen.UI _menu.IngredientsList.Clear(); foreach (var entity in containedSolids) { - if (_entityManager.Deleted(entity)) + if (EntMan.Deleted(entity)) { return; } @@ -101,11 +97,11 @@ namespace Content.Client.Kitchen.UI // TODO just use sprite view Texture? texture; - if (_entityManager.TryGetComponent(entity, out IconComponent? iconComponent)) + if (EntMan.TryGetComponent(entity, out var iconComponent)) { - texture = _entityManager.System().GetIcon(iconComponent); + texture = EntMan.System().GetIcon(iconComponent); } - else if (_entityManager.TryGetComponent(entity, out SpriteComponent? spriteComponent)) + else if (EntMan.TryGetComponent(entity, out var spriteComponent)) { texture = spriteComponent.Icon?.Default; } @@ -114,7 +110,7 @@ namespace Content.Client.Kitchen.UI continue; } - var solidItem = _menu.IngredientsList.AddItem(_entityManager.GetComponent(entity).EntityName, texture); + var solidItem = _menu.IngredientsList.AddItem(EntMan.GetComponent(entity).EntityName, texture); var solidIndex = _menu.IngredientsList.IndexOf(solidItem); _solids.Add(solidIndex, entity); } diff --git a/Content.Client/Kitchen/UI/ReagentGrinderBoundUserInterface.cs b/Content.Client/Kitchen/UI/ReagentGrinderBoundUserInterface.cs index e05c871146..c8c978d313 100644 --- a/Content.Client/Kitchen/UI/ReagentGrinderBoundUserInterface.cs +++ b/Content.Client/Kitchen/UI/ReagentGrinderBoundUserInterface.cs @@ -8,18 +8,20 @@ namespace Content.Client.Kitchen.UI { public sealed class ReagentGrinderBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [ViewVariables] private GrinderMenu? _menu; - public ReagentGrinderBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) { } + public ReagentGrinderBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { base.Open(); - _menu = new GrinderMenu(this, _entityManager, _prototypeManager); + _menu = new GrinderMenu(this, EntMan, _prototypeManager); _menu.OpenCentered(); _menu.OnClose += Close; } @@ -38,10 +40,8 @@ namespace Content.Client.Kitchen.UI protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - if (!(state is ReagentGrinderInterfaceState cState)) - { + if (state is not ReagentGrinderInterfaceState cState) return; - } _menu?.UpdateState(cState); } @@ -52,10 +52,29 @@ namespace Content.Client.Kitchen.UI _menu?.HandleMessage(message); } - public void StartGrinding(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind)); - public void StartJuicing(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice)); - public void EjectAll(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ReagentGrinderEjectChamberAllMessage()); - public void EjectBeaker(BaseButton.ButtonEventArgs? args = null) => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId)); - public void EjectChamberContent(EntityUid uid) => SendMessage(new ReagentGrinderEjectChamberContentMessage(uid)); + public void StartGrinding(BaseButton.ButtonEventArgs? _ = null) + { + SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind)); + } + + public void StartJuicing(BaseButton.ButtonEventArgs? _ = null) + { + SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice)); + } + + public void EjectAll(BaseButton.ButtonEventArgs? _ = null) + { + SendMessage(new ReagentGrinderEjectChamberAllMessage()); + } + + public void EjectBeaker(BaseButton.ButtonEventArgs? _ = null) + { + SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId)); + } + + public void EjectChamberContent(EntityUid uid) + { + SendMessage(new ReagentGrinderEjectChamberContentMessage(uid)); + } } } diff --git a/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs b/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs index 352e90958b..d393c43f93 100644 --- a/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs +++ b/Content.Client/Labels/UI/HandLabelerBoundUserInterface.cs @@ -1,6 +1,5 @@ using Content.Shared.Labels; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Labels.UI { @@ -9,9 +8,10 @@ namespace Content.Client.Labels.UI /// public sealed class HandLabelerBoundUserInterface : BoundUserInterface { + [ViewVariables] private HandLabelerWindow? _window; - public HandLabelerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public HandLabelerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs index 03159b5859..35094cecab 100644 --- a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs +++ b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs @@ -8,14 +8,14 @@ namespace Content.Client.Lathe.UI [UsedImplicitly] public sealed class LatheBoundUserInterface : BoundUserInterface { - [ViewVariables] private LatheMenu? _menu; - [ViewVariables] private LatheQueueMenu? _queueMenu; + [ViewVariables] + private LatheMenu? _menu; - public EntityUid Lathe; + [ViewVariables] + private LatheQueueMenu? _queueMenu; - public LatheBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public LatheBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - Lathe = owner.Owner; } protected override void Open() @@ -55,8 +55,8 @@ namespace Content.Client.Lathe.UI case LatheUpdateState msg: if (_menu != null) _menu.Recipes = msg.Recipes; - _menu?.PopulateRecipes(Lathe); - _menu?.PopulateMaterials(Lathe); + _menu?.PopulateRecipes(Owner); + _menu?.PopulateMaterials(Owner); _queueMenu?.PopulateList(msg.Queue); _queueMenu?.SetInfo(msg.CurrentlyProducing); break; diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs index 7247db647b..8162ec64ae 100644 --- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs +++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs @@ -16,8 +16,8 @@ namespace Content.Client.Lathe.UI; [GenerateTypedNameReferences] public sealed partial class LatheMenu : DefaultWindow { - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; private readonly SpriteSystem _spriteSystem; private readonly LatheSystem _lathe; @@ -32,24 +32,24 @@ public sealed partial class LatheMenu : DefaultWindow RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); - _spriteSystem = _entityManager.EntitySysManager.GetEntitySystem(); - _lathe = _entityManager.EntitySysManager.GetEntitySystem(); + _spriteSystem = _entityManager.System(); + _lathe = _entityManager.System(); - Title = _entityManager.GetComponent(owner.Lathe).EntityName; + Title = _entityManager.GetComponent(owner.Owner).EntityName; SearchBar.OnTextChanged += _ => { - PopulateRecipes(owner.Lathe); + PopulateRecipes(owner.Owner); }; AmountLineEdit.OnTextChanged += _ => { - PopulateRecipes(owner.Lathe); + PopulateRecipes(owner.Owner); }; QueueButton.OnPressed += a => OnQueueButtonPressed?.Invoke(a); ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a); - if (_entityManager.TryGetComponent(owner.Lathe, out var latheComponent)) + if (_entityManager.TryGetComponent(owner.Owner, out var latheComponent)) { if (!latheComponent.DynamicRecipes.Any()) { diff --git a/Content.Client/MachineLinking/UI/SignalPortSelectorBoundUserInterface.cs b/Content.Client/MachineLinking/UI/SignalPortSelectorBoundUserInterface.cs index 82ce7d1081..9e56a30afe 100644 --- a/Content.Client/MachineLinking/UI/SignalPortSelectorBoundUserInterface.cs +++ b/Content.Client/MachineLinking/UI/SignalPortSelectorBoundUserInterface.cs @@ -1,18 +1,23 @@ using Content.Shared.MachineLinking; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.MachineLinking.UI { public sealed class SignalPortSelectorBoundUserInterface : BoundUserInterface { + [ViewVariables] private SignalPortSelectorMenu? _menu; + [ViewVariables] private string? _selectedTransmitterPort; + + [ViewVariables] private string? _selectedReceiverPort; - public SignalPortSelectorBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] Enum uiKey) : base(owner, uiKey) { } + public SignalPortSelectorBoundUserInterface([NotNull] EntityUid owner, [NotNull] Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { diff --git a/Content.Client/MachineLinking/UI/SignalTimerBoundUserInterface.cs b/Content.Client/MachineLinking/UI/SignalTimerBoundUserInterface.cs index e9cfba697f..09bdedfd94 100644 --- a/Content.Client/MachineLinking/UI/SignalTimerBoundUserInterface.cs +++ b/Content.Client/MachineLinking/UI/SignalTimerBoundUserInterface.cs @@ -8,9 +8,10 @@ public sealed class SignalTimerBoundUserInterface : BoundUserInterface { [Dependency] private readonly IGameTiming _gameTiming = default!; + [ViewVariables] private SignalTimerWindow? _window; - public SignalTimerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public SignalTimerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs b/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs index 94313877cd..ba4362a472 100644 --- a/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs +++ b/Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs @@ -6,9 +6,10 @@ namespace Content.Client.MagicMirror; public sealed class MagicMirrorBoundUserInterface : BoundUserInterface { + [ViewVariables] private MagicMirrorWindow? _window; - public MagicMirrorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public MagicMirrorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -20,13 +21,13 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface _window.OnHairSelected += tuple => SelectHair(MagicMirrorCategory.Hair, tuple.id, tuple.slot); _window.OnHairColorChanged += args => ChangeColor(MagicMirrorCategory.Hair, args.marking, args.slot); - _window.OnHairSlotAdded += delegate() { AddSlot(MagicMirrorCategory.Hair); }; + _window.OnHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.Hair); }; _window.OnHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.Hair, args); _window.OnFacialHairSelected += tuple => SelectHair(MagicMirrorCategory.FacialHair, tuple.id, tuple.slot); _window.OnFacialHairColorChanged += args => ChangeColor(MagicMirrorCategory.FacialHair, args.marking, args.slot); - _window.OnFacialHairSlotAdded += delegate() { AddSlot(MagicMirrorCategory.FacialHair); }; + _window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); }; _window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args); _window.OpenCentered(); diff --git a/Content.Client/Mech/Ui/MechBoundUserInterface.cs b/Content.Client/Mech/Ui/MechBoundUserInterface.cs index 0fae4e993c..62b4fdf250 100644 --- a/Content.Client/Mech/Ui/MechBoundUserInterface.cs +++ b/Content.Client/Mech/Ui/MechBoundUserInterface.cs @@ -9,23 +9,18 @@ namespace Content.Client.Mech.Ui; [UsedImplicitly] public sealed class MechBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _ent = default!; - - private readonly EntityUid _mech; - + [ViewVariables] private MechMenu? _menu; - public MechBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public MechBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); - _mech = owner.Owner; } protected override void Open() { base.Open(); - _menu = new(_mech); + _menu = new(Owner); _menu.OnClose += Close; _menu.OpenCenteredLeft(); @@ -49,7 +44,7 @@ public sealed class MechBoundUserInterface : BoundUserInterface public void UpdateEquipmentControls(MechBoundUiState state) { - if (!_ent.TryGetComponent(_mech, out var mechComp)) + if (!EntMan.TryGetComponent(Owner, out var mechComp)) return; foreach (var ent in mechComp.EquipmentContainer.ContainedEntities) @@ -77,7 +72,7 @@ public sealed class MechBoundUserInterface : BoundUserInterface public UIFragment? GetEquipmentUi(EntityUid? uid) { - var component = _ent.GetComponentOrNull(uid); + var component = EntMan.GetComponentOrNull(uid); component?.Ui?.Setup(this, uid); return component?.Ui; } diff --git a/Content.Client/Medical/CrewMonitoring/CrewMonitoringBoundUserInterface.cs b/Content.Client/Medical/CrewMonitoring/CrewMonitoringBoundUserInterface.cs index c1093472b9..fc632575c7 100644 --- a/Content.Client/Medical/CrewMonitoring/CrewMonitoringBoundUserInterface.cs +++ b/Content.Client/Medical/CrewMonitoring/CrewMonitoringBoundUserInterface.cs @@ -1,25 +1,22 @@ using Content.Shared.Medical.CrewMonitoring; -using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Medical.CrewMonitoring { public sealed class CrewMonitoringBoundUserInterface : BoundUserInterface { - private readonly IEntityManager _entManager; + [ViewVariables] private CrewMonitoringWindow? _menu; - public CrewMonitoringBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public CrewMonitoringBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - _entManager = IoCManager.Resolve(); } protected override void Open() { EntityUid? gridUid = null; - if (_entManager.TryGetComponent(Owner.Owner, out var xform)) + if (EntMan.TryGetComponent(Owner, out var xform)) { gridUid = xform.GridUid; } @@ -37,7 +34,7 @@ namespace Content.Client.Medical.CrewMonitoring switch (state) { case CrewMonitoringState st: - _entManager.TryGetComponent(Owner.Owner, out var xform); + EntMan.TryGetComponent(Owner, out var xform); _menu?.ShowSensors(st.Sensors, xform?.Coordinates, st.Snap, st.Precision); break; diff --git a/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs b/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs index 7c50c150b2..264c297b63 100644 --- a/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs +++ b/Content.Client/NetworkConfigurator/NetworkConfiguratorBoundUserInterface.cs @@ -7,19 +7,20 @@ namespace Content.Client.NetworkConfigurator; public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; + private readonly NetworkConfiguratorSystem _netConfig; - private NetworkConfiguratorListMenu? _listMenu; + [ViewVariables] private NetworkConfiguratorConfigurationMenu? _configurationMenu; + + [ViewVariables] private NetworkConfiguratorLinkMenu? _linkMenu; - private NetworkConfiguratorSystem _netConfig; + [ViewVariables] + private NetworkConfiguratorListMenu? _listMenu; - public NetworkConfiguratorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public NetworkConfiguratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); - - _netConfig = _entityManager.System(); + _netConfig = EntMan.System(); } public void OnRemoveButtonPressed(string address) @@ -48,7 +49,7 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface _configurationMenu.Clear.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Clear); _configurationMenu.Copy.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Copy); _configurationMenu.Show.OnPressed += OnShowPressed; - _configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner.Owner); + _configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner); _configurationMenu.OpenCentered(); break; case NetworkConfiguratorUiKey.Link: @@ -61,7 +62,7 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface private void OnShowPressed(BaseButton.ButtonEventArgs args) { - _netConfig.ToggleVisualization(Owner.Owner, args.Button.Pressed); + _netConfig.ToggleVisualization(Owner, args.Button.Pressed); } protected override void UpdateState(BoundUserInterfaceState state) diff --git a/Content.Client/Nuke/NukeBoundUserInterface.cs b/Content.Client/Nuke/NukeBoundUserInterface.cs index 33f99ea9b5..59fbc5b319 100644 --- a/Content.Client/Nuke/NukeBoundUserInterface.cs +++ b/Content.Client/Nuke/NukeBoundUserInterface.cs @@ -8,9 +8,10 @@ namespace Content.Client.Nuke [UsedImplicitly] public sealed class NukeBoundUserInterface : BoundUserInterface { + [ViewVariables] private NukeMenu? _menu; - public NukeBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] Enum uiKey) : base(owner, uiKey) + public NukeBoundUserInterface([NotNull] EntityUid owner, [NotNull] Enum uiKey) : base(owner, uiKey) { } @@ -57,10 +58,8 @@ namespace Content.Client.Nuke switch (state) { case NukeUiState msg: - { _menu.UpdateState(msg); break; - } } } diff --git a/Content.Client/PDA/PdaBoundUserInterface.cs b/Content.Client/PDA/PdaBoundUserInterface.cs index 6e569dcf13..bd23d5ea55 100644 --- a/Content.Client/PDA/PdaBoundUserInterface.cs +++ b/Content.Client/PDA/PdaBoundUserInterface.cs @@ -5,7 +5,6 @@ using Content.Shared.Containers.ItemSlots; using Content.Shared.CrewManifest; using Content.Shared.PDA; using JetBrains.Annotations; -using Robust.Client.GameObjects; using Robust.Client.UserInterface; using Robust.Shared.Configuration; @@ -14,14 +13,13 @@ namespace Content.Client.PDA [UsedImplicitly] public sealed class PdaBoundUserInterface : CartridgeLoaderBoundUserInterface { - [Dependency] private readonly IEntityManager? _entityManager = default!; [Dependency] private readonly IConfigurationManager _configManager = default!; + [ViewVariables] private PdaMenu? _menu; - public PdaBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public PdaBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); } protected override void Open() @@ -132,7 +130,7 @@ namespace Content.Client.PDA private PdaBorderColorComponent? GetBorderColorComponent() { - return _entityManager?.GetComponentOrNull(Owner.Owner); + return EntMan.GetComponentOrNull(Owner); } } } diff --git a/Content.Client/PDA/Ringer/RingerBoundUserInterface.cs b/Content.Client/PDA/Ringer/RingerBoundUserInterface.cs index 78231a6cd0..bb8b785287 100644 --- a/Content.Client/PDA/Ringer/RingerBoundUserInterface.cs +++ b/Content.Client/PDA/Ringer/RingerBoundUserInterface.cs @@ -2,14 +2,16 @@ using Content.Shared.PDA; using Content.Shared.PDA.Ringer; using JetBrains.Annotations; using Robust.Client.GameObjects; + namespace Content.Client.PDA.Ringer { [UsedImplicitly] public sealed class RingerBoundUserInterface : BoundUserInterface { + [ViewVariables] private RingtoneMenu? _menu; - public RingerBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public RingerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Paper/UI/PaperBoundUserInterface.cs b/Content.Client/Paper/UI/PaperBoundUserInterface.cs index 8c0338f805..5befadb673 100644 --- a/Content.Client/Paper/UI/PaperBoundUserInterface.cs +++ b/Content.Client/Paper/UI/PaperBoundUserInterface.cs @@ -10,16 +10,16 @@ namespace Content.Client.Paper.UI [UsedImplicitly] public sealed class PaperBoundUserInterface : BoundUserInterface { + [ViewVariables] private PaperWindow? _window; - public PaperBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public PaperBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } protected override void Open() { base.Open(); - var entityMgr = IoCManager.Resolve(); _window = new PaperWindow(); _window.OnClose += Close; @@ -33,7 +33,7 @@ namespace Content.Client.Paper.UI } }; - if (entityMgr.TryGetComponent(Owner.Owner, out var visuals)) + if (EntMan.TryGetComponent(Owner, out var visuals)) { _window.InitVisuals(visuals); } diff --git a/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorBoundUserInterface.cs b/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorBoundUserInterface.cs index 734def3653..cde5ba9ef7 100644 --- a/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorBoundUserInterface.cs +++ b/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorBoundUserInterface.cs @@ -5,9 +5,10 @@ namespace Content.Client.ParticleAccelerator.UI { public sealed class ParticleAcceleratorBoundUserInterface : BoundUserInterface { + [ViewVariables] private ParticleAcceleratorControlMenu? _menu; - public ParticleAcceleratorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ParticleAcceleratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Pinpointer/UI/StationMapBoundUserInterface.cs b/Content.Client/Pinpointer/UI/StationMapBoundUserInterface.cs index e4c6a2a1d5..1483e75e73 100644 --- a/Content.Client/Pinpointer/UI/StationMapBoundUserInterface.cs +++ b/Content.Client/Pinpointer/UI/StationMapBoundUserInterface.cs @@ -1,13 +1,13 @@ using Robust.Client.GameObjects; -using Robust.Client.Player; namespace Content.Client.Pinpointer.UI; public sealed class StationMapBoundUserInterface : BoundUserInterface { + [ViewVariables] private StationMapWindow? _window; - public StationMapBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public StationMapBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -17,12 +17,12 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface _window?.Close(); EntityUid? gridUid = null; - if (IoCManager.Resolve().TryGetComponent(Owner.Owner, out var xform)) + if (EntMan.TryGetComponent(Owner, out var xform)) { gridUid = xform.GridUid; } - _window = new StationMapWindow(gridUid, Owner.Owner); + _window = new StationMapWindow(gridUid, Owner); _window.OpenCentered(); _window.OnClose += Close; } diff --git a/Content.Client/Power/APC/ApcBoundUserInterface.cs b/Content.Client/Power/APC/ApcBoundUserInterface.cs index d85edb8d1a..fbcbf01156 100644 --- a/Content.Client/Power/APC/ApcBoundUserInterface.cs +++ b/Content.Client/Power/APC/ApcBoundUserInterface.cs @@ -2,29 +2,28 @@ using Content.Shared.APC; using JetBrains.Annotations; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; -using Robust.Shared.ViewVariables; namespace Content.Client.Power.APC { [UsedImplicitly] public sealed class ApcBoundUserInterface : BoundUserInterface { - [ViewVariables] private ApcMenu? _menu; + [ViewVariables] + private ApcMenu? _menu; + + public ApcBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { base.Open(); - _menu = new ApcMenu(this,Owner); + _menu = new ApcMenu(this); _menu.OnClose += Close; _menu.OpenCentered(); } - public ApcBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) - { - } - protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); diff --git a/Content.Client/Power/APC/UI/ApcMenu.xaml.cs b/Content.Client/Power/APC/UI/ApcMenu.xaml.cs index 15b3e0b67d..3bddcfd928 100644 --- a/Content.Client/Power/APC/UI/ApcMenu.xaml.cs +++ b/Content.Client/Power/APC/UI/ApcMenu.xaml.cs @@ -18,12 +18,12 @@ namespace Content.Client.Power.APC.UI public sealed partial class ApcMenu : FancyWindow { [Dependency] private readonly IEntityManager _entityManager = default!; - public ApcMenu(ApcBoundUserInterface owner, ClientUserInterfaceComponent component) + public ApcMenu(ApcBoundUserInterface owner) { IoCManager.InjectDependencies(this); RobustXamlLoader.Load(this); - EntityView.Sprite = _entityManager.GetComponent(component.Owner); + EntityView.SetEntity(owner.Owner); BreakerButton.OnPressed += _ => owner.BreakerPressed(); } diff --git a/Content.Client/Power/PowerMonitoringWindow.xaml.cs b/Content.Client/Power/PowerMonitoringWindow.xaml.cs index 9e519b6ec7..6629433598 100644 --- a/Content.Client/Power/PowerMonitoringWindow.xaml.cs +++ b/Content.Client/Power/PowerMonitoringWindow.xaml.cs @@ -1,22 +1,14 @@ -using System; using System.Linq; using System.Numerics; using Content.Client.Computer; -using Content.Client.IoC; using Content.Shared.Power; using JetBrains.Annotations; using Robust.Client.AutoGenerated; using Robust.Client.GameObjects; using Robust.Client.Graphics; -using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Maths; -using Robust.Shared.Timing; using Robust.Shared.Prototypes; namespace Content.Client.Power; @@ -25,12 +17,14 @@ namespace Content.Client.Power; public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWindow { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + private readonly SpriteSystem _spriteSystem = default!; public PowerMonitoringWindow() { RobustXamlLoader.Load(this); SetSize = MinSize = new Vector2(300, 450); IoCManager.InjectDependencies(this); + _spriteSystem = IoCManager.Resolve().System(); MasterTabContainer.SetTabTitle(0, Loc.GetString("power-monitoring-window-tab-sources")); MasterTabContainer.SetTabTitle(1, Loc.GetString("power-monitoring-window-tab-loads")); } @@ -45,7 +39,7 @@ public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWind // This means filtering out loads that are not either: // + Batteries (always important) // + Meaningful (size above 0) - loads = loads.Where(a => a.IsBattery || (a.Size > 0.0f)).ToArray(); + loads = loads.Where(a => a.IsBattery || a.Size > 0.0f).ToArray(); } UpdateList(TotalLoadsNum, scc.TotalLoads, LoadsList, loads); } @@ -69,7 +63,7 @@ public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWind _prototypeManager.TryIndex(ent.IconEntityPrototypeId, out EntityPrototype? entityPrototype); IRsiStateLike? iconState = null; if (entityPrototype != null) - iconState = SpriteComponent.GetPrototypeIcon(entityPrototype, StaticIoC.ResC); + iconState = _spriteSystem.GetPrototypeIcon(entityPrototype); var icon = iconState?.GetFrame(RSI.State.Direction.South, 0); var item = list[i]; item.Text = $"{ent.NameLocalized} {Loc.GetString("power-monitoring-window-value", ("value", ent.Size))}"; @@ -81,6 +75,8 @@ public sealed partial class PowerMonitoringWindow : DefaultWindow, IComputerWind [UsedImplicitly] public sealed class PowerMonitoringConsoleBoundUserInterface : ComputerBoundUserInterface { - public PowerMonitoringConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public PowerMonitoringConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } } diff --git a/Content.Client/Power/SolarControlWindow.xaml.cs b/Content.Client/Power/SolarControlWindow.xaml.cs index 4b5053a6ab..86032cccb1 100644 --- a/Content.Client/Power/SolarControlWindow.xaml.cs +++ b/Content.Client/Power/SolarControlWindow.xaml.cs @@ -4,14 +4,11 @@ using Content.Client.Computer; using Content.Shared.Solar; using JetBrains.Annotations; using Robust.Client.AutoGenerated; -using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; -using Robust.Shared.IoC; -using Robust.Shared.Maths; using Robust.Shared.Timing; namespace Content.Client.Power @@ -19,6 +16,7 @@ namespace Content.Client.Power [GenerateTypedNameReferences] public sealed partial class SolarControlWindow : DefaultWindow, IComputerWindow { + [ViewVariables] private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0); public SolarControlWindow() @@ -28,9 +26,10 @@ namespace Content.Client.Power public void SetupComputerWindow(ComputerBoundUserInterfaceBase cb) { - PanelRotation.OnTextEntered += text => { - double value; - if (!double.TryParse((string?) text.Text, out value)) return; + PanelRotation.OnTextEntered += text => + { + if (!double.TryParse((string?) text.Text, out var value)) + return; SolarControlConsoleAdjustMessage msg = new() { @@ -43,9 +42,11 @@ namespace Content.Client.Power _lastState.Rotation = msg.Rotation; NotARadar.UpdateState(_lastState); }; - PanelVelocity.OnTextEntered += text => { - double value; - if (!double.TryParse((string?) text.Text, out value)) return; + + PanelVelocity.OnTextEntered += text => + { + if (!double.TryParse((string?) text.Text, out var value)) + return; SolarControlConsoleAdjustMessage msg = new() { @@ -61,14 +62,14 @@ namespace Content.Client.Power }; } - private string FormatAngle(Angle d) + private static string FormatAngle(Angle d) { return d.Degrees.ToString("F1"); } // The idea behind this is to prevent every update from the server // breaking the textfield. - private void UpdateField(LineEdit field, string newValue) + private static void UpdateField(LineEdit field, string newValue) { if (!field.HasKeyboardFocus()) { @@ -92,7 +93,7 @@ namespace Content.Client.Power { // This is used for client-side prediction of the panel rotation. // This makes the display feel a lot smoother. - private IGameTiming _gameTiming = IoCManager.Resolve(); + [Dependency] private readonly IGameTiming _gameTiming = default!; private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0); @@ -105,6 +106,7 @@ namespace Content.Client.Power public SolarControlNotARadar() { + IoCManager.InjectDependencies(this); MinSize = new Vector2(SizeFull, SizeFull); } @@ -114,7 +116,7 @@ namespace Content.Client.Power _lastStateTime = _gameTiming.CurTime; } - public Angle PredictedPanelRotation => _lastState.Rotation + (_lastState.AngularVelocity * ((_gameTiming.CurTime - _lastStateTime).TotalSeconds)); + public Angle PredictedPanelRotation => _lastState.Rotation + _lastState.AngularVelocity * (_gameTiming.CurTime - _lastStateTime).TotalSeconds; protected override void Draw(DrawingHandleScreen handle) { @@ -137,7 +139,7 @@ namespace Content.Client.Power for (var i = 0; i < gridLinesRadial; i++) { - Angle angle = (Math.PI / gridLinesRadial) * i; + Angle angle = Math.PI / gridLinesRadial * i; var aExtent = angle.ToVec() * RadiusCircle; handle.DrawLine(new Vector2(point, point) - aExtent, new Vector2(point, point) + aExtent, gridLines); } @@ -162,6 +164,8 @@ namespace Content.Client.Power [UsedImplicitly] public sealed class SolarControlConsoleBoundUserInterface : ComputerBoundUserInterface { - public SolarControlConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public SolarControlConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } } } diff --git a/Content.Client/Research/UI/DiskConsoleBoundUserInterface.cs b/Content.Client/Research/UI/DiskConsoleBoundUserInterface.cs index b3bce0c99b..da008ca04c 100644 --- a/Content.Client/Research/UI/DiskConsoleBoundUserInterface.cs +++ b/Content.Client/Research/UI/DiskConsoleBoundUserInterface.cs @@ -6,11 +6,11 @@ namespace Content.Client.Research.UI { public sealed class DiskConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private DiskConsoleMenu? _menu; - public DiskConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public DiskConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } protected override void Open() diff --git a/Content.Client/Research/UI/ResearchClientBoundUserInterface.cs b/Content.Client/Research/UI/ResearchClientBoundUserInterface.cs index ca8534eebc..07dd35a005 100644 --- a/Content.Client/Research/UI/ResearchClientBoundUserInterface.cs +++ b/Content.Client/Research/UI/ResearchClientBoundUserInterface.cs @@ -5,9 +5,10 @@ namespace Content.Client.Research.UI { public sealed class ResearchClientBoundUserInterface : BoundUserInterface { + [ViewVariables] private ResearchClientServerSelectionMenu? _menu; - public ResearchClientBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ResearchClientBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { SendMessage(new ResearchClientSyncMessage()); } diff --git a/Content.Client/Research/UI/ResearchConsoleBoundUserInterface.cs b/Content.Client/Research/UI/ResearchConsoleBoundUserInterface.cs index 272d546a54..f29e66baae 100644 --- a/Content.Client/Research/UI/ResearchConsoleBoundUserInterface.cs +++ b/Content.Client/Research/UI/ResearchConsoleBoundUserInterface.cs @@ -7,20 +7,18 @@ namespace Content.Client.Research.UI; [UsedImplicitly] public sealed class ResearchConsoleBoundUserInterface : BoundUserInterface { - + [ViewVariables] private ResearchConsoleMenu? _consoleMenu; - - public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public ResearchConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } protected override void Open() { base.Open(); - var owner = Owner.Owner; + var owner = Owner; _consoleMenu = new ResearchConsoleMenu(owner); diff --git a/Content.Client/Salvage/UI/SalvageExpeditionConsoleBoundUserInterface.cs b/Content.Client/Salvage/UI/SalvageExpeditionConsoleBoundUserInterface.cs index 6f5ee423e6..d594bdd6fd 100644 --- a/Content.Client/Salvage/UI/SalvageExpeditionConsoleBoundUserInterface.cs +++ b/Content.Client/Salvage/UI/SalvageExpeditionConsoleBoundUserInterface.cs @@ -1,4 +1,3 @@ -using Content.Shared.Salvage; using Content.Shared.Salvage.Expeditions; using JetBrains.Annotations; using Robust.Client.GameObjects; @@ -8,9 +7,10 @@ namespace Content.Client.Salvage.UI; [UsedImplicitly] public sealed class SalvageExpeditionConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private SalvageExpeditionWindow? _window; - public SalvageExpeditionConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public SalvageExpeditionConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Shuttles/BUI/EmergencyConsoleBoundUserInterface.cs b/Content.Client/Shuttles/BUI/EmergencyConsoleBoundUserInterface.cs index 4d32d585dd..3123e9a216 100644 --- a/Content.Client/Shuttles/BUI/EmergencyConsoleBoundUserInterface.cs +++ b/Content.Client/Shuttles/BUI/EmergencyConsoleBoundUserInterface.cs @@ -2,12 +2,13 @@ using Content.Client.Computer; using Content.Client.Shuttles.UI; using Content.Shared.Shuttles.BUIStates; using JetBrains.Annotations; -using Robust.Client.GameObjects; namespace Content.Client.Shuttles.BUI; [UsedImplicitly] public sealed class EmergencyConsoleBoundUserInterface : ComputerBoundUserInterface { - public EmergencyConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public EmergencyConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } } diff --git a/Content.Client/Shuttles/BUI/IFFConsoleBoundUserInterface.cs b/Content.Client/Shuttles/BUI/IFFConsoleBoundUserInterface.cs index 1e9cc7729c..086369aa26 100644 --- a/Content.Client/Shuttles/BUI/IFFConsoleBoundUserInterface.cs +++ b/Content.Client/Shuttles/BUI/IFFConsoleBoundUserInterface.cs @@ -9,16 +9,17 @@ namespace Content.Client.Shuttles.BUI; [UsedImplicitly] public sealed class IFFConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private IFFConsoleWindow? _window; - public IFFConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public IFFConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } protected override void Open() { base.Open(); + _window = new IFFConsoleWindow(); _window.OnClose += Close; _window.ShowIFF += SendIFFMessage; diff --git a/Content.Client/Shuttles/BUI/RadarConsoleBoundUserInterface.cs b/Content.Client/Shuttles/BUI/RadarConsoleBoundUserInterface.cs index 6278389fff..e8cc64a00b 100644 --- a/Content.Client/Shuttles/BUI/RadarConsoleBoundUserInterface.cs +++ b/Content.Client/Shuttles/BUI/RadarConsoleBoundUserInterface.cs @@ -8,13 +8,17 @@ namespace Content.Client.Shuttles.BUI; [UsedImplicitly] public sealed class RadarConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private RadarConsoleWindow? _window; - public RadarConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public RadarConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { base.Open(); + _window = new RadarConsoleWindow(); _window.OnClose += Close; _window.OpenCentered(); diff --git a/Content.Client/Shuttles/BUI/ShuttleConsoleBoundUserInterface.cs b/Content.Client/Shuttles/BUI/ShuttleConsoleBoundUserInterface.cs index 8328dbe5f9..b970097641 100644 --- a/Content.Client/Shuttles/BUI/ShuttleConsoleBoundUserInterface.cs +++ b/Content.Client/Shuttles/BUI/ShuttleConsoleBoundUserInterface.cs @@ -1,6 +1,5 @@ using Content.Client.Shuttles.UI; using Content.Shared.Shuttles.BUIStates; -using Content.Shared.Shuttles.Components; using Content.Shared.Shuttles.Events; using JetBrains.Annotations; using Robust.Client.GameObjects; @@ -10,9 +9,12 @@ namespace Content.Client.Shuttles.BUI; [UsedImplicitly] public sealed class ShuttleConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private ShuttleConsoleWindow? _window; - public ShuttleConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) {} + public ShuttleConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { @@ -51,17 +53,17 @@ public sealed class ShuttleConsoleBoundUserInterface : BoundUserInterface private void OnStopAutodockPressed(EntityUid obj) { - SendMessage(new StopAutodockRequestMessage() {DockEntity = obj}); + SendMessage(new StopAutodockRequestMessage() { DockEntity = obj }); } private void OnAutodockPressed(EntityUid obj) { - SendMessage(new AutodockRequestMessage() {DockEntity = obj}); + SendMessage(new AutodockRequestMessage() { DockEntity = obj }); } private void OnUndockPressed(EntityUid obj) { - SendMessage(new UndockRequestMessage() {DockEntity = obj}); + SendMessage(new UndockRequestMessage() { DockEntity = obj }); } protected override void UpdateState(BoundUserInterfaceState state) diff --git a/Content.Client/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Client/Shuttles/Systems/ShuttleConsoleSystem.cs index f9e01c09fd..f18f27ccd2 100644 --- a/Content.Client/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Client/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -52,13 +52,13 @@ namespace Content.Client.Shuttles.Systems return; } - if (!TryComp(console, out var shuttleConsoleComponent)) + if (!HasComp(console)) { - Logger.Warning($"Unable to set Helmsman console to {console}"); + Log.Warning($"Unable to set Helmsman console to {console}"); return; } - component.Console = shuttleConsoleComponent; + component.Console = console; ActionBlockerSystem.UpdateCanMove(uid); _input.Contexts.SetActiveContext("shuttle"); } diff --git a/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs b/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs index 34c3328792..0743312e11 100644 --- a/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs +++ b/Content.Client/StationRecords/GeneralStationRecordConsoleBoundUserInterface.cs @@ -5,10 +5,12 @@ namespace Content.Client.StationRecords; public sealed class GeneralStationRecordConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private GeneralStationRecordConsoleWindow? _window = default!; - public GeneralStationRecordConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) - {} + public GeneralStationRecordConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } protected override void Open() { diff --git a/Content.Client/Storage/StorageBoundUserInterface.cs b/Content.Client/Storage/StorageBoundUserInterface.cs index eb22307318..bd83670b3c 100644 --- a/Content.Client/Storage/StorageBoundUserInterface.cs +++ b/Content.Client/Storage/StorageBoundUserInterface.cs @@ -1,7 +1,6 @@ using Content.Client.Examine; using Content.Client.Storage.UI; using Content.Client.UserInterface.Controls; -using Content.Client.Verbs; using Content.Client.Verbs.UI; using Content.Shared.Input; using Content.Shared.Interaction; @@ -17,9 +16,10 @@ namespace Content.Client.Storage [UsedImplicitly] public sealed class StorageBoundUserInterface : BoundUserInterface { - [ViewVariables] private StorageWindow? _window; + [ViewVariables] + private StorageWindow? _window; - public StorageBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -29,9 +29,10 @@ namespace Content.Client.Storage if (_window == null) { - var entMan = IoCManager.Resolve(); - _window = new StorageWindow(entMan) - {Title = entMan.GetComponent(Owner.Owner).EntityName}; + _window = new StorageWindow(EntMan) + { + Title = EntMan.GetComponent(Owner).EntityName + }; _window.EntityList.GenerateItem += _window.GenerateButton; _window.EntityList.ItemPressed += InteractWithItem; @@ -48,14 +49,14 @@ namespace Content.Client.Storage public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData) { - if (cData is not EntityListData {Uid: var entity}) + if (cData is not EntityListData { Uid: var entity }) return; if (args.Event.Function == EngineKeyFunctions.UIClick) { SendMessage(new StorageInteractWithItemEvent(entity)); } - else if (IoCManager.Resolve().EntityExists(entity)) + else if (EntMan.EntityExists(entity)) { OnButtonPressed(args.Event, entity); } @@ -63,12 +64,9 @@ namespace Content.Client.Storage private void OnButtonPressed(GUIBoundKeyEventArgs args, EntityUid entity) { - var entitySys = IoCManager.Resolve(); - var entities = IoCManager.Resolve(); - if (args.Function == ContentKeyFunctions.ExamineEntity) { - entitySys.GetEntitySystem() + EntMan.System() .DoExamine(entity); } else if (args.Function == EngineKeyFunctions.UseSecondary) @@ -77,12 +75,12 @@ namespace Content.Client.Storage } else if (args.Function == ContentKeyFunctions.ActivateItemInWorld) { - entities.EntityNetManager?.SendSystemNetworkMessage( + EntMan.EntityNetManager?.SendSystemNetworkMessage( new InteractInventorySlotEvent(entity, altInteract: false)); } else if (args.Function == ContentKeyFunctions.AltActivateItemInWorld) { - entities.RaisePredictiveEvent(new InteractInventorySlotEvent(entity, altInteract: true)); + EntMan.RaisePredictiveEvent(new InteractInventorySlotEvent(entity, altInteract: true)); } else { diff --git a/Content.Client/Store/Ui/StoreBoundUserInterface.cs b/Content.Client/Store/Ui/StoreBoundUserInterface.cs index 8ff5ff1ca8..0860abb9fa 100644 --- a/Content.Client/Store/Ui/StoreBoundUserInterface.cs +++ b/Content.Client/Store/Ui/StoreBoundUserInterface.cs @@ -8,13 +8,14 @@ namespace Content.Client.Store.Ui; [UsedImplicitly] public sealed class StoreBoundUserInterface : BoundUserInterface { + [ViewVariables] private StoreMenu? _menu; + [ViewVariables] private string _windowName = Loc.GetString("store-ui-default-title"); - public StoreBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public StoreBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } protected override void Open() diff --git a/Content.Client/Strip/StrippableSystem.cs b/Content.Client/Strip/StrippableSystem.cs index bc7e325550..9aefde6211 100644 --- a/Content.Client/Strip/StrippableSystem.cs +++ b/Content.Client/Strip/StrippableSystem.cs @@ -36,7 +36,7 @@ public sealed class StrippableSystem : SharedStrippableSystem if (!TryComp(uid, out ClientUserInterfaceComponent? uiComp)) return; - foreach (var ui in uiComp.Interfaces) + foreach (var ui in uiComp.OpenInterfaces.Values) { if (ui is StrippableBoundUserInterface stripUi) stripUi.DirtyMenu(); diff --git a/Content.Client/SurveillanceCamera/UI/SurveillanceCameraMonitorBoundUi.cs b/Content.Client/SurveillanceCamera/UI/SurveillanceCameraMonitorBoundUi.cs index c979c36cd4..2213eb832d 100644 --- a/Content.Client/SurveillanceCamera/UI/SurveillanceCameraMonitorBoundUi.cs +++ b/Content.Client/SurveillanceCamera/UI/SurveillanceCameraMonitorBoundUi.cs @@ -6,18 +6,19 @@ namespace Content.Client.SurveillanceCamera.UI; public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IEntityManager _entityManager = default!; private readonly EyeLerpingSystem _eyeLerpingSystem; private readonly SurveillanceCameraMonitorSystem _surveillanceCameraMonitorSystem; + [ViewVariables] private SurveillanceCameraMonitorWindow? _window; + + [ViewVariables] private EntityUid? _currentCamera; - public SurveillanceCameraMonitorBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public SurveillanceCameraMonitorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - IoCManager.InjectDependencies(this); - _eyeLerpingSystem = _entityManager.EntitySysManager.GetEntitySystem(); - _surveillanceCameraMonitorSystem = _entityManager.EntitySysManager.GetEntitySystem(); + _eyeLerpingSystem = EntMan.System(); + _surveillanceCameraMonitorSystem = EntMan.System(); } protected override void Open() @@ -54,7 +55,7 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter private void OnCameraSwitchTimer() { - _surveillanceCameraMonitorSystem.AddTimer(Owner.Owner, _window!.OnSwitchTimerComplete); + _surveillanceCameraMonitorSystem.AddTimer(Owner, _window!.OnSwitchTimerComplete); } private void OnCameraRefresh() @@ -85,7 +86,7 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter if (_currentCamera != null) { - _surveillanceCameraMonitorSystem.RemoveTimer(Owner.Owner); + _surveillanceCameraMonitorSystem.RemoveTimer(Owner); _eyeLerpingSystem.RemoveEye(_currentCamera.Value); _currentCamera = null; } @@ -104,7 +105,7 @@ public sealed class SurveillanceCameraMonitorBoundUserInterface : BoundUserInter _currentCamera = cast.ActiveCamera; } - if (_entityManager.TryGetComponent(cast.ActiveCamera, out EyeComponent? eye)) + if (EntMan.TryGetComponent(cast.ActiveCamera, out var eye)) { _window.UpdateState(eye.Eye, cast.Subnets, cast.ActiveAddress, cast.ActiveSubnet, cast.Cameras); } diff --git a/Content.Client/SurveillanceCamera/UI/SurveillanceCameraSetupBoundUi.cs b/Content.Client/SurveillanceCamera/UI/SurveillanceCameraSetupBoundUi.cs index 7fc8614146..1880e431ee 100644 --- a/Content.Client/SurveillanceCamera/UI/SurveillanceCameraSetupBoundUi.cs +++ b/Content.Client/SurveillanceCamera/UI/SurveillanceCameraSetupBoundUi.cs @@ -5,15 +5,16 @@ namespace Content.Client.SurveillanceCamera.UI; public sealed class SurveillanceCameraSetupBoundUi : BoundUserInterface { - private SurveillanceCameraSetupWindow? _window; - private SurveillanceCameraSetupUiKey _type; + [ViewVariables] + private readonly SurveillanceCameraSetupUiKey _type; - public SurveillanceCameraSetupBoundUi(ClientUserInterfaceComponent component, Enum uiKey) : base(component, uiKey) + [ViewVariables] + private SurveillanceCameraSetupWindow? _window; + + public SurveillanceCameraSetupBoundUi(EntityUid component, Enum uiKey) : base(component, uiKey) { if (uiKey is not SurveillanceCameraSetupUiKey key) - { return; - } _type = key; } diff --git a/Content.Client/UserInterface/Systems/Atmos/GasTank/GasTankBoundUserInterface.cs b/Content.Client/UserInterface/Systems/Atmos/GasTank/GasTankBoundUserInterface.cs index 577187b053..ee8cb28d2c 100644 --- a/Content.Client/UserInterface/Systems/Atmos/GasTank/GasTankBoundUserInterface.cs +++ b/Content.Client/UserInterface/Systems/Atmos/GasTank/GasTankBoundUserInterface.cs @@ -5,19 +5,21 @@ using Robust.Client.GameObjects; namespace Content.Client.UserInterface.Systems.Atmos.GasTank { [UsedImplicitly] - public sealed class GasTankBoundUserInterface - : BoundUserInterface + public sealed class GasTankBoundUserInterface : BoundUserInterface { - public GasTankBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : - base(owner, uiKey) + [ViewVariables] + private GasTankWindow? _window; + + public GasTankBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } - private GasTankWindow? _window; - public void SetOutputPressure(in float value) { - SendMessage(new GasTankSetPressureMessage {Pressure = value}); + SendMessage(new GasTankSetPressureMessage + { + Pressure = value + }); } public void ToggleInternals() diff --git a/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs b/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs index 516d5c6c81..7a68907871 100644 --- a/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs +++ b/Content.Client/VendingMachines/VendingMachineBoundUserInterface.cs @@ -11,9 +11,10 @@ namespace Content.Client.VendingMachines [ViewVariables] private VendingMachineMenu? _menu; + [ViewVariables] private List _cachedInventory = new(); - public VendingMachineBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public VendingMachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -21,12 +22,11 @@ namespace Content.Client.VendingMachines { base.Open(); - var entMan = IoCManager.Resolve(); - var vendingMachineSys = entMan.System(); + var vendingMachineSys = EntMan.System(); - _cachedInventory = vendingMachineSys.GetAllInventory(Owner.Owner); + _cachedInventory = vendingMachineSys.GetAllInventory(Owner); - _menu = new VendingMachineMenu {Title = entMan.GetComponent(Owner.Owner).EntityName}; + _menu = new VendingMachineMenu { Title = EntMan.GetComponent(Owner).EntityName }; _menu.OnClose += Close; _menu.OnItemSelected += OnItemSelected; diff --git a/Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs b/Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs index 1427248c35..0650482b10 100644 --- a/Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs +++ b/Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs @@ -5,12 +5,13 @@ namespace Content.Client.VoiceMask; public sealed class VoiceMaskBoundUserInterface : BoundUserInterface { - public VoiceMaskBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + [ViewVariables] + private VoiceMaskNameChangeWindow? _window; + + public VoiceMaskBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } - private VoiceMaskNameChangeWindow? _window; - protected override void Open() { base.Open(); diff --git a/Content.Client/Weapons/Melee/UI/MeleeSpeechBoundUserInterface.cs b/Content.Client/Weapons/Melee/UI/MeleeSpeechBoundUserInterface.cs index 56079652bd..f3e0c0a539 100644 --- a/Content.Client/Weapons/Melee/UI/MeleeSpeechBoundUserInterface.cs +++ b/Content.Client/Weapons/Melee/UI/MeleeSpeechBoundUserInterface.cs @@ -8,9 +8,10 @@ namespace Content.Client.Weapons.Melee.UI; /// public sealed class MeleeSpeechBoundUserInterface : BoundUserInterface { + [ViewVariables] private MeleeSpeechWindow? _window; - public MeleeSpeechBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public MeleeSpeechBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -50,7 +51,9 @@ public sealed class MeleeSpeechBoundUserInterface : BoundUserInterface protected override void Dispose(bool disposing) { base.Dispose(disposing); - if (!disposing) return; - _window?.Dispose(); - } + if (!disposing) + return; + + _window?.Dispose(); + } } diff --git a/Content.Client/Wires/UI/WiresBoundUserInterface.cs b/Content.Client/Wires/UI/WiresBoundUserInterface.cs index cd2b3ea02e..5a8869a204 100644 --- a/Content.Client/Wires/UI/WiresBoundUserInterface.cs +++ b/Content.Client/Wires/UI/WiresBoundUserInterface.cs @@ -1,14 +1,14 @@ using Content.Shared.Wires; using Robust.Client.GameObjects; -using Robust.Shared.GameObjects; namespace Content.Client.Wires.UI { public sealed class WiresBoundUserInterface : BoundUserInterface { + [ViewVariables] private WiresMenu? _menu; - public WiresBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public WiresBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleBoundUserInterface.cs b/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleBoundUserInterface.cs index 7baa32c1c8..9039a2e831 100644 --- a/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleBoundUserInterface.cs +++ b/Content.Client/Xenoarchaeology/Ui/AnalysisConsoleBoundUserInterface.cs @@ -7,11 +7,11 @@ namespace Content.Client.Xenoarchaeology.Ui; [UsedImplicitly] public sealed class AnalysisConsoleBoundUserInterface : BoundUserInterface { + [ViewVariables] private AnalysisConsoleMenu? _consoleMenu; - public AnalysisConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) + public AnalysisConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - } protected override void Open() diff --git a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs index cd19803772..bd5b95e08e 100644 --- a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs +++ b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs @@ -753,22 +753,26 @@ public abstract partial class InteractionTest return false; } - if (!CEntMan.TryGetComponent(target, out ClientUserInterfaceComponent? ui)) + if (!CEntMan.TryGetComponent(target, out var ui)) { if (shouldSucceed) Assert.Fail($"Entity {SEntMan.ToPrettyString(target.Value)} does not have a bui component"); return false; } - bui = ui.Interfaces.FirstOrDefault(x => x.UiKey.Equals(key)); - if (bui == null) + if (!ui.OpenInterfaces.TryGetValue(key, out bui)) { if (shouldSucceed) Assert.Fail($"Entity {SEntMan.ToPrettyString(target.Value)} does not have an open bui with key {key.GetType()}.{key}."); return false; } - Assert.That(shouldSucceed, Is.True); + var bui2 = bui; + Assert.Multiple(() => + { + Assert.That(bui2.UiKey, Is.EqualTo(key), $"Bound user interface {bui2} is indexed by a key other than the one assigned to it somehow. {bui2.UiKey} != {key}"); + Assert.That(shouldSucceed, Is.True); + }); return true; } diff --git a/Content.Server/Access/Systems/AgentIDCardSystem.cs b/Content.Server/Access/Systems/AgentIDCardSystem.cs index 118a29ba87..b749dc9769 100644 --- a/Content.Server/Access/Systems/AgentIDCardSystem.cs +++ b/Content.Server/Access/Systems/AgentIDCardSystem.cs @@ -21,7 +21,7 @@ namespace Content.Server.Access.Systems // BUI SubscribeLocalEvent(AfterUIOpen); SubscribeLocalEvent(OnNameChanged); - SubscribeLocalEvent (OnJobChanged); + SubscribeLocalEvent(OnJobChanged); } private void OnAfterInteract(EntityUid uid, AgentIDCardComponent component, AfterInteractEvent args) @@ -55,14 +55,14 @@ namespace Content.Server.Access.Systems private void AfterUIOpen(EntityUid uid, AgentIDCardComponent component, AfterActivatableUIOpenEvent args) { - if (!_uiSystem.TryGetUi(component.Owner, AgentIDCardUiKey.Key, out var ui)) + if (!_uiSystem.TryGetUi(uid, AgentIDCardUiKey.Key, out var ui)) return; if (!TryComp(uid, out var idCard)) return; var state = new AgentIDCardBoundUserInterfaceState(idCard.FullName ?? "", idCard.JobTitle ?? ""); - ui.SetState(state, args.Session); + UserInterfaceSystem.SetUiState(ui, state, args.Session); } private void OnJobChanged(EntityUid uid, AgentIDCardComponent comp, AgentIDCardJobChangedMessage args) diff --git a/Content.Server/AirlockPainter/AirlockPainterSystem.cs b/Content.Server/AirlockPainter/AirlockPainterSystem.cs index 2626c410fb..85723fc14e 100644 --- a/Content.Server/AirlockPainter/AirlockPainterSystem.cs +++ b/Content.Server/AirlockPainter/AirlockPainterSystem.cs @@ -57,7 +57,9 @@ namespace Content.Server.AirlockPainter if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) return; DirtyUI(uid, component); - component.Owner.GetUIOrNull(AirlockPainterUiKey.Key)?.Open(actor.PlayerSession); + + if (_userInterfaceSystem.TryGetUi(uid, AirlockPainterUiKey.Key, out var bui)) + _userInterfaceSystem.OpenUi(bui, actor.PlayerSession); args.Handled = true; } diff --git a/Content.Server/Alert/Click/StopPiloting.cs b/Content.Server/Alert/Click/StopPiloting.cs index 8384dec258..391ec7de91 100644 --- a/Content.Server/Alert/Click/StopPiloting.cs +++ b/Content.Server/Alert/Click/StopPiloting.cs @@ -16,8 +16,8 @@ namespace Content.Server.Alert.Click { var entManager = IoCManager.Resolve(); - if (entManager.TryGetComponent(player, out PilotComponent? pilotComponent) && - pilotComponent.Console != null) + if (entManager.TryGetComponent(player, out PilotComponent? pilotComponent) + && pilotComponent.Console != null) { entManager.System().RemovePilot(player, pilotComponent); } diff --git a/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs b/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs index 8440d83bfb..3b427f65f4 100644 --- a/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs +++ b/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs @@ -94,7 +94,7 @@ public sealed class AmeControllerSystem : EntitySystem return; var state = GetUiState(uid, controller); - _userInterfaceSystem.SetUiState(bui, state); + UserInterfaceSystem.SetUiState(bui, state); } private AmeControllerBoundUserInterfaceState GetUiState(EntityUid uid, AmeControllerComponent controller) diff --git a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs index 339cec06da..1e78dc3575 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Orders.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Orders.cs @@ -1,12 +1,6 @@ using System.Diagnostics.CodeAnalysis; -using Content.Server.Access.Systems; using Content.Server.Cargo.Components; using Content.Server.Labels.Components; -using Content.Server.DeviceLinking.Systems; -using Content.Server.Popups; -using Content.Server.Station.Systems; -using Content.Shared.Access.Systems; -using Content.Shared.Administration.Logs; using Content.Shared.Cargo; using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.Events; @@ -14,7 +8,6 @@ using Content.Shared.Cargo.Prototypes; using Content.Shared.Database; using Content.Shared.GameTicking; using Content.Server.Paper; -using Content.Shared.Access.Components; using Robust.Server.GameObjects; using Robust.Shared.Map; using Robust.Shared.Players; @@ -49,7 +42,7 @@ namespace Content.Server.Cargo.Systems private void OnInit(EntityUid uid, CargoOrderConsoleComponent orderConsole, ComponentInit args) { var station = _station.GetOwningStation(uid); - UpdateOrderState(orderConsole, station); + UpdateOrderState(uid, station); } private void Reset(RoundRestartCleanupEvent ev) @@ -77,12 +70,13 @@ namespace Content.Server.Cargo.Systems account.Balance += account.IncreasePerSecond * Delay; } - foreach (var comp in EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var _)) { - if (!_uiSystem.IsUiOpen(comp.Owner, CargoConsoleUiKey.Orders)) continue; + if (!_uiSystem.IsUiOpen(uid, CargoConsoleUiKey.Orders)) continue; - var station = _station.GetOwningStation(comp.Owner); - UpdateOrderState(comp, station); + var station = _station.GetOwningStation(uid); + UpdateOrderState(uid, station); } } } @@ -91,7 +85,7 @@ namespace Content.Server.Cargo.Systems private void OnApproveOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleApproveOrderMessage args) { - if (args.Session.AttachedEntity is not {Valid: true} player) + if (args.Session.AttachedEntity is not { Valid: true } player) return; if (!_accessReaderSystem.IsAllowed(player, uid)) @@ -101,11 +95,10 @@ namespace Content.Server.Cargo.Systems return; } - var orderDatabase = GetOrderDatabase(component); - var bankAccount = GetBankAccount(component); + var bankAccount = GetBankAccount(uid, component); // No station to deduct from. - if (orderDatabase == null || bankAccount == null) + if (!TryGetOrderDatabase(uid, out var dbUid, out var orderDatabase, component) || bankAccount == null) { ConsolePopup(args.Session, Loc.GetString("cargo-console-station-not-found")); PlayDenySound(uid, component); @@ -113,8 +106,8 @@ namespace Content.Server.Cargo.Systems } // Find our order again. It might have been dispatched or approved already - var order = orderDatabase.Orders.Find(order => (args.OrderId == order.OrderId) && !order.Approved); - if(order == null) + var order = orderDatabase.Orders.Find(order => args.OrderId == order.OrderId && !order.Approved); + if (order == null) { return; } @@ -167,30 +160,30 @@ namespace Content.Server.Cargo.Systems $"{ToPrettyString(player):user} approved order [orderId:{order.OrderId}, quantity:{order.OrderQuantity}, product:{order.ProductId}, requester:{order.Requester}, reason:{order.Reason}] with balance at {bankAccount.Balance}"); DeductFunds(bankAccount, cost); - UpdateOrders(orderDatabase); + UpdateOrders(dbUid!.Value, orderDatabase); } private void OnRemoveOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleRemoveOrderMessage args) { - var orderDatabase = GetOrderDatabase(component); - if (orderDatabase == null) return; - RemoveOrder(orderDatabase, args.OrderId); + if (!TryGetOrderDatabase(uid, out var dbUid, out var orderDatabase, component)) + return; + + RemoveOrder(dbUid!.Value, args.OrderId, orderDatabase); } private void OnAddOrderMessage(EntityUid uid, CargoOrderConsoleComponent component, CargoConsoleAddOrderMessage args) { - if (args.Session.AttachedEntity is not {Valid: true} player) + if (args.Session.AttachedEntity is not { Valid: true } player) return; if (args.Amount <= 0) return; - var bank = GetBankAccount(component); + var bank = GetBankAccount(uid, component); if (bank == null) return; - var orderDatabase = GetOrderDatabase(component); - if (orderDatabase == null) + if (!TryGetOrderDatabase(uid, out var dbUid, out var orderDatabase, component)) return; if (!_protoMan.TryIndex(args.CargoProductId, out var product)) @@ -201,7 +194,7 @@ namespace Content.Server.Cargo.Systems var data = GetOrderData(args, product, GenerateOrderId(orderDatabase)); - if (!TryAddOrder(orderDatabase, data)) + if (!TryAddOrder(dbUid!.Value, data, orderDatabase)) { PlayDenySound(uid, component); return; @@ -216,46 +209,50 @@ namespace Content.Server.Cargo.Systems private void OnOrderUIOpened(EntityUid uid, CargoOrderConsoleComponent component, BoundUIOpenedEvent args) { var station = _station.GetOwningStation(uid); - UpdateOrderState(component, station); + UpdateOrderState(uid, station); } #endregion - private void UpdateOrderState(CargoOrderConsoleComponent component, EntityUid? station) + private void UpdateOrderState(EntityUid consoleUid, EntityUid? station) { if (station == null || !TryComp(station, out var orderDatabase) || !TryComp(station, out var bankAccount)) return; - var state = new CargoConsoleInterfaceState( - MetaData(station.Value).EntityName, - GetOutstandingOrderCount(orderDatabase), - orderDatabase.Capacity, - bankAccount.Balance, - orderDatabase.Orders); - - _uiSystem.GetUiOrNull(component.Owner, CargoConsoleUiKey.Orders)?.SetState(state); + if (_uiSystem.TryGetUi(consoleUid, CargoConsoleUiKey.Orders, out var bui)) + UserInterfaceSystem.SetUiState(bui, new CargoConsoleInterfaceState( + MetaData(station.Value).EntityName, + GetOutstandingOrderCount(orderDatabase), + orderDatabase.Capacity, + bankAccount.Balance, + orderDatabase.Orders + )); } - private void ConsolePopup(ICommonSession session, string text) => _popup.PopupCursor(text, session); + private void ConsolePopup(ICommonSession session, string text) + { + _popup.PopupCursor(text, session); + } private void PlayDenySound(EntityUid uid, CargoOrderConsoleComponent component) { _audio.PlayPvs(_audio.GetSound(component.ErrorSound), uid); } - private CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id) + private static CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id) { return new CargoOrderData(id, cargoProduct.Product, cargoProduct.PointCost, args.Amount, args.Requester, args.Reason); } - public int GetOutstandingOrderCount(StationCargoOrderDatabaseComponent component) + public static int GetOutstandingOrderCount(StationCargoOrderDatabaseComponent component) { var amount = 0; foreach (var order in component.Orders) { - if (!order.Approved) continue; + if (!order.Approved) + continue; amount += order.OrderQuantity - order.NumDispatched; } @@ -266,32 +263,41 @@ namespace Content.Server.Cargo.Systems /// Updates all of the cargo-related consoles for a particular station. /// This should be called whenever orders change. /// - private void UpdateOrders(StationCargoOrderDatabaseComponent component) + private void UpdateOrders(EntityUid dbUid, StationCargoOrderDatabaseComponent _) { // Order added so all consoles need updating. var orderQuery = AllEntityQuery(); - while (orderQuery.MoveNext(out var uid, out var comp)) + while (orderQuery.MoveNext(out var uid, out var _)) { var station = _station.GetOwningStation(uid); - if (station != component.Owner) + if (station != dbUid) continue; - UpdateOrderState(comp, station); + UpdateOrderState(uid, station); } var consoleQuery = AllEntityQuery(); - while (consoleQuery.MoveNext(out var uid, out var comp)) + while (consoleQuery.MoveNext(out var uid, out var _)) { var station = _station.GetOwningStation(uid); - if (station != component.Owner) + if (station != dbUid) continue; UpdateShuttleState(uid, station); } } - public bool AddAndApproveOrder(StationCargoOrderDatabaseComponent component, string spawnId, int cost, int qty, string sender, string description, string dest) + public bool AddAndApproveOrder( + EntityUid dbUid, + string spawnId, + int cost, + int qty, + string sender, + string description, + string dest, + StationCargoOrderDatabaseComponent component + ) { DebugTools.Assert(_protoMan.HasIndex(spawnId)); // Make an order @@ -306,31 +312,31 @@ namespace Content.Server.Cargo.Systems $"AddAndApproveOrder {description} added order [orderId:{order.OrderId}, quantity:{order.OrderQuantity}, product:{order.ProductId}, requester:{order.Requester}, reason:{order.Reason}]"); // Add it to the list - return TryAddOrder(component, order); + return TryAddOrder(dbUid, order, component); } - private bool TryAddOrder(StationCargoOrderDatabaseComponent component, CargoOrderData data) + private bool TryAddOrder(EntityUid dbUid, CargoOrderData data, StationCargoOrderDatabaseComponent component) { component.Orders.Add(data); - UpdateOrders(component); + UpdateOrders(dbUid, component); return true; } - private int GenerateOrderId(StationCargoOrderDatabaseComponent orderDB) + private static int GenerateOrderId(StationCargoOrderDatabaseComponent orderDB) { // We need an arbitrary unique ID to identify orders, since they may // want to be cancelled later. return ++orderDB.NumOrdersCreated; } - public void RemoveOrder(StationCargoOrderDatabaseComponent orderDB, int index) + public void RemoveOrder(EntityUid dbUid, int index, StationCargoOrderDatabaseComponent orderDB) { var sequenceIdx = orderDB.Orders.FindIndex(order => order.OrderId == index); if (sequenceIdx != -1) { orderDB.Orders.RemoveAt(sequenceIdx); } - UpdateOrders(orderDB); + UpdateOrders(dbUid, orderDB); } public void ClearOrders(StationCargoOrderDatabaseComponent component) @@ -341,7 +347,7 @@ namespace Content.Server.Cargo.Systems Dirty(component); } - private bool PopFrontOrder(StationCargoOrderDatabaseComponent orderDB, [NotNullWhen(true)] out CargoOrderData? orderOut) + private static bool PopFrontOrder(StationCargoOrderDatabaseComponent orderDB, [NotNullWhen(true)] out CargoOrderData? orderOut) { var orderIdx = orderDB.Orders.FindIndex(order => order.Approved); if (orderIdx == -1) @@ -353,7 +359,7 @@ namespace Content.Server.Cargo.Systems orderOut = orderDB.Orders[orderIdx]; orderOut.NumDispatched++; - if(orderOut.NumDispatched >= orderOut.OrderQuantity) + if (orderOut.NumDispatched >= orderOut.OrderQuantity) { // Order is complete. Remove from the queue. orderDB.Orders.RemoveAt(orderIdx); @@ -375,7 +381,7 @@ namespace Content.Server.Cargo.Systems { // fill in the order data var val = Loc.GetString("cargo-console-paper-print-name", ("orderNumber", order.OrderId)); - MetaData(printed).EntityName = val; + _metaSystem.SetEntityName(printed, val); _paperSystem.SetContent(printed, Loc.GetString( "cargo-console-paper-print-text", @@ -407,20 +413,18 @@ namespace Content.Server.Cargo.Systems #region Station - private StationBankAccountComponent? GetBankAccount(CargoOrderConsoleComponent component) + private StationBankAccountComponent? GetBankAccount(EntityUid uid, CargoOrderConsoleComponent _) { - var station = _station.GetOwningStation(component.Owner); + var station = _station.GetOwningStation(uid); TryComp(station, out var bankComponent); return bankComponent; } - private StationCargoOrderDatabaseComponent? GetOrderDatabase(CargoOrderConsoleComponent component) + private bool TryGetOrderDatabase(EntityUid uid, [MaybeNullWhen(false)] out EntityUid? dbUid, [MaybeNullWhen(false)] out StationCargoOrderDatabaseComponent dbComp, CargoOrderConsoleComponent _) { - var station = _station.GetOwningStation(component.Owner); - - TryComp(station, out var orderComponent); - return orderComponent; + dbUid = _station.GetOwningStation(uid); + return TryComp(dbUid, out dbComp); } #endregion diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index a54ed58761..e596360c87 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -2,8 +2,6 @@ using System.Linq; using Content.Server.Cargo.Components; using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Events; -using Content.Server.Shuttles.Systems; -using Content.Server.Stack; using Content.Shared.Stacks; using Content.Shared.Cargo; using Content.Shared.Cargo.BUI; @@ -12,15 +10,13 @@ using Content.Shared.Cargo.Events; using Content.Shared.CCVar; using Content.Shared.GameTicking; using Content.Shared.Whitelist; -using Robust.Shared.Configuration; +using Robust.Server.GameObjects; using Robust.Shared.Map; using Robust.Shared.Random; using Robust.Shared.Utility; -using Robust.Shared.Prototypes; using Content.Shared.Coordinates; using Content.Shared.Mobs; using Content.Shared.Mobs.Components; -using Robust.Shared.Containers; namespace Content.Server.Cargo.Systems; @@ -73,7 +69,7 @@ public sealed partial class CargoSystem #region Console - private void UpdateCargoShuttleConsoles(EntityUid shuttleUid, CargoShuttleComponent component) + private void UpdateCargoShuttleConsoles(EntityUid shuttleUid, CargoShuttleComponent _) { // Update pilot consoles that are already open. _console.RefreshDroneConsoles(); @@ -81,7 +77,7 @@ public sealed partial class CargoSystem // Update order consoles. var shuttleConsoleQuery = AllEntityQuery(); - while (shuttleConsoleQuery.MoveNext(out var uid, out _)) + while (shuttleConsoleQuery.MoveNext(out var uid, out var _)) { var stationUid = _station.GetOwningStation(uid); if (stationUid != shuttleUid) @@ -96,12 +92,12 @@ public sealed partial class CargoSystem var bui = _uiSystem.GetUi(uid, CargoPalletConsoleUiKey.Sale); if (Transform(uid).GridUid is not EntityUid gridUid) { - _uiSystem.SetUiState(bui, + UserInterfaceSystem.SetUiState(bui, new CargoPalletConsoleInterfaceState(0, 0, false)); return; } GetPalletGoods(gridUid, out var toSell, out var amount); - _uiSystem.SetUiState(bui, + UserInterfaceSystem.SetUiState(bui, new CargoPalletConsoleInterfaceState((int) amount, toSell.Count, true)); } @@ -147,11 +143,12 @@ public sealed partial class CargoSystem var orders = GetProjectedOrders(station ?? EntityUid.Invalid, orderDatabase, shuttle); var shuttleName = orderDatabase?.Shuttle != null ? MetaData(orderDatabase.Shuttle.Value).EntityName : string.Empty; - _uiSystem.GetUiOrNull(uid, CargoConsoleUiKey.Shuttle)?.SetState( - new CargoShuttleConsoleBoundUserInterfaceState( + if (_uiSystem.TryGetUi(uid, CargoConsoleUiKey.Shuttle, out var bui)) + UserInterfaceSystem.SetUiState(bui, new CargoShuttleConsoleBoundUserInterfaceState( station != null ? MetaData(station.Value).EntityName : Loc.GetString("cargo-shuttle-console-station-unknown"), string.IsNullOrEmpty(shuttleName) ? Loc.GetString("cargo-shuttle-console-shuttle-not-found") : shuttleName, - orders)); + orders + )); } #endregion @@ -172,10 +169,10 @@ public sealed partial class CargoSystem return orders; var spaceRemaining = GetCargoSpace(shuttleUid); - for( var i = 0; i < component.Orders.Count && spaceRemaining > 0; i++) + for (var i = 0; i < component.Orders.Count && spaceRemaining > 0; i++) { var order = component.Orders[i]; - if(order.Approved) + if (order.Approved) { var numToShip = order.OrderQuantity - order.NumDispatched; if (numToShip > spaceRemaining) @@ -311,7 +308,7 @@ public sealed partial class CargoSystem while (pads.Count > 0) { var coordinates = new EntityCoordinates(shuttleUid, xformQuery.GetComponent(_random.PickAndTake(pads).Entity).LocalPosition); - if(!FulfillOrder(orderDatabase, coordinates, shuttle.PrinterOutput)) + if (!FulfillOrder(orderDatabase, coordinates, shuttle.PrinterOutput)) { break; } @@ -328,14 +325,14 @@ public sealed partial class CargoSystem var bui = _uiSystem.GetUi(uid, CargoPalletConsoleUiKey.Sale); if (Transform(uid).GridUid is not EntityUid gridUid) { - _uiSystem.SetUiState(bui, + UserInterfaceSystem.SetUiState(bui, new CargoPalletConsoleInterfaceState(0, 0, false)); return; } SellPallets(gridUid, null, out var price); var stackPrototype = _protoMan.Index(component.CashType); - _stack.Spawn((int)price, stackPrototype, uid.ToCoordinates()); + _stack.Spawn((int) price, stackPrototype, uid.ToCoordinates()); UpdatePalletConsoleInterface(uid); } @@ -352,7 +349,7 @@ public sealed partial class CargoSystem } AddCargoContents(uid, component, orderDatabase); - UpdateOrders(orderDatabase); + UpdateOrders(stationUid!.Value, orderDatabase); UpdateCargoShuttleConsoles(uid, component); } @@ -397,7 +394,7 @@ public sealed partial class CargoSystem // Shuttle may not have been in the cargo dimension (e.g. on the station map) so need to delete. var query = AllEntityQuery(); - while (query.MoveNext(out var uid, out var comp)) + while (query.MoveNext(out var uid, out var _)) { if (TryComp(uid, out var station)) { @@ -427,7 +424,7 @@ public sealed partial class CargoSystem } }; - MetaData(mapUid).EntityName = $"Trading post {_random.Next(1000):000}"; + _metaSystem.SetEntityName(mapUid, $"Trading post {_random.Next(1000):000}"); _console.RefreshShuttleConsoles(); } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs b/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs index 29cab7877b..3f78a48fe5 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs @@ -65,10 +65,10 @@ public sealed partial class CargoSystem } var xform = Transform(uid); - if (FulfillOrder(orderDatabase, xform.Coordinates,comp.PrinterOutput)) + if (FulfillOrder(orderDatabase, xform.Coordinates, comp.PrinterOutput)) { _audio.PlayPvs(_audio.GetSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f)); - UpdateOrders(orderDatabase); + UpdateOrders(station!.Value, orderDatabase); comp.CurrentState = CargoTelepadState.Teleporting; _appearance.SetData(uid, CargoTelepadVisuals.State, CargoTelepadState.Teleporting, appearance); diff --git a/Content.Server/Cargo/Systems/CargoSystem.cs b/Content.Server/Cargo/Systems/CargoSystem.cs index d56a97b4af..b5926dcfd6 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.cs @@ -43,6 +43,7 @@ public sealed partial class CargoSystem : SharedCargoSystem [Dependency] private readonly StackSystem _stack = default!; [Dependency] private readonly StationSystem _station = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; + [Dependency] private readonly MetaDataSystem _metaSystem = default!; private ISawmill _sawmill = default!; @@ -76,7 +77,7 @@ public sealed partial class CargoSystem : SharedCargoSystem component.Balance += balanceAdded; var query = EntityQueryEnumerator(); - while (query.MoveNext(out var oUid, out var oComp)) + while (query.MoveNext(out var oUid, out var _)) { if (!_uiSystem.IsUiOpen(oUid, CargoConsoleUiKey.Orders)) continue; @@ -85,7 +86,7 @@ public sealed partial class CargoSystem : SharedCargoSystem if (station != uid) continue; - UpdateOrderState(oComp, station); + UpdateOrderState(oUid, station); } } } diff --git a/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs b/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs index a7089df4e5..9254fe1532 100644 --- a/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs +++ b/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs @@ -36,7 +36,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// and use this method to update its state so the cartridge loaders state can be added to it. /// /// - public void UpdateUiState(EntityUid loaderUid, CartridgeLoaderUiState state, IPlayerSession? session = default!, CartridgeLoaderComponent? loader = default!) + public void UpdateUiState(EntityUid loaderUid, CartridgeLoaderUiState state, IPlayerSession? session = default!, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader)) return; @@ -44,9 +44,8 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem state.ActiveUI = loader.ActiveProgram; state.Programs = GetAvailablePrograms(loaderUid, loader); - var ui = _userInterfaceSystem.GetUiOrNull(loader.Owner, loader.UiKey); - if (ui != null) - _userInterfaceSystem.SetUiState(ui, state, session); + if (_userInterfaceSystem.TryGetUi(loaderUid, loader.UiKey, out var ui)) + UserInterfaceSystem.SetUiState(ui, state, session); } /// @@ -65,9 +64,8 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem if (!Resolve(loaderUid, ref loader)) return; - var ui = _userInterfaceSystem.GetUiOrNull(loader.Owner, loader.UiKey); - if (ui != null) - _userInterfaceSystem.SetUiState(ui, state, session); + if (_userInterfaceSystem.TryGetUi(loaderUid, loader.UiKey, out var ui)) + UserInterfaceSystem.SetUiState(ui, state, session); } /// @@ -76,7 +74,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// The cartridge loaders uid /// The cartridge loader component /// A list of all the available program entity ids - public List GetAvailablePrograms(EntityUid uid, CartridgeLoaderComponent? loader = default!) + public List GetAvailablePrograms(EntityUid uid, CartridgeLoaderComponent? loader = default!) { if (!Resolve(uid, ref loader)) return new List(); @@ -120,7 +118,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// Whether the program can be deinstalled or not /// The cartridge loader component /// Whether installing the cartridge was successful - public bool InstallProgram(EntityUid loaderUid, string prototype, bool deinstallable = true, CartridgeLoaderComponent? loader = default!) + public bool InstallProgram(EntityUid loaderUid, string prototype, bool deinstallable = true, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader) || loader.InstalledPrograms.Count >= loader.DiskSpace) return false; @@ -150,7 +148,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// The uid of the program to be uninstalled /// The cartridge loader component /// Whether uninstalling the program was successful - public bool UninstallProgram(EntityUid loaderUid, EntityUid programUid, CartridgeLoaderComponent? loader = default!) + public bool UninstallProgram(EntityUid loaderUid, EntityUid programUid, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader) || !ContainsCartridge(programUid, loader, true)) return false; @@ -168,7 +166,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// /// Activates a program or cartridge and displays its ui fragment. Deactivates any previously active program. /// - public void ActivateProgram(EntityUid loaderUid, EntityUid programUid, CartridgeLoaderComponent? loader = default!) + public void ActivateProgram(EntityUid loaderUid, EntityUid programUid, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader)) return; @@ -189,7 +187,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// /// Deactivates the currently active program or cartridge. /// - public void DeactivateProgram(EntityUid loaderUid, EntityUid programUid, CartridgeLoaderComponent? loader = default!) + public void DeactivateProgram(EntityUid loaderUid, EntityUid programUid, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader)) return; @@ -210,7 +208,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// /// Programs wanting to use this functionality will have to provide a way to register and unregister themselves as background programs through their ui fragment. /// - public void RegisterBackgroundProgram(EntityUid loaderUid, EntityUid cartridgeUid, CartridgeLoaderComponent? loader = default!) + public void RegisterBackgroundProgram(EntityUid loaderUid, EntityUid cartridgeUid, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader)) return; @@ -227,7 +225,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem /// /// Unregisters the given program as running in the background /// - public void UnregisterBackgroundProgram(EntityUid loaderUid, EntityUid cartridgeUid, CartridgeLoaderComponent? loader = default!) + public void UnregisterBackgroundProgram(EntityUid loaderUid, EntityUid cartridgeUid, CartridgeLoaderComponent? loader = default!) { if (!Resolve(loaderUid, ref loader)) return; @@ -306,7 +304,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem RaiseLocalEvent(component.ActiveProgram.Value, new CartridgeUiReadyEvent(loaderUid)); break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException($"Unrecognized UI action passed from cartridge loader ui {message.Action}."); } } @@ -379,7 +377,7 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem } } - private bool ContainsCartridge(EntityUid cartridgeUid, CartridgeLoaderComponent loader , bool onlyInstalled = false) + private static bool ContainsCartridge(EntityUid cartridgeUid, CartridgeLoaderComponent loader, bool onlyInstalled = false) { return !onlyInstalled && loader.CartridgeSlot.Item?.Equals(cartridgeUid) == true || loader.InstalledPrograms.Contains(cartridgeUid); } diff --git a/Content.Server/Cloning/CloningConsoleSystem.cs b/Content.Server/Cloning/CloningConsoleSystem.cs index 0391cf541b..165923038e 100644 --- a/Content.Server/Cloning/CloningConsoleSystem.cs +++ b/Content.Server/Cloning/CloningConsoleSystem.cs @@ -1,10 +1,8 @@ using System.Linq; using JetBrains.Annotations; -using Robust.Shared.Timing; using Content.Server.Administration.Logs; using Content.Server.Medical.Components; using Content.Server.Cloning.Components; -using Content.Server.DeviceLinking.Events; using Content.Server.DeviceLinking.Systems; using Content.Server.Power.Components; using Content.Server.Mind.Components; @@ -62,12 +60,12 @@ namespace Content.Server.Cloning TryClone(uid, consoleComponent.CloningPod.Value, consoleComponent.GeneticScanner.Value, consoleComponent: consoleComponent); break; } - UpdateUserInterface(consoleComponent); + UpdateUserInterface(uid, consoleComponent); } private void OnPowerChanged(EntityUid uid, CloningConsoleComponent component, ref PowerChangedEvent args) { - UpdateUserInterface(component); + UpdateUserInterface(uid, component); } private void OnMapInit(EntityUid uid, CloningConsoleComponent component, MapInitEvent args) @@ -115,12 +113,12 @@ namespace Content.Server.Cloning if (args.Port == CloningConsoleComponent.PodPort) component.CloningPod = null; - UpdateUserInterface(component); + UpdateUserInterface(uid, component); } private void OnUIOpen(EntityUid uid, CloningConsoleComponent component, AfterActivatableUIOpenEvent args) { - UpdateUserInterface(component); + UpdateUserInterface(uid, component); } private void OnAnchorChanged(EntityUid uid, CloningConsoleComponent component, ref AnchorStateChangedEvent args) @@ -130,27 +128,27 @@ namespace Content.Server.Cloning RecheckConnections(uid, component.CloningPod, component.GeneticScanner, component); return; } - UpdateUserInterface(component); + UpdateUserInterface(uid, component); } - public void UpdateUserInterface(CloningConsoleComponent consoleComponent) + public void UpdateUserInterface(EntityUid consoleUid, CloningConsoleComponent consoleComponent) { - var ui = _uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key); - if (ui == null) + if (!_uiSystem.TryGetUi(consoleUid, CloningConsoleUiKey.Key, out var ui)) return; - if (!_powerReceiverSystem.IsPowered(consoleComponent.Owner)) + + if (!_powerReceiverSystem.IsPowered(consoleUid)) { _uiSystem.CloseAll(ui); return; } var newState = GetUserInterfaceState(consoleComponent); - _uiSystem.SetUiState(ui, newState); + UserInterfaceSystem.SetUiState(ui, newState); } public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent? cloningPod = null, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null) { - if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp)) + if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp)) return; if (!Transform(cloningPodUid).Anchored || !Transform(scannerUid).Anchored) @@ -192,7 +190,7 @@ namespace Content.Server.Cloning consoleComp.CloningPodInRange = podDistance <= consoleComp.MaxDistance; } - UpdateUserInterface(consoleComp); + UpdateUserInterface(console, consoleComp); } private CloningConsoleBoundUserInterfaceState GetUserInterfaceState(CloningConsoleComponent consoleComponent) { diff --git a/Content.Server/Cloning/CloningSystem.cs b/Content.Server/Cloning/CloningSystem.cs index 993099f997..eb57aa6ad3 100644 --- a/Content.Server/Cloning/CloningSystem.cs +++ b/Content.Server/Cloning/CloningSystem.cs @@ -33,7 +33,6 @@ using Robust.Shared.Random; using Robust.Shared.Configuration; using Robust.Shared.Containers; using Robust.Shared.Physics.Components; -using Content.Shared.Humanoid; using Content.Shared.Doors.Components; using Content.Shared.Emag.Systems; using Robust.Shared.Audio; @@ -66,6 +65,7 @@ namespace Content.Server.Cloning [Dependency] private readonly MaterialStorageSystem _material = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly MindSystem _mindSystem = default!; + [Dependency] private readonly MetaDataSystem _metaSystem = default!; public readonly Dictionary ClonesWaitingForMind = new(); public const float EasyModeCloningCost = 0.7f; @@ -87,7 +87,7 @@ namespace Content.Server.Cloning private void OnComponentInit(EntityUid uid, CloningPodComponent clonePod, ComponentInit args) { - clonePod.BodyContainer = _containerSystem.EnsureContainer(clonePod.Owner, "clonepod-bodyContainer"); + clonePod.BodyContainer = _containerSystem.EnsureContainer(uid, "clonepod-bodyContainer"); _signalSystem.EnsureSinkPorts(uid, CloningPodComponent.PodPort); } @@ -124,12 +124,12 @@ namespace Content.Server.Cloning if (clonedComponent.Parent == EntityUid.Invalid || !EntityManager.EntityExists(clonedComponent.Parent) || !TryComp(clonedComponent.Parent, out var cloningPodComponent) || - clonedComponent.Owner != cloningPodComponent.BodyContainer.ContainedEntity) + uid != cloningPodComponent.BodyContainer.ContainedEntity) { - EntityManager.RemoveComponent(clonedComponent.Owner); + EntityManager.RemoveComponent(uid); return; } - UpdateStatus(CloningPodStatus.Cloning, cloningPodComponent); + UpdateStatus(clonedComponent.Parent, CloningPodStatus.Cloning, cloningPodComponent); } private void OnPortDisconnected(EntityUid uid, CloningPodComponent pod, PortDisconnectedEvent args) @@ -147,7 +147,7 @@ namespace Content.Server.Cloning _cloningConsoleSystem.RecheckConnections(component.ConnectedConsole.Value, uid, console.GeneticScanner, console); return; } - _cloningConsoleSystem.UpdateUserInterface(console); + _cloningConsoleSystem.UpdateUserInterface(component.ConnectedConsole.Value, console); } private void OnExamined(EntityUid uid, CloningPodComponent component, ExaminedEvent args) @@ -230,11 +230,11 @@ namespace Content.Server.Cloning chance *= failChanceModifier; if (cellularDmg > 0 && clonePod.ConnectedConsole != null) - _chatSystem.TrySendInGameICMessage(clonePod.ConnectedConsole.Value, Loc.GetString("cloning-console-cellular-warning", ("percent", Math.Round(100 - (chance * 100)))), InGameICChatType.Speak, false); + _chatSystem.TrySendInGameICMessage(clonePod.ConnectedConsole.Value, Loc.GetString("cloning-console-cellular-warning", ("percent", Math.Round(100 - chance * 100))), InGameICChatType.Speak, false); if (_robustRandom.Prob(chance)) { - UpdateStatus(CloningPodStatus.Gore, clonePod); + UpdateStatus(uid, CloningPodStatus.Gore, clonePod); clonePod.FailedClone = true; AddComp(uid); return true; @@ -242,21 +242,21 @@ namespace Content.Server.Cloning } // end of genetic damage checks - var mob = Spawn(speciesPrototype.Prototype, Transform(clonePod.Owner).MapPosition); + var mob = Spawn(speciesPrototype.Prototype, Transform(uid).MapPosition); _humanoidSystem.CloneAppearance(bodyToClone, mob); var ev = new CloningEvent(bodyToClone, mob); RaiseLocalEvent(bodyToClone, ref ev); if (!ev.NameHandled) - MetaData(mob).EntityName = MetaData(bodyToClone).EntityName; + _metaSystem.SetEntityName(mob, MetaData(bodyToClone).EntityName); var cloneMindReturn = EntityManager.AddComponent(mob); cloneMindReturn.Mind = mind; - cloneMindReturn.Parent = clonePod.Owner; + cloneMindReturn.Parent = uid; clonePod.BodyContainer.Insert(mob); ClonesWaitingForMind.Add(mind, mob); - UpdateStatus(CloningPodStatus.NoMind, clonePod); + UpdateStatus(uid, CloningPodStatus.NoMind, clonePod); _euiManager.OpenEui(new AcceptCloningEui(mind, this), client); AddComp(uid); @@ -276,17 +276,18 @@ namespace Content.Server.Cloning return true; } - public void UpdateStatus(CloningPodStatus status, CloningPodComponent cloningPod) + public void UpdateStatus(EntityUid podUid, CloningPodStatus status, CloningPodComponent cloningPod) { cloningPod.Status = status; - _appearance.SetData(cloningPod.Owner, CloningPodVisuals.Status, cloningPod.Status); + _appearance.SetData(podUid, CloningPodVisuals.Status, cloningPod.Status); } public override void Update(float frameTime) { - foreach (var (_, cloning) in EntityManager.EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var _, out var cloning)) { - if (!_powerReceiverSystem.IsPowered(cloning.Owner)) + if (!_powerReceiverSystem.IsPowered(uid)) continue; if (cloning.BodyContainer.ContainedEntity == null && !cloning.FailedClone) @@ -297,9 +298,9 @@ namespace Content.Server.Cloning continue; if (cloning.FailedClone) - EndFailedCloning(cloning.Owner, cloning); + EndFailedCloning(uid, cloning); else - Eject(cloning.Owner, cloning); + Eject(uid, cloning); } } @@ -321,14 +322,14 @@ namespace Content.Server.Cloning if (!Resolve(uid, ref clonePod)) return; - if (clonePod.BodyContainer.ContainedEntity is not {Valid: true} entity || clonePod.CloningProgress < clonePod.CloningTime) + if (clonePod.BodyContainer.ContainedEntity is not { Valid: true } entity || clonePod.CloningProgress < clonePod.CloningTime) return; EntityManager.RemoveComponent(entity); clonePod.BodyContainer.Remove(entity); clonePod.CloningProgress = 0f; clonePod.UsedBiomass = 0; - UpdateStatus(CloningPodStatus.Idle, clonePod); + UpdateStatus(uid, CloningPodStatus.Idle, clonePod); RemCompDeferred(uid); } @@ -336,7 +337,7 @@ namespace Content.Server.Cloning { clonePod.FailedClone = false; clonePod.CloningProgress = 0f; - UpdateStatus(CloningPodStatus.Idle, clonePod); + UpdateStatus(uid, CloningPodStatus.Idle, clonePod); var transform = Transform(uid); var indices = _transformSystem.GetGridOrMapTilePosition(uid); @@ -350,7 +351,7 @@ namespace Content.Server.Cloning Solution bloodSolution = new(); - int i = 0; + var i = 0; while (i < 1) { tileMix?.AdjustMoles(Gas.Miasma, 6f); @@ -362,7 +363,7 @@ namespace Content.Server.Cloning if (!HasComp(uid)) { - _material.SpawnMultipleFromMaterial(_robustRandom.Next(1, (int) (clonePod.UsedBiomass / 2.5)), clonePod.RequiredMaterial, Transform(uid).Coordinates); + _material.SpawnMultipleFromMaterial(_robustRandom.Next(1, (int) (clonePod.UsedBiomass / 2.5)), clonePod.RequiredMaterial, Transform(uid).Coordinates); } clonePod.UsedBiomass = 0; @@ -386,7 +387,8 @@ namespace Content.Server.Cloning public readonly EntityUid Source; public readonly EntityUid Target; - public CloningEvent(EntityUid source, EntityUid target) { + public CloningEvent(EntityUid source, EntityUid target) + { Source = source; Target = target; } diff --git a/Content.Server/Communications/CommunicationsConsoleSystem.cs b/Content.Server/Communications/CommunicationsConsoleSystem.cs index 45d291ec5d..b9b701efdb 100644 --- a/Content.Server/Communications/CommunicationsConsoleSystem.cs +++ b/Content.Server/Communications/CommunicationsConsoleSystem.cs @@ -37,6 +37,7 @@ namespace Content.Server.Communications [Dependency] private readonly StationSystem _stationSystem = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; private const int MaxMessageLength = 256; private const int MaxMessageNewlines = 2; @@ -46,7 +47,7 @@ namespace Content.Server.Communications { // All events that refresh the BUI SubscribeLocalEvent(OnAlertLevelChanged); - SubscribeLocalEvent((_, comp, _) => UpdateCommsConsoleInterface(comp)); + SubscribeLocalEvent((uid, comp, _) => UpdateCommsConsoleInterface(uid, comp)); SubscribeLocalEvent(_ => OnGenericBroadcastEvent()); SubscribeLocalEvent(_ => OnGenericBroadcastEvent()); @@ -59,7 +60,8 @@ namespace Content.Server.Communications public override void Update(float frameTime) { - foreach (var comp in EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp)) { // TODO refresh the UI in a less horrible way if (comp.AnnouncementCooldownRemaining >= 0f) @@ -74,8 +76,8 @@ namespace Content.Server.Communications comp.UIUpdateAccumulator -= UIUpdateInterval; - if (comp.UserInterface is {} ui && ui.SubscribedSessions.Count > 0) - UpdateCommsConsoleInterface(comp); + if (comp.UserInterface is { } ui && ui.SubscribedSessions.Count > 0) + UpdateCommsConsoleInterface(uid, comp); } base.Update(frameTime); @@ -86,9 +88,10 @@ namespace Content.Server.Communications /// private void OnGenericBroadcastEvent() { - foreach (var comp in EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp)) { - UpdateCommsConsoleInterface(comp); + UpdateCommsConsoleInterface(uid, comp); } } @@ -98,13 +101,12 @@ namespace Content.Server.Communications /// Alert level changed event arguments private void OnAlertLevelChanged(AlertLevelChangedEvent args) { - foreach (var comp in EntityQuery(true)) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp)) { - var entStation = _stationSystem.GetOwningStation(comp.Owner); + var entStation = _stationSystem.GetOwningStation(uid); if (args.Station == entStation) - { - UpdateCommsConsoleInterface(comp); - } + UpdateCommsConsoleInterface(uid, comp); } } @@ -113,9 +115,10 @@ namespace Content.Server.Communications /// public void UpdateCommsConsoleInterface() { - foreach (var comp in EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp)) { - UpdateCommsConsoleInterface(comp); + UpdateCommsConsoleInterface(uid, comp); } } @@ -123,10 +126,8 @@ namespace Content.Server.Communications /// Updates the UI for a particular comms console. /// /// - public void UpdateCommsConsoleInterface(CommunicationsConsoleComponent comp) + public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComponent comp) { - var uid = comp.Owner; - var stationUid = _stationSystem.GetOwningStation(uid); List? levels = null; string currentLevel = default!; @@ -154,19 +155,18 @@ namespace Content.Server.Communications } } - comp.UserInterface?.SetState( - new CommunicationsConsoleInterfaceState( + if (comp.UserInterface is not null) + UserInterfaceSystem.SetUiState(comp.UserInterface, new CommunicationsConsoleInterfaceState( CanAnnounce(comp), CanCallOrRecall(comp), levels, currentLevel, currentDelay, _roundEndSystem.ExpectedCountdownEnd - ) - ); + )); } - private bool CanAnnounce(CommunicationsConsoleComponent comp) + private static bool CanAnnounce(CommunicationsConsoleComponent comp) { return comp.AnnouncementCooldownRemaining <= 0f; } @@ -207,7 +207,7 @@ namespace Content.Server.Communications private void OnSelectAlertLevelMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleSelectAlertLevelMessage message) { - if (message.Session.AttachedEntity is not {Valid: true} mob) return; + if (message.Session.AttachedEntity is not { Valid: true } mob) return; if (!CanUse(mob, uid)) { _popupSystem.PopupCursor(Loc.GetString("comms-console-permission-denied"), message.Session, PopupType.Medium); @@ -224,7 +224,8 @@ namespace Content.Server.Communications private void OnAnnounceMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleAnnounceMessage message) { - var msgChars = (message.Message.Length <= MaxMessageLength ? message.Message.Trim() : $"{message.Message.Trim().Substring(0, MaxMessageLength)}...").ToCharArray(); + var msgWords = message.Message.Trim(); + var msgChars = (msgWords.Length <= MaxMessageLength ? msgWords : $"{msgWords[0..MaxMessageLength]}...").ToCharArray(); var newlines = 0; for (var i = 0; i < msgChars.Length; i++) @@ -240,7 +241,7 @@ namespace Content.Server.Communications var msg = new string(msgChars); var author = Loc.GetString("comms-console-announcement-unknown-sender"); - if (message.Session.AttachedEntity is {Valid: true} mob) + if (message.Session.AttachedEntity is { Valid: true } mob) { if (!CanAnnounce(comp)) { @@ -260,7 +261,7 @@ namespace Content.Server.Communications } comp.AnnouncementCooldownRemaining = comp.DelayBetweenAnnouncements; - UpdateCommsConsoleInterface(comp); + UpdateCommsConsoleInterface(uid, comp); // allow admemes with vv Loc.TryGetString(comp.AnnouncementDisplayName, out var title); @@ -285,7 +286,7 @@ namespace Content.Server.Communications private void OnCallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleCallEmergencyShuttleMessage message) { if (!CanCallOrRecall(comp)) return; - if (message.Session.AttachedEntity is not {Valid: true} mob) return; + if (message.Session.AttachedEntity is not { Valid: true } mob) return; if (!CanUse(mob, uid)) { _popupSystem.PopupEntity(Loc.GetString("comms-console-permission-denied"), uid, message.Session); @@ -298,7 +299,7 @@ namespace Content.Server.Communications private void OnRecallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleRecallEmergencyShuttleMessage message) { if (!CanCallOrRecall(comp)) return; - if (message.Session.AttachedEntity is not {Valid: true} mob) return; + if (message.Session.AttachedEntity is not { Valid: true } mob) return; if (!CanUse(mob, uid)) { _popupSystem.PopupEntity(Loc.GetString("comms-console-permission-denied"), uid, message.Session); diff --git a/Content.Server/Configurable/ConfigurationSystem.cs b/Content.Server/Configurable/ConfigurationSystem.cs index 9b43d0f65d..cfe580f391 100644 --- a/Content.Server/Configurable/ConfigurationSystem.cs +++ b/Content.Server/Configurable/ConfigurationSystem.cs @@ -43,7 +43,7 @@ public sealed class ConfigurationSystem : EntitySystem private void UpdateUi(EntityUid uid, ConfigurationComponent component) { if (_uiSystem.TryGetUi(uid, ConfigurationUiKey.Key, out var ui)) - ui.SetState(new ConfigurationBoundUserInterfaceState(component.Config)); + UserInterfaceSystem.SetUiState(ui, new ConfigurationBoundUserInterfaceState(component.Config)); } private void OnUpdate(EntityUid uid, ConfigurationComponent component, ConfigurationUpdatedMessage args) diff --git a/Content.Server/Crayon/CrayonSystem.cs b/Content.Server/Crayon/CrayonSystem.cs index e326bbb0c0..fd684f53d7 100644 --- a/Content.Server/Crayon/CrayonSystem.cs +++ b/Content.Server/Crayon/CrayonSystem.cs @@ -4,7 +4,6 @@ using Content.Server.Administration.Logs; using Content.Server.Decals; using Content.Server.Nutrition.EntitySystems; using Content.Server.Popups; -using Content.Shared.Audio; using Content.Shared.Crayon; using Content.Shared.Database; using Content.Shared.Decals; @@ -13,15 +12,15 @@ using Content.Shared.Interaction.Events; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.GameStates; -using Robust.Shared.Player; using Robust.Shared.Prototypes; +using Robust.Shared.Random; namespace Content.Server.Crayon; public sealed class CrayonSystem : SharedCrayonSystem { - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly DecalSystem _decals = default!; [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; @@ -33,8 +32,8 @@ public sealed class CrayonSystem : SharedCrayonSystem SubscribeLocalEvent(OnCrayonInit); SubscribeLocalEvent(OnCrayonBoundUI); SubscribeLocalEvent(OnCrayonBoundUIColor); - SubscribeLocalEvent(OnCrayonUse, before: new []{ typeof(FoodSystem) }); - SubscribeLocalEvent(OnCrayonAfterInteract, after: new []{ typeof(FoodSystem) }); + SubscribeLocalEvent(OnCrayonUse, before: new[] { typeof(FoodSystem) }); + SubscribeLocalEvent(OnCrayonAfterInteract, after: new[] { typeof(FoodSystem) }); SubscribeLocalEvent(OnCrayonDropped); SubscribeLocalEvent(OnCrayonGetState); } @@ -67,11 +66,11 @@ public sealed class CrayonSystem : SharedCrayonSystem return; } - if(!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f,-0.5f)), out _, component.Color, cleanable: true)) + if (!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f, -0.5f)), out _, component.Color, cleanable: true)) return; if (component.UseSound != null) - _audio.PlayPvs(component.UseSound, uid, AudioHelpers.WithVariation(0.125f)); + _audio.PlayPvs(component.UseSound, uid, AudioParams.Default.WithVariation(0.125f)); // Decrease "Ammo" component.Charges--; @@ -100,7 +99,7 @@ public sealed class CrayonSystem : SharedCrayonSystem if (component.UserInterface?.SubscribedSessions.Contains(actor.PlayerSession) == true) { // Tell the user interface the selected stuff - _uiSystem.SetUiState(component.UserInterface, new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color)); + UserInterfaceSystem.SetUiState(component.UserInterface, new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color)); } args.Handled = true; diff --git a/Content.Server/DeviceLinking/Systems/SignalTimerSystem.cs b/Content.Server/DeviceLinking/Systems/SignalTimerSystem.cs index 56705274db..c42e1e5a5a 100644 --- a/Content.Server/DeviceLinking/Systems/SignalTimerSystem.cs +++ b/Content.Server/DeviceLinking/Systems/SignalTimerSystem.cs @@ -1,5 +1,4 @@ using Content.Server.DeviceLinking.Components; -using Content.Server.Interaction; using Content.Server.UserInterface; using Content.Shared.Access.Systems; using Content.Shared.MachineLinking; @@ -17,7 +16,6 @@ public sealed class SignalTimerSystem : EntitySystem [Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!; [Dependency] private readonly AccessReaderSystem _accessReader = default!; - [Dependency] private readonly InteractionSystem _interaction = default!; public override void Initialize() { @@ -42,7 +40,7 @@ public sealed class SignalTimerSystem : EntitySystem if (_ui.TryGetUi(uid, SignalTimerUiKey.Key, out var bui)) { - _ui.SetUiState(bui, new SignalTimerBoundUserInterfaceState(component.Label, + UserInterfaceSystem.SetUiState(bui, new SignalTimerBoundUserInterfaceState(component.Label, TimeSpan.FromSeconds(component.Delay).Minutes.ToString("D2"), TimeSpan.FromSeconds(component.Delay).Seconds.ToString("D2"), component.CanEditLabel, @@ -62,7 +60,7 @@ public sealed class SignalTimerSystem : EntitySystem if (_ui.TryGetUi(uid, SignalTimerUiKey.Key, out var bui)) { - _ui.SetUiState(bui, new SignalTimerBoundUserInterfaceState(signalTimer.Label, + UserInterfaceSystem.SetUiState(bui, new SignalTimerBoundUserInterfaceState(signalTimer.Label, TimeSpan.FromSeconds(signalTimer.Delay).Minutes.ToString("D2"), TimeSpan.FromSeconds(signalTimer.Delay).Seconds.ToString("D2"), signalTimer.CanEditLabel, @@ -115,7 +113,7 @@ public sealed class SignalTimerSystem : EntitySystem if (!IsMessageValid(uid, args)) return; - component.Label = args.Text[..Math.Min(5,args.Text.Length)]; + component.Label = args.Text[..Math.Min(5, args.Text.Length)]; _appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, component.Label); } diff --git a/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs b/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs index 61567adb65..276e3ebb65 100644 --- a/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs @@ -68,15 +68,13 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem { base.Update(frameTime); - foreach (var component in EntityManager.EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var component)) { - var uid = component.Owner; - - if (component.ActiveDeviceList != null && EntityManager.EntityExists(component.ActiveDeviceList.Value) && - _interactionSystem.InRangeUnobstructed(uid, component.ActiveDeviceList.Value)) - { + if (component.ActiveDeviceList != null + && EntityManager.EntityExists(component.ActiveDeviceList.Value) + && _interactionSystem.InRangeUnobstructed(uid, component.ActiveDeviceList.Value)) continue; - } //The network configurator is a handheld device. There can only ever be an ui session open for the player holding the device. _uiSystem.TryCloseAll(uid, NetworkConfiguratorUiKey.Configure); @@ -95,10 +93,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem if (!Resolve(configuratorUid, ref configurator)) return; - TryAddNetworkDevice(targetUid, userUid, configurator); + TryAddNetworkDevice(configuratorUid, targetUid, userUid, configurator); } - private void TryAddNetworkDevice(EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator, DeviceNetworkComponent? device = null) + private void TryAddNetworkDevice(EntityUid configuratorUid, EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator, DeviceNetworkComponent? device = null) { if (!targetUid.HasValue || !Resolve(targetUid.Value, ref device, false)) return; @@ -122,7 +120,7 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem return; } - address = $"UID: {targetUid.Value.ToString()}"; + address = $"UID: {targetUid.Value}"; } if (configurator.Devices.ContainsValue(targetUid.Value)) @@ -135,7 +133,6 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem _popupSystem.PopupCursor(Loc.GetString("network-configurator-device-saved", ("address", device.Address), ("device", targetUid)), userUid, PopupType.Medium); - var configuratorUid = configurator.Owner; _adminLogger.Add(LogType.DeviceLinking, LogImpact.Low, $"{ToPrettyString(userUid):actor} saved {ToPrettyString(targetUid.Value):subject} to {ToPrettyString(configuratorUid):tool}"); UpdateListUiState(configuratorUid, configurator); @@ -167,11 +164,11 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem || HasComp(target) && HasComp(configurator.ActiveDeviceLink)) return; - _popupSystem.PopupEntity(Loc.GetString("network-configurator-link-mode-started", ("device", Name(target.Value))), target.Value, user); + _popupSystem.PopupEntity(Loc.GetString("network-configurator-link-mode-started", ("device", Name(target.Value))), target.Value, user); configurator.ActiveDeviceLink = target; } - private void TryLinkDefaults(EntityUid uid, NetworkConfiguratorComponent configurator, EntityUid? targetUid, EntityUid user) + private void TryLinkDefaults(EntityUid _, NetworkConfiguratorComponent configurator, EntityUid? targetUid, EntityUid user) { if (!configurator.LinkModeActive || !configurator.ActiveDeviceLink.HasValue || !targetUid.HasValue || configurator.ActiveDeviceLink == targetUid) @@ -297,11 +294,11 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem if (!HasComp(target)) { - TryAddNetworkDevice(target, user, configurator); + TryAddNetworkDevice(uid, target, user, configurator); return; } - OpenDeviceListUi(target, user, configurator); + OpenDeviceListUi(uid, target, user, configurator); } private void DetermineMode(EntityUid configuratorUid, NetworkConfiguratorComponent configurator, EntityUid? target, EntityUid userUid) @@ -382,7 +379,8 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem return; } - if (configurator is {LinkModeActive: true, ActiveDeviceLink: { }} && (HasComp(args.Target) || HasComp(args.Target))) + if (configurator is { LinkModeActive: true, ActiveDeviceLink: { } } + && (HasComp(args.Target) || HasComp(args.Target))) { AlternativeVerb verb = new() { @@ -460,7 +458,7 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem /// /// Opens the config ui. It can be used to modify the devices in the targets device list. /// - private void OpenDeviceListUi(EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator) + private void OpenDeviceListUi(EntityUid configuratorUid, EntityUid? targetUid, EntityUid userUid, NetworkConfiguratorComponent configurator) { if (Delay(configurator)) return; @@ -470,13 +468,15 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem configurator.ActiveDeviceList = targetUid; Dirty(configurator); - _uiSystem.GetUiOrNull(configurator.Owner, NetworkConfiguratorUiKey.Configure)?.Open(actor.PlayerSession); - _uiSystem.TrySetUiState( - configurator.Owner, - NetworkConfiguratorUiKey.Configure, - new DeviceListUserInterfaceState( + + if (!_uiSystem.TryGetUi(configuratorUid, NetworkConfiguratorUiKey.Configure, out var bui)) + return; + + if (_uiSystem.OpenUi(bui, actor.PlayerSession)) + UserInterfaceSystem.SetUiState(bui, new DeviceListUserInterfaceState( _deviceListSystem.GetDeviceList(configurator.ActiveDeviceList.Value) - .Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet())); + .Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet() + )); } /// @@ -504,7 +504,8 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem component.Devices.Remove(invalidDevice); } - _uiSystem.GetUiOrNull(uid, NetworkConfiguratorUiKey.List)?.SetState(new NetworkConfiguratorUserInterfaceState(devices)); + if (_uiSystem.TryGetUi(uid, NetworkConfiguratorUiKey.List, out var bui)) + UserInterfaceSystem.SetUiState(bui, new NetworkConfiguratorUserInterfaceState(devices)); } /// diff --git a/Content.Server/Disposal/Mailing/MailingUnitSystem.cs b/Content.Server/Disposal/Mailing/MailingUnitSystem.cs index bc70bcb6dc..6e08224778 100644 --- a/Content.Server/Disposal/Mailing/MailingUnitSystem.cs +++ b/Content.Server/Disposal/Mailing/MailingUnitSystem.cs @@ -4,7 +4,6 @@ using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; using Content.Server.Disposal.Unit.EntitySystems; using Content.Server.Power.Components; -using Content.Server.UserInterface; using Content.Shared.Disposal; using Content.Shared.Interaction; using Robust.Server.GameObjects; @@ -178,7 +177,7 @@ public sealed class MailingUnitSystem : EntitySystem var state = new MailingUnitBoundUserInterfaceState(component.DisposalUnitInterfaceState, component.Target, component.TargetList, component.Tag); if (_userInterfaceSystem.TryGetUi(uid, MailingUnitUiKey.Key, out var bui)) - _userInterfaceSystem.SetUiState(bui, state); + UserInterfaceSystem.SetUiState(bui, state); } private void OnTargetSelected(EntityUid uid, MailingUnitComponent component, TargetSelectedMessage args) diff --git a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs index 8bd31ce2d6..cf819dfd78 100644 --- a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs +++ b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs @@ -326,7 +326,7 @@ namespace Content.Server.Disposal.Tube } if (_uiSystem.TryGetUi(uid, SharedDisposalTaggerComponent.DisposalTaggerUiKey.Key, out var bui)) - _uiSystem.SetUiState(bui, new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState(tagger.Tag)); + UserInterfaceSystem.SetUiState(bui, new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState(tagger.Tag)); } /// @@ -339,7 +339,7 @@ namespace Content.Server.Disposal.Tube if (router.Tags.Count <= 0) { if (bui is not null) - _uiSystem.SetUiState(bui, new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState("")); + UserInterfaceSystem.SetUiState(bui, new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState("")); return; } @@ -354,7 +354,7 @@ namespace Content.Server.Disposal.Tube taglist.Remove(taglist.Length - 2, 2); if (bui is not null) - _uiSystem.SetUiState(bui, new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState(taglist.ToString())); + UserInterfaceSystem.SetUiState(bui, new SharedDisposalTaggerComponent.DisposalTaggerUserInterfaceState(taglist.ToString())); } private void OnAnchorChange(EntityUid uid, DisposalTubeComponent component, ref AnchorStateChangedEvent args) diff --git a/Content.Server/Instruments/InstrumentSystem.cs b/Content.Server/Instruments/InstrumentSystem.cs index 6e395a27bb..31269c5dcd 100644 --- a/Content.Server/Instruments/InstrumentSystem.cs +++ b/Content.Server/Instruments/InstrumentSystem.cs @@ -198,7 +198,9 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem // Just in case Clean((instrument).Owner); - instrument.UserInterface?.CloseAll(); + + if (instrument.UserInterface is not null) + _userInterfaceSystem.CloseAll(instrument.UserInterface); } instrument.Timer += frameTime; @@ -217,7 +219,7 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem if (!Resolve(uid, ref component)) return; - var ui = uid.GetUIOrNull(InstrumentUiKey.Key); - ui?.Toggle(session); + if (_userInterfaceSystem.TryGetUi(uid, InstrumentUiKey.Key, out var bui)) + _userInterfaceSystem.ToggleUi(bui, session); } } diff --git a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs index 66b3c03910..fe8064381b 100644 --- a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs @@ -50,14 +50,14 @@ namespace Content.Server.Kitchen.EntitySystems SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnSolutionChange); - SubscribeLocalEvent(OnInteractUsing, after: new[]{typeof(AnchorableSystem)}); + SubscribeLocalEvent(OnInteractUsing, after: new[] { typeof(AnchorableSystem) }); SubscribeLocalEvent(OnBreak); SubscribeLocalEvent(OnPowerChanged); SubscribeLocalEvent(OnSuicide); SubscribeLocalEvent(OnRefreshParts); SubscribeLocalEvent(OnUpgradeExamine); - SubscribeLocalEvent((u,c,m) => Wzhzhzh(u,c,m.Session.AttachedEntity)); + SubscribeLocalEvent((u, c, m) => Wzhzhzh(u, c, m.Session.AttachedEntity)); SubscribeLocalEvent(OnEjectMessage); SubscribeLocalEvent(OnEjectIndex); SubscribeLocalEvent(OnSelectTime); @@ -70,7 +70,7 @@ namespace Content.Server.Kitchen.EntitySystems { if (!TryComp(uid, out var microwaveComponent)) return; - SetAppearance(microwaveComponent, MicrowaveVisualState.Cooking); + SetAppearance(uid, MicrowaveVisualState.Cooking, microwaveComponent); microwaveComponent.PlayingStream = _audio.PlayPvs(microwaveComponent.LoopingSound, uid, AudioParams.Default.WithLoop(true).WithMaxDistance(5)); @@ -80,7 +80,7 @@ namespace Content.Server.Kitchen.EntitySystems { if (!TryComp(uid, out var microwaveComponent)) return; - SetAppearance(microwaveComponent, MicrowaveVisualState.Idle); + SetAppearance(uid, MicrowaveVisualState.Idle, microwaveComponent); microwaveComponent.PlayingStream?.Stop(); } @@ -175,7 +175,7 @@ namespace Content.Server.Kitchen.EntitySystems private void OnInit(EntityUid uid, MicrowaveComponent component, ComponentInit ags) { - component.Storage = _container.EnsureContainer(uid,"microwave_entity_container"); + component.Storage = _container.EnsureContainer(uid, "microwave_entity_container"); } private void OnSuicide(EntityUid uid, MicrowaveComponent component, SuicideEvent args) @@ -227,7 +227,7 @@ namespace Content.Server.Kitchen.EntitySystems private void OnInteractUsing(EntityUid uid, MicrowaveComponent component, InteractUsingEvent args) { - if(args.Handled) + if (args.Handled) return; if (!(TryComp(uid, out var apc) && apc.Powered)) { @@ -255,7 +255,7 @@ namespace Content.Server.Kitchen.EntitySystems private void OnBreak(EntityUid uid, MicrowaveComponent component, BreakageEventArgs args) { component.Broken = true; - SetAppearance(component, MicrowaveVisualState.Broken); + SetAppearance(uid, MicrowaveVisualState.Broken, component); RemComp(uid); _sharedContainer.EmptyContainer(component.Storage); UpdateUserInterfaceState(uid, component); @@ -265,7 +265,7 @@ namespace Content.Server.Kitchen.EntitySystems { if (!args.Powered) { - SetAppearance(component, MicrowaveVisualState.Idle); + SetAppearance(uid, MicrowaveVisualState.Idle, component); RemComp(uid); _sharedContainer.EmptyContainer(component.Storage); } @@ -288,22 +288,22 @@ namespace Content.Server.Kitchen.EntitySystems var ui = _userInterface.GetUiOrNull(uid, MicrowaveUiKey.Key); if (ui == null) return; - var state = new MicrowaveUpdateUserInterfaceState( + + UserInterfaceSystem.SetUiState(ui, new MicrowaveUpdateUserInterfaceState( component.Storage.ContainedEntities.ToArray(), HasComp(uid), component.CurrentCookTimeButtonIndex, component.CurrentCookTimerTime - ); - _userInterface.SetUiState(ui, state); + )); } - public void SetAppearance(MicrowaveComponent component, MicrowaveVisualState state) + public void SetAppearance(EntityUid uid, MicrowaveVisualState state, MicrowaveComponent component) { var display = component.Broken ? MicrowaveVisualState.Broken : state; - _appearance.SetData(component.Owner, PowerDeviceVisuals.VisualState, display); + _appearance.SetData(uid, PowerDeviceVisuals.VisualState, display); } - public bool HasContents(MicrowaveComponent component) + public static bool HasContents(MicrowaveComponent component) { return component.Storage.ContainedEntities.Any(); } @@ -338,7 +338,7 @@ namespace Content.Server.Kitchen.EntitySystems if (_tag.HasTag(item, "MicrowaveMachineUnsafe") || _tag.HasTag(item, "Metal")) { component.Broken = true; - SetAppearance(component, MicrowaveVisualState.Broken); + SetAppearance(uid, MicrowaveVisualState.Broken, component); _audio.PlayPvs(component.ItemBreakSound, uid); return; } @@ -390,11 +390,11 @@ namespace Content.Server.Kitchen.EntitySystems UpdateUserInterfaceState(uid, component); } - public (FoodRecipePrototype, int) CanSatisfyRecipe(MicrowaveComponent component, FoodRecipePrototype recipe, Dictionary solids, Dictionary reagents) + public static (FoodRecipePrototype, int) CanSatisfyRecipe(MicrowaveComponent component, FoodRecipePrototype recipe, Dictionary solids, Dictionary reagents) { var portions = 0; - if(component.CurrentCookTimerTime % recipe.CookTime != 0) + if (component.CurrentCookTimerTime % recipe.CookTime != 0) { //can't be a multiple of this recipe return (recipe, 0); @@ -427,13 +427,15 @@ namespace Content.Server.Kitchen.EntitySystems } //cook only as many of those portions as time allows - return (recipe, (int)Math.Min(portions, component.CurrentCookTimerTime / recipe.CookTime)); + return (recipe, (int) Math.Min(portions, component.CurrentCookTimerTime / recipe.CookTime)); } public override void Update(float frameTime) { base.Update(frameTime); - foreach (var (active, microwave) in EntityManager.EntityQuery()) + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var active, out var microwave)) { //check if there's still cook time left active.CookTimeRemaining -= frameTime; @@ -445,7 +447,7 @@ namespace Content.Server.Kitchen.EntitySystems if (active.PortionedRecipe.Item1 != null) { - var coords = Transform(microwave.Owner).Coordinates; + var coords = Transform(uid).Coordinates; for (var i = 0; i < active.PortionedRecipe.Item2; i++) { SubtractContents(microwave, active.PortionedRecipe.Item1); @@ -454,9 +456,9 @@ namespace Content.Server.Kitchen.EntitySystems } _sharedContainer.EmptyContainer(microwave.Storage); - UpdateUserInterfaceState(microwave.Owner, microwave); - EntityManager.RemoveComponentDeferred(active.Owner); - _audio.PlayPvs(microwave.FoodDoneSound, microwave.Owner, AudioParams.Default.WithVolume(-1)); + UpdateUserInterfaceState(uid, microwave); + EntityManager.RemoveComponentDeferred(uid); + _audio.PlayPvs(microwave.FoodDoneSound, uid, AudioParams.Default.WithVolume(-1)); } } diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index beec389d8e..508b580fa1 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -46,7 +46,7 @@ namespace Content.Server.Lathe SubscribeLocalEvent(OnLatheQueueRecipeMessage); SubscribeLocalEvent(OnLatheSyncRequestMessage); - SubscribeLocalEvent((u,c,_) => UpdateUserInterfaceState(u,c)); + SubscribeLocalEvent((u, c, _) => UpdateUserInterfaceState(u, c)); SubscribeLocalEvent(OnMaterialAmountChanged); SubscribeLocalEvent(OnGetRecipes); @@ -55,12 +55,12 @@ namespace Content.Server.Lathe public override void Update(float frameTime) { var query = EntityQueryEnumerator(); - while(query.MoveNext(out var uid, out var comp, out var lathe)) + while (query.MoveNext(out var uid, out var comp, out var lathe)) { if (lathe.CurrentRecipe == null) continue; - if ( _timing.CurTime - comp.StartTime >= comp.ProductionLength) + if (_timing.CurTime - comp.StartTime >= comp.ProductionLength) FinishProducing(uid, lathe); } } @@ -70,7 +70,7 @@ namespace Content.Server.Lathe if (args.Storage != uid) return; var materialWhitelist = new List(); - var recipes = GetAllBaseRecipes(component); + var recipes = GetAllBaseRecipes(component); foreach (var id in recipes) { if (!_proto.TryIndex(id, out var proto)) @@ -108,7 +108,7 @@ namespace Content.Server.Lathe return ev.Recipes; } - public List GetAllBaseRecipes(LatheComponent component) + public static List GetAllBaseRecipes(LatheComponent component) { return component.StaticRecipes.Union(component.DynamicRecipes).ToList(); } @@ -186,7 +186,7 @@ namespace Content.Server.Lathe var producing = component.CurrentRecipe ?? component.Queue.FirstOrDefault(); var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing); - _uiSys.SetUiState(ui, state); + UserInterfaceSystem.SetUiState(ui, state); } private void OnGetRecipes(EntityUid uid, TechnologyDatabaseComponent component, LatheGetRecipesEvent args) diff --git a/Content.Server/MachineLinking/System/SignalLinkerSystem.cs b/Content.Server/MachineLinking/System/SignalLinkerSystem.cs index 008e878891..08b2ef9c76 100644 --- a/Content.Server/MachineLinking/System/SignalLinkerSystem.cs +++ b/Content.Server/MachineLinking/System/SignalLinkerSystem.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Diagnostics.CodeAnalysis; using Content.Server.DeviceLinking.Components; using Content.Server.MachineLinking.Components; -using Content.Server.MachineLinking.Events; using Content.Server.Power.Components; using Content.Server.Tools; using Content.Shared.DeviceLinking.Events; @@ -246,9 +245,9 @@ namespace Content.Server.MachineLinking.System return; } - if (TryGetOrOpenUI(actor, linker, out var bui)) + if (TryGetOrOpenUI(args.Used, out var bui, actor)) { - TryUpdateUI(linker, transmitter, receiver, bui); + TryUpdateUI(args.Used, uid, linker.SavedReceiver!.Value, bui, transmitter, receiver); args.Handled = true; } } @@ -275,26 +274,29 @@ namespace Content.Server.MachineLinking.System return; } - if (TryGetOrOpenUI(actor, linker, out var bui)) + if (TryGetOrOpenUI(args.Used, out var bui, actor)) { - TryUpdateUI(linker, transmitter, receiver, bui); + TryUpdateUI(args.Used, linker.SavedTransmitter!.Value, uid, bui, transmitter, receiver); args.Handled = true; } } - private bool TryGetOrOpenUI(ActorComponent actor, SignalLinkerComponent linker, [NotNullWhen(true)] out BoundUserInterface? bui) + private bool TryGetOrOpenUI(EntityUid linkerUid, [NotNullWhen(true)] out BoundUserInterface? bui, ActorComponent actor) { - if (_userInterfaceSystem.TryGetUi(linker.Owner, SignalLinkerUiKey.Key, out bui)) + if (_userInterfaceSystem.TryGetUi(linkerUid, SignalLinkerUiKey.Key, out bui)) { - bui.Open(actor.PlayerSession); + _userInterfaceSystem.OpenUi(bui, actor.PlayerSession); return true; } return false; } - private bool TryUpdateUI(SignalLinkerComponent linker, SignalTransmitterComponent transmitter, SignalReceiverComponent receiver, BoundUserInterface? bui = null) + private bool TryUpdateUI(EntityUid linkerUid, EntityUid transmitterUid, EntityUid receiverUid, BoundUserInterface? bui = null, SignalTransmitterComponent? transmitter = null, SignalReceiverComponent? receiver = null) { - if (bui == null && !_userInterfaceSystem.TryGetUi(linker.Owner, SignalLinkerUiKey.Key, out bui)) + if (!Resolve(transmitterUid, ref transmitter) || !Resolve(receiverUid, ref receiver)) + return false; + + if (bui == null && !_userInterfaceSystem.TryGetUi(linkerUid, SignalLinkerUiKey.Key, out bui)) return false; var outKeys = transmitter.Outputs.Keys.ToList(); @@ -304,24 +306,30 @@ namespace Content.Server.MachineLinking.System { foreach (var re in transmitter.Outputs[outKeys[i]]) { - if (re.Uid == receiver.Owner) + if (re.Uid == receiverUid) links.Add((i, inKeys.IndexOf(re.Port))); } } - bui.SetState(new SignalPortsState($"{Name(transmitter.Owner)} ({transmitter.Owner})", outKeys, - $"{Name(receiver.Owner)} ({receiver.Owner})", inKeys, links)); + UserInterfaceSystem.SetUiState(bui, new SignalPortsState( + $"{Name(transmitterUid)} ({transmitterUid})", + outKeys, + $"{Name(receiverUid)} ({receiverUid})", + inKeys, + links + )); return true; } - private bool TryLink(SignalTransmitterComponent transmitter, SignalReceiverComponent receiver, SignalPortSelected args, EntityUid? user, bool quiet = false, bool checkRange = true) + private bool TryLink(EntityUid transmitterUid, EntityUid receiverUid, SignalPortSelected args, EntityUid? user, bool quiet = false, bool checkRange = true, SignalTransmitterComponent? transmitter = null, SignalReceiverComponent? receiver = null) { - if (!transmitter.Outputs.TryGetValue(args.TransmitterPort, out var linkedReceivers) || - !receiver.Inputs.TryGetValue(args.ReceiverPort, out var linkedTransmitters)) - { + if (!Resolve(transmitterUid, ref transmitter) || !Resolve(receiverUid, ref receiver)) + return false; + + if (!transmitter.Outputs.TryGetValue(args.TransmitterPort, out var linkedReceivers) + || !receiver.Inputs.TryGetValue(args.ReceiverPort, out var linkedTransmitters)) return false; - } quiet |= !user.HasValue; @@ -329,11 +337,11 @@ namespace Content.Server.MachineLinking.System // transmitter ports. foreach (var identifier in linkedTransmitters) { - if (identifier.Uid == transmitter.Owner && identifier.Port == args.TransmitterPort) + if (identifier.Uid == transmitterUid && identifier.Port == args.TransmitterPort) return true; } - if (checkRange && !IsInRange(transmitter, receiver)) + if (checkRange && !IsInRange(transmitterUid, receiverUid, transmitter, receiver)) { if (!quiet) _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-out-of-range"), user!.Value); @@ -341,35 +349,35 @@ namespace Content.Server.MachineLinking.System } // allow other systems to refuse the connection - var linkAttempt = new LinkAttemptEvent(user, transmitter.Owner, args.TransmitterPort, receiver.Owner, args.ReceiverPort); - RaiseLocalEvent(transmitter.Owner, linkAttempt, true); + var linkAttempt = new LinkAttemptEvent(user, transmitterUid, args.TransmitterPort, receiverUid, args.ReceiverPort); + RaiseLocalEvent(transmitterUid, linkAttempt, true); if (linkAttempt.Cancelled) { if (!quiet) - _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-connection-refused", ("machine", transmitter.Owner)), user!.Value); + _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-connection-refused", ("machine", transmitterUid)), user!.Value); return false; } - RaiseLocalEvent(receiver.Owner, linkAttempt, true); + RaiseLocalEvent(receiverUid, linkAttempt, true); if (linkAttempt.Cancelled) { if (!quiet) - _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-connection-refused", ("machine", receiver.Owner)), user!.Value); + _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-connection-refused", ("machine", receiverUid)), user!.Value); return false; } - linkedReceivers.Add(new(receiver.Owner, args.ReceiverPort)); - linkedTransmitters.Add(new(transmitter.Owner, args.TransmitterPort)); + linkedReceivers.Add(new(receiverUid, args.ReceiverPort)); + linkedTransmitters.Add(new(transmitterUid, args.TransmitterPort)); if (!quiet) { _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-linked-port", - ("machine1", transmitter.Owner), ("port1", PortName(args.TransmitterPort)), - ("machine2", receiver.Owner), ("port2", PortName(args.ReceiverPort))), + ("machine1", transmitterUid), ("port1", PortName(args.TransmitterPort)), + ("machine2", receiverUid), ("port2", PortName(args.ReceiverPort))), user!.Value, PopupType.Medium); } - var newLink = new NewLinkEvent(user, transmitter.Owner, args.TransmitterPort, receiver.Owner, args.ReceiverPort); - RaiseLocalEvent(receiver.Owner, newLink); - RaiseLocalEvent(transmitter.Owner, newLink); + var newLink = new NewLinkEvent(user, transmitterUid, args.TransmitterPort, receiverUid, args.ReceiverPort); + RaiseLocalEvent(receiverUid, newLink); + RaiseLocalEvent(transmitterUid, newLink); return true; } @@ -382,22 +390,25 @@ namespace Content.Server.MachineLinking.System !receiver.Inputs.TryGetValue(args.ReceiverPort, out var transmitters)) return; - if (args.Session.AttachedEntity is not { Valid: true} attached) + if (args.Session.AttachedEntity is not { Valid: true } attached) return; - if (receivers.Contains(new(receiver.Owner, args.ReceiverPort)) || - transmitters.Contains(new(transmitter.Owner, args.TransmitterPort))) + var receiverUid = linker.SavedReceiver.Value; + var transmitterUid = linker.SavedTransmitter.Value; + + if (receivers.Contains(new(receiverUid, args.ReceiverPort)) || + transmitters.Contains(new(transmitterUid, args.TransmitterPort))) { // link already exists, remove it - if (receivers.Remove(new(receiver.Owner, args.ReceiverPort)) && - transmitters.Remove(new(transmitter.Owner, args.TransmitterPort))) + if (receivers.Remove(new(receiverUid, args.ReceiverPort)) && + transmitters.Remove(new(transmitterUid, args.TransmitterPort))) { - RaiseLocalEvent(receiver.Owner, new PortDisconnectedEvent(args.ReceiverPort), true); - RaiseLocalEvent(transmitter.Owner, new PortDisconnectedEvent(args.TransmitterPort), true); + RaiseLocalEvent(receiverUid, new PortDisconnectedEvent(args.ReceiverPort), true); + RaiseLocalEvent(transmitterUid, new PortDisconnectedEvent(args.TransmitterPort), true); _popupSystem.PopupCursor(Loc.GetString("signal-linker-component-unlinked-port", - ("machine1", transmitter.Owner), ("port1", PortName(args.TransmitterPort)), - ("machine2", receiver.Owner), ("port2", PortName(args.ReceiverPort))), + ("machine1", transmitterUid), ("port1", PortName(args.TransmitterPort)), + ("machine2", receiverUid), ("port2", PortName(args.ReceiverPort))), attached, PopupType.Medium); } else @@ -407,10 +418,10 @@ namespace Content.Server.MachineLinking.System } else { - TryLink(transmitter, receiver, args, attached); + TryLink(transmitterUid, receiverUid, args, attached, transmitter: transmitter, receiver: receiver); } - TryUpdateUI(linker, transmitter, receiver); + TryUpdateUI(uid, transmitterUid, receiverUid, transmitter: transmitter, receiver: receiver); } /// @@ -432,19 +443,22 @@ namespace Content.Server.MachineLinking.System !TryComp(linker.SavedReceiver, out SignalReceiverComponent? receiver)) return; + var transmitterUid = linker.SavedTransmitter.Value; + var receiverUid = linker.SavedReceiver.Value; + foreach (var (port, receivers) in transmitter.Outputs) { - if (receivers.RemoveAll(id => id.Uid == receiver.Owner) > 0) - RaiseLocalEvent(transmitter.Owner, new PortDisconnectedEvent(port), true); + if (receivers.RemoveAll(id => id.Uid == receiverUid) > 0) + RaiseLocalEvent(transmitterUid, new PortDisconnectedEvent(port), true); } foreach (var (port, transmitters) in receiver.Inputs) { - if (transmitters.RemoveAll(id => id.Uid == transmitter.Owner) > 0) - RaiseLocalEvent(receiver.Owner, new PortDisconnectedEvent(port), true); + if (transmitters.RemoveAll(id => id.Uid == transmitterUid) > 0) + RaiseLocalEvent(receiverUid, new PortDisconnectedEvent(port), true); } - TryUpdateUI(linker, transmitter, receiver); + TryUpdateUI(uid, transmitterUid, receiverUid, transmitter: transmitter, receiver: receiver); } private void OnLinkerLinkDefaultSelected(EntityUid uid, SignalLinkerComponent linker, LinkerLinkDefaultSelected args) @@ -456,8 +470,11 @@ namespace Content.Server.MachineLinking.System if (args.Session.AttachedEntity is not { Valid: true } user) return; - TryLinkDefaults(linker.SavedReceiver!.Value, linker.SavedTransmitter!.Value, user, receiver, transmitter); - TryUpdateUI(linker, transmitter, receiver); + var transmitterUid = linker.SavedTransmitter!.Value; + var receiverUid = linker.SavedReceiver!.Value; + + TryLinkDefaults(receiverUid, transmitterUid, user, receiver, transmitter); + TryUpdateUI(uid, transmitterUid, receiverUid, transmitter: transmitter, receiver: receiver); } /// @@ -470,7 +487,7 @@ namespace Content.Server.MachineLinking.System if (!Resolve(receiverUid, ref receiver, false) || !Resolve(transmitterUid, ref transmitter, false)) return false; - if (!IsInRange(transmitter, receiver)) + if (!IsInRange(transmitterUid, receiverUid, transmitter, receiver)) return false; var allLinksSucceeded = true; @@ -478,14 +495,14 @@ namespace Content.Server.MachineLinking.System // First, disconnect existing links. foreach (var (port, receivers) in transmitter.Outputs) { - if (receivers.RemoveAll(id => id.Uid == receiver.Owner) > 0) - RaiseLocalEvent(transmitter.Owner, new PortDisconnectedEvent(port), true); + if (receivers.RemoveAll(id => id.Uid == receiverUid) > 0) + RaiseLocalEvent(transmitterUid, new PortDisconnectedEvent(port), true); } foreach (var (port, transmitters) in receiver.Inputs) { - if (transmitters.RemoveAll(id => id.Uid == transmitter.Owner) > 0) - RaiseLocalEvent(receiver.Owner, new PortDisconnectedEvent(port), true); + if (transmitters.RemoveAll(id => id.Uid == transmitterUid) > 0) + RaiseLocalEvent(receiverUid, new PortDisconnectedEvent(port), true); } // Then make any valid default connections. @@ -498,7 +515,7 @@ namespace Content.Server.MachineLinking.System foreach (var inPort in prototype.DefaultLinks) { if (receiver.Inputs.ContainsKey(inPort)) - allLinksSucceeded &= TryLink(transmitter, receiver, new(outPort, inPort), user, quiet: true, checkRange: false); + allLinksSucceeded &= TryLink(transmitterUid, receiverUid, new(outPort, inPort), user, quiet: true, checkRange: false, transmitter: transmitter, receiver: receiver); } } @@ -511,16 +528,16 @@ namespace Content.Server.MachineLinking.System component.SavedReceiver = null; } - private bool IsInRange(SignalTransmitterComponent transmitterComponent, SignalReceiverComponent receiverComponent) + private bool IsInRange(EntityUid transmitterUid, EntityUid receiverUid, SignalTransmitterComponent transmitterComponent, SignalReceiverComponent _) { - if (TryComp(transmitterComponent.Owner, out ApcPowerReceiverComponent? transmitterPower) && - TryComp(receiverComponent.Owner, out ApcPowerReceiverComponent? receiverPower) && + if (TryComp(transmitterUid, out ApcPowerReceiverComponent? transmitterPower) && + TryComp(receiverUid, out ApcPowerReceiverComponent? receiverPower) && transmitterPower.Provider?.Net == receiverPower.Provider?.Net) return true; // TODO: As elsewhere don't use mappos inrange. - return Comp(transmitterComponent.Owner).MapPosition.InRange( - Comp(receiverComponent.Owner).MapPosition, transmitterComponent.TransmissionRange); + return Comp(transmitterUid).MapPosition.InRange( + Comp(receiverUid).MapPosition, transmitterComponent.TransmissionRange); } private bool IsLinkerInteractable(EntityUid uid, SignalLinkerComponent linkerComponent) diff --git a/Content.Server/Mech/Systems/MechSystem.cs b/Content.Server/Mech/Systems/MechSystem.cs index dca7f9c6c5..37c9db2b0a 100644 --- a/Content.Server/Mech/Systems/MechSystem.cs +++ b/Content.Server/Mech/Systems/MechSystem.cs @@ -2,6 +2,7 @@ using System.Linq; using Content.Server.Atmos.EntitySystems; using Content.Server.Mech.Components; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.ActionBlocker; using Content.Shared.Damage; using Content.Shared.DoAfter; @@ -33,6 +34,7 @@ public sealed class MechSystem : SharedMechSystem [Dependency] private readonly UserInterfaceSystem _ui = default!; [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; + [Dependency] private readonly BatterySystem _batterySystem = default!; private ISawmill _sawmill = default!; @@ -69,7 +71,7 @@ public sealed class MechSystem : SharedMechSystem #endregion } - private void OnMechCanMoveEvent(EntityUid uid, MechComponent component , UpdateCanMoveEvent args) + private void OnMechCanMoveEvent(EntityUid uid, MechComponent component, UpdateCanMoveEvent args) { if (component.Broken || component.Integrity <= 0 || component.Energy <= 0) args.Cancel(); @@ -300,7 +302,7 @@ public sealed class MechSystem : SharedMechSystem EquipmentStates = ev.States }; var ui = _ui.GetUi(uid, MechUiKey.Key); - _ui.SetUiState(ui, state); + UserInterfaceSystem.SetUiState(ui, state); } public override bool TryInsert(EntityUid uid, EntityUid? toInsert, MechComponent? component = null) @@ -318,7 +320,7 @@ public sealed class MechSystem : SharedMechSystem { var tile = grid.GetTileRef(coordinates); - if (_atmosphere.GetTileMixture(tile.GridUid, null, tile.GridIndices, true) is {} environment) + if (_atmosphere.GetTileMixture(tile.GridUid, null, tile.GridIndices, true) is { } environment) { _atmosphere.Merge(mechAir.Air, environment.RemoveVolume(MechAirComponent.GasMixVolume)); } @@ -342,7 +344,7 @@ public sealed class MechSystem : SharedMechSystem { var tile = grid.GetTileRef(coordinates); - if (_atmosphere.GetTileMixture(tile.GridUid, null, tile.GridIndices, true) is {} environment) + if (_atmosphere.GetTileMixture(tile.GridUid, null, tile.GridIndices, true) is { } environment) { _atmosphere.Merge(environment, mechAir.Air); mechAir.Air.Clear(); @@ -376,7 +378,7 @@ public sealed class MechSystem : SharedMechSystem if (!TryComp(battery, out var batteryComp)) return false; - batteryComp.CurrentCharge = batteryComp.CurrentCharge + delta.Float(); + _batterySystem.SetCharge(battery!.Value, batteryComp.CurrentCharge + delta.Float(), batteryComp); if (batteryComp.CurrentCharge != component.Energy) //if there's a discrepency, we have to resync them { _sawmill.Debug($"Battery charge was not equal to mech charge. Battery {batteryComp.CurrentCharge}. Mech {component.Energy}"); diff --git a/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs b/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs index f2e59f9773..3b73ce80c4 100644 --- a/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs +++ b/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs @@ -1,23 +1,17 @@ using System.Linq; using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; -using Content.Server.Medical.SuitSensors; -using Content.Server.UserInterface; -using Content.Shared.Medical.CrewMonitoring; -using Robust.Shared.Map; -using Content.Shared.Medical.SuitSensor; -using Robust.Shared.Timing; using Content.Server.PowerCell; +using Content.Shared.Medical.CrewMonitoring; +using Content.Shared.Medical.SuitSensor; +using Robust.Server.GameObjects; namespace Content.Server.Medical.CrewMonitoring { public sealed class CrewMonitoringConsoleSystem : EntitySystem { - [Dependency] private readonly SuitSensorSystem _sensors = default!; - [Dependency] private readonly SharedTransformSystem _xform = default!; - [Dependency] private readonly IGameTiming _gameTiming = default!; - [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly PowerCellSystem _cell = default!; + [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; public override void Initialize() { @@ -60,14 +54,12 @@ namespace Content.Server.Medical.CrewMonitoring if (!Resolve(uid, ref component)) return; - var ui = component.Owner.GetUIOrNull(CrewMonitoringUIKey.Key); - if (ui == null) + if (!_uiSystem.TryGetUi(uid, CrewMonitoringUIKey.Key, out var bui)) return; // update all sensors info var allSensors = component.ConnectedSensors.Values.ToList(); - var uiState = new CrewMonitoringState(allSensors, component.Snap, component.Precision); - ui.SetState(uiState); + UserInterfaceSystem.SetUiState(bui, new CrewMonitoringState(allSensors, component.Snap, component.Precision)); } } } diff --git a/Content.Server/Medical/MedicalScannerSystem.cs b/Content.Server/Medical/MedicalScannerSystem.cs index fff9b3a2cb..57ca815cb7 100644 --- a/Content.Server/Medical/MedicalScannerSystem.cs +++ b/Content.Server/Medical/MedicalScannerSystem.cs @@ -88,7 +88,7 @@ namespace Content.Server.Medical !CanScannerInsert(uid, args.Using.Value, component)) return; - string name = "Unknown"; + var name = "Unknown"; if (TryComp(args.Using.Value, out var metadata)) name = metadata.EntityName; @@ -109,11 +109,13 @@ namespace Content.Server.Medical // Eject verb if (IsOccupied(component)) { - AlternativeVerb verb = new(); - verb.Act = () => EjectBody(uid, component); - verb.Category = VerbCategory.Eject; - verb.Text = Loc.GetString("medical-scanner-verb-noun-occupant"); - verb.Priority = 1; // Promote to top to make ejecting the ALT-click action + AlternativeVerb verb = new() + { + Act = () => EjectBody(uid, component), + Category = VerbCategory.Eject, + Text = Loc.GetString("medical-scanner-verb-noun-occupant"), + Priority = 1 // Promote to top to make ejecting the ALT-click action + }; args.Verbs.Add(verb); } @@ -122,9 +124,11 @@ namespace Content.Server.Medical CanScannerInsert(uid, args.User, component) && _blocker.CanMove(args.User)) { - AlternativeVerb verb = new(); - verb.Act = () => InsertBody(uid, args.User, component); - verb.Text = Loc.GetString("medical-scanner-verb-enter"); + AlternativeVerb verb = new() + { + Act = () => InsertBody(uid, args.User, component), + Text = Loc.GetString("medical-scanner-verb-enter") + }; args.Verbs.Add(verb); } } @@ -154,7 +158,7 @@ namespace Content.Server.Medical _cloningConsoleSystem.RecheckConnections(component.ConnectedConsole.Value, console.CloningPod, uid, console); return; } - _cloningConsoleSystem.UpdateUserInterface(console); + _cloningConsoleSystem.UpdateUserInterface(component.ConnectedConsole.Value, console); } private MedicalScannerStatus GetStatus(EntityUid uid, MedicalScannerComponent scannerComponent) { @@ -174,7 +178,7 @@ namespace Content.Server.Medical return MedicalScannerStatus.Off; } - public bool IsOccupied(MedicalScannerComponent scannerComponent) + public static bool IsOccupied(MedicalScannerComponent scannerComponent) { return scannerComponent.BodyContainer.ContainedEntity != null; } @@ -212,7 +216,7 @@ namespace Content.Server.Medical _updateDif -= UpdateRate; var query = EntityQueryEnumerator(); - while(query.MoveNext(out var uid, out var scanner)) + while (query.MoveNext(out var uid, out var scanner)) { UpdateAppearance(uid, scanner); } @@ -238,7 +242,7 @@ namespace Content.Server.Medical if (!Resolve(uid, ref scannerComponent)) return; - if (scannerComponent.BodyContainer.ContainedEntity is not {Valid: true} contained) + if (scannerComponent.BodyContainer.ContainedEntity is not { Valid: true } contained) return; scannerComponent.BodyContainer.Remove(contained); diff --git a/Content.Server/Nuke/NukeSystem.cs b/Content.Server/Nuke/NukeSystem.cs index cd033cc81a..70dfd2ed92 100644 --- a/Content.Server/Nuke/NukeSystem.cs +++ b/Content.Server/Nuke/NukeSystem.cs @@ -31,6 +31,7 @@ namespace Content.Server.Nuke [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!; + [Dependency] private readonly SharedTransformSystem _xformSystem = default!; /// /// Used to calculate when the nuke song should start playing for maximum kino with the nuke sfx @@ -82,16 +83,16 @@ namespace Content.Server.Nuke { base.Update(frameTime); - var query = EntityQuery(); - foreach (var nuke in query) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var nuke)) { switch (nuke.Status) { case NukeStatus.ARMED: - TickTimer(nuke.Owner, frameTime, nuke); + TickTimer(uid, frameTime, nuke); break; case NukeStatus.COOLDOWN: - TickCooldown(nuke.Owner, frameTime, nuke); + TickCooldown(uid, frameTime, nuke); break; } } @@ -180,8 +181,11 @@ namespace Content.Server.Nuke // manually set transform anchor (bypassing anchorable) // todo: it will break pullable system - transform.Coordinates = transform.Coordinates.SnapToGrid(); - transform.Anchored = !transform.Anchored; + _xformSystem.SetCoordinates(uid, transform, transform.Coordinates.SnapToGrid()); + if (transform.Anchored) + _xformSystem.Unanchor(uid, transform); + else + _xformSystem.AnchorEntity(uid, transform); UpdateUserInterface(uid, component); } @@ -243,7 +247,7 @@ namespace Content.Server.Nuke private void OnDoAfter(EntityUid uid, NukeComponent component, DoAfterEvent args) { - if(args.Handled || args.Cancelled) + if (args.Handled || args.Cancelled) return; DisarmBomb(uid, component); @@ -317,7 +321,6 @@ namespace Content.Server.Nuke component.Status = NukeStatus.AWAIT_CODE; break; case NukeStatus.AWAIT_CODE: - { if (!component.DiskSlot.HasItem) { component.Status = NukeStatus.AWAIT_DISK; @@ -339,7 +342,6 @@ namespace Content.Server.Nuke } break; - } case NukeStatus.AWAIT_ARM: // do nothing, wait for arm button to be pressed break; @@ -378,7 +380,7 @@ namespace Content.Server.Nuke CooldownTime = (int) component.CooldownTime }; - _ui.SetUiState(ui, state); + UserInterfaceSystem.SetUiState(ui, state); } private void PlayNukeKeypadSound(EntityUid uid, int number, NukeComponent? component = null) @@ -444,7 +446,7 @@ namespace Content.Server.Nuke if (stationUid != null) _alertLevel.SetLevel(stationUid.Value, component.AlertLevelOnActivate, true, true, true, true); - var pos = nukeXform.MapPosition; + var pos = nukeXform.MapPosition; var x = (int) pos.X; var y = (int) pos.Y; var posText = $"({x}, {y})"; @@ -458,7 +460,7 @@ namespace Content.Server.Nuke _soundSystem.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound)); _itemSlots.SetLock(uid, component.DiskSlot, true); - nukeXform.Anchored = true; + _xformSystem.AnchorEntity(uid, nukeXform); component.Status = NukeStatus.ARMED; UpdateUserInterface(uid, component); } diff --git a/Content.Server/PDA/Ringer/RingerSystem.cs b/Content.Server/PDA/Ringer/RingerSystem.cs index 0682566469..03aa1069e6 100644 --- a/Content.Server/PDA/Ringer/RingerSystem.cs +++ b/Content.Server/PDA/Ringer/RingerSystem.cs @@ -147,7 +147,7 @@ namespace Content.Server.PDA.Ringer private void UpdateRingerUserInterface(EntityUid uid, RingerComponent ringer) { if (_ui.TryGetUi(uid, RingerUiKey.Key, out var bui)) - _ui.SetUiState(bui, new RingerUpdateState(HasComp(uid), ringer.Ringtone)); + UserInterfaceSystem.SetUiState(bui, new RingerUpdateState(HasComp(uid), ringer.Ringtone)); } public bool ToggleRingerUI(EntityUid uid, IPlayerSession session) diff --git a/Content.Server/Paper/PaperSystem.cs b/Content.Server/Paper/PaperSystem.cs index 8748b3c6cf..45a990be80 100644 --- a/Content.Server/Paper/PaperSystem.cs +++ b/Content.Server/Paper/PaperSystem.cs @@ -23,6 +23,7 @@ namespace Content.Server.Paper [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly TagSystem _tagSystem = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; + [Dependency] private readonly MetaDataSystem _metaSystem = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; public override void Initialize() @@ -88,7 +89,7 @@ namespace Content.Server.Paper if (paperComp.StampedBy.Count > 0) { - string commaSeparated = string.Join(", ", paperComp.StampedBy); + var commaSeparated = string.Join(", ", paperComp.StampedBy); args.PushMarkup( Loc.GetString( "paper-component-examine-detail-stamped-by", ("paper", uid), ("stamps", commaSeparated)) @@ -115,10 +116,11 @@ namespace Content.Server.Paper if (TryComp(args.Used, out var stampComp) && TryStamp(uid, stampComp.StampedName, stampComp.StampState, paperComp)) { // successfully stamped, play popup - var stampPaperOtherMessage = Loc.GetString("paper-component-action-stamp-paper-other", ("user", Identity.Entity(args.User, EntityManager)),("target", Identity.Entity(args.Target, EntityManager)),("stamp", args.Used)); - _popupSystem.PopupEntity(stampPaperOtherMessage, args.User, Filter.PvsExcept(args.User, entityManager: EntityManager), true); - var stampPaperSelfMessage = Loc.GetString("paper-component-action-stamp-paper-self", ("target", Identity.Entity(args.Target, EntityManager)),("stamp", args.Used)); - _popupSystem.PopupEntity(stampPaperSelfMessage, args.User, args.User); + var stampPaperOtherMessage = Loc.GetString("paper-component-action-stamp-paper-other", ("user", Identity.Entity(args.User, EntityManager)), ("target", Identity.Entity(args.Target, EntityManager)), ("stamp", args.Used)); + _popupSystem.PopupEntity(stampPaperOtherMessage, args.User, Filter.PvsExcept(args.User, entityManager: EntityManager), true); + + var stampPaperSelfMessage = Loc.GetString("paper-component-action-stamp-paper-self", ("target", Identity.Entity(args.Target, EntityManager)), ("stamp", args.Used)); + _popupSystem.PopupEntity(stampPaperSelfMessage, args.User, args.User); _audio.PlayPvs(stampComp.Sound, uid); @@ -140,7 +142,7 @@ namespace Content.Server.Paper _appearance.SetData(uid, PaperVisuals.Status, PaperStatus.Written, appearance); if (TryComp(uid, out var meta)) - meta.EntityDescription = ""; + _metaSystem.SetEntityDescription(uid, "", meta); if (args.Session.AttachedEntity != null) _adminLogger.Add(LogType.Chat, LogImpact.Low, @@ -198,8 +200,8 @@ namespace Content.Server.Paper if (!Resolve(uid, ref paperComp)) return; - var state = new PaperBoundUserInterfaceState(paperComp.Content, paperComp.StampedBy, paperComp.Mode); - _uiSystem.TrySetUiState(uid, PaperUiKey.Key, state, session); + if (_uiSystem.TryGetUi(uid, PaperUiKey.Key, out var bui)) + UserInterfaceSystem.SetUiState(bui, new PaperBoundUserInterfaceState(paperComp.Content, paperComp.StampedBy, paperComp.Mode), session); } } diff --git a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs index 8d6ddac4a9..8756111ad1 100644 --- a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs +++ b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs @@ -1,9 +1,9 @@ -using Content.Server.Mind.Components; using Content.Server.ParticleAccelerator.Components; using Content.Server.Power.Components; using Content.Shared.Database; using Content.Shared.Singularity.Components; using Robust.Server.Player; +using Robust.Server.GameObjects; using Robust.Shared.Utility; using System.Diagnostics; @@ -69,7 +69,7 @@ public sealed partial class ParticleAcceleratorSystem if (comp.Enabled || !comp.CanBeEnabled) return; - if (user?.AttachedEntity is {} player) + if (user?.AttachedEntity is { } player) _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} has turned {ToPrettyString(uid)} on"); comp.Enabled = true; @@ -89,7 +89,7 @@ public sealed partial class ParticleAcceleratorSystem if (!comp.Enabled) return; - if (user?.AttachedEntity is {} player) + if (user?.AttachedEntity is { } player) _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} has turned {ToPrettyString(uid)} off"); comp.Enabled = false; @@ -146,7 +146,7 @@ public sealed partial class ParticleAcceleratorSystem if (strength == comp.SelectedStrength) return; - if (user?.AttachedEntity is {} player) + if (user?.AttachedEntity is { } player) { var impact = strength switch { @@ -221,7 +221,7 @@ public sealed partial class ParticleAcceleratorSystem receive = powerConsumer.ReceivedPower; } - _uiSystem.SetUiState(bui, new ParticleAcceleratorUIState( + UserInterfaceSystem.SetUiState(bui, new ParticleAcceleratorUIState( comp.Assembled, comp.Enabled, comp.SelectedStrength, diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index d640a384d4..2deea3b4a0 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -11,8 +11,6 @@ using Content.Shared.Shuttles.Systems; using Robust.Server.GameObjects; using Robust.Shared.Map; using Robust.Shared.Physics.Components; -using Robust.Shared.Physics.Systems; -using Robust.Shared.Player; namespace Content.Server.Physics.Controllers { @@ -20,8 +18,9 @@ namespace Content.Server.Physics.Controllers { [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly ThrusterSystem _thruster = default!; + [Dependency] private readonly SharedTransformSystem _xformSystem = default!; - private Dictionary> _shuttlePilots = new(); + private Dictionary)> _shuttlePilots = new(); public override void Initialize() { @@ -165,7 +164,8 @@ namespace Content.Server.Physics.Controllers protected override void HandleShuttleInput(EntityUid uid, ShuttleButtons button, ushort subTick, bool state) { - if (!TryComp(uid, out var pilot) || pilot.Console == null) return; + if (!TryComp(uid, out var pilot) || pilot.Console == null) + return; ResetSubtick(pilot); @@ -191,7 +191,7 @@ namespace Content.Server.Physics.Controllers pilot.HeldButtons = buttons; } - private void ApplyTick(PilotComponent component, float fraction) + private static void ApplyTick(PilotComponent component, float fraction) { var x = 0; var y = 0; @@ -248,12 +248,14 @@ namespace Content.Server.Physics.Controllers private void HandleShuttleMovement(float frameTime) { - var newPilots = new Dictionary>(); + var newPilots = new Dictionary)>(); // We just mark off their movement and the shuttle itself does its own movement - foreach (var (pilot, mover) in EntityManager.EntityQuery()) + var activePilotQuery = EntityQueryEnumerator(); + var shuttleQuery = GetEntityQuery(); + while (activePilotQuery.MoveNext(out var uid, out var pilot, out var mover)) { - var consoleEnt = pilot.Console?.Owner; + var consoleEnt = pilot.Console; // TODO: This is terrible. Just make a new mover and also make it remote piloting + device networks if (TryComp(consoleEnt, out var cargoConsole)) @@ -265,23 +267,25 @@ namespace Content.Server.Physics.Controllers var gridId = xform.GridUid; // This tries to see if the grid is a shuttle and if the console should work. - if (!_mapManager.TryGetGrid(gridId, out var grid) || - !EntityManager.TryGetComponent(grid.Owner, out ShuttleComponent? shuttleComponent) || - !shuttleComponent.Enabled) continue; + if (!_mapManager.TryGetGrid(gridId, out var _) || + !shuttleQuery.TryGetComponent(gridId, out var shuttleComponent) || + !shuttleComponent.Enabled) + continue; - if (!newPilots.TryGetValue(shuttleComponent, out var pilots)) + if (!newPilots.TryGetValue(gridId!.Value, out var pilots)) { - pilots = new List<(PilotComponent, InputMoverComponent, TransformComponent)>(); - newPilots[shuttleComponent] = pilots; + pilots = (shuttleComponent, new List<(EntityUid, PilotComponent, InputMoverComponent, TransformComponent)>()); + newPilots[gridId.Value] = pilots; } - pilots.Add((pilot, mover, xform)); + pilots.Item2.Add((uid, pilot, mover, xform)); } // Reset inputs for non-piloted shuttles. - foreach (var (shuttle, _) in _shuttlePilots) + foreach (var (shuttleUid, (shuttle, _)) in _shuttlePilots) { - if (newPilots.ContainsKey(shuttle) || CanPilot(shuttle)) continue; + if (newPilots.ContainsKey(shuttleUid) || CanPilot(shuttleUid)) + continue; _thruster.DisableLinearThrusters(shuttle); } @@ -290,35 +294,37 @@ namespace Content.Server.Physics.Controllers // Collate all of the linear / angular velocites for a shuttle // then do the movement input once for it. - foreach (var (shuttle, pilots) in _shuttlePilots) + var xformQuery = GetEntityQuery(); + foreach (var (shuttleUid, (shuttle, pilots)) in _shuttlePilots) { - if (Paused(shuttle.Owner) || CanPilot(shuttle) || !TryComp(shuttle.Owner, out PhysicsComponent? body)) continue; + if (Paused(shuttleUid) || CanPilot(shuttleUid) || !TryComp(shuttleUid, out var body)) + continue; - var shuttleNorthAngle = Transform(body.Owner).WorldRotation; + var shuttleNorthAngle = _xformSystem.GetWorldRotation(shuttleUid, xformQuery); // Collate movement linear and angular inputs together var linearInput = Vector2.Zero; var brakeInput = 0f; var angularInput = 0f; - foreach (var (pilot, _, consoleXform) in pilots) + foreach (var (pilotUid, pilot, _, consoleXform) in pilots) { - var pilotInput = GetPilotVelocityInput(pilot); + var (strafe, rotation, brakes) = GetPilotVelocityInput(pilot); - if (pilotInput.Brakes > 0f) + if (brakes > 0f) { - brakeInput += pilotInput.Brakes; + brakeInput += brakes; } - if (pilotInput.Strafe.Length() > 0f) + if (strafe.Length() > 0f) { var offsetRotation = consoleXform.LocalRotation; - linearInput += offsetRotation.RotateVec(pilotInput.Strafe); + linearInput += offsetRotation.RotateVec(strafe); } - if (pilotInput.Rotation != 0f) + if (rotation != 0f) { - angularInput += pilotInput.Rotation; + angularInput += rotation; } } @@ -390,7 +396,7 @@ namespace Content.Server.Physics.Controllers if (impulse.Length() > maxVelocity) impulse = impulse.Normalized() * maxVelocity; - PhysicsSystem.ApplyForce(shuttle.Owner, impulse, body: body); + PhysicsSystem.ApplyForce(shuttleUid, impulse, body: body); } else { @@ -413,7 +419,7 @@ namespace Content.Server.Physics.Controllers if (!torque.Equals(0f)) { - PhysicsSystem.ApplyTorque(shuttle.Owner, torque, body: body); + PhysicsSystem.ApplyTorque(shuttleUid, torque, body: body); _thruster.SetAngularThrust(shuttle, true); } } @@ -425,14 +431,14 @@ namespace Content.Server.Physics.Controllers if (linearInput.Length().Equals(0f)) { - PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, true); + PhysicsSystem.SetSleepingAllowed(shuttleUid, body, true); if (brakeInput.Equals(0f)) _thruster.DisableLinearThrusters(shuttle); } else { - PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, false); + PhysicsSystem.SetSleepingAllowed(shuttleUid, body, false); var angle = linearInput.ToWorldAngle(); var linearDir = angle.GetDir(); var dockFlag = linearDir.AsFlag(); @@ -478,7 +484,7 @@ namespace Content.Server.Physics.Controllers force.X -= thrust; break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException($"Attempted to apply thrust to shuttle {shuttleUid} along invalid dir {dir}."); } _thruster.EnableLinearThrustDirection(shuttle, dir); @@ -497,20 +503,20 @@ namespace Content.Server.Physics.Controllers if (totalForce.Length() > maxVelocity) totalForce = totalForce.Normalized() * maxVelocity; - PhysicsSystem.ApplyForce(shuttle.Owner, totalForce, body: body); + PhysicsSystem.ApplyForce(shuttleUid, totalForce, body: body); } } if (MathHelper.CloseTo(angularInput, 0f)) { - PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, true); + PhysicsSystem.SetSleepingAllowed(shuttleUid, body, true); if (brakeInput <= 0f) _thruster.SetAngularThrust(shuttle, false); } else { - PhysicsSystem.SetSleepingAllowed(shuttle.Owner, body, false); + PhysicsSystem.SetSleepingAllowed(shuttleUid, body, false); var torque = shuttle.AngularThrust * -angularInput; // Need to cap the velocity if 1 tick of input brings us over cap so we don't continuously @@ -523,18 +529,18 @@ namespace Content.Server.Physics.Controllers if (!torque.Equals(0f)) { - PhysicsSystem.ApplyTorque(shuttle.Owner, torque, body: body); + PhysicsSystem.ApplyTorque(shuttleUid, torque, body: body); _thruster.SetAngularThrust(shuttle, true); } } } } - private bool CanPilot(ShuttleComponent shuttle) + private bool CanPilot(EntityUid shuttleUid) { - return TryComp(shuttle.Owner, out var ftl) && - (ftl.State & (FTLState.Starting | FTLState.Travelling | FTLState.Arriving)) != 0x0 || - HasComp(shuttle.Owner); + return TryComp(shuttleUid, out var ftl) + && (ftl.State & (FTLState.Starting | FTLState.Travelling | FTLState.Arriving)) != 0x0 + || HasComp(shuttleUid); } } diff --git a/Content.Server/Power/EntitySystems/PowerMonitoringConsoleSystem.cs b/Content.Server/Power/EntitySystems/PowerMonitoringConsoleSystem.cs index 543e4eef03..3a4da764ce 100644 --- a/Content.Server/Power/EntitySystems/PowerMonitoringConsoleSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerMonitoringConsoleSystem.cs @@ -15,8 +15,8 @@ internal sealed class PowerMonitoringConsoleSystem : EntitySystem private float _updateTimer = 0.0f; private const float UpdateTime = 1.0f; - [Dependency] private UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; + [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!; public override void Update(float frameTime) { @@ -24,9 +24,11 @@ internal sealed class PowerMonitoringConsoleSystem : EntitySystem if (_updateTimer >= UpdateTime) { _updateTimer -= UpdateTime; - foreach (var component in EntityQuery()) + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var component)) { - UpdateUIState(component.Owner, component); + UpdateUIState(uid, component); } } } @@ -52,8 +54,7 @@ internal sealed class PowerMonitoringConsoleSystem : EntitySystem if (!_nodeContainer.TryGetNode(ncComp, "hv", out var node)) return; - var netQ = node.NodeGroup as PowerNet; - if (netQ != null) + if (node.NodeGroup is PowerNet netQ) { foreach (PowerConsumerComponent pcc in netQ.Consumers) { @@ -92,9 +93,10 @@ internal sealed class PowerMonitoringConsoleSystem : EntitySystem // Sort loads.Sort(CompareLoadOrSources); sources.Sort(CompareLoadOrSources); + // Actually set state. - var state = new PowerMonitoringConsoleBoundInterfaceState(totalSources, totalLoads, sources.ToArray(), loads.ToArray()); - _userInterfaceSystem.GetUiOrNull(target, PowerMonitoringConsoleUiKey.Key)?.SetState(state); + if (_userInterfaceSystem.TryGetUi(target, PowerMonitoringConsoleUiKey.Key, out var bui)) + UserInterfaceSystem.SetUiState(bui, new PowerMonitoringConsoleBoundInterfaceState(totalSources, totalLoads, sources.ToArray(), loads.ToArray())); } private int CompareLoadOrSources(PowerMonitoringConsoleEntry x, PowerMonitoringConsoleEntry y) diff --git a/Content.Server/Salvage/SalvageSystem.Expeditions.cs b/Content.Server/Salvage/SalvageSystem.Expeditions.cs index 24b2b22196..d074812624 100644 --- a/Content.Server/Salvage/SalvageSystem.Expeditions.cs +++ b/Content.Server/Salvage/SalvageSystem.Expeditions.cs @@ -290,16 +290,14 @@ public sealed partial class SalvageSystem { // send it to cargo, no rewards otherwise. if (!TryComp(comp.Station, out var cargoDb)) - { return; - } foreach (var reward in comp.Rewards) { var sender = Loc.GetString("cargo-gift-default-sender"); var desc = Loc.GetString("salvage-expedition-reward-description"); var dest = Loc.GetString("cargo-gift-default-dest"); - _cargo.AddAndApproveOrder(cargoDb, reward, 0, 1, sender, desc, dest); + _cargo.AddAndApproveOrder(comp.Station, reward, 0, 1, sender, desc, dest, cargoDb); } } } diff --git a/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs b/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs index da21887f30..b2a5fd3a80 100644 --- a/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs +++ b/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs @@ -7,7 +7,7 @@ namespace Content.Server.Shuttles.Components public sealed class ShuttleConsoleComponent : SharedShuttleConsoleComponent { [ViewVariables] - public readonly List SubscribedPilots = new(); + public readonly List SubscribedPilots = new(); /// /// How much should the pilot's eye be zoomed by when piloting using this console? diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs index a72419cc8e..842bf62688 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs @@ -10,6 +10,7 @@ using Content.Shared.Popups; using Content.Shared.Shuttles.BUIStates; using Content.Shared.Shuttles.Events; using Content.Shared.Shuttles.Systems; +using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Map; using Robust.Shared.Player; @@ -264,7 +265,8 @@ public sealed partial class EmergencyShuttleSystem } // TODO: This is fucking bad - if (!component.AuthorizedEntities.Remove(MetaData(idCard.Owner).EntityName)) return; + if (!component.AuthorizedEntities.Remove(MetaData(idCard.Owner).EntityName)) + return; _logger.Add(LogType.EmergencyShuttle, LogImpact.High, $"Emergency shuttle early launch REPEAL by {args.Session:user}"); var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count; @@ -276,7 +278,8 @@ public sealed partial class EmergencyShuttleSystem private void OnEmergencyAuthorize(EntityUid uid, EmergencyShuttleConsoleComponent component, EmergencyShuttleAuthorizeMessage args) { var player = args.Session.AttachedEntity; - if (player == null) return; + if (player == null) + return; if (!_idSystem.TryFindIdCard(player.Value, out var idCard) || !_reader.IsAllowed(idCard.Owner, uid)) { @@ -285,7 +288,8 @@ public sealed partial class EmergencyShuttleSystem } // TODO: This is fucking bad - if (!component.AuthorizedEntities.Add(MetaData(idCard.Owner).EntityName)) return; + if (!component.AuthorizedEntities.Add(MetaData(idCard.Owner).EntityName)) + return; _logger.Add(LogType.EmergencyShuttle, LogImpact.High, $"Emergency shuttle early launch AUTH by {args.Session:user}"); var remaining = component.AuthorizationsRequired - component.AuthorizedEntities.Count; @@ -296,7 +300,7 @@ public sealed partial class EmergencyShuttleSystem playSound: false, colorOverride: DangerColor); if (!CheckForLaunch(component)) - SoundSystem.Play("/Audio/Misc/notice1.ogg", Filter.Broadcast()); + _audio.PlayGlobal("/Audio/Misc/notice1.ogg", Filter.Broadcast(), recordReplay: true); UpdateAllEmergencyConsoles(); } @@ -317,9 +321,10 @@ public sealed partial class EmergencyShuttleSystem private void UpdateAllEmergencyConsoles() { - foreach (var comp in EntityQuery(true)) + var query = AllEntityQuery(); + while (query.MoveNext(out var uid, out var comp)) { - UpdateConsoleState(comp.Owner, comp); + UpdateConsoleState(uid, comp); } } @@ -332,12 +337,16 @@ public sealed partial class EmergencyShuttleSystem auths.Add(auth); } - _uiSystem.GetUiOrNull(uid, EmergencyConsoleUiKey.Key)?.SetState(new EmergencyConsoleBoundUserInterfaceState() - { - EarlyLaunchTime = EarlyLaunchAuthorized ? _timing.CurTime + TimeSpan.FromSeconds(_consoleAccumulator) : null, - Authorizations = auths, - AuthorizationsRequired = component.AuthorizationsRequired, - }); + if (_uiSystem.TryGetUi(uid, EmergencyConsoleUiKey.Key, out var bui)) + UserInterfaceSystem.SetUiState( + bui, + new EmergencyConsoleBoundUserInterfaceState() + { + EarlyLaunchTime = EarlyLaunchAuthorized ? _timing.CurTime + TimeSpan.FromSeconds(_consoleAccumulator) : null, + Authorizations = auths, + AuthorizationsRequired = component.AuthorizationsRequired, + } + ); } private bool CheckForLaunch(EmergencyShuttleConsoleComponent component) @@ -375,7 +384,7 @@ public sealed partial class EmergencyShuttleSystem playSound: false, colorOverride: DangerColor); - SoundSystem.Play("/Audio/Misc/notice1.ogg", Filter.Broadcast()); + _audio.PlayGlobal("/Audio/Misc/notice1.ogg", Filter.Broadcast(), recordReplay: true); } public bool DelayEmergencyRoundEnd() diff --git a/Content.Server/Shuttles/Systems/RadarConsoleSystem.cs b/Content.Server/Shuttles/Systems/RadarConsoleSystem.cs index 17341ab7ec..a52c40cb2c 100644 --- a/Content.Server/Shuttles/Systems/RadarConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/RadarConsoleSystem.cs @@ -20,36 +20,36 @@ public sealed class RadarConsoleSystem : SharedRadarConsoleSystem private void OnRadarStartup(EntityUid uid, RadarConsoleComponent component, ComponentStartup args) { - UpdateState(component); + UpdateState(uid, component); } - protected override void UpdateState(RadarConsoleComponent component) + protected override void UpdateState(EntityUid uid, RadarConsoleComponent component) { - var xform = Transform(component.Owner); + var xform = Transform(uid); var onGrid = xform.ParentUid == xform.GridUid; EntityCoordinates? coordinates = onGrid ? xform.Coordinates : null; Angle? angle = onGrid ? xform.LocalRotation : null; // Use ourself I guess. - if (TryComp(component.Owner, out var intrinsic)) + if (TryComp(uid, out var intrinsic)) { foreach (var uiKey in intrinsic.UIs) { if (uiKey.Key?.Equals(RadarConsoleUiKey.Key) == true) { - coordinates = new EntityCoordinates(component.Owner, Vector2.Zero); + coordinates = new EntityCoordinates(uid, Vector2.Zero); angle = Angle.Zero; break; } } } - var radarState = new RadarConsoleBoundInterfaceState( - component.MaxRange, - coordinates, - angle, - new List()); - - _uiSystem.GetUiOrNull(component.Owner, RadarConsoleUiKey.Key)?.SetState(radarState); + if (_uiSystem.TryGetUi(uid, RadarConsoleUiKey.Key, out var bui)) + UserInterfaceSystem.SetUiState(bui, new RadarConsoleBoundInterfaceState( + component.MaxRange, + coordinates, + angle, + new List() + )); } } diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 16b55e70e5..1d8cf56748 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -135,7 +135,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem RefreshShuttleConsoles(); } - public void RefreshShuttleConsoles(EntityUid uid) + public void RefreshShuttleConsoles(EntityUid _) { // TODO: Should really call this per shuttle in some instances. RefreshShuttleConsoles(); @@ -149,7 +149,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem var docks = GetAllDocks(); var query = AllEntityQuery(); - while (query.MoveNext(out var uid, out var comp)) + while (query.MoveNext(out var uid, out var _)) { UpdateState(uid, docks); } @@ -160,7 +160,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem /// private void OnConsoleUIClose(EntityUid uid, ShuttleConsoleComponent component, BoundUIClosedEvent args) { - if ((ShuttleConsoleUiKey)args.UiKey != ShuttleConsoleUiKey.Key || + if ((ShuttleConsoleUiKey) args.UiKey != ShuttleConsoleUiKey.Key || args.Session.AttachedEntity is not { } user) { return; @@ -211,19 +211,18 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem { RemovePilot(user, pilotComponent); - if (console == component) - { + // This feels backwards; is this intended to be a toggle? + if (console == uid) return false; - } } - AddPilot(user, component); + AddPilot(uid, user, component); return true; } private void OnGetState(EntityUid uid, PilotComponent component, ref ComponentGetState args) { - args.State = new PilotComponentState(component.Console?.Owner); + args.State = new PilotComponentState(component.Console); } /// @@ -328,15 +327,16 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem docks ??= GetAllDocks(); - _ui.GetUiOrNull(consoleUid, ShuttleConsoleUiKey.Key) - ?.SetState(new ShuttleConsoleBoundInterfaceState( + if (_ui.TryGetUi(consoleUid, ShuttleConsoleUiKey.Key, out var bui)) + UserInterfaceSystem.SetUiState(bui, new ShuttleConsoleBoundInterfaceState( ftlState, ftlTime, destinations, range, consoleXform?.Coordinates, consoleXform?.LocalRotation, - docks)); + docks + )); } public override void Update(float frameTime) @@ -351,7 +351,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem if (comp.Console == null) continue; - if (!_blocker.CanInteract(uid, comp.Console.Owner)) + if (!_blocker.CanInteract(uid, comp.Console)) { toRemove.Add((uid, comp)); } @@ -395,21 +395,21 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem ClearPilots(component); } - public void AddPilot(EntityUid entity, ShuttleConsoleComponent component) + public void AddPilot(EntityUid uid, EntityUid entity, ShuttleConsoleComponent component) { - if (!EntityManager.TryGetComponent(entity, out PilotComponent? pilotComponent) || - component.SubscribedPilots.Contains(pilotComponent)) + if (!EntityManager.TryGetComponent(entity, out PilotComponent? pilotComponent) + || component.SubscribedPilots.Contains(entity)) { return; } - _eyeSystem.SetZoom(entity, component.Zoom, ignoreLimits:true); + _eyeSystem.SetZoom(entity, component.Zoom, ignoreLimits: true); - component.SubscribedPilots.Add(pilotComponent); + component.SubscribedPilots.Add(entity); _alertsSystem.ShowAlert(entity, AlertType.PilotingShuttle); - pilotComponent.Console = component; + pilotComponent.Console = uid; ActionBlockerSystem.UpdateCanMove(entity); pilotComponent.Position = EntityManager.GetComponent(entity).Coordinates; Dirty(pilotComponent); @@ -419,14 +419,14 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem { var console = pilotComponent.Console; - if (console is not ShuttleConsoleComponent helmsman) + if (!TryComp(console, out var helm)) return; pilotComponent.Console = null; pilotComponent.Position = null; _eyeSystem.ResetZoom(pilotUid); - if (!helmsman.SubscribedPilots.Remove(pilotComponent)) + if (!helm.SubscribedPilots.Remove(pilotUid)) return; _alertsSystem.ClearAlert(pilotUid, AlertType.PilotingShuttle); @@ -447,9 +447,11 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem public void ClearPilots(ShuttleConsoleComponent component) { + var query = GetEntityQuery(); while (component.SubscribedPilots.TryGetValue(0, out var pilot)) { - RemovePilot(pilot.Owner, pilot); + if (query.TryGetComponent(pilot, out var pilotComponent)) + RemovePilot(pilot, pilotComponent); } } } diff --git a/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs b/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs index f542b025c3..d79f993d87 100644 --- a/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs +++ b/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs @@ -2,6 +2,7 @@ using Content.Server.Solar.Components; using Content.Server.UserInterface; using Content.Shared.Solar; using JetBrains.Annotations; +using Robust.Server.GameObjects; namespace Content.Server.Solar.EntitySystems { @@ -11,7 +12,8 @@ namespace Content.Server.Solar.EntitySystems [UsedImplicitly] internal sealed class PowerSolarControlConsoleSystem : EntitySystem { - [Dependency] private PowerSolarSystem _powerSolarSystem = default!; + [Dependency] private readonly PowerSolarSystem _powerSolarSystem = default!; + [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; /// /// Timer used to avoid updating the UI state every frame (which would be overkill) @@ -32,9 +34,10 @@ namespace Content.Server.Solar.EntitySystems { _updateTimer -= 1; var state = new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun); - foreach (var component in EntityManager.EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var _, out var uiComp)) { - component.Owner.GetUIOrNull(SolarControlConsoleUiKey.Key)?.SetState(state); + _uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp); } } } diff --git a/Content.Server/StationEvents/Events/CargoGiftsRule.cs b/Content.Server/StationEvents/Events/CargoGiftsRule.cs index 5ee9f63fbd..f6ee90a568 100644 --- a/Content.Server/StationEvents/Events/CargoGiftsRule.cs +++ b/Content.Server/StationEvents/Events/CargoGiftsRule.cs @@ -1,28 +1,17 @@ using System.Linq; -using Content.Server.Anomaly; using Content.Server.Cargo.Components; using Content.Server.Cargo.Systems; using Content.Server.GameTicking; using Content.Server.GameTicking.Rules.Components; -using Content.Server.Station.Components; -using Content.Server.Station.Systems; using Content.Server.StationEvents.Components; -using Content.Shared.Access.Components; -using Content.Shared.Administration.Logs; -using Content.Shared.Cargo; using Content.Shared.Cargo.Prototypes; -using Content.Shared.Database; using Robust.Shared.Prototypes; -using Robust.Shared.Random; -using Robust.Shared.Utility; namespace Content.Server.StationEvents.Events; public sealed class CargoGiftsRule : StationEventSystem { [Dependency] private readonly CargoSystem _cargoSystem = default!; - [Dependency] private readonly StationSystem _stationSystem = default!; - [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly GameTicker _ticker = default!; @@ -61,7 +50,7 @@ public sealed class CargoGiftsRule : StationEventSystem } // Add some presents - int outstanding = _cargoSystem.GetOutstandingOrderCount(cargoDb); + var outstanding = CargoSystem.GetOutstandingOrderCount(cargoDb); while (outstanding < cargoDb.Capacity - component.OrderSpaceToLeave && component.Gifts.Count > 0) { // I wish there was a nice way to pop this @@ -71,13 +60,15 @@ public sealed class CargoGiftsRule : StationEventSystem var product = _prototypeManager.Index(productId); if (!_cargoSystem.AddAndApproveOrder( - cargoDb, + station!.Value, product.Product, product.PointCost, qty, Loc.GetString(component.Sender), Loc.GetString(component.Description), - Loc.GetString(component.Dest))) + Loc.GetString(component.Dest), + cargoDb + )) { break; } diff --git a/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs b/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs index 494d92e050..6f3a2a5fa1 100644 --- a/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs +++ b/Content.Server/StationRecords/Systems/GeneralStationRecordConsoleSystem.cs @@ -99,9 +99,7 @@ public sealed class GeneralStationRecordConsoleSystem : EntitySystem private void SetStateForInterface(EntityUid uid, GeneralStationRecordConsoleState newState) { - _userInterface - .GetUiOrNull(uid, GeneralStationRecordConsoleKey.Key) - ?.SetState(newState); + _userInterface.TrySetUiState(uid, GeneralStationRecordConsoleKey.Key, newState); } private bool IsSkippedRecord(GeneralStationRecordsFilter filter, diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 25eae824c1..300e0af9f5 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -23,7 +23,6 @@ using Content.Shared.Storage; using Content.Shared.Storage.Components; using Content.Shared.Timing; using Content.Shared.Verbs; -using JetBrains.Annotations; using Robust.Server.Containers; using Robust.Server.GameObjects; using Robust.Server.Player; @@ -33,7 +32,6 @@ using Robust.Shared.Map; using Robust.Shared.Physics.Systems; using Robust.Shared.Player; using Robust.Shared.Random; -using Robust.Shared.Timing; using Robust.Shared.Utility; using static Content.Shared.Storage.SharedStorageComponent; @@ -43,6 +41,7 @@ namespace Content.Server.Storage.EntitySystems { [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IAdminManager _admin = default!; + [Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly ContainerSystem _containerSystem = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; [Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!; @@ -68,7 +67,7 @@ namespace Content.Server.Storage.EntitySystems SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent>(AddOpenUiVerb); SubscribeLocalEvent>(AddTransferVerbs); - SubscribeLocalEvent(OnInteractUsing, after: new []{ typeof(ItemSlotsSystem)} ); + SubscribeLocalEvent(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) }); SubscribeLocalEvent(OnActivate); SubscribeLocalEvent(OnImplantActivate); SubscribeLocalEvent(AfterInteract); @@ -98,7 +97,7 @@ namespace Content.Server.Storage.EntitySystems private void AddOpenUiVerb(EntityUid uid, ServerStorageComponent component, GetVerbsEvent args) { - bool silent = false; + var silent = false; if (!args.CanAccess || !args.CanInteract || TryComp(uid, out var lockComponent) && lockComponent.Locked) { // we allow admins to open the storage anyways @@ -115,7 +114,7 @@ namespace Content.Server.Storage.EntitySystems return; // Does this player currently have the storage UI open? - bool uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession); + var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession); ActivationVerb verb = new() { @@ -125,13 +124,13 @@ namespace Content.Server.Storage.EntitySystems { verb.Text = Loc.GetString("verb-common-close-ui"); verb.Icon = new SpriteSpecifier.Texture( - new ("/Textures/Interface/VerbIcons/close.svg.192dpi.png")); + new("/Textures/Interface/VerbIcons/close.svg.192dpi.png")); } else { verb.Text = Loc.GetString("verb-common-open-ui"); verb.Icon = new SpriteSpecifier.Texture( - new ("/Textures/Interface/VerbIcons/open.svg.192dpi.png")); + new("/Textures/Interface/VerbIcons/open.svg.192dpi.png")); } args.Verbs.Add(verb); } @@ -169,7 +168,8 @@ namespace Content.Server.Storage.EntitySystems if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) return; - Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used})."); + _logManager.GetSawmill(storageComp.LoggerName) + .Debug($"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used})."); if (HasComp(uid)) return; @@ -253,7 +253,7 @@ namespace Content.Server.Storage.EntitySystems // Pick up the clicked entity if (storageComp.QuickInsert) { - if (args.Target is not {Valid: true} target) + if (args.Target is not { Valid: true } target) return; if (_containerSystem.IsEntityInContainer(target) @@ -267,7 +267,9 @@ namespace Content.Server.Storage.EntitySystems var position = EntityCoordinates.FromMap( parent.IsValid() ? parent : uid, - transformEnt.MapPosition); + transformEnt.MapPosition, + _transform + ); if (PlayerInsertEntityInWorld(uid, args.User, target, storageComp)) { @@ -307,8 +309,9 @@ namespace Content.Server.Storage.EntitySystems var position = EntityCoordinates.FromMap( xform.ParentUid.IsValid() ? xform.ParentUid : uid, - new MapCoordinates(_transform.GetWorldPosition(targetXform, xformQuery), - targetXform.MapID), EntityManager); + new MapCoordinates(_transform.GetWorldPosition(targetXform, xformQuery), targetXform.MapID), + _transform + ); if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component)) { @@ -353,7 +356,7 @@ namespace Content.Server.Storage.EntitySystems if (!Exists(args.InteractedItemUID)) { - Logger.Error($"Player {args.Session} interacted with non-existent item {args.InteractedItemUID} stored in {ToPrettyString(uid)}"); + Log.Error($"Player {args.Session} interacted with non-existent item {args.InteractedItemUID} stored in {ToPrettyString(uid)}"); return; } @@ -605,29 +608,6 @@ namespace Content.Server.Storage.EntitySystems return true; } - private bool CanCombineStacks( - ServerStorageComponent storageComp, - StackComponent stack) - { - if (storageComp.Storage == null) - return false; - - var stackQuery = GetEntityQuery(); - var countLeft = stack.Count; - foreach (var ent in storageComp.Storage.ContainedEntities) - { - if (!stackQuery.TryGetComponent(ent, out var destStack)) - continue; - - if (destStack.StackTypeId != stack.StackTypeId) - continue; - - countLeft -= _stack.GetAvailableSpace(stack); - } - - return countLeft <= 0; - } - // REMOVE: remove and drop on the ground public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null) { @@ -705,7 +685,8 @@ namespace Content.Server.Storage.EntitySystems _useDelay.BeginDelay(uid, useDelay); } - Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity})."); + _logManager.GetSawmill(storageComp.LoggerName) + .Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity})."); var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key); if (bui != null) @@ -750,10 +731,10 @@ namespace Content.Server.Storage.EntitySystems var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key); if (bui != null) - _uiSystem.SetUiState(bui, state); + UserInterfaceSystem.SetUiState(bui, state); } - private void Popup(EntityUid uid, EntityUid player, string message, ServerStorageComponent storageComp) + private void Popup(EntityUid _, EntityUid player, string message, ServerStorageComponent storageComp) { if (!storageComp.ShowPopup) return; @@ -761,8 +742,7 @@ namespace Content.Server.Storage.EntitySystems _popupSystem.PopupEntity(Loc.GetString(message), player, player); } - private void PopupEnt(EntityUid uid, EntityUid player, string message, EntityUid entityUid, - ServerStorageComponent storageComp) + private void PopupEnt(EntityUid _, EntityUid player, string message, EntityUid entityUid, ServerStorageComponent storageComp) { if (!storageComp.ShowPopup) return; diff --git a/Content.Server/Store/Systems/StoreSystem.Ui.cs b/Content.Server/Store/Systems/StoreSystem.Ui.cs index cde624ef72..19f5a2105e 100644 --- a/Content.Server/Store/Systems/StoreSystem.Ui.cs +++ b/Content.Server/Store/Systems/StoreSystem.Ui.cs @@ -98,7 +98,7 @@ public sealed partial class StoreSystem // only tell operatives to lock their uplink if it can be locked var showFooter = HasComp(store); var state = new StoreUpdateState(component.LastAvailableListings, allCurrency, showFooter); - _ui.SetUiState(ui, state); + UserInterfaceSystem.SetUiState(ui, state); } private void OnRequestUpdate(EntityUid uid, StoreComponent component, StoreRequestUpdateInterfaceMessage args) @@ -119,7 +119,7 @@ public sealed partial class StoreSystem var listing = component.Listings.FirstOrDefault(x => x.Equals(msg.Listing)); if (listing == null) //make sure this listing actually exists { - Logger.Debug("listing does not exist"); + Log.Debug("listing does not exist"); return; } @@ -205,7 +205,7 @@ public sealed partial class StoreSystem if (proto.Cash == null || !proto.CanWithdraw) return; - if (msg.Session.AttachedEntity is not { Valid: true} buyer) + if (msg.Session.AttachedEntity is not { Valid: true } buyer) return; FixedPoint2 amountRemaining = msg.Amount; diff --git a/Content.Server/Store/Systems/StoreSystem.cs b/Content.Server/Store/Systems/StoreSystem.cs index 634f1257b9..3f769b6736 100644 --- a/Content.Server/Store/Systems/StoreSystem.cs +++ b/Content.Server/Store/Systems/StoreSystem.cs @@ -1,5 +1,3 @@ -using Content.Server.Mind.Components; -using Content.Server.PDA.Ringer; using Content.Server.Store.Components; using Content.Server.UserInterface; using Content.Shared.FixedPoint; @@ -185,7 +183,7 @@ public sealed partial class StoreSystem : EntitySystem var ui = _ui.GetUiOrNull(uid, StoreUiKey.Key); if (ui != null) { - _ui.SetUiState(ui, new StoreInitializeState(preset.StoreName)); + UserInterfaceSystem.SetUiState(ui, new StoreInitializeState(preset.StoreName)); } } } diff --git a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs index 486ce3b752..ae17ca4f8f 100644 --- a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs +++ b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs @@ -137,13 +137,12 @@ public sealed class SurveillanceCameraRouterSystem : EntitySystem private void OpenSetupInterface(EntityUid uid, EntityUid player, SurveillanceCameraRouterComponent? camera = null, ActorComponent? actor = null) { - if (!Resolve(uid, ref camera) - || !Resolve(player, ref actor)) - { + if (!Resolve(uid, ref camera) || !Resolve(player, ref actor)) + return; + if (!_userInterface.TryGetUi(uid, SurveillanceCameraSetupUiKey.Router, out var bui)) return; - } - _userInterface.GetUiOrNull(uid, SurveillanceCameraSetupUiKey.Router)!.Open(actor.PlayerSession); + _userInterface.OpenUi(bui, actor.PlayerSession); UpdateSetupInterface(uid, camera); } diff --git a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs index 32bb567678..f159ec52d9 100644 --- a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs +++ b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs @@ -197,13 +197,12 @@ public sealed class SurveillanceCameraSystem : EntitySystem private void OpenSetupInterface(EntityUid uid, EntityUid player, SurveillanceCameraComponent? camera = null, ActorComponent? actor = null) { - if (!Resolve(uid, ref camera) - || !Resolve(player, ref actor)) - { + if (!Resolve(uid, ref camera) || !Resolve(player, ref actor)) + return; + if (!_userInterface.TryGetUi(uid, SurveillanceCameraSetupUiKey.Camera, out var bui)) return; - } - _userInterface.GetUiOrNull(uid, SurveillanceCameraSetupUiKey.Camera)!.Open(actor.PlayerSession); + _userInterface.OpenUi(bui, actor.PlayerSession); UpdateSetupInterface(uid, camera); } diff --git a/Content.Server/UserInterface/ActivatableUISystem.cs b/Content.Server/UserInterface/ActivatableUISystem.cs index 8730c347dc..eb1343560c 100644 --- a/Content.Server/UserInterface/ActivatableUISystem.cs +++ b/Content.Server/UserInterface/ActivatableUISystem.cs @@ -144,7 +144,7 @@ public sealed partial class ActivatableUISystem : EntitySystem RaiseLocalEvent((aui).Owner, bae, false); SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui); - ui.Toggle(actor.PlayerSession); + _uiSystem.ToggleUi(ui, actor.PlayerSession); //Let the component know a user opened it so it can do whatever it needs to do var aae = new AfterActivatableUIOpenEvent(user, actor.PlayerSession); @@ -167,8 +167,12 @@ public sealed partial class ActivatableUISystem : EntitySystem public void CloseAll(EntityUid uid, ActivatableUIComponent? aui = null) { - if (!Resolve(uid, ref aui, false)) return; - aui.UserInterface?.CloseAll(); + if (!Resolve(uid, ref aui, false)) + return; + if (aui.UserInterface is null) + return; + + _uiSystem.CloseAll(aui.UserInterface); } private void OnHandDeselected(EntityUid uid, ActivatableUIComponent? aui, HandDeselectedEvent args) diff --git a/Content.Server/UserInterface/IntrinsicUISystem.cs b/Content.Server/UserInterface/IntrinsicUISystem.cs index 9811e9c6bc..7d76bfe8b6 100644 --- a/Content.Server/UserInterface/IntrinsicUISystem.cs +++ b/Content.Server/UserInterface/IntrinsicUISystem.cs @@ -8,6 +8,7 @@ namespace Content.Server.UserInterface; public sealed class IntrinsicUISystem : EntitySystem { [Dependency] private readonly ActionsSystem _actionsSystem = default!; + [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; public override void Initialize() { @@ -54,7 +55,7 @@ public sealed class IntrinsicUISystem : EntitySystem if (attempt.Cancelled) return false; - ui.Toggle(actor.PlayerSession); + _uiSystem.ToggleUi(ui, actor.PlayerSession); return true; } diff --git a/Content.Server/VoiceMask/VoiceMaskSystem.cs b/Content.Server/VoiceMask/VoiceMaskSystem.cs index 43b627c6a0..05a87891e0 100644 --- a/Content.Server/VoiceMask/VoiceMaskSystem.cs +++ b/Content.Server/VoiceMask/VoiceMaskSystem.cs @@ -5,10 +5,8 @@ using Content.Shared.Actions; using Content.Shared.Database; using Content.Shared.Inventory.Events; using Content.Shared.Preferences; -using Content.Shared.Verbs; using Content.Shared.VoiceMask; using Robust.Server.GameObjects; -using Robust.Shared.Player; namespace Content.Server.VoiceMask; @@ -71,11 +69,11 @@ public sealed partial class VoiceMaskSystem : EntitySystem private void OpenUI(EntityUid player, ActorComponent? actor = null) { if (!Resolve(player, ref actor)) - { return; - } + if (!_uiSystem.TryGetUi(player, VoiceMaskUIKey.Key, out var bui)) + return; - _uiSystem.GetUiOrNull(player, VoiceMaskUIKey.Key)?.Open(actor.PlayerSession); + _uiSystem.OpenUi(bui, actor.PlayerSession); UpdateUI(player); } @@ -86,7 +84,8 @@ public sealed partial class VoiceMaskSystem : EntitySystem return; } - _uiSystem.GetUiOrNull(owner, VoiceMaskUIKey.Key)?.SetState(new VoiceMaskBuiState(component.VoiceName)); + if (_uiSystem.TryGetUi(owner, VoiceMaskUIKey.Key, out var bui)) + UserInterfaceSystem.SetUiState(bui, new VoiceMaskBuiState(component.VoiceName)); } } diff --git a/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs b/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs index a9930ec36f..b68e621704 100644 --- a/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs +++ b/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs @@ -1,6 +1,5 @@ using System.Linq; using Content.Server.Construction; -using Content.Server.DeviceLinking.Events; using Content.Server.MachineLinking.Components; using Content.Server.Paper; using Content.Server.Power.Components; @@ -41,6 +40,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem [Dependency] private readonly ArtifactSystem _artifact = default!; [Dependency] private readonly PaperSystem _paper = default!; [Dependency] private readonly ResearchSystem _research = default!; + [Dependency] private readonly MetaDataSystem _metaSystem = default!; /// public override void Initialize() @@ -66,11 +66,11 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem SubscribeLocalEvent(OnPrintButton); SubscribeLocalEvent(OnExtractButton); - SubscribeLocalEvent((e,c,_) => UpdateUserInterface(e,c), - after: new []{typeof(ResearchSystem)}); - SubscribeLocalEvent((e,c,_) => UpdateUserInterface(e,c), - after: new []{typeof(ResearchSystem)}); - SubscribeLocalEvent((e,c,_) => UpdateUserInterface(e,c)); + SubscribeLocalEvent((e, c, _) => UpdateUserInterface(e, c), + after: new[] { typeof(ResearchSystem) }); + SubscribeLocalEvent((e, c, _) => UpdateUserInterface(e, c), + after: new[] { typeof(ResearchSystem) }); + SubscribeLocalEvent((e, c, _) => UpdateUserInterface(e, c)); } public override void Update(float frameTime) @@ -83,7 +83,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem if (scan.Console != null) UpdateUserInterface(scan.Console.Value); - if (_timing.CurTime - active.StartTime < (scan.AnalysisDuration * scan.AnalysisDurationMulitplier)) + if (_timing.CurTime - active.StartTime < scan.AnalysisDuration * scan.AnalysisDurationMulitplier) continue; FinishScan(uid, scan, active); @@ -222,7 +222,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem canScan, canPrint, msg, scanning, remaining, totalTime, points); var bui = _ui.GetUi(uid, ArtifactAnalzyerUiKey.Key); - _ui.SetUiState(bui, state); + UserInterfaceSystem.SetUiState(bui, state); } /// @@ -277,7 +277,7 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem analyzer.ReadyToPrint = false; var report = Spawn(component.ReportEntityId, Transform(uid).Coordinates); - MetaData(report).EntityName = Loc.GetString("analysis-report-title", ("id", analyzer.LastAnalyzedNode.Id)); + _metaSystem.SetEntityName(report, Loc.GetString("analysis-report-title", ("id", analyzer.LastAnalyzedNode.Id))); var msg = GetArtifactScanMessage(analyzer); if (msg == null) diff --git a/Content.Shared/Shuttles/Components/PilotComponent.cs b/Content.Shared/Shuttles/Components/PilotComponent.cs index 6d05a18c4a..ad176bb301 100644 --- a/Content.Shared/Shuttles/Components/PilotComponent.cs +++ b/Content.Shared/Shuttles/Components/PilotComponent.cs @@ -13,12 +13,14 @@ namespace Content.Shared.Shuttles.Components [NetworkedComponent] public sealed class PilotComponent : Component { - [ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; } + [ViewVariables] + public EntityUid? Console { get; set; } /// /// Where we started piloting from to check if we should break from moving too far. /// - [ViewVariables] public EntityCoordinates? Position { get; set; } + [ViewVariables] + public EntityCoordinates? Position { get; set; } public const float BreakDistance = 0.25f; diff --git a/Content.Shared/Shuttles/Components/RadarConsoleComponent.cs b/Content.Shared/Shuttles/Components/RadarConsoleComponent.cs index 2cc37620ec..718c5204c1 100644 --- a/Content.Shared/Shuttles/Components/RadarConsoleComponent.cs +++ b/Content.Shared/Shuttles/Components/RadarConsoleComponent.cs @@ -13,7 +13,7 @@ public sealed class RadarConsoleComponent : Component set => IoCManager .Resolve() .GetEntitySystem() - .SetRange(this, value); + .SetRange(Owner, value, this); } [DataField("maxRange")] diff --git a/Content.Shared/Shuttles/Systems/SharedRadarConsoleSystem.cs b/Content.Shared/Shuttles/Systems/SharedRadarConsoleSystem.cs index 826eaf13b3..2e98e89923 100644 --- a/Content.Shared/Shuttles/Systems/SharedRadarConsoleSystem.cs +++ b/Content.Shared/Shuttles/Systems/SharedRadarConsoleSystem.cs @@ -18,7 +18,9 @@ public abstract class SharedRadarConsoleSystem : EntitySystem private void OnHandleState(EntityUid uid, RadarConsoleComponent component, ref ComponentHandleState args) { - if (args.Current is not RadarConsoleComponentState state) return; + if (args.Current is not RadarConsoleComponentState state) + return; + component.MaxRange = state.Range; } @@ -30,14 +32,18 @@ public abstract class SharedRadarConsoleSystem : EntitySystem }; } - protected virtual void UpdateState(RadarConsoleComponent component) {} - - public void SetRange(RadarConsoleComponent component, float value) + protected virtual void UpdateState(EntityUid uid, RadarConsoleComponent component) { - if (component.MaxRange.Equals(value)) return; + } + + public void SetRange(EntityUid uid, float value, RadarConsoleComponent component) + { + if (component.MaxRange.Equals(value)) + return; + component.MaxRange = value; - Dirty(component); - UpdateState(component); + Dirty(uid, component); + UpdateState(uid, component); } [Serializable, NetSerializable] diff --git a/Content.Shared/Shuttles/Systems/SharedShuttleConsoleSystem.cs b/Content.Shared/Shuttles/Systems/SharedShuttleConsoleSystem.cs index 28a0cf9c7c..5b3949b6c2 100644 --- a/Content.Shared/Shuttles/Systems/SharedShuttleConsoleSystem.cs +++ b/Content.Shared/Shuttles/Systems/SharedShuttleConsoleSystem.cs @@ -1,5 +1,4 @@ using Content.Shared.ActionBlocker; -using Content.Shared.Movement; using Content.Shared.Movement.Events; using Content.Shared.Shuttles.Components; using Robust.Shared.Serialization; @@ -43,8 +42,9 @@ namespace Content.Shared.Shuttles.Systems { if (component.LifeStage > ComponentLifeStage.Running) return; + if (component.Console == null) + return; - if (component.Console == null) return; args.Cancel(); } }