]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Dragdrop fold rollerbed (#30002)
authorShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Wed, 7 Aug 2024 09:19:10 +0000 (02:19 -0700)
committerGitHub <noreply@github.com>
Wed, 7 Aug 2024 09:19:10 +0000 (19:19 +1000)
* 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
Content.Shared/Foldable/DeployFoldableSystem.cs
Content.Shared/Strip/SharedStrippableSystem.cs

index aab6a6277625651a7c94dac374c6317b358c212d..a34cd0f5b11ede7f1b2aabc3f7285030686a4f08 100644 (file)
@@ -518,6 +518,9 @@ public sealed class DragDropSystem : SharedDragDropSystem
         if (dropEv2.Handled)
             return dropEv2.CanDrop;
 
+        if (dropEv.Handled && dropEv.CanDrop)
+            return true;
+
         return null;
     }
 
index fa2e3f87892eb217777c195521078304da0ac092..16315cde69963c3bcbc04989e0777ce4b975699d 100644 (file)
@@ -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 sealed class DeployFoldableSystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<DeployFoldableComponent, AfterInteractEvent>(OnAfterInteract);
+        SubscribeLocalEvent<DeployFoldableComponent, CanDragEvent>(OnCanDrag);
+        SubscribeLocalEvent<DeployFoldableComponent, DragDropDraggedEvent>(OnDragDropDragged);
+        SubscribeLocalEvent<DeployFoldableComponent, CanDropDraggedEvent>(OnCanDropDragged);
+    }
+
+    private void OnCanDropDragged(Entity<DeployFoldableComponent> ent, ref CanDropDraggedEvent args)
+    {
+        if (args.User != args.Target)
+            return;
+
+        args.Handled = true;
+        args.CanDrop = true;
+    }
+
+    private void OnDragDropDragged(Entity<DeployFoldableComponent> ent, ref DragDropDraggedEvent args)
+    {
+        if (!TryComp<FoldableComponent>(ent, out var foldable)
+            || !_foldable.TrySetFolded(ent, foldable, true))
+            return;
+
+        _hands.PickupOrDrop(args.User, ent.Owner);
+
+        args.Handled = true;
+    }
+
+    private void OnCanDrag(Entity<DeployFoldableComponent> ent, ref CanDragEvent args)
+    {
+        if (!TryComp<FoldableComponent>(ent, out var foldable)
+            || foldable.IsFolded)
+            return;
+
+        args.Handled = true;
     }
 
     private void OnAfterInteract(Entity<DeployFoldableComponent> ent, ref AfterInteractEvent args)
index 38e2f9fd7a52b1ccc576d31d21259870bd6bef75..e42f6e3aa783960fe5d43485ba2b927dda3d1f9c 100644 (file)
@@ -61,11 +61,12 @@ public abstract class SharedStrippableSystem : EntitySystem
 
     private void OnCanDropOn(EntityUid uid, StrippingComponent component, ref CanDropTargetEvent args)
     {
-        args.Handled = true;
-        args.CanDrop |= uid == args.User &&
-                        HasComp<StrippableComponent>(args.Dragged) &&
-                        HasComp<HandsComponent>(args.User) &&
-                        HasComp<StrippingComponent>(args.User);
+        var val = uid == args.User &&
+                  HasComp<StrippableComponent>(args.Dragged) &&
+                  HasComp<HandsComponent>(args.User) &&
+                  HasComp<StrippingComponent>(args.User);
+        args.Handled |= val;
+        args.CanDrop |= val;
     }
 
     private void OnCanDrop(EntityUid uid, StrippableComponent component, ref CanDropDraggedEvent args)