Increase dragging dead zone (#7416)

This commit is contained in:
Leon Friedrich
2022-04-09 09:17:52 +12:00
committed by GitHub
parent 7900abb888
commit bec0b63dc1
4 changed files with 25 additions and 7 deletions

View File

@@ -210,7 +210,8 @@ namespace Content.Client.Actions.UI
_slots[i] = slot;
}
DragDropHelper = new DragDropHelper<ActionSlot>(OnBeginActionDrag, OnContinueActionDrag, OnEndActionDrag, DragDeadZone);
DragDropHelper = new DragDropHelper<ActionSlot>(OnBeginActionDrag, OnContinueActionDrag, OnEndActionDrag);
DragDropHelper.Deadzone = DragDeadZone;
MinSize = (10, 400);
}

View File

@@ -21,14 +21,12 @@ namespace Content.Client.DragDrop
/// <typeparam name="T">thing being dragged and dropped</typeparam>
public sealed class DragDropHelper<T>
{
private const float DefaultDragDeadzone = 2f;
private readonly IInputManager _inputManager;
private readonly OnBeginDrag _onBeginDrag;
private readonly OnEndDrag _onEndDrag;
private readonly OnContinueDrag _onContinueDrag;
private readonly float _deadzone;
public float Deadzone = 2f;
/// <summary>
/// Convenience method, current mouse screen position as provided by inputmanager.
@@ -67,9 +65,8 @@ namespace Content.Client.DragDrop
/// <param name="deadzone">drag will be triggered when mouse leaves
/// this deadzone around the mousedown position</param>
public DragDropHelper(OnBeginDrag onBeginDrag, OnContinueDrag onContinueDrag,
OnEndDrag onEndDrag, float deadzone = DefaultDragDeadzone)
OnEndDrag onEndDrag)
{
_deadzone = deadzone;
_inputManager = IoCManager.Resolve<IInputManager>();
_onBeginDrag = onBeginDrag;
_onEndDrag = onEndDrag;
@@ -128,7 +125,7 @@ namespace Content.Client.DragDrop
case DragState.MouseDown:
{
var screenPos = _inputManager.MouseScreenPosition;
if ((_mouseDownScreenPos.Position - screenPos.Position).Length > _deadzone)
if ((_mouseDownScreenPos.Position - screenPos.Position).Length > Deadzone)
{
StartDragging();
}

View File

@@ -1,6 +1,7 @@
using Content.Client.Outline;
using Content.Client.Viewport;
using Content.Shared.ActionBlocker;
using Content.Shared.CCVar;
using Content.Shared.DragDrop;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
@@ -11,6 +12,7 @@ using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.State;
using Robust.Shared.Configuration;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Prototypes;
@@ -30,6 +32,7 @@ namespace Content.Client.DragDrop
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IConfigurationManager _cfgMan = default!;
[Dependency] private readonly InteractionOutlineSystem _outline = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly InputSystem _inputSystem = default!;
@@ -75,6 +78,7 @@ namespace Content.Client.DragDrop
UpdatesOutsidePrediction = true;
_dragDropHelper = new DragDropHelper<EntityUid>(OnBeginDrag, OnContinueDrag, OnEndDrag);
_cfgMan.OnValueChanged(CCVars.DragDropDeadZone, SetDeadZone, true);
_dropTargetInRangeShader = _prototypeManager.Index<ShaderPrototype>(ShaderDropTargetInRange).Instance();
_dropTargetOutOfRangeShader = _prototypeManager.Index<ShaderPrototype>(ShaderDropTargetOutOfRange).Instance();
@@ -84,8 +88,14 @@ namespace Content.Client.DragDrop
.Register<DragDropSystem>();
}
private void SetDeadZone(float deadZone)
{
_dragDropHelper.Deadzone = deadZone;
}
public override void Shutdown()
{
_cfgMan.UnsubValueChanged(CCVars.DragDropDeadZone, SetDeadZone);
_dragDropHelper.EndDrag();
CommandBinds.Unregister<DragDropSystem>();
base.Shutdown();

View File

@@ -869,5 +869,15 @@ namespace Content.Shared.CCVar
/// </summary>
public static readonly CVarDef<int> ResourceUploadingStoreDeletionDays =
CVarDef.Create("netres.store_deletion_days", 30, CVar.SERVER | CVar.SERVERONLY);
/*
* Controls
*/
/// <summary>
/// Deadzone for drag-drop interactions.
/// </summary>
public static readonly CVarDef<float> DragDropDeadZone =
CVarDef.Create("control.drag_dead_zone", 12f, CVar.CLIENTONLY | CVar.ARCHIVE);
}
}