Refactors the paper bin behavior for dragging to pick up into an element (#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
This commit is contained in:
spessbro
2021-03-08 16:50:53 -08:00
committed by GitHub
parent cb122c5019
commit cbeb9c5be4
3 changed files with 32 additions and 15 deletions
+29
View File
@@ -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)
+2 -15
View File
@@ -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
@@ -26,6 +27,7 @@
P.forceMove(src)
bin_pen = P
update_appearance()
/obj/item/paper_bin/Destroy()
if(papers)
@@ -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)
+1
View File
@@ -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"