Skip to content

Commit

Permalink
Dragdrop fold rollerbed (space-wizards#30002)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ShadowCommander authored and themias committed Aug 9, 2024
1 parent b8e10b1 commit 075c547
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Content.Client/Interaction/DragDropSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ private void RemoveHighlights()
if (dropEv2.Handled)
return dropEv2.CanDrop;

if (dropEv.Handled && dropEv.CanDrop)
return true;

return null;
}

Expand Down
33 changes: 33 additions & 0 deletions Content.Shared/Foldable/DeployFoldableSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
Expand All @@ -14,6 +15,38 @@ public override void Initialize()
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)
Expand Down
11 changes: 6 additions & 5 deletions Content.Shared/Strip/SharedStrippableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public bool TryOpenStrippingUi(EntityUid user, Entity<StrippableComponent> targe

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)
Expand Down

0 comments on commit 075c547

Please sign in to comment.