From ef70629702b547e77cd5d18cbad9f9a13033d792 Mon Sep 17 00:00:00 2001
From: Kot <1192090+koteq@users.noreply.github.com>
Date: Wed, 17 Jan 2024 02:35:48 +0400
Subject: [PATCH] Fix DragDropHelper not respecting the control.drag_dead_zone
cvar (#24166)
Fix regression with the drag_dead_zone cvar not being used
---
Content.Client/Interaction/DragDropHelper.cs | 24 ++++++++++++++++----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/Content.Client/Interaction/DragDropHelper.cs b/Content.Client/Interaction/DragDropHelper.cs
index ce5e08207c..abe35bf6d9 100644
--- a/Content.Client/Interaction/DragDropHelper.cs
+++ b/Content.Client/Interaction/DragDropHelper.cs
@@ -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;
/// thing being dragged and dropped
public sealed class DragDropHelper
{
- 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;
///
/// Convenience method, current mouse screen position as provided by inputmanager.
@@ -63,10 +66,16 @@ public sealed class DragDropHelper
///
public DragDropHelper(OnBeginDrag onBeginDrag, OnContinueDrag onContinueDrag, OnEndDrag onEndDrag)
{
- _inputManager = IoCManager.Resolve();
+ IoCManager.InjectDependencies(this);
_onBeginDrag = onBeginDrag;
_onEndDrag = onEndDrag;
_onContinueDrag = onContinueDrag;
+ _cfg.OnValueChanged(CCVars.DragDropDeadZone, SetDeadZone, true);
+ }
+
+ ~DragDropHelper()
+ {
+ _cfg.UnsubValueChanged(CCVars.DragDropDeadZone, SetDeadZone);
}
///
@@ -121,7 +130,7 @@ public sealed class DragDropHelper
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
}
}
}
+
+ private void SetDeadZone(float value)
+ {
+ _deadzone = value;
+ }
}
///