/// </summary>
private bool _isReplaying;
- private float _deadzone;
+ public float Deadzone;
private DragState _state = DragState.NotDragging;
private void SetDeadZone(float deadZone)
{
- _deadzone = deadZone;
+ Deadzone = deadZone;
}
public override void Shutdown()
_draggedEntity = entity;
_state = DragState.MouseDown;
- _mouseDownScreenPos = _inputManager.MouseScreenPosition;
+ _mouseDownScreenPos = args.ScreenCoordinates;
_mouseDownTime = 0;
// don't want anything else to process the click,
if (TryComp<SpriteComponent>(_draggedEntity, out var draggedSprite))
{
+ var screenPos = _inputManager.MouseScreenPosition;
+ // No _draggedEntity in null window (Happens in tests)
+ if (!screenPos.IsValid)
+ return;
+
// pop up drag shadow under mouse
- var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition);
+ var mousePos = _eyeManager.PixelToMap(screenPos);
_dragShadow = EntityManager.SpawnEntity("dragshadow", mousePos);
var dragSprite = Comp<SpriteComponent>(_dragShadow.Value);
dragSprite.CopyFrom(draggedSprite);
case DragState.MouseDown:
{
var screenPos = _inputManager.MouseScreenPosition;
- if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > _deadzone)
+ if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > Deadzone)
{
StartDrag();
}
BoundKeyFunction key,
BoundKeyState state,
NetCoordinates? coordinates = null,
- NetEntity? cursorEntity = null)
+ NetEntity? cursorEntity = null,
+ ScreenCoordinates? screenCoordinates = null)
{
var coords = coordinates ?? TargetCoords;
var target = cursorEntity ?? Target ?? default;
- ScreenCoordinates screen = default;
+ var screen = screenCoordinates ?? default;
var funcId = InputManager.NetworkBindMap.KeyFunctionID(key);
var message = new ClientFullInputCmdMessage(CTiming.CurTick, CTiming.TickFraction, funcId)
--- /dev/null
+using Content.Client.Interaction;
+using Content.IntegrationTests.Tests.Interaction;
+using Robust.Shared.GameObjects;
+using Robust.Shared.Input;
+using Robust.Shared.Map;
+
+namespace Content.IntegrationTests.Tests.Strip;
+
+public sealed class StrippableTest : InteractionTest
+{
+ protected override string PlayerPrototype => "MobHuman";
+
+ [Test]
+ public async Task DragDropOpensStrip()
+ {
+ // Spawn one tile away
+ TargetCoords = SEntMan.GetNetCoordinates(new EntityCoordinates(MapData.MapUid, 1, 0));
+ await SpawnTarget("MobHuman");
+
+ var userInterface = Comp<UserInterfaceComponent>(Target);
+ Assert.That(userInterface.Actors.Count == 0);
+
+ // screenCoordinates diff needs to be larger than DragDropSystem._deadzone
+ var screenX = CEntMan.System<DragDropSystem>().Deadzone + 1f;
+
+ // Start drag
+ await SetKey(EngineKeyFunctions.Use,
+ BoundKeyState.Down,
+ TargetCoords,
+ Target,
+ screenCoordinates: new ScreenCoordinates(screenX, 0f, WindowId.Main));
+
+ await RunTicks(5);
+
+ // End drag
+ await SetKey(EngineKeyFunctions.Use,
+ BoundKeyState.Up,
+ PlayerCoords,
+ Player,
+ screenCoordinates: new ScreenCoordinates(0f, 0f, WindowId.Main));
+
+ await RunTicks(5);
+
+ Assert.That(userInterface.Actors.Count > 0);
+ }
+}