From 9645f5528b23c361db82748648ecf8b6850e7ff4 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:12:01 -0700 Subject: [PATCH] Strip drag drop test (#30754) * Add test for drag drop to open strip menu * Make screencoords change based on deadzone --- Content.Client/Interaction/DragDropSystem.cs | 15 ++++-- .../Interaction/InteractionTest.Helpers.cs | 5 +- .../Tests/Strip/StrippableTest.cs | 46 +++++++++++++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 Content.IntegrationTests/Tests/Strip/StrippableTest.cs diff --git a/Content.Client/Interaction/DragDropSystem.cs b/Content.Client/Interaction/DragDropSystem.cs index a34cd0f5b1..4145999579 100644 --- a/Content.Client/Interaction/DragDropSystem.cs +++ b/Content.Client/Interaction/DragDropSystem.cs @@ -90,7 +90,7 @@ public sealed class DragDropSystem : SharedDragDropSystem /// private bool _isReplaying; - private float _deadzone; + public float Deadzone; private DragState _state = DragState.NotDragging; @@ -122,7 +122,7 @@ public sealed class DragDropSystem : SharedDragDropSystem private void SetDeadZone(float deadZone) { - _deadzone = deadZone; + Deadzone = deadZone; } public override void Shutdown() @@ -212,7 +212,7 @@ public sealed class DragDropSystem : SharedDragDropSystem _draggedEntity = entity; _state = DragState.MouseDown; - _mouseDownScreenPos = _inputManager.MouseScreenPosition; + _mouseDownScreenPos = args.ScreenCoordinates; _mouseDownTime = 0; // don't want anything else to process the click, @@ -240,8 +240,13 @@ public sealed class DragDropSystem : SharedDragDropSystem if (TryComp(_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(_dragShadow.Value); dragSprite.CopyFrom(draggedSprite); @@ -534,7 +539,7 @@ public sealed class DragDropSystem : SharedDragDropSystem case DragState.MouseDown: { var screenPos = _inputManager.MouseScreenPosition; - if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > _deadzone) + if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > Deadzone) { StartDrag(); } diff --git a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs index 0f2c314ed0..d431c440a2 100644 --- a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs +++ b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs @@ -1207,11 +1207,12 @@ public abstract partial class InteractionTest 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) diff --git a/Content.IntegrationTests/Tests/Strip/StrippableTest.cs b/Content.IntegrationTests/Tests/Strip/StrippableTest.cs new file mode 100644 index 0000000000..f65bab1f81 --- /dev/null +++ b/Content.IntegrationTests/Tests/Strip/StrippableTest.cs @@ -0,0 +1,46 @@ +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(Target); + Assert.That(userInterface.Actors.Count == 0); + + // screenCoordinates diff needs to be larger than DragDropSystem._deadzone + var screenX = CEntMan.System().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); + } +}