]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix DragDropHelper not respecting the control.drag_dead_zone cvar (#24166)
authorKot <1192090+koteq@users.noreply.github.com>
Tue, 16 Jan 2024 22:35:48 +0000 (02:35 +0400)
committerGitHub <noreply@github.com>
Tue, 16 Jan 2024 22:35:48 +0000 (14:35 -0800)
Fix regression with the drag_dead_zone cvar not being used

Content.Client/Interaction/DragDropHelper.cs

index ce5e08207c27fa75238027c85a8294eca4574d3b..abe35bf6d9a8d6ca7aee56eacdfc7d0a0e8ddb78 100644 (file)
@@ -1,4 +1,6 @@
-using Robust.Client.Input;
+using Content.Shared.CCVar;
+using Robust.Client.Input;
+using Robust.Shared.Configuration;
 using Robust.Shared.Map;
 
 namespace Content.Client.Interaction;
@@ -20,12 +22,13 @@ namespace Content.Client.Interaction;
 /// <typeparam name="T">thing being dragged and dropped</typeparam>
 public sealed class DragDropHelper<T>
 {
-    private readonly IInputManager _inputManager;
+    [Dependency] private readonly IInputManager _inputManager = default!;
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
 
     private readonly OnBeginDrag _onBeginDrag;
     private readonly OnEndDrag _onEndDrag;
     private readonly OnContinueDrag _onContinueDrag;
-    public float Deadzone = 2f;
+    private float _deadzone;
 
     /// <summary>
     /// Convenience method, current mouse screen position as provided by inputmanager.
@@ -63,10 +66,16 @@ public sealed class DragDropHelper<T>
     /// <param name="onEndDrag"><see cref="OnEndDrag"/></param>
     public DragDropHelper(OnBeginDrag onBeginDrag, OnContinueDrag onContinueDrag, OnEndDrag onEndDrag)
     {
-        _inputManager = IoCManager.Resolve<IInputManager>();
+        IoCManager.InjectDependencies(this);
         _onBeginDrag = onBeginDrag;
         _onEndDrag = onEndDrag;
         _onContinueDrag = onContinueDrag;
+        _cfg.OnValueChanged(CCVars.DragDropDeadZone, SetDeadZone, true);
+    }
+
+    ~DragDropHelper()
+    {
+        _cfg.UnsubValueChanged(CCVars.DragDropDeadZone, SetDeadZone);
     }
 
     /// <summary>
@@ -121,7 +130,7 @@ public sealed class DragDropHelper<T>
             case DragState.MouseDown:
             {
                 var screenPos = _inputManager.MouseScreenPosition;
-                if ((_mouseDownScreenPos.Position - screenPos.Position).Length() > Deadzone)
+                if ((_mouseDownScreenPos.Position - screenPos.Position).Length() > _deadzone)
                 {
                     StartDragging();
                 }
@@ -139,6 +148,11 @@ public sealed class DragDropHelper<T>
             }
         }
     }
+
+    private void SetDeadZone(float value)
+    {
+        _deadzone = value;
+    }
 }
 
 /// <summary>