From 075c5474b551a6ed377cf4d6c8179289bf3ce8b3 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 7 Aug 2024 02:19:10 -0700 Subject: [PATCH] Dragdrop fold rollerbed (#30002) * Deploy foldable * Add NetworkedComponent and access to the component * Add handled to afterinteract * Use drop target location instead of setcoordinates * Put back in hand after failed deploy This prevents dropping the bed when clicking while inside a locker. * Created BaseDeployFoldable for folding chairs, body bags, and rollerbeds * Add dragdrop to fold rollerbed to hand --- Content.Client/Interaction/DragDropSystem.cs | 3 ++ .../Foldable/DeployFoldableSystem.cs | 33 +++++++++++++++++++ .../Strip/SharedStrippableSystem.cs | 11 ++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Content.Client/Interaction/DragDropSystem.cs b/Content.Client/Interaction/DragDropSystem.cs index aab6a6277625..a34cd0f5b11e 100644 --- a/Content.Client/Interaction/DragDropSystem.cs +++ b/Content.Client/Interaction/DragDropSystem.cs @@ -518,6 +518,9 @@ private void RemoveHighlights() if (dropEv2.Handled) return dropEv2.CanDrop; + if (dropEv.Handled && dropEv.CanDrop) + return true; + return null; } diff --git a/Content.Shared/Foldable/DeployFoldableSystem.cs b/Content.Shared/Foldable/DeployFoldableSystem.cs index fa2e3f87892e..16315cde6996 100644 --- a/Content.Shared/Foldable/DeployFoldableSystem.cs +++ b/Content.Shared/Foldable/DeployFoldableSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.DragDrop; using Content.Shared.Hands.Components; using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction; @@ -14,6 +15,38 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnAfterInteract); + SubscribeLocalEvent(OnCanDrag); + SubscribeLocalEvent(OnDragDropDragged); + SubscribeLocalEvent(OnCanDropDragged); + } + + private void OnCanDropDragged(Entity ent, ref CanDropDraggedEvent args) + { + if (args.User != args.Target) + return; + + args.Handled = true; + args.CanDrop = true; + } + + private void OnDragDropDragged(Entity ent, ref DragDropDraggedEvent args) + { + if (!TryComp(ent, out var foldable) + || !_foldable.TrySetFolded(ent, foldable, true)) + return; + + _hands.PickupOrDrop(args.User, ent.Owner); + + args.Handled = true; + } + + private void OnCanDrag(Entity ent, ref CanDragEvent args) + { + if (!TryComp(ent, out var foldable) + || foldable.IsFolded) + return; + + args.Handled = true; } private void OnAfterInteract(Entity ent, ref AfterInteractEvent args) diff --git a/Content.Shared/Strip/SharedStrippableSystem.cs b/Content.Shared/Strip/SharedStrippableSystem.cs index 38e2f9fd7a52..e42f6e3aa783 100644 --- a/Content.Shared/Strip/SharedStrippableSystem.cs +++ b/Content.Shared/Strip/SharedStrippableSystem.cs @@ -61,11 +61,12 @@ public bool TryOpenStrippingUi(EntityUid user, Entity targe private void OnCanDropOn(EntityUid uid, StrippingComponent component, ref CanDropTargetEvent args) { - args.Handled = true; - args.CanDrop |= uid == args.User && - HasComp(args.Dragged) && - HasComp(args.User) && - HasComp(args.User); + var val = uid == args.User && + HasComp(args.Dragged) && + HasComp(args.User) && + HasComp(args.User); + args.Handled |= val; + args.CanDrop |= val; } private void OnCanDrop(EntityUid uid, StrippableComponent component, ref CanDropDraggedEvent args)