Skip to content

Commit

Permalink
Merge pull request #3442 from MistakeNot4892/tabledrag
Browse files Browse the repository at this point in the history
Adds dragging items around tables and racks.
  • Loading branch information
out-of-phaze authored Dec 6, 2023
2 parents f86861b + f2b8d60 commit dd0d506
Show file tree
Hide file tree
Showing 69 changed files with 127 additions and 90 deletions.
1 change: 1 addition & 0 deletions code/__defines/structures.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define STRUCTURE_FLAG_SURFACE BITFLAG(0)
21 changes: 20 additions & 1 deletion code/_helpers/animations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,23 @@
for(var/i in 2 to segments) //2 because 1 is covered above
animate(transform = matrices[i], time = speed)
//doesn't have an object argument because this is "Stacking" with the animate call above
//3 billion% intentional
//3 billion% intentional

// This proc is used to move an atom to a target loc and then interpolite to give the illusion of sliding from start to end.
/proc/do_visual_slide(var/atom/movable/sliding, var/turf/from, var/from_pixel_x, var/from_pixel_y, var/turf/target, var/target_pixel_x, var/target_pixel_y, var/center_of_mass)
set waitfor = FALSE
var/start_pixel_x = sliding.pixel_x - ((target.x-from.x) * world.icon_size)
var/start_pixel_y = sliding.pixel_y - ((target.y-from.y) * world.icon_size)
// Clear our glide so we don't do an animation when dropped into the target turf.
var/old_animate_movement = sliding.animate_movement
sliding.animate_movement = NO_STEPS
sleep(2 * world.tick_lag) // Due to BYOND being byond, animate_movement has to be set for at least 2 ticks before gliding will be disabled.
sliding.forceMove(target)
// Reset our glide_size now that movement has completed.
sliding.animate_movement = old_animate_movement
sliding.pixel_x = start_pixel_x
sliding.pixel_y = start_pixel_y
if(center_of_mass)
target_pixel_x -= center_of_mass["x"]
target_pixel_y -= center_of_mass["y"]
animate(sliding, pixel_x = target_pixel_x, pixel_y = target_pixel_y, time = 1 SECOND)
24 changes: 12 additions & 12 deletions code/_onclick/drag_drop.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
almost anything into a trash can.
*/

/atom/MouseDrop(atom/over)
/atom/MouseDrop(over_object, src_location, over_location, src_control, over_control, params)
SHOULD_CALL_PARENT(TRUE)
if(!can_mouse_drop(over, usr) || !handle_mouse_drop(over, usr))
if(!can_mouse_drop(over_object, usr, params = params) || !handle_mouse_drop(over_object, usr, params))
. = ..()

/atom/proc/handle_mouse_drop(var/atom/over, var/mob/user)
. = over?.receive_mouse_drop(src, user)
/atom/proc/handle_mouse_drop(atom/over, mob/user, params)
. = over?.receive_mouse_drop(src, user, params)

// Can the user drop something onto this atom?
/atom/proc/user_can_mousedrop_onto(var/mob/user, var/atom/being_dropped, var/incapacitation_flags)
return !user.incapacitated(incapacitation_flags) && check_mousedrop_interactivity(user) && user.check_dexterity(DEXTERITY_EQUIP_ITEM)
/atom/proc/user_can_mousedrop_onto(mob/user, atom/being_dropped, incapacitation_flags, params)
return !user.incapacitated(incapacitation_flags) && check_mousedrop_interactivity(user, params) && user.check_dexterity(DEXTERITY_EQUIP_ITEM)

/atom/proc/check_mousedrop_interactivity(var/mob/user)
/atom/proc/check_mousedrop_interactivity(mob/user, params)
return CanPhysicallyInteract(user)

// This proc checks if an atom can be mousedropped onto the target by the user.
/atom/proc/can_mouse_drop(var/atom/over, var/mob/user = usr, var/incapacitation_flags = INCAPACITATION_DEFAULT)
/atom/proc/can_mouse_drop(var/atom/over, var/mob/user = usr, var/incapacitation_flags = INCAPACITATION_DEFAULT, var/params)
SHOULD_CALL_PARENT(TRUE)
if(!istype(user) || !istype(over) ||QDELETED(user) || QDELETED(over) || QDELETED(src))
return FALSE
if(!over.user_can_mousedrop_onto(user, src, incapacitation_flags))
if(!over.user_can_mousedrop_onto(user, src, incapacitation_flags, params))
return FALSE
if(!check_mousedrop_adjacency(over, user))
if(!check_mousedrop_adjacency(over, user, params))
return FALSE
return TRUE

/atom/proc/check_mousedrop_adjacency(var/atom/over, var/mob/user)
/atom/proc/check_mousedrop_adjacency(atom/over, mob/user, params)
. = (Adjacent(user) && ((over in user?.client?.screen) || over.Adjacent(user)))

// Receive a mouse drop.
// Returns false if the atom is valid for dropping further up the chain, true if the drop has been handled.
/atom/proc/receive_mouse_drop(var/atom/dropping, var/mob/user)
/atom/proc/receive_mouse_drop(atom/dropping, mob/user, params)
var/mob/living/H = user
if(istype(H) && !H.anchored && can_climb(H) && dropping == user)
do_climb(dropping)
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/hud/ability_screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
my_mob.client.screen -= src
my_mob = null

/obj/screen/ability_master/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/screen/ability_master/handle_mouse_drop(atom/over, mob/user, params)
if(showing)
return FALSE
. = ..()
Expand Down
4 changes: 2 additions & 2 deletions code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
is_spawnable_type = FALSE
var/globalscreen = FALSE //Global screens are not qdeled when the holding mob is destroyed.

/obj/screen/receive_mouse_drop(atom/dropping, mob/user)
/obj/screen/receive_mouse_drop(atom/dropping, mob/user, params)
return TRUE

/obj/screen/check_mousedrop_interactivity(var/mob/user)
/obj/screen/check_mousedrop_interactivity(mob/user, params)
return user.client && (src in user.client.screen)

/obj/screen/text
Expand Down
2 changes: 1 addition & 1 deletion code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
/atom/movable/proc/can_buckle_mob(var/mob/living/dropping)
. = (can_buckle && istype(dropping) && !dropping.buckled && !dropping.anchored && !dropping.buckled_mob && !buckled_mob)

/atom/movable/receive_mouse_drop(atom/dropping, mob/living/user)
/atom/movable/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && can_buckle_mob(dropping))
user_buckle_mob(dropping, user)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/OpTable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
/obj/machinery/optable/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
. = (air_group || height == 0 || (istype(mover) && mover.checkpass(PASS_FLAG_TABLE)))

/obj/machinery/optable/receive_mouse_drop(atom/dropping, mob/user)
/obj/machinery/optable/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!.)
if(istype(dropping, /obj/item) && user.get_active_hand() == dropping && user.try_unequip(dropping, loc))
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/Sleeper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
return TRUE
return ..()

/obj/machinery/sleeper/receive_mouse_drop(var/atom/dropping, var/mob/user)
/obj/machinery/sleeper/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && ismob(dropping))
var/mob/target = dropping
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/bodyscanner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
icon_state = "body_scanner_2"

//Like grap-put, but for mouse-drop.
/obj/machinery/bodyscanner/receive_mouse_drop(var/atom/dropping, var/mob/user)
/obj/machinery/bodyscanner/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && isliving(dropping))
var/mob/living/M = dropping
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/cryopod.dm
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
src.add_fingerprint(target)

//Like grap-put, but for mouse-drop.
/obj/machinery/cryopod/receive_mouse_drop(var/atom/dropping, var/mob/user)
/obj/machinery/cryopod/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && check_occupant_allowed(dropping))
if(occupant)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/kitchen/gibber.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
else
return ..()

/obj/machinery/gibber/receive_mouse_drop(atom/dropping, mob/user)
/obj/machinery/gibber/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && ismob(dropping))
move_into_gibber(user, dropping)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/oxygen_pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
breather = null
return ..()

/obj/machinery/oxygen_pump/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/machinery/oxygen_pump/handle_mouse_drop(atom/over, mob/user, params)
if(ishuman(over) && can_apply_to_target(over, user))
user.visible_message(SPAN_NOTICE("\The [user] begins placing the mask onto \the [over].."))
if(do_mob(user, over, 25) && can_apply_to_target(over, user))
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/rechargestation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
. = ..()
update_icon()

/obj/machinery/recharge_station/receive_mouse_drop(var/atom/dropping, var/mob/user)
/obj/machinery/recharge_station/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && isliving(dropping))
var/mob/living/M = dropping
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/self_destruct.dm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
update_icon()
src.add_fingerprint(user)

/obj/machinery/self_destruct/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/machinery/self_destruct/handle_mouse_drop(atom/over, mob/user, params)
if(over == user && cylinder)
if(armed)
to_chat(user, SPAN_WARNING("Disarm the cylinder first."))
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/self_destruct_storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

..()

/obj/machinery/nuclear_cylinder_storage/handle_mouse_drop(atom/over, mob/user)
/obj/machinery/nuclear_cylinder_storage/handle_mouse_drop(atom/over, mob/user, params)
if(over == user && open && !panel_open && length(cylinders))
var/cylinder = cylinders[1]
user.visible_message(
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/suit_cycler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
DROP_NULL(boots)
return ..()

/obj/machinery/suit_cycler/receive_mouse_drop(var/atom/dropping, var/mob/user)
/obj/machinery/suit_cycler/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && ismob(dropping) && try_move_inside(dropping, user))
return TRUE
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/vending/_vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
. = ..()
SSnano.update_uis(src)

/obj/machinery/vending/receive_mouse_drop(atom/dropping, var/mob/user)
/obj/machinery/vending/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && dropping.loc == user && attempt_to_stock(dropping, user))
return TRUE
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/vending_deconstruction.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
/obj/structure/vending_refill/get_mechanics_info()
return "Drag to a vendor to restock. Generally can not be opened."

/obj/structure/vending_refill/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/structure/vending_refill/handle_mouse_drop(atom/over, mob/user, params)
if(istype(over, /obj/machinery/vending))
var/obj/machinery/vending/vendor = over
var/obj/machinery/vending/vendor = over
var/target_type = vendor.base_type || vendor.type
if(ispath(expected_type, target_type))
for(var/datum/stored_items/R in product_records)
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/vitals_monitor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
if(beep && victim && victim.get_pulse())
playsound(src, 'sound/machines/quiet_beep.ogg', 40)

/obj/machinery/vitals_monitor/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/machinery/vitals_monitor/handle_mouse_drop(atom/over, mob/user, params)
if(ishuman(over))
if(victim)
victim = null
Expand Down
16 changes: 14 additions & 2 deletions code/game/objects/item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,24 @@
/obj/item/check_mousedrop_adjacency(var/atom/over, var/mob/user)
. = (loc == user && istype(over, /obj/screen/inventory)) || ..()

/obj/item/handle_mouse_drop(atom/over, mob/user)

/obj/item/handle_mouse_drop(atom/over, mob/user, params)
if(over == user)
usr.face_atom(src)
dragged_onto(over)
return TRUE

// Allow dragging items onto/around tables and racks.
if(istype(over, /obj/structure))
var/obj/structure/struct = over
if(struct.structure_flags & STRUCTURE_FLAG_SURFACE)
if(user == loc && !user.try_unequip(src, get_turf(user)))
return TRUE
if(!isturf(loc))
return TRUE
var/list/click_data = params2list(params)
do_visual_slide(src, get_turf(src), pixel_x, pixel_y, get_turf(over), text2num(click_data["icon-x"])-1, text2num(click_data["icon-y"])-1, center_of_mass && cached_json_decode(center_of_mass))
return TRUE

// Try to drag-equip the item.
var/obj/screen/inventory/inv = over
if(user.client && istype(inv) && inv.slot_id && (over in user.client.screen))
Expand All @@ -282,6 +293,7 @@
user.equip_to_slot_if_possible(src, inv.slot_id)
return TRUE


. = ..()

/obj/item/proc/dragged_onto(var/mob/user)
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/bodybag.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
. = new item_path(get_turf(src))
qdel(src)

/obj/structure/closet/body_bag/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/structure/closet/body_bag/handle_mouse_drop(atom/over, mob/user, params)
if(over == user && (in_range(src, user) || (src in user.contents)))
fold(user)
return TRUE
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/storage/backpack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
/obj/item/crowbar
)

/obj/item/storage/backpack/satchel/flat/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/item/storage/backpack/satchel/flat/handle_mouse_drop(atom/over, mob/user, params)
var/turf/T = get_turf(src)
if(hides_under_flooring() && isturf(T) && !T.is_plating())
return TRUE
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/storage/internal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//items that use internal storage have the option of calling this to emulate default storage handle_mouse_drop behaviour.
//returns 1 if the master item's parent's handle_mouse_drop() should be called, 0 otherwise. It's strange, but no other way of
//doing it without the ability to call another proc's parent, really.
/obj/item/storage/internal/proc/handle_storage_internal_mouse_drop(mob/user, obj/over_object)
/obj/item/storage/internal/proc/handle_storage_internal_mouse_drop(mob/user, obj/over_object, params)
if (ishuman(user) || issmall(user)) //so monkeys can take off their backpacks -- Urist

if(over_object == user && Adjacent(user)) // this must come before the screen objects only block
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/storage/laundry_basket.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
else
icon_state = "laundry-empty"

/obj/item/storage/laundry_basket/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/item/storage/laundry_basket/handle_mouse_drop(atom/over, mob/user, params)
if(over == user)
return TRUE
. = ..()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/storage/secure.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
. = ..()


/obj/item/storage/secure/handle_mouse_drop(atom/over, mob/user)
/obj/item/storage/secure/handle_mouse_drop(atom/over, mob/user, params)
var/datum/extension/lockable/lock = get_extension(src, /datum/extension/lockable)
if(lock.locked)
add_fingerprint(user)
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/storage/storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
QDEL_NULL(storage_ui)
. = ..()

/obj/item/storage/handle_mouse_drop(var/atom/over, var/mob/user)
/obj/item/storage/handle_mouse_drop(atom/over, mob/user, params)
if(canremove && (ishuman(user) || isrobot(user) || isanimal(user)) && !user.incapacitated(INCAPACITATION_DISRUPTED) && over == user)
open(user)
return TRUE
Expand Down Expand Up @@ -318,7 +318,7 @@
remove_from_storage(I, T, 1)
finish_bulk_removal()

/obj/item/storage/receive_mouse_drop(atom/dropping, mob/living/user)
/obj/item/storage/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && scoop_inside(dropping, user))
return TRUE
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/storage/wall_mirror.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
clear_ui_users(ui_users)
. = ..()

/obj/structure/mirror/handle_mouse_drop(atom/over, mob/user)
if(!(. = mirror_storage?.handle_storage_internal_mouse_drop(user, over)))
/obj/structure/mirror/handle_mouse_drop(atom/over, mob/user, params)
if(!(. = mirror_storage?.handle_storage_internal_mouse_drop(user, over, params)))
flick("mirror_open",src)
return
if((. = ..()))
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/structures/__structure.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
layer = STRUCTURE_LAYER
abstract_type = /obj/structure

var/structure_flags
var/last_damage_message
var/health = 0
var/maxhealth = 50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ var/global/list/closets = list()
)
physically_destroyed()

/obj/structure/closet/receive_mouse_drop(atom/dropping, mob/user)
/obj/structure/closet/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
var/atom/movable/AM = dropping
if(!. && istype(AM) && opened && !istype(AM, /obj/structure/closet) && AM.simulated && !AM.anchored && (large || !ismob(AM)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
visible_message("<span class='danger'>[user] strikes [src] with [I].</span>")
check_health()

/obj/structure/closet/statue/receive_mouse_drop(atom/dropping, var/mob/user)
/obj/structure/closet/statue/receive_mouse_drop(atom/dropping, mob/user, params)
return TRUE

/obj/structure/closet/statue/relaymove()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/structures/crematorium.dm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
/obj/structure/crematorium_tray/attack_robot(mob/user)
return attack_hand_with_interaction_checks(user)

/obj/structure/crematorium_tray/receive_mouse_drop(atom/dropping, mob/user)
/obj/structure/crematorium_tray/receive_mouse_drop(atom/dropping, mob/user, params)
. = ..()
if(!. && (ismob(dropping) || istype(dropping, /obj/structure/closet/body_bag)))
var/atom/movable/AM = dropping
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/structures/fireaxe_cabinet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
toggle_open(user)
return TRUE

/obj/structure/fireaxecabinet/handle_mouse_drop(atom/over, mob/user)
/obj/structure/fireaxecabinet/handle_mouse_drop(atom/over, mob/user, params)
if(over == user)
if(!open)
to_chat(user, SPAN_WARNING("\The [src] is closed."))
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/structures/iv_drip.dm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

add_overlay(light)

/obj/structure/iv_drip/handle_mouse_drop(atom/over, mob/user)
/obj/structure/iv_drip/handle_mouse_drop(atom/over, mob/user, params)
if(attached)
drip_detach()
return TRUE
Expand Down
Loading

0 comments on commit dd0d506

Please sign in to comment.