]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make NetworkConfigurator use BoundUserInterfaceCheckRangeEvent (#28293)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sun, 26 May 2024 03:20:29 +0000 (15:20 +1200)
committerGitHub <noreply@github.com>
Sun, 26 May 2024 03:20:29 +0000 (13:20 +1000)
Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs

index 346012415857807d7a02ddbaffaa2be12b59f260..402d005dd47539da4af8fe55389470507c8b782d 100644 (file)
@@ -63,9 +63,21 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
         SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorToggleLinkMessage>(OnToggleLinks);
         SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorButtonPressedMessage>(OnConfigButtonPressed);
 
+        SubscribeLocalEvent<NetworkConfiguratorComponent, BoundUserInterfaceCheckRangeEvent>(OnUiRangeCheck);
+
         SubscribeLocalEvent<DeviceListComponent, ComponentRemove>(OnComponentRemoved);
     }
 
+    private void OnUiRangeCheck(Entity<NetworkConfiguratorComponent> ent, ref BoundUserInterfaceCheckRangeEvent args)
+    {
+        if (ent.Comp.ActiveDeviceList == null || args.Result == BoundUserInterfaceRangeResult.Fail)
+            return;
+
+        DebugTools.Assert(Exists(ent.Comp.ActiveDeviceList));
+        if (!_interactionSystem.InRangeUnobstructed(args.Actor!, ent.Comp.ActiveDeviceList.Value))
+            args.Result = BoundUserInterfaceRangeResult.Fail;
+    }
+
     private void OnShutdown(EntityUid uid, NetworkConfiguratorComponent component, ComponentShutdown args)
     {
         ClearDevices(uid, component);
@@ -75,23 +87,6 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
         component.ActiveDeviceList = null;
     }
 
-    public override void Update(float frameTime)
-    {
-        base.Update(frameTime);
-
-        var query = EntityQueryEnumerator<NetworkConfiguratorComponent>();
-        while (query.MoveNext(out var uid, out var component))
-        {
-            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.CloseUi(uid, NetworkConfiguratorUiKey.Configure);
-        }
-    }
-
     private void OnMapInit(EntityUid uid, NetworkConfiguratorComponent component, MapInitEvent args)
     {
         UpdateListUiState(uid, component);