From 6e034d9186dd00a7ee2c1f10a75f075600e45563 Mon Sep 17 00:00:00 2001
From: SabreML <57483089+SabreML@users.noreply.github.com>
Date: Sat, 17 Feb 2024 19:55:01 +0000
Subject: [PATCH 1/3] Gun & Equip HUD button refactor
I removed the `if("Reset Machine")` part rather than refactoring it because, as far as I can tell, nothing actually uses it.
---
code/_onclick/hud/human.dm | 36 ++++-------
code/_onclick/hud/screen_objects.dm | 92 ++++++++++++++++-------------
2 files changed, 63 insertions(+), 65 deletions(-)
diff --git a/code/_onclick/hud/human.dm b/code/_onclick/hud/human.dm
index 37a858d76699..b8b55b42c028 100644
--- a/code/_onclick/hud/human.dm
+++ b/code/_onclick/hud/human.dm
@@ -272,18 +272,14 @@
static_inventory += using
/datum/hud/human/proc/draw_hand_equip(datum/custom_hud/ui_datum, ui_alpha, ui_color)
- var/atom/movable/screen/using = new /atom/movable/screen()
- using.name = "equip"
- using.icon = ui_datum.ui_style_icon
- using.icon_state = "act_equip"
- using.screen_loc = ui_datum.ui_equip
- using.layer = ABOVE_HUD_LAYER
- using.plane = ABOVE_HUD_PLANE
+ var/atom/movable/screen/equip/equip_button = new()
+ equip_button.icon = ui_datum.ui_style_icon
+ equip_button.screen_loc = ui_datum.ui_equip
if(ui_color)
- using.color = ui_color
+ equip_button.color = ui_color
if(ui_alpha)
- using.alpha = ui_alpha
- static_inventory += using
+ equip_button.alpha = ui_alpha
+ static_inventory += equip_button
/datum/hud/human/proc/draw_oxygen(datum/custom_hud/ui_datum)
oxygen_icon = new /atom/movable/screen/oxygen()
@@ -312,38 +308,28 @@
infodisplay += locate_leader
/datum/hud/human/proc/draw_gun_related(datum/custom_hud/ui_datum, ui_alpha)
- use_attachment = new /atom/movable/screen()
+ use_attachment = new /atom/movable/screen/gun/attachment()
use_attachment.icon = ui_datum.ui_style_icon
- use_attachment.icon_state = "gun_attach"
- use_attachment.name = "Activate weapon attachment"
use_attachment.screen_loc = ui_datum.ui_gun_attachment
static_inventory += use_attachment
- toggle_raillight = new /atom/movable/screen()
+ toggle_raillight = new /atom/movable/screen/gun/rail_light()
toggle_raillight.icon = ui_datum.ui_style_icon
- toggle_raillight.icon_state = "gun_raillight"
- toggle_raillight.name = "Toggle Rail Flashlight"
toggle_raillight.screen_loc = ui_datum.ui_gun_railtoggle
static_inventory += toggle_raillight
- eject_mag = new /atom/movable/screen()
+ eject_mag = new /atom/movable/screen/gun/eject_magazine()
eject_mag.icon = ui_datum.ui_style_icon
- eject_mag.icon_state = "gun_loaded"
- eject_mag.name = "Eject magazine"
eject_mag.screen_loc = ui_datum.ui_gun_eject
static_inventory += eject_mag
- toggle_burst = new /atom/movable/screen()
+ toggle_burst = new /atom/movable/screen/gun/toggle_firemode()
toggle_burst.icon = ui_datum.ui_style_icon
- toggle_burst.icon_state = "gun_burst"
- toggle_burst.name = "Toggle burst fire"
toggle_burst.screen_loc = ui_datum.ui_gun_burst
static_inventory += toggle_burst
- unique_action = new /atom/movable/screen()
+ unique_action = new /atom/movable/screen/gun/unique_action()
unique_action.icon = ui_datum.ui_style_icon
- unique_action.icon_state = "gun_unique"
- unique_action.name = "Use unique action"
unique_action.screen_loc = ui_datum.ui_gun_unique
static_inventory += unique_action
diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm
index 1eb555fceaf7..0a05ce058c88 100644
--- a/code/_onclick/hud/screen_objects.dm
+++ b/code/_onclick/hud/screen_objects.dm
@@ -211,54 +211,53 @@
update_icon(user)
return 1
-/atom/movable/screen/clicked(mob/user)
- if(!user)
- return TRUE
+/atom/movable/screen/gun
+ /// The proc/verb which should be called on the gun.
+ var/gun_proc_ref
- if(isobserver(user))
- return TRUE
+/atom/movable/screen/gun/clicked(mob/user)
+ . = ..()
+ if(.)
+ return
+ // If the user has a gun in their active hand, call `gun_proc_ref` on it.
+ var/obj/item/weapon/gun/held_item = user.get_held_item()
+ if(istype(held_item))
+ call(held_item, gun_proc_ref)()
- switch(name)
- if("equip")
- if(ishuman(user))
- var/mob/living/carbon/human/human = user
- human.quick_equip()
- return 1
+/atom/movable/screen/gun/attachment
+ name = "Activate weapon attachment"
+ icon_state = "gun_attach"
+ gun_proc_ref = TYPE_VERB_REF(/obj/item/weapon/gun, activate_attachment_verb)
- if("Reset Machine")
- user.unset_interaction()
- return 1
+/atom/movable/screen/gun/rail_light
+ name = "Toggle rail flashlight"
+ icon_state = "gun_raillight"
+ gun_proc_ref = TYPE_VERB_REF(/obj/item/weapon/gun, activate_rail_attachment_verb)
- if("Activate weapon attachment")
- var/obj/item/weapon/gun/held_item = user.get_held_item()
- if(istype(held_item))
- held_item.activate_attachment_verb()
- return 1
+/atom/movable/screen/gun/eject_magazine
+ name = "Eject magazine"
+ icon_state = "gun_loaded"
+ gun_proc_ref = TYPE_VERB_REF(/obj/item/weapon/gun, empty_mag)
- if("Toggle Rail Flashlight")
- var/obj/item/weapon/gun/held_item = user.get_held_item()
- if(istype(held_item))
- held_item.activate_rail_attachment_verb()
- return 1
+/atom/movable/screen/gun/toggle_firemode
+ name = "Toggle firemode"
+ icon_state = "gun_burst"
+ gun_proc_ref = TYPE_VERB_REF(/obj/item/weapon/gun, use_toggle_burst)
- if("Eject magazine")
- var/obj/item/weapon/gun/held_item = user.get_held_item()
- if(istype(held_item))
- held_item.empty_mag()
- return 1
+/atom/movable/screen/gun/unique_action
+ name = "Use unique action"
+ icon_state = "gun_unique"
+ gun_proc_ref = TYPE_VERB_REF(/obj/item/weapon/gun, use_unique_action)
- if("Toggle burst fire")
- var/obj/item/weapon/gun/held_item = user.get_held_item()
- if(istype(held_item))
- held_item.use_toggle_burst()
- return 1
- if("Use unique action")
- var/obj/item/weapon/gun/held_item = user.get_held_item()
- if(istype(held_item))
- held_item.use_unique_action()
- return 1
- return 0
+/atom/movable/screen/clicked(mob/user)
+ if(!user)
+ return TRUE
+
+ if(isobserver(user))
+ return TRUE
+
+ return FALSE
/atom/movable/screen/inventory/clicked(mob/user)
@@ -585,6 +584,19 @@
vision_define = XENO_VISION_LEVEL_NO_NVG
to_chat(owner, SPAN_NOTICE("Night vision mode switched to [vision_define]."))
+/atom/movable/screen/equip
+ name = "equip"
+ icon_state = "act_equip"
+ layer = ABOVE_HUD_LAYER
+ plane = ABOVE_HUD_PLANE
+
+/atom/movable/screen/equip/clicked(mob/user)
+ . = ..()
+ if(. || !ishuman(user))
+ return TRUE
+ var/mob/living/carbon/human/human_user = user
+ human_user.quick_equip()
+
/atom/movable/screen/bodytemp
name = "body temperature"
icon_state = "temp0"
From 38814a8f6e71a63af4f68ecaa38bde6253e4fe68 Mon Sep 17 00:00:00 2001
From: SabreML <57483089+SabreML@users.noreply.github.com>
Date: Wed, 21 Feb 2024 10:27:29 +0000
Subject: [PATCH 2/3] De-callening
Co-Authored-By: harryob
---
code/_onclick/hud/screen_objects.dm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm
index 0a05ce058c88..75ee1a81fff2 100644
--- a/code/_onclick/hud/screen_objects.dm
+++ b/code/_onclick/hud/screen_objects.dm
@@ -222,7 +222,7 @@
// If the user has a gun in their active hand, call `gun_proc_ref` on it.
var/obj/item/weapon/gun/held_item = user.get_held_item()
if(istype(held_item))
- call(held_item, gun_proc_ref)()
+ INVOKE_ASYNC(held_item, gun_proc_ref)
/atom/movable/screen/gun/attachment
name = "Activate weapon attachment"
From 56940f52bc5c98afb077a139fca3ddc22e2750ae Mon Sep 17 00:00:00 2001
From: SabreML <57483089+SabreML@users.noreply.github.com>
Date: Wed, 21 Feb 2024 10:31:15 +0000
Subject: [PATCH 3/3] mods
---
code/_onclick/hud/screen_objects.dm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm
index 11b5742d1e13..edf2d44a0714 100644
--- a/code/_onclick/hud/screen_objects.dm
+++ b/code/_onclick/hud/screen_objects.dm
@@ -252,7 +252,7 @@
gun_proc_ref = TYPE_VERB_REF(/obj/item/weapon/gun, use_unique_action)
-/atom/movable/screen/clicked(mob/user)
+/atom/movable/screen/clicked(mob/user, list/mods)
if(!user)
return TRUE