Skip to content

Commit

Permalink
Gun action (and equip) buttons refactor (#5750)
Browse files Browse the repository at this point in the history
# About the pull request

Refactors the 'gun action' buttons and the 'equip' button to have each
have their own `/atom/movable/screen` subtype, rather than all of their
functionality being done through `if()` checks in
`/atom/movable/screen/clicked()`.

*The 'gun action' buttons being these:*

![image](https://github.com/cmss13-devs/cmss13/assets/57483089/3c73da3e-4b99-4ad5-b66d-f01077f686d4)

*And the 'equip' button being this:*

![image](https://github.com/cmss13-devs/cmss13/assets/57483089/1a60d926-605d-45b4-9a9a-5a6a05cfc657)

# Explain why it's good for the game

Cleaner code, and the gun buttons now show their names in the status bar
when hovered over thanks to this:

https://github.com/cmss13-devs/cmss13/blob/1bc0fa54e985fef991e06a85871b0a62cf15e5b2/code/modules/statusbar/statusbar.dm#L23
(That line has been there for a couple of years, but
`/atom/movable/screen/gun` didn't exist until now.)

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>

Put screenshots and videos here with an empty line between the
screenshots and the `<details>` tags.

</details>


# Changelog
:cl:
refactor: Refactored the 'gun action' buttons, making them show their
names in the status bar when hovered over.
/:cl:

---------

Co-authored-by: harryob <[email protected]>
  • Loading branch information
SabreML and harryob authored Feb 21, 2024
1 parent 62c4634 commit 06eebf0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 65 deletions.
36 changes: 11 additions & 25 deletions code/_onclick/hud/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
92 changes: 52 additions & 40 deletions code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -213,54 +213,53 @@
update_icon(user)
return 1

/atom/movable/screen/clicked(mob/user, list/mods)
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, list/mods)
. = ..()
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))
INVOKE_ASYNC(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, list/mods)
if(!user)
return TRUE

if(isobserver(user))
return TRUE

return FALSE


/atom/movable/screen/inventory/clicked(mob/user)
Expand Down Expand Up @@ -587,6 +586,19 @@
vision_define = XENO_VISION_LEVEL_NO_NVG
to_chat(owner, SPAN_NOTICE("Night vision mode switched to <b>[vision_define]</b>."))

/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"
Expand Down

0 comments on commit 06eebf0

Please sign in to comment.