Skip to content

Commit

Permalink
Items can be dragged around tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Dec 2, 2023
1 parent 0344046 commit f2b8d60
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
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)
4 changes: 2 additions & 2 deletions code/_onclick/drag_drop.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
almost anything into a trash can.
*/

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

/atom/proc/handle_mouse_drop(atom/over, mob/user, params)
Expand Down
8 changes: 5 additions & 3 deletions code/game/objects/item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@
if(istype(over, /obj/structure))
var/obj/structure/struct = over
if(struct.structure_flags & STRUCTURE_FLAG_SURFACE)
if(user == loc && !user.try_unequip(src))
if(user == loc && !user.try_unequip(src, get_turf(user)))
return TRUE
if(isturf(loc))
dropInto(get_turf(over))
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
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/observer/ghost/ghost.dm
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
show_browser(src, dat, "window=manifest;size=370x420;can_close=1")

//This is called when a ghost is drag clicked to something.
/mob/observer/ghost/MouseDrop(src_object, over_object, src_location, over_location, src_control, over_control, params)
/mob/observer/ghost/MouseDrop(over_object, src_location, over_location, src_control, over_control, params)
SHOULD_CALL_PARENT(FALSE)
var/atom/over = src_object
var/atom/over = over_object
if(!usr || !over)
return
if(isghost(usr) && usr.client && isliving(over))
Expand Down

0 comments on commit f2b8d60

Please sign in to comment.