Strip drag drop test (#30754)

* Add test for drag drop to open strip menu

* Make screencoords change based on deadzone
This commit is contained in:
ShadowCommander
2024-08-07 19:12:01 -07:00
committed by GitHub
parent d86c886f61
commit 9645f5528b
3 changed files with 59 additions and 7 deletions

View File

@@ -90,7 +90,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
/// </summary> /// </summary>
private bool _isReplaying; private bool _isReplaying;
private float _deadzone; public float Deadzone;
private DragState _state = DragState.NotDragging; private DragState _state = DragState.NotDragging;
@@ -122,7 +122,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
private void SetDeadZone(float deadZone) private void SetDeadZone(float deadZone)
{ {
_deadzone = deadZone; Deadzone = deadZone;
} }
public override void Shutdown() public override void Shutdown()
@@ -212,7 +212,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
_draggedEntity = entity; _draggedEntity = entity;
_state = DragState.MouseDown; _state = DragState.MouseDown;
_mouseDownScreenPos = _inputManager.MouseScreenPosition; _mouseDownScreenPos = args.ScreenCoordinates;
_mouseDownTime = 0; _mouseDownTime = 0;
// don't want anything else to process the click, // don't want anything else to process the click,
@@ -240,8 +240,13 @@ public sealed class DragDropSystem : SharedDragDropSystem
if (TryComp<SpriteComponent>(_draggedEntity, out var draggedSprite)) 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 // pop up drag shadow under mouse
var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition); var mousePos = _eyeManager.PixelToMap(screenPos);
_dragShadow = EntityManager.SpawnEntity("dragshadow", mousePos); _dragShadow = EntityManager.SpawnEntity("dragshadow", mousePos);
var dragSprite = Comp<SpriteComponent>(_dragShadow.Value); var dragSprite = Comp<SpriteComponent>(_dragShadow.Value);
dragSprite.CopyFrom(draggedSprite); dragSprite.CopyFrom(draggedSprite);
@@ -534,7 +539,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
case DragState.MouseDown: case DragState.MouseDown:
{ {
var screenPos = _inputManager.MouseScreenPosition; var screenPos = _inputManager.MouseScreenPosition;
if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > _deadzone) if ((_mouseDownScreenPos!.Value.Position - screenPos.Position).Length() > Deadzone)
{ {
StartDrag(); StartDrag();
} }

View File

@@ -1207,11 +1207,12 @@ public abstract partial class InteractionTest
BoundKeyFunction key, BoundKeyFunction key,
BoundKeyState state, BoundKeyState state,
NetCoordinates? coordinates = null, NetCoordinates? coordinates = null,
NetEntity? cursorEntity = null) NetEntity? cursorEntity = null,
ScreenCoordinates? screenCoordinates = null)
{ {
var coords = coordinates ?? TargetCoords; var coords = coordinates ?? TargetCoords;
var target = cursorEntity ?? Target ?? default; var target = cursorEntity ?? Target ?? default;
ScreenCoordinates screen = default; var screen = screenCoordinates ?? default;
var funcId = InputManager.NetworkBindMap.KeyFunctionID(key); var funcId = InputManager.NetworkBindMap.KeyFunctionID(key);
var message = new ClientFullInputCmdMessage(CTiming.CurTick, CTiming.TickFraction, funcId) var message = new ClientFullInputCmdMessage(CTiming.CurTick, CTiming.TickFraction, funcId)

View File

@@ -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<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);
}
}