]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Kill `UserInterfaceHelpers` (#20912)
authorKara <lunarautomaton6@gmail.com>
Wed, 11 Oct 2023 09:17:59 +0000 (02:17 -0700)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 09:17:59 +0000 (20:17 +1100)
12 files changed:
Content.Server/Communications/CommunicationsConsoleComponent.cs
Content.Server/Communications/CommunicationsConsoleSystem.cs
Content.Server/Crayon/CrayonComponent.cs
Content.Server/Crayon/CrayonSystem.cs
Content.Server/Instruments/InstrumentComponent.cs
Content.Server/Instruments/InstrumentSystem.cs
Content.Server/Medical/Components/HealthAnalyzerComponent.cs
Content.Server/Medical/HealthAnalyzerSystem.cs
Content.Server/UserInterface/ActivatableUIComponent.cs
Content.Server/UserInterface/ActivatableUISystem.cs
Content.Server/UserInterface/IntrinsicUISystem.cs
Content.Server/UserInterface/UserInterfaceHelpers.cs [deleted file]

index 82a4a94539775f165be8520eaf25fd33ec488488..e2aa0d7620140f80112732ab74a98a8e9e750105 100644 (file)
@@ -55,7 +55,5 @@ namespace Content.Server.Communications
         /// </summary>
         [DataField]
         public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg");
-
-        public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key);
     }
 }
index e2a96335d019a3640885a477da2d7ca6014f8cb9..b5c938549291050b89dd4283787a55cc54bf2ed3 100644 (file)
@@ -72,8 +72,8 @@ namespace Content.Server.Communications
 
                 comp.UIUpdateAccumulator -= UIUpdateInterval;
 
-                if (comp.UserInterface is { } ui && ui.SubscribedSessions.Count > 0)
-                    UpdateCommsConsoleInterface(uid, comp);
+                if (_uiSystem.TryGetUi(uid, CommunicationsConsoleUiKey.Key, out var ui) && ui.SubscribedSessions.Count > 0)
+                    UpdateCommsConsoleInterface(uid, comp, ui);
             }
 
             base.Update(frameTime);
@@ -121,9 +121,11 @@ namespace Content.Server.Communications
         /// <summary>
         /// Updates the UI for a particular comms console.
         /// </summary>
-        /// <param name="comp"></param>
-        public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComponent comp)
+        public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComponent comp, PlayerBoundUserInterface? ui = null)
         {
+            if (ui == null && !_uiSystem.TryGetUi(uid, CommunicationsConsoleUiKey.Key, out ui))
+                return;
+
             var stationUid = _stationSystem.GetOwningStation(uid);
             List<string>? levels = null;
             string currentLevel = default!;
@@ -151,15 +153,14 @@ namespace Content.Server.Communications
                 }
             }
 
-            if (comp.UserInterface is not null)
-                _uiSystem.SetUiState(comp.UserInterface, new CommunicationsConsoleInterfaceState(
-                    CanAnnounce(comp),
-                    CanCallOrRecall(comp),
-                    levels,
-                    currentLevel,
-                    currentDelay,
-                    _roundEndSystem.ExpectedCountdownEnd
-                ));
+            _uiSystem.SetUiState(ui, new CommunicationsConsoleInterfaceState(
+                CanAnnounce(comp),
+                CanCallOrRecall(comp),
+                levels,
+                currentLevel,
+                currentDelay,
+                _roundEndSystem.ExpectedCountdownEnd
+            ));
         }
 
         private static bool CanAnnounce(CommunicationsConsoleComponent comp)
@@ -203,7 +204,9 @@ 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);
@@ -284,8 +287,12 @@ 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 (!CanCallOrRecall(comp))
+                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);
@@ -306,8 +313,12 @@ 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 (!CanCallOrRecall(comp))
+                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);
index 6f2cd6d397e40298b9e13a7b61c7e3259dc0a215..df20681938d6f967d67689d0472736cae8a5391a 100644 (file)
@@ -24,7 +24,5 @@ namespace Content.Server.Crayon
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField("deleteEmpty")]
         public bool DeleteEmpty = true;
-
-        [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
     }
 }
index 7cc2c20d897e22f1793fa23f297b9204fea45ff2..d225df2daea12c9355134ad687721fc7acbed397 100644 (file)
@@ -74,7 +74,8 @@ public sealed class CrayonSystem : SharedCrayonSystem
 
         // Decrease "Ammo"
         component.Charges--;
-        Dirty(component);
+        Dirty(uid, component);
+
         _adminLogger.Add(LogType.CrayonDraw, LogImpact.Low, $"{EntityManager.ToPrettyString(args.User):user} drew a {component.Color:color} {component.SelectedState}");
         args.Handled = true;
 
@@ -89,17 +90,16 @@ public sealed class CrayonSystem : SharedCrayonSystem
             return;
 
         if (!TryComp<ActorComponent>(args.User, out var actor) ||
-            component.UserInterface == null)
+            !_uiSystem.TryGetUi(uid, SharedCrayonComponent.CrayonUiKey.Key, out var ui))
         {
             return;
         }
 
-        _uiSystem.ToggleUi(component.UserInterface, actor.PlayerSession);
-
-        if (component.UserInterface?.SubscribedSessions.Contains(actor.PlayerSession) == true)
+        _uiSystem.ToggleUi(ui, actor.PlayerSession);
+        if (ui.SubscribedSessions.Contains(actor.PlayerSession))
         {
             // Tell the user interface the selected stuff
-            _uiSystem.SetUiState(component.UserInterface, new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color));
+            _uiSystem.SetUiState(ui, new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color));
         }
 
         args.Handled = true;
@@ -108,22 +108,22 @@ public sealed class CrayonSystem : SharedCrayonSystem
     private void OnCrayonBoundUI(EntityUid uid, CrayonComponent component, CrayonSelectMessage args)
     {
         // Check if the selected state is valid
-        if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon")) return;
+        if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon"))
+            return;
 
         component.SelectedState = args.State;
 
-        Dirty(component);
+        Dirty(uid, component);
     }
 
     private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args)
     {
         // you still need to ensure that the given color is a valid color
-        if (component.SelectableColor && args.Color != component.Color)
-        {
-            component.Color = args.Color;
+        if (!component.SelectableColor || args.Color == component.Color)
+            return;
 
-            Dirty(component);
-        }
+        component.Color = args.Color;
+        Dirty(uid, component);
 
     }
 
@@ -134,7 +134,7 @@ public sealed class CrayonSystem : SharedCrayonSystem
         // Get the first one from the catalog and set it as default
         var decal = _prototypeManager.EnumeratePrototypes<DecalPrototype>().FirstOrDefault(x => x.Tags.Contains("crayon"));
         component.SelectedState = decal?.ID ?? string.Empty;
-        Dirty(component);
+        Dirty(uid, component);
     }
 
     private void OnCrayonDropped(EntityUid uid, CrayonComponent component, DroppedEvent args)
index 5a6b5828da2ed4c40926221d1da31815c431bfe4..810d265314662132d64e171ec97625e2eabe3f64 100644 (file)
@@ -20,8 +20,6 @@ public sealed partial class InstrumentComponent : SharedInstrumentComponent
     public IPlayerSession? InstrumentPlayer =>
         _entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser
         ?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession;
-
-    [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
 }
 
 [RegisterComponent]
index 4e002eb677c1f6b08504e345dd774d2eedbf5686..ec233821051b8d25dd60976aba8392bfae9f5cfc 100644 (file)
@@ -5,7 +5,6 @@ using Content.Server.Stunnable;
 using Content.Shared.Administration;
 using Content.Shared.Instruments;
 using Content.Shared.Instruments.UI;
-using Content.Shared.Interaction;
 using Content.Shared.Physics;
 using Content.Shared.Popups;
 using JetBrains.Annotations;
@@ -17,7 +16,6 @@ using Robust.Shared.Configuration;
 using Robust.Shared.Console;
 using Robust.Shared.GameStates;
 using Robust.Shared.Timing;
-using Robust.Shared.Utility;
 
 namespace Content.Server.Instruments;
 
@@ -435,9 +433,7 @@ public sealed partial class InstrumentSystem : SharedInstrumentSystem
 
                 // Just in case
                 Clean(uid);
-
-                if (instrument.UserInterface is not null)
-                    _bui.CloseAll(instrument.UserInterface);
+                _bui.TryCloseAll(uid, InstrumentUiKey.Key);
             }
 
             instrument.Timer += frameTime;
index 4b0bb5ff1fb7e20a787a16b609ff175b0a0895dd..39b1df573f20641d9c1253fce52a1ff718f686e9 100644 (file)
@@ -17,8 +17,6 @@ namespace Content.Server.Medical.Components
         [DataField("scanDelay")]
         public float ScanDelay = 0.8f;
 
-        public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
-
         /// <summary>
         ///     Sound played on scanning begin
         /// </summary>
index 79d55e8068c2d8b535584cd5b83d7f179c769e47..6e2f7fdf368cf6ef4a549d598060052948b1f1c3 100644 (file)
@@ -51,12 +51,12 @@ namespace Content.Server.Medical
             args.Handled = true;
         }
 
-        private void OpenUserInterface(EntityUid user, HealthAnalyzerComponent healthAnalyzer)
+        private void OpenUserInterface(EntityUid user, EntityUid analyzer)
         {
-            if (!TryComp<ActorComponent>(user, out var actor) || healthAnalyzer.UserInterface == null)
+            if (!TryComp<ActorComponent>(user, out var actor) || !_uiSystem.TryGetUi(analyzer, HealthAnalyzerUiKey.Key, out var ui))
                 return;
 
-            _uiSystem.OpenUi(healthAnalyzer.UserInterface ,actor.PlayerSession);
+            _uiSystem.OpenUi(ui ,actor.PlayerSession);
         }
 
         public void UpdateScannedUser(EntityUid uid, EntityUid user, EntityUid? target, HealthAnalyzerComponent? healthAnalyzer)
@@ -64,7 +64,7 @@ namespace Content.Server.Medical
             if (!Resolve(uid, ref healthAnalyzer))
                 return;
 
-            if (target == null || healthAnalyzer.UserInterface == null)
+            if (target == null || !_uiSystem.TryGetUi(uid, HealthAnalyzerUiKey.Key, out var ui))
                 return;
 
             if (!HasComp<DamageableComponent>(target))
@@ -73,9 +73,9 @@ namespace Content.Server.Medical
             TryComp<TemperatureComponent>(target, out var temp);
             TryComp<BloodstreamComponent>(target, out var bloodstream);
 
-            OpenUserInterface(user, healthAnalyzer);
+            OpenUserInterface(user, uid);
 
-            _uiSystem.SendUiMessage(healthAnalyzer.UserInterface, new HealthAnalyzerScannedUserMessage(GetNetEntity(target), temp != null ? temp.CurrentTemperature : float.NaN,
+            _uiSystem.SendUiMessage(ui, new HealthAnalyzerScannedUserMessage(GetNetEntity(target), temp != null ? temp.CurrentTemperature : float.NaN,
                 bloodstream != null ? bloodstream.BloodSolution.FillFraction : float.NaN));
         }
     }
index ff605c81190381dba13a7dc0098134640beb3dc0..bb020608e2042e1d0531aaebd34fd25ef08e13fa 100644 (file)
@@ -11,8 +11,6 @@ namespace Content.Server.UserInterface
         [ViewVariables]
         public Enum? Key { get; set; }
 
-        [ViewVariables] public PlayerBoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null;
-
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField]
         public bool InHandsOnly { get; set; } = false;
index c200d7a3f0045c56ffc2806457435278b882500a..59086415b46ca6221ce972808a7cb084541c650d 100644 (file)
@@ -76,7 +76,7 @@ public sealed partial class ActivatableUISystem : EntitySystem
             return;
 
         ActivationVerb verb = new();
-        verb.Act = () => InteractUI(args.User, component);
+        verb.Act = () => InteractUI(args.User, uid, component);
         verb.Text = Loc.GetString(component.VerbText);
         // TODO VERBS add "open UI" icon?
         args.Verbs.Add(verb);
@@ -84,16 +84,24 @@ public sealed partial class ActivatableUISystem : EntitySystem
 
     private void OnActivate(EntityUid uid, ActivatableUIComponent component, ActivateInWorldEvent args)
     {
-        if (args.Handled) return;
-        if (component.InHandsOnly) return;
-        args.Handled = InteractUI(args.User, component);
+        if (args.Handled)
+            return;
+
+        if (component.InHandsOnly)
+            return;
+
+        args.Handled = InteractUI(args.User, uid, component);
     }
 
     private void OnUseInHand(EntityUid uid, ActivatableUIComponent component, UseInHandEvent args)
     {
-        if (args.Handled) return;
-        if (component.rightClickOnly) return;
-        args.Handled = InteractUI(args.User, component);
+        if (args.Handled)
+            return;
+
+        if (component.rightClickOnly)
+            return;
+
+        args.Handled = InteractUI(args.User, uid, component);
     }
 
     private void OnParentChanged(EntityUid uid, ActivatableUIComponent aui, ref EntParentChangedMessage args)
@@ -103,53 +111,64 @@ public sealed partial class ActivatableUISystem : EntitySystem
 
     private void OnUIClose(EntityUid uid, ActivatableUIComponent component, BoundUIClosedEvent args)
     {
-        if (args.Session != component.CurrentSingleUser) return;
-        if (args.UiKey != component.Key) return;
+        if (args.Session != component.CurrentSingleUser)
+            return;
+
+        if (!Equals(args.UiKey, component.Key))
+            return;
+
         SetCurrentSingleUser(uid, null, component);
     }
 
-    private bool InteractUI(EntityUid user, ActivatableUIComponent aui)
+    private bool InteractUI(EntityUid user, EntityUid uiEntity, ActivatableUIComponent aui)
     {
-        if (!_blockerSystem.CanInteract(user, aui.Owner) && (!aui.AllowSpectator || !HasComp<GhostComponent>(user)))
+        if (!_blockerSystem.CanInteract(user, uiEntity) && (!aui.AllowSpectator || !HasComp<GhostComponent>(user)))
             return false;
 
         if (aui.RequireHands && !HasComp<HandsComponent>(user))
             return false;
 
-        if (!EntityManager.TryGetComponent(user, out ActorComponent? actor)) return false;
+        if (!EntityManager.TryGetComponent(user, out ActorComponent? actor))
+            return false;
+
+        if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession))
+            return false;
 
-        if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) return false;
+        if (aui.Key == null)
+            return false;
 
-        var ui = aui.UserInterface;
-        if (ui == null) return false;
+        if (!_uiSystem.TryGetUi(uiEntity, aui.Key, out var ui))
+            return false;
 
         if (aui.SingleUser && (aui.CurrentSingleUser != null) && (actor.PlayerSession != aui.CurrentSingleUser))
         {
             // If we get here, supposedly, the object is in use.
             // Check with BUI that it's ACTUALLY in use just in case.
             // Since this could brick the object if it goes wrong.
-            if (ui.SubscribedSessions.Count != 0) return false;
+            if (ui.SubscribedSessions.Count != 0)
+                return false;
         }
 
         // If we've gotten this far, fire a cancellable event that indicates someone is about to activate this.
         // This is so that stuff can require further conditions (like power).
         var oae = new ActivatableUIOpenAttemptEvent(user);
-        var uae = new UserOpenActivatableUIAttemptEvent(user, aui.Owner);
-        RaiseLocalEvent(user, uae, false);
-        RaiseLocalEvent((aui).Owner, oae, false);
-        if (oae.Cancelled || uae.Cancelled) return false;
+        var uae = new UserOpenActivatableUIAttemptEvent(user, uiEntity);
+        RaiseLocalEvent(user, uae);
+        RaiseLocalEvent(uiEntity, oae);
+        if (oae.Cancelled || uae.Cancelled)
+            return false;
 
         // Give the UI an opportunity to prepare itself if it needs to do anything
         // before opening
         var bae = new BeforeActivatableUIOpenEvent(user);
-        RaiseLocalEvent((aui).Owner, bae, false);
+        RaiseLocalEvent(uiEntity, bae);
 
-        SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui);
+        SetCurrentSingleUser(uiEntity, actor.PlayerSession, aui);
         _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);
-        RaiseLocalEvent((aui).Owner, aae, false);
+        RaiseLocalEvent(uiEntity, aae);
 
         return true;
     }
@@ -163,24 +182,28 @@ public sealed partial class ActivatableUISystem : EntitySystem
 
         aui.CurrentSingleUser = v;
 
-        RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent(), false);
+        RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent());
     }
 
     public void CloseAll(EntityUid uid, ActivatableUIComponent? aui = null)
     {
         if (!Resolve(uid, ref aui, false))
             return;
-        if (aui.UserInterface is null)
+
+        if (aui.Key == null || !_uiSystem.TryGetUi(uid, aui.Key, out var ui))
             return;
 
-        _uiSystem.CloseAll(aui.UserInterface);
+        _uiSystem.CloseAll(ui);
     }
 
     private void OnHandDeselected(EntityUid uid, ActivatableUIComponent? aui, HandDeselectedEvent args)
     {
-        if (!Resolve(uid, ref aui, false)) return;
+        if (!Resolve(uid, ref aui, false))
+            return;
+
         if (!aui.CloseOnHandDeselect)
             return;
+
         CloseAll(uid, aui);
     }
 }
index bd449df5f5d879eac86fedccc91dbc573b953301..27b682cd41e642bd621034ccbf2876b47764aa42 100644 (file)
@@ -1,5 +1,4 @@
 using Content.Server.Actions;
-using Content.Shared.Actions;
 using Content.Shared.UserInterface;
 using Robust.Server.GameObjects;
 
@@ -36,19 +35,19 @@ public sealed class IntrinsicUISystem : EntitySystem
 
         if (key is null)
         {
-            Logger.ErrorS("bui", $"Entity {ToPrettyString(uid)} has an invalid intrinsic UI.");
+            Log.Error($"Entity {ToPrettyString(uid)} has an invalid intrinsic UI.");
         }
 
         var ui = GetUIOrNull(uid, key, iui);
 
         if (ui is null)
         {
-            Logger.ErrorS("bui", $"Couldn't get UI {key} on {ToPrettyString(uid)}");
+            Log.Error($"Couldn't get UI {key} on {ToPrettyString(uid)}");
             return false;
         }
 
         var attempt = new IntrinsicUIOpenAttemptEvent(uid, key);
-        RaiseLocalEvent(uid, attempt, false);
+        RaiseLocalEvent(uid, attempt);
         if (attempt.Cancelled)
             return false;
 
@@ -61,7 +60,7 @@ public sealed class IntrinsicUISystem : EntitySystem
         if (!Resolve(uid, ref component))
             return null;
 
-        return key is null ? null : uid.GetUIOrNull(key);
+        return key is null ? null : _uiSystem.GetUiOrNull(uid, key);
     }
 }
 
diff --git a/Content.Server/UserInterface/UserInterfaceHelpers.cs b/Content.Server/UserInterface/UserInterfaceHelpers.cs
deleted file mode 100644 (file)
index 865772c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-using Robust.Server.GameObjects;
-
-namespace Content.Server.UserInterface
-{
-    public static class UserInterfaceHelpers
-    {
-        [Obsolete("Use UserInterfaceSystem")]
-        public static PlayerBoundUserInterface? GetUIOrNull(this EntityUid entity, Enum uiKey)
-        {
-            return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<UserInterfaceSystem>().GetUiOrNull(entity, uiKey);
-        }
-    }
-}