Skip to content

Commit 0469065

Browse files
authored
Item pickup/drop animations play in many more appropriate places (#817)
1 parent d0f61f5 commit 0469065

43 files changed

Lines changed: 155 additions & 143 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

code/datums/elements/bed_tucking.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
if(!istype(target_bed))
4646
return
4747

48-
if(!tucker.transferItemToLoc(tucked, target_bed.drop_location(), silent = FALSE))
48+
if(!tucker.transfer_item_to_turf(tucked, target_bed.drop_location()))
4949
return
5050

5151
to_chat(tucker, span_notice("You lay [tucked] out on [target_bed]."))

code/datums/storage/storage.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ GLOBAL_LIST_EMPTY(cached_storage_typecaches)
443443
SEND_SIGNAL(src, COMSIG_STORAGE_STORED_ITEM, to_insert, user, force)
444444
to_insert.forceMove(real_location)
445445
item_insertion_feedback(user, to_insert, override)
446+
if(get(real_location, /mob) != user)
447+
to_insert.do_pickup_animation(real_location, user)
446448
return TRUE
447449

448450
/// Since items inside storages ignore transparency for QOL reasons, we're tracking when things are dropped onto them instead of our UI elements

code/game/machinery/_machinery.dm

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,28 @@
414414
/**
415415
* Puts passed object in to user's hand
416416
*
417-
* Puts the passed object in to the users hand if they are adjacent.
418-
* If the user is not adjacent then place the object on top of the machine.
417+
* The passed object is usually something that was in the object and is being ejected
418+
*
419+
* Handles checking if the user can hold the item and if they are in range,
420+
* otherwise dumps the item on the ground of src
419421
*
420422
* Vars:
421423
* * object (obj) The object to be moved in to the users hand.
422424
* * user (mob/living) The user to recive the object
425+
*
426+
* Returns TRUE if the object was put in to the users hand, FALSE if it was dropped on the ground.
423427
*/
424-
/obj/machinery/proc/try_put_in_hand(obj/object, mob/living/user)
425-
if(!issilicon(user) && in_range(src, user))
426-
user.put_in_hands(object)
427-
else
428-
object.forceMove(drop_location())
428+
/obj/proc/try_put_in_hand(obj/item/object, mob/living/user)
429+
if(user?.can_hold_items(object) && in_range(src, user))
430+
object.add_fingerprint(user)
431+
add_fingerprint(user)
432+
if(user.put_in_hands(object, ignore_animation = TRUE))
433+
if(get(src, /mob) != user) // Only play pickup if we aren't also being held
434+
object.do_pickup_animation(user, src)
435+
return TRUE
436+
object.forceMove(drop_location())
437+
object.do_drop_animation(src)
438+
return FALSE
429439

430440
/obj/machinery/proc/can_be_occupant(atom/movable/occupant_atom)
431441
return occupant_typecache ? is_type_in_typecache(occupant_atom, occupant_typecache) : isliving(occupant_atom)

code/game/machinery/cell_charger.dm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@
9292
if(!charging)
9393
return
9494

95-
user.put_in_hands(charging)
96-
charging.add_fingerprint(user)
95+
try_put_in_hand(charging, user)
9796

9897
user.visible_message(span_notice("[user] removes [charging] from [src]."), span_notice("You remove [charging] from [src]."))
9998

code/game/machinery/civilian_bounties.dm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@
250250
to_chat(user, span_warning("That slot is empty!"))
251251
return FALSE
252252
else
253-
target.forceMove(drop_location())
254-
if(!issilicon(user) && Adjacent(user))
255-
user.put_in_hands(target)
253+
try_put_in_hand(target, user)
256254
user.visible_message(span_notice("[user] gets \the [target] from \the [src]."), \
257255
span_notice("You get \the [target] from \the [src]."))
258256
playsound(src, 'sound/machines/terminal_insert_disc.ogg', 50, FALSE)

code/game/machinery/recharger.dm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@
125125
if(.)
126126
return
127127

128-
add_fingerprint(user)
129-
if(isnull(charging) || user.put_in_hands(charging))
128+
if(isnull(charging))
130129
return
131-
charging.forceMove(drop_location())
130+
try_put_in_hand(charging, user)
132131

133132
/obj/machinery/recharger/attack_tk(mob/user)
134133
if(isnull(charging))

code/game/machinery/slotmachine.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
var/obj/item/coin/inserted_coin = inserted
101101
if(paymode == COIN)
102102
if(prob(2))
103-
if(!user.transferItemToLoc(inserted_coin, drop_location(), silent = FALSE))
103+
if(!user.transfer_item_to_turf(inserted_coin, drop_location()))
104104
return ITEM_INTERACT_BLOCKING
105105
inserted_coin.throw_at(user, 3, 10)
106106
if(prob(10))

code/game/objects/items.dm

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -596,18 +596,16 @@
596596

597597
//If the item is in a storage item, take it out
598598
var/outside_storage = !loc.atom_storage
599-
var/turf/storage_turf
600-
if(loc.atom_storage)
601-
//We want the pickup animation to play even if we're moving the item between movables. Unless the mob is not located on a turf.
602-
if(isturf(user.loc))
603-
storage_turf = get_turf(loc)
604-
if(!loc.atom_storage.remove_single(user, src, user, silent = TRUE))
605-
return
599+
var/atom/anim_loc = loc
600+
if(loc.atom_storage && !loc.atom_storage?.remove_single(user, src, user, silent = TRUE))
601+
return
606602
if(QDELETED(src)) //moving it out of the storage destroyed it.
607603
return
608604

609-
if(storage_turf)
610-
do_pickup_animation(user, storage_turf)
605+
if(isturf(user.loc))
606+
// Animation only plays if the user is on a turf
607+
// However if the anim_loc is not on a turf (ie held by a mob) we need to use user loc
608+
do_pickup_animation(user, (isturf(anim_loc) || isturf(anim_loc.loc)) ? anim_loc : user.loc)
611609

612610
if(throwing)
613611
throwing.finalize(FALSE)
@@ -618,7 +616,7 @@
618616
. = FALSE
619617
pickup(user)
620618
add_fingerprint(user)
621-
if(!user.put_in_active_hand(src, ignore_animation = !outside_storage))
619+
if(!user.put_in_active_hand(src, ignore_animation = TRUE))
622620
user.dropItemToGround(src)
623621
return TRUE
624622

@@ -1272,9 +1270,11 @@
12721270

12731271
///Called by the carbon throw_item() proc. Returns null if the item negates the throw, or a reference to the thing to suffer the throw else.
12741272
/obj/item/proc/on_thrown(mob/living/carbon/user, atom/target)
1275-
if((item_flags & ABSTRACT) || HAS_TRAIT(src, TRAIT_NODROP))
1273+
if(item_flags & ABSTRACT)
1274+
return
1275+
// Skip animation is important here because it interferes with the throwing animation.
1276+
if(!user.transferItemToLoc(src, drop_location(), silent = TRUE, animated = FALSE))
12761277
return
1277-
user.dropItemToGround(src, silent = TRUE)
12781278
if(throwforce && HAS_TRAIT(user, TRAIT_PACIFISM))
12791279
to_chat(user, span_notice("You set [src] down gently on the ground."))
12801280
return
@@ -1463,8 +1463,8 @@
14631463
pickup_animation.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
14641464

14651465
var/direction = get_dir(source, target)
1466-
var/to_x = target.base_pixel_x
1467-
var/to_y = target.base_pixel_y
1466+
var/to_x = (target.pixel_x + target.pixel_w) - (source.pixel_x + source.pixel_w)
1467+
var/to_y = (target.pixel_y + target.pixel_z) - (source.pixel_y + source.pixel_z)
14681468

14691469
if(direction & NORTH)
14701470
to_y += 32
@@ -1495,8 +1495,8 @@
14951495

14961496
var/turf/current_turf = get_turf(src)
14971497
var/direction = get_dir(moving_from, current_turf)
1498-
var/from_x = moving_from.base_pixel_x
1499-
var/from_y = moving_from.base_pixel_y
1498+
var/from_x = moving_from.pixel_x + moving_from.pixel_w
1499+
var/from_y = moving_from.pixel_y + moving_from.pixel_z
15001500

15011501
if(direction & NORTH)
15021502
from_y -= 32

code/game/objects/items/tail_pin.dm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@
3535

3636
MAPPING_DIRECTIONAL_HELPERS(/obj/structure/sign/poster/party_game, 32)
3737

38-
/obj/structure/sign/poster/party_game/attackby(obj/item/I, mob/user, params)
38+
/obj/structure/sign/poster/party_game/attackby(obj/item/attacking_item, mob/user, list/modifiers, list/attack_modifiers)
3939
. = ..()
40-
if(!istype(I,/obj/item/tail_pin))//We're using the same trick that tables use for placing objects x and y onto the click location.
40+
if(!istype(attacking_item, /obj/item/tail_pin))//We're using the same trick that tables use for placing objects x and y onto the click location.
4141
return
42-
if(!user.transferItemToLoc(I, drop_location(), silent = FALSE))
43-
return
44-
var/list/modifiers = params2list(params)
45-
if(!LAZYACCESS(modifiers, ICON_X) || !LAZYACCESS(modifiers, ICON_Y))
42+
43+
var/x_offset = 0
44+
var/y_offset = 0
45+
if(LAZYACCESS(modifiers, ICON_X) && LAZYACCESS(modifiers, ICON_Y))
46+
x_offset = clamp(text2num(LAZYACCESS(modifiers, ICON_X)) - 16, -(ICON_SIZE_X/2), ICON_SIZE_X/2)
47+
y_offset = clamp(text2num(LAZYACCESS(modifiers, ICON_Y)) - 16, -(ICON_SIZE_Y/2), ICON_SIZE_Y/2)
48+
if(!user.transfer_item_to_turf(attacking_item, drop_location(), x_offset, y_offset))
4649
return
47-
I.pixel_x = clamp(text2num(LAZYACCESS(modifiers, ICON_X)) - 16, -(world.icon_size/2), world.icon_size/2)
48-
I.pixel_y = clamp(text2num(LAZYACCESS(modifiers, ICON_Y)) - 16, -(world.icon_size/2), world.icon_size/2)
4950
return TRUE

code/game/objects/structures/beds_chairs/chair.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/chair/stool, 0)
347347
var/obj/item/C = new item_chair(loc)
348348
C.set_custom_materials(custom_materials)
349349
TransferComponents(C)
350-
user.put_in_hands(C)
350+
try_put_in_hand(C, user)
351351
qdel(src)
352352

353353
/obj/structure/chair/user_buckle_mob(mob/living/M, mob/user, check_loc = TRUE)

0 commit comments

Comments
 (0)