[MIRROR] Gun locker now uses a radial menu (#147)

* Gun locker now uses a radial menu (#52506)

* Gun Locker Radials

* Smaller radius

* Review fixes

* Update code/game/objects/structures/guncase.dm

Co-authored-by: Rohesie <rohesie@gmail.com>

* Review fixes 2

* Apply suggestions from code review

Co-authored-by: Rohesie <rohesie@gmail.com>

Co-authored-by: Rohesie <rohesie@gmail.com>

* Gun locker now uses a radial menu

Co-authored-by: Arkatos1 <43862960+Arkatos1@users.noreply.github.com>
Co-authored-by: Rohesie <rohesie@gmail.com>
This commit is contained in:
SkyratBot
2020-07-31 00:37:21 +02:00
committed by GitHub
co-authored by Rohesie Arkatos1
parent 81088b45bb
commit dd5c687981
+45 -24
View File
@@ -60,36 +60,57 @@
if(iscyborg(user) || isalien(user))
return
if(contents.len && open)
ShowWindow(user)
show_menu(user)
else
open = !open
update_icon()
/obj/structure/guncase/proc/ShowWindow(mob/user)
var/dat = {"<div class='block'>
<h3>Stored Guns</h3>
<table align='center'>"}
if(LAZYLEN(contents))
for(var/i in 1 to contents.len)
var/obj/item/I = contents[i]
dat += "<tr><A href='?src=[REF(src)];retrieve=[REF(I)]'>[I.name]</A><br>"
dat += "</table></div>"
/**
* show_menu: Shows a radial menu to a user consisting of an available weaponry for taking
*
* Arguments:
* * user The mob to which we are showing the radial menu
*/
/obj/structure/guncase/proc/show_menu(mob/user)
if(!LAZYLEN(contents))
return
var/datum/browser/popup = new(user, "gunlocker", "<div align='center'>[name]</div>", 350, 300)
popup.set_content(dat)
popup.open(FALSE)
var/list/display_names = list()
var/list/items = list()
for(var/i in 1 to length(contents))
var/obj/item/thing = contents[i]
display_names["[thing.name] ([i])"] = REF(thing)
var/image/item_image = image(icon = thing.icon, icon_state = thing.icon_state)
if(length(thing.overlays))
item_image.copy_overlays(thing)
items += list("[thing.name] ([i])" = item_image)
/obj/structure/guncase/Topic(href, href_list)
if(href_list["retrieve"])
var/obj/item/O = locate(href_list["retrieve"]) in contents
if(!O || !istype(O))
return
if(!usr.canUseTopic(src, BE_CLOSE) || !open)
return
if(ishuman(usr))
if(!usr.put_in_hands(O))
O.forceMove(get_turf(src))
update_icon()
var/pick = show_radial_menu(user, src, items, custom_check = CALLBACK(src, .proc/check_menu, user), radius = 36, require_near = TRUE)
if(!pick)
return
var/weapon_reference = display_names[pick]
var/obj/item/weapon = locate(weapon_reference) in contents
if(!istype(weapon))
return
if(!user.put_in_hands(weapon))
weapon.forceMove(get_turf(src))
update_icon()
/**
* check_menu: Checks if we are allowed to interact with a radial menu
*
* Arguments:
* * user The mob interacting with a menu
*/
/obj/structure/guncase/proc/check_menu(mob/living/carbon/human/user)
if(!open)
return FALSE
if(!istype(user))
return FALSE
if(user.incapacitated())
return FALSE
return TRUE
/obj/structure/guncase/handle_atom_del(atom/A)
update_icon()