Skip to content

Commit

Permalink
Refactors the paper bin behavior for dragging to pick up into an elem…
Browse files Browse the repository at this point in the history
…ent (#57501)

* Drag pickup element for the paper bin behavior

* invokes async on put_in_hands to comply with the linter

* documented and like better names

* blackspace
  • Loading branch information
spessbro authored and Gboster-0 committed Oct 21, 2023
1 parent b50713c commit 586a0cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
29 changes: 29 additions & 0 deletions code/datums/elements/drag_pickup.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* drag_pickup element; for allowing things to be picked up by dragging.
*
* Used for paper bins.
*/
/datum/element/drag_pickup
element_flags = ELEMENT_DETACH

/datum/element/drag_pickup/Attach(datum/target)
if(!ismovable(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_MOUSEDROP_ONTO, .proc/pick_up)
return ..()

/datum/element/drag_pickup/Detach(datum/source, force)
UnregisterSignal(source, COMSIG_MOUSEDROP_ONTO)
return ..()

/datum/element/drag_pickup/proc/pick_up(atom/source, atom/over, mob/user)
SIGNAL_HANDLER
var/mob/living/picker = user
if(!istype(picker) || picker.incapacitated() || !source.Adjacent(picker))
return

if(over == picker)
INVOKE_ASYNC(picker, /mob/.proc/put_in_hands, source)
else if(istype(over, /atom/movable/screen/inventory/hand))
var/atom/movable/screen/inventory/hand/Selected_hand = over
picker.putItemFromInventoryInHandIfPossible(source, Selected_hand.held_index)
5 changes: 3 additions & 2 deletions code/modules/paperwork/paperbin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/obj/item/paper_bin/Initialize(mapload)
. = ..()
interaction_flags_item &= ~INTERACT_ITEM_ATTACK_HAND_PICKUP
AddElement(/datum/element/drag_pickup)
if(!mapload)
return
var/obj/item/pen/P = locate(/obj/item/pen) in src.loc
Expand Down Expand Up @@ -55,8 +56,8 @@

add_fingerprint(M)

/obj/item/paper_bin/attack_paw(mob/user)
return attack_hand(user)
/obj/item/paper_bin/attack_paw(mob/user, list/modifiers)
return attack_hand(user, modifiers)

//ATTACK HAND IGNORING PARENT RETURN VALUE
/obj/item/paper_bin/attack_hand(mob/user)
Expand Down
1 change: 1 addition & 0 deletions lobotomy-corp13.dme
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@
#include "code\datums\elements\decal.dm"
#include "code\datums\elements\deferred_aquarium_content.dm"
#include "code\datums\elements\digitalcamo.dm"
#include "code\datums\elements\drag_pickup.dm"
#include "code\datums\elements\dryable.dm"
#include "code\datums\elements\earhealing.dm"
#include "code\datums\elements\embed.dm"
Expand Down

0 comments on commit 586a0cc

Please sign in to comment.