]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Nodescanner now works with right click (#26873)
authorosjarw <62134478+osjarw@users.noreply.github.com>
Fri, 14 Jun 2024 02:01:32 +0000 (05:01 +0300)
committerGitHub <noreply@github.com>
Fri, 14 Jun 2024 02:01:32 +0000 (22:01 -0400)
Content.Server/Xenoarchaeology/Equipment/Systems/NodeScannerSystem.cs
Resources/Locale/en-US/xenoarchaeology/node-scanner.ftl

index fc9ab2894294f252f248c22121c015e1bd8dea97..b388f3a6d49ae1f531297b6962d137a407002079 100644 (file)
@@ -3,6 +3,7 @@ using Content.Server.Xenoarchaeology.Equipment.Components;
 using Content.Server.Xenoarchaeology.XenoArtifacts;
 using Content.Shared.Interaction;
 using Content.Shared.Timing;
+using Content.Shared.Verbs;
 
 namespace Content.Server.Xenoarchaeology.Equipment.Systems;
 
@@ -14,23 +15,44 @@ public sealed class NodeScannerSystem : EntitySystem
     /// <inheritdoc/>
     public override void Initialize()
     {
-        SubscribeLocalEvent<NodeScannerComponent, AfterInteractEvent>(OnAfterInteract);
+        SubscribeLocalEvent<NodeScannerComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
+        SubscribeLocalEvent<NodeScannerComponent, GetVerbsEvent<UtilityVerb>>(AddScanVerb);
     }
 
-    private void OnAfterInteract(EntityUid uid, NodeScannerComponent component, AfterInteractEvent args)
+    private void OnBeforeRangedInteract(EntityUid uid, NodeScannerComponent component, BeforeRangedInteractEvent args)
     {
-        if (!args.CanReach || args.Target == null)
+        if (args.Handled || !args.CanReach || args.Target is not {} target)
             return;
 
-        if (!TryComp<ArtifactComponent>(args.Target, out var artifact) || artifact.CurrentNodeId == null)
+        if (!TryComp<ArtifactComponent>(target, out var artifact) || artifact.CurrentNodeId == null)
             return;
 
-        if (args.Handled)
-            return;
+        CreatePopup(uid, target, artifact);
         args.Handled = true;
+    }
+
+    private void AddScanVerb(EntityUid uid, NodeScannerComponent component, GetVerbsEvent<UtilityVerb> args)
+    {
+        if (!args.CanAccess)
+            return;
 
-        var target = args.Target.Value;
+        if (!TryComp<ArtifactComponent>(args.Target, out var artifact) || artifact.CurrentNodeId == null)
+            return;
+
+        var verb = new UtilityVerb()
+        {
+            Act = () =>
+            {
+                CreatePopup(uid, args.Target, artifact);
+            },
+            Text = Loc.GetString("node-scan-tooltip")
+        };
 
+        args.Verbs.Add(verb);
+    }
+
+    private void CreatePopup(EntityUid uid, EntityUid target, ArtifactComponent artifact)
+    {
         if (TryComp(uid, out UseDelayComponent? useDelay)
             && !_useDelay.TryResetDelay((uid, useDelay), true))
             return;
index 14b07941a64f102a41310c9c854417721e8a0b9f..4a05414c46020fc99e8ac1bcba4bcc83fd1fe49a 100644 (file)
@@ -1 +1,2 @@
-node-scan-popup = The node ID is {$id}
\ No newline at end of file
+node-scan-popup = The node ID is {$id}
+node-scan-tooltip = Scan artifact