From 563a7d4a9941e112d7668f5f8d443e5c747da087 Mon Sep 17 00:00:00 2001 From: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Date: Tue, 5 Dec 2023 21:48:54 -0600 Subject: [PATCH] Improved weapon menus (#2506) ## About The Pull Request Uses radial menus to let you better pick what attachments/modkits/trophies you want to remove ![image](https://github.com/shiptest-ss13/Shiptest/assets/86381784/89214d04-fa56-4c46-a697-0ee470604164) ![image](https://github.com/shiptest-ss13/Shiptest/assets/86381784/a67cd03f-bad6-45ce-8e08-785d8121d233) https://github.com/shiptest-ss13/Shiptest/assets/86381784/cc0d7d4b-0c40-4c8e-bb30-debc15b422fb ## Why It's Good For The Game I have always hated when I want to remove a trophies and it dumps everything onto the floor. Input menus are also unappealing to look at and it will make it easier to add other removable attachments ## Changelog :cl: add: improved radial menu for mining tools tweak: menus for removing attachments /:cl: --- .../mining/equipment/kinetic_crusher.dm | 15 ++++--- code/modules/projectiles/gun.dm | 42 ++++++++---------- code/modules/projectiles/guns/energy.dm | 44 +++++++++---------- .../guns/energy/kinetic_accelerator.dm | 14 ++++-- 4 files changed, 60 insertions(+), 55 deletions(-) diff --git a/code/modules/mining/equipment/kinetic_crusher.dm b/code/modules/mining/equipment/kinetic_crusher.dm index 8cf62d92abd4..debdb2e2ea02 100644 --- a/code/modules/mining/equipment/kinetic_crusher.dm +++ b/code/modules/mining/equipment/kinetic_crusher.dm @@ -64,11 +64,16 @@ /obj/item/kinetic_crusher/attackby(obj/item/I, mob/living/user) if(I.tool_behaviour == TOOL_CROWBAR) if(LAZYLEN(trophies)) - to_chat(user, "You remove [src]'s trophies.") - I.play_tool_sound(src) - for(var/t in trophies) - var/obj/item/crusher_trophy/T = t - T.remove_from(src, user) + var/list/choose_options = list() + for(var/obj/item/crusher_trophy/T in trophies) + choose_options += list(T.name = image(icon = T.icon, icon_state = T.icon_state)) + var/picked_option = show_radial_menu(user, src, choose_options, radius = 38, require_near = TRUE) + if(picked_option) + to_chat(user, "You remove [picked_option].") + I.play_tool_sound(src) + for(var/obj/item/crusher_trophy/T in trophies) + if(T.name == picked_option) + T.remove_from(src, user) else to_chat(user, "There are no trophies on [src].") else if(istype(I, /obj/item/crusher_trophy)) diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index b250e23751d5..d6b9e05413a9 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -67,6 +67,7 @@ lefthand_file = 'icons/mob/inhands/weapons/guns_lefthand.dmi' righthand_file = 'icons/mob/inhands/weapons/guns_righthand.dmi' + var/list/attachment_options = list() //This.. works for now.. gun refactor soon var/obj/item/firing_pin/pin = /obj/item/firing_pin //standard firing pin for most guns var/can_flashlight = FALSE //if a flashlight can be added or removed if it already has one. @@ -545,33 +546,26 @@ return if(!user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) return - if((can_flashlight && gun_light) && (can_bayonet && bayonet)) //give them a choice instead of removing both - var/list/possible_items = list(gun_light, bayonet) - var/obj/item/item_to_remove = input(user, "Select an attachment to remove", "Attachment Removal") as null|obj in sortNames(possible_items) - if(!item_to_remove || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) - return - return remove_gun_attachment(user, I, item_to_remove) - - else if(gun_light && can_flashlight) //if it has a gun_light and can_flashlight is false, the flashlight is permanently attached. + attachment_options = list() + get_gun_attachments() + if(LAZYLEN(attachment_options) == 1) + remove_gun_attachments(user, I, attachment_options[1]) + else if (LAZYLEN(attachment_options)) + var/picked_option = show_radial_menu(user, src, attachment_options, radius = 38, require_near = TRUE) + remove_gun_attachments(user, I, picked_option) + +/obj/item/gun/proc/get_gun_attachments() + if(can_flashlight && gun_light) + attachment_options += list("Light" = image(icon = gun_light.icon, icon_state = gun_light.icon_state)) + if(can_bayonet && bayonet) + attachment_options += list("Knife" = image(icon = bayonet.icon, icon_state = bayonet.icon_state)) + +/obj/item/gun/proc/remove_gun_attachments(mob/living/user, obj/item/I, picked_option) + if(picked_option == "Light") return remove_gun_attachment(user, I, gun_light, "unscrewed") - - else if(bayonet && can_bayonet) //if it has a bayonet, and the bayonet can be removed + else if(picked_option == "Knife") return remove_gun_attachment(user, I, bayonet, "unfix") - /*WS Edit - Fixes Pin Removal - else if(pin && user.is_holding(src)) - user.visible_message("[user] attempts to remove [pin] from [src] with [I].", - "You attempt to remove [pin] from [src]. (It will take [DisplayTimeText(FIRING_PIN_REMOVAL_DELAY)].)", null, 3) - if(I.use_tool(src, user, FIRING_PIN_REMOVAL_DELAY, volume = 50)) - if(!pin) //check to see if the pin is still there, or we can spam messages by clicking multiple times during the tool delay - return - user.visible_message("[pin] is pried out of [src] by [user], destroying the pin in the process.", - "You pry [pin] out with [I], destroying the pin in the process.", null, 3) - QDEL_NULL(pin) - return TRUE - WS End */ - - /obj/item/gun/welder_act(mob/living/user, obj/item/I) . = ..() if(.) diff --git a/code/modules/projectiles/guns/energy.dm b/code/modules/projectiles/guns/energy.dm index 7ba4a57bc057..229d49c4a8c6 100644 --- a/code/modules/projectiles/guns/energy.dm +++ b/code/modules/projectiles/guns/energy.dm @@ -128,27 +128,29 @@ to_chat(user, "You cannot seem to get \the [src] out of your hands!") return FALSE -/obj/item/gun/energy/proc/eject_cell(mob/user, obj/item/stock_parts/cell/gun/tac_load = null) - playsound(src, load_sound, sound_volume, load_sound_vary) - cell.forceMove(drop_location()) - var/obj/item/stock_parts/cell/gun/old_cell = cell - /*if(insert_cell(user, tac_load)) - to_chat(user, "You perform a tactical reload on \the [src].") - else - to_chat(user, "You dropped the old cell, but the new one doesn't fit. How embarassing.")*/ - cell = null - user.put_in_hands(old_cell) - old_cell.update_appearance() - to_chat(user, "You pull the cell out of \the [src].") - update_appearance() +/obj/item/gun/energy/proc/eject_cell(mob/user, obj/item/I) + to_chat(user, "You begin unscrewing and pulling out the cell...") + if(I.use_tool(src, user, unscrewing_time, volume=100)) + to_chat(user, "You remove the power cell.") + playsound(src, load_sound, sound_volume, load_sound_vary) + cell.forceMove(drop_location()) + var/obj/item/stock_parts/cell/gun/old_cell = cell + cell = null + user.put_in_hands(old_cell) + old_cell.update_appearance() + to_chat(user, "You pull the cell out of \the [src].") + update_appearance() -/obj/item/gun/energy/screwdriver_act(mob/living/user, obj/item/I) - if(cell && !internal_cell && !bayonet && (!gun_light || !can_flashlight)) - to_chat(user, "You begin unscrewing and pulling out the cell...") - if(I.use_tool(src, user, unscrewing_time, volume=100)) - to_chat(user, "You remove the power cell.") - eject_cell(user) - return ..() +/obj/item/gun/energy/get_gun_attachments() + if(cell && !internal_cell) + attachment_options += list("Cell" = image(icon = cell.icon, icon_state = cell.icon_state)) + ..() + +/obj/item/gun/energy/remove_gun_attachments(mob/living/user, obj/item/I, picked_option) + if(picked_option == "Cell") + eject_cell(user, I) + return TRUE + ..() /obj/item/gun/energy/can_shoot(visuals) if(safety && !visuals) @@ -226,8 +228,6 @@ . = ..() if(!automatic_charge_overlays || QDELETED(src)) return - if(cell) - . += "[icon_state]_cell" // Every time I see code this "flexible", a kitten fucking dies //it got worse //todo: refactor this a bit to allow showing of charge on a gun's cell var/overlay_icon_state = "[icon_state]_charge" diff --git a/code/modules/projectiles/guns/energy/kinetic_accelerator.dm b/code/modules/projectiles/guns/energy/kinetic_accelerator.dm index 8a829153fcfd..5f39d407d749 100644 --- a/code/modules/projectiles/guns/energy/kinetic_accelerator.dm +++ b/code/modules/projectiles/guns/energy/kinetic_accelerator.dm @@ -49,11 +49,17 @@ /obj/item/gun/energy/kinetic_accelerator/crowbar_act(mob/living/user, obj/item/I) . = TRUE - if(modkits.len) - to_chat(user, "You pry the modifications out.") - I.play_tool_sound(src, 100) + if(LAZYLEN(modkits)) + var/list/choose_options = list() for(var/obj/item/borg/upgrade/modkit/M in modkits) - M.uninstall(src) + choose_options += list(M.name = image(icon = M.icon, icon_state = M.icon_state)) + var/picked_option = show_radial_menu(user, src, choose_options, radius = 38, require_near = TRUE) + if(picked_option) + to_chat(user, "You remove [picked_option].") + I.play_tool_sound(src, 100) + for(var/obj/item/borg/upgrade/modkit/M in modkits) + if(M.name == picked_option) + M.uninstall(src) else to_chat(user, "There are no modifications currently installed.")