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 (tgstation#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 Mar 9, 2021
1 parent cb122c5 commit cbeb9c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 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)
17 changes: 2 additions & 15 deletions code/modules/paperwork/paperbin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
/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
if(P && !bin_pen)
P.forceMove(src)
bin_pen = P
update_appearance()


/obj/item/paper_bin/Destroy()
if(papers)
Expand All @@ -40,21 +42,6 @@
update_appearance()
..()

/obj/item/paper_bin/MouseDrop(atom/over_object)
. = ..()
var/mob/living/M = usr
if(!istype(M) || M.incapacitated() || !Adjacent(M))
return

if(over_object == M)
M.put_in_hands(src)

else if(istype(over_object, /atom/movable/screen/inventory/hand))
var/atom/movable/screen/inventory/hand/H = over_object
M.putItemFromInventoryInHandIfPossible(src, H.held_index)

add_fingerprint(M)

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

Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,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 cbeb9c5

Please sign in to comment.