Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make click dragging an item onto a stored HUD equip it #15381

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/datums/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
if (master && (!master.click_check || (usr in master.mobs)))
master.MouseDrop(src, over_object, src_location, over_location, over_control, params)

MouseDrop_T(atom/movable/O as obj, mob/user as mob)
MouseDrop_T(atom/movable/O as obj, mob/user as mob, src_location, over_location, over_control, src_control, params)
if (master && (!master.click_check || (user in master.mobs)))
master.MouseDrop_T(src, O, user)
master.MouseDrop_T(src, O, user, params)

disposing()
src.master = null
Expand Down Expand Up @@ -240,7 +240,7 @@
proc/MouseEntered(id,location, control, params)
proc/MouseExited(id)
proc/MouseDrop(var/atom/movable/screen/hud/H, atom/over_object, src_location, over_location, over_control, params)
proc/MouseDrop_T(var/atom/movable/screen/hud/H, atom/movable/O as obj, mob/user as mob)
proc/MouseDrop_T(var/atom/movable/screen/hud/H, atom/movable/O as obj, mob/user as mob, params)

/*
dynamic hud stuff
Expand Down
129 changes: 74 additions & 55 deletions code/datums/hud/storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,61 +31,16 @@
relay_click(id, mob/user, params)
switch (id)
if ("boxes")
if (params && islist(src.obj_locs))
var/list/prams = params
if (!islist(prams))
prams = params2list(prams)
if (islist(prams))
var/clicked_loc = prams["screen-loc"] // should be in the format 1:16,1:16 (tile x : pixel offset x, tile y : pixel offset y)
//DEBUG_MESSAGE(clicked_loc)
//var/regex/loc_regex = regex("(\\d*):\[^,]*,(\\d*):\[^\n]*")
//clicked_loc = loc_regex.Replace(clicked_loc, "$1,$2")
//DEBUG_MESSAGE(clicked_loc)

//MBC : I DONT KNOW REGEX BUT THE ABOVE IS NOT WORKING LETS DO THIS INSTEAD


var/firstcolon = findtext(clicked_loc,":")
var/comma = findtext(clicked_loc,",")
var/secondcolon = findtext(clicked_loc,":",comma)
if (firstcolon == secondcolon)
if (firstcolon > comma)
firstcolon = 0
else
secondcolon = 0

var/x = copytext(clicked_loc,1,firstcolon ? firstcolon : comma)
var/px = firstcolon ? copytext(clicked_loc,firstcolon+1,comma) : 0
var/y = copytext(clicked_loc,comma+1,secondcolon ? secondcolon : 0)
var/py = secondcolon ? copytext(clicked_loc,secondcolon+1) : 0

if (user.client && user.client.byond_version == 512 && user.client.byond_build == 1469) //sWAP EM BECAUSE OF BAD BYOND BUG
var/temp = y
y = px
px = temp

//ddumb hack for offset storage
var/turfd = (isturf(master.linked_item.loc) && !istype(master.linked_item, /obj/item/bible))

var/pixel_y_adjust = 0
if (user && user.client && user.client.tg_layout && !turfd)
pixel_y_adjust = 1

if (pixel_y_adjust && text2num(py) > 16)
y = text2num(y) + 1
py = text2num(py) - 16
//end dumb hack

clicked_loc = "[x],[y]"


var/obj/item/I = src.obj_locs[clicked_loc]
if (I)
//DEBUG_MESSAGE("clicking [I] with params [list2params(params)]")
user.click(I, params)
else if (user.equipped())
//DEBUG_MESSAGE("clicking [src.master.linked_item] with [user.equipped()] with params [list2params(params)]")
user.click(src.master.linked_item, params)
var/clicked_loc = src.get_clicked_position(user, params)
if (!clicked_loc)
return
var/obj/item/I = src.obj_locs[clicked_loc]
if (I)
//DEBUG_MESSAGE("clicking [I] with params [list2params(params)]")
user.click(I, params)
else if (user.equipped())
//DEBUG_MESSAGE("clicking [src.master.linked_item] with [user.equipped()] with params [list2params(params)]")
user.click(src.master.linked_item, params)

if ("close")
user.detach_hud(src)
Expand All @@ -105,6 +60,70 @@
if (!H) return
sel.screen_loc = null

MouseDrop_T(atom/movable/screen/hud/H, atom/movable/O, mob/user, params)
if (!(user in src.mobs))
return
if (!(O in src.master.get_contents()))
return
var/clicked_position = src.get_clicked_position(user, params)
if (!clicked_position)
return
if (src.obj_locs[clicked_position] == O)
user.click(O, params2list(params))

proc/get_clicked_position(mob/user, list/params)
FlameArrow57 marked this conversation as resolved.
Show resolved Hide resolved
if (!params)
return
if (!islist(src.obj_locs))
return

var/list/prams = params
if (!islist(prams))
prams = params2list(prams)
if (!islist(prams))
return

var/clicked_loc = prams["screen-loc"] // should be in the format 1:16,1:16 (tile x : pixel offset x, tile y : pixel offset y)
//DEBUG_MESSAGE(clicked_loc)
//var/regex/loc_regex = regex("(\\d*):\[^,]*,(\\d*):\[^\n]*")
//clicked_loc = loc_regex.Replace(clicked_loc, "$1,$2")
//DEBUG_MESSAGE(clicked_loc)

//MBC : I DONT KNOW REGEX BUT THE ABOVE IS NOT WORKING LETS DO THIS INSTEAD

var/firstcolon = findtext(clicked_loc,":")
var/comma = findtext(clicked_loc,",")
var/secondcolon = findtext(clicked_loc,":",comma)
if (firstcolon == secondcolon)
if (firstcolon > comma)
firstcolon = 0
else
secondcolon = 0

var/x = copytext(clicked_loc,1,firstcolon ? firstcolon : comma)
var/px = firstcolon ? copytext(clicked_loc,firstcolon+1,comma) : 0
var/y = copytext(clicked_loc,comma+1,secondcolon ? secondcolon : 0)
var/py = secondcolon ? copytext(clicked_loc,secondcolon+1) : 0

if (user.client && user.client.byond_version == 512 && user.client.byond_build == 1469) //sWAP EM BECAUSE OF BAD BYOND BUG
var/temp = y
y = px
px = temp

//ddumb hack for offset storage
var/turfd = (isturf(master.linked_item.loc) && !istype(master.linked_item, /obj/item/bible))

var/pixel_y_adjust = 0
if (user && user.client && user.client.tg_layout && !turfd)
pixel_y_adjust = 1

if (pixel_y_adjust && text2num(py) > 16)
y = text2num(y) + 1
py = text2num(py) - 16
//end dumb hack

return "[x],[y]"

//idk if i can even use the params of mousedrop for this
/*
mouse_drop(var/atom/movable/screen/hud/H, atom/over_object, src_location, over_location, over_control, params)
Expand Down