From a133c8c4f4a1178185ce5d13da9ee02fe993b55f Mon Sep 17 00:00:00 2001 From: Bloop <13398309+vinylspiders@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:35:03 -0500 Subject: [PATCH] Fix ammo counter HUD not updating properly, and some hard dels (#555) * Fix for flavortext * changelog fix * Revert "changelog fix" This reverts commit 16fc8a3501f041d592fd94575c406312ec4f7715. * Testing ammo counter harddel * Update gun_hud_component.dm * Update gun_hud_component.dm * Update gun_hud_component.dm * Update gun_hud_component.dm * Update gun_hud_component.dm * Can't rely on that. * Fixes ammo hud not updating for self-reloading energy weapons * Revert "Fix for flavortext" This reverts commit fcbe257ebacbaaf750b3d78037afb30b6217bcfc. * Whoops * Update gun_hud_component.dm * Update gun_hud_component.dm --- code/_onclick/hud/hud.dm | 1 + .../projectiles/guns/energy/recharge.dm | 4 ++++ modular_nova/modules/gunhud/code/gun_hud.dm | 4 ++++ .../modules/gunhud/code/gun_hud_component.dm | 19 ++++++++++++++++--- tgstation.dme | 1 + 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 modular_nova/master_files/code/modules/projectiles/guns/energy/recharge.dm diff --git a/code/_onclick/hud/hud.dm b/code/_onclick/hud/hud.dm index aceb360c953..f18f44c2ecb 100644 --- a/code/_onclick/hud/hud.dm +++ b/code/_onclick/hud/hud.dm @@ -270,6 +270,7 @@ GLOBAL_LIST_INIT(available_erp_ui_styles, list( combo_display = null //NOVA EDIT START - SKYRAT HUD + ammo_counter = null wanted_lvl = null // NOVA EDIT END - SKYRAT HUD diff --git a/modular_nova/master_files/code/modules/projectiles/guns/energy/recharge.dm b/modular_nova/master_files/code/modules/projectiles/guns/energy/recharge.dm new file mode 100644 index 00000000000..26fdfce3037 --- /dev/null +++ b/modular_nova/master_files/code/modules/projectiles/guns/energy/recharge.dm @@ -0,0 +1,4 @@ +// self-reloading weapons need their ammo hud updated whenever reload() is called +/obj/item/gun/energy/recharge/reload() + . = ..() + SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) diff --git a/modular_nova/modules/gunhud/code/gun_hud.dm b/modular_nova/modules/gunhud/code/gun_hud.dm index e323026cb0b..b9f8886b572 100644 --- a/modular_nova/modules/gunhud/code/gun_hud.dm +++ b/modular_nova/modules/gunhud/code/gun_hud.dm @@ -33,6 +33,8 @@ var/oth_h ///This is the custom indicator sprite that will appear in the box at the bottom of the ammo hud, use this for something like semi/auto toggle on a gun. var/indicator + // is the ui on or off? + var/on ///This proc simply resets the hud to standard and removes it from the players visible hud. /atom/movable/screen/ammo_counter/proc/turn_off() @@ -45,10 +47,12 @@ oth_h = "" indicator = "" update_appearance() + on = FALSE ///This proc turns the hud on, but does not set it to anything other than the currently set values /atom/movable/screen/ammo_counter/proc/turn_on() invisibility = 0 + on = TRUE ///This is the main proc for altering the hud's appeareance, it controls the setting of the overlays. Use the OTH and below variables to set it accordingly. /atom/movable/screen/ammo_counter/proc/set_hud(_backing_color, _oth_o, _oth_t, _oth_h, _indicator, _oth_backing = "oth_light") diff --git a/modular_nova/modules/gunhud/code/gun_hud_component.dm b/modular_nova/modules/gunhud/code/gun_hud_component.dm index 54b8122fb10..33a2a686aab 100644 --- a/modular_nova/modules/gunhud/code/gun_hud_component.dm +++ b/modular_nova/modules/gunhud/code/gun_hud_component.dm @@ -1,5 +1,8 @@ /datum/component/ammo_hud + /// The ammo counter screen object itself var/atom/movable/screen/ammo_counter/hud + /// A weakref to the mob who currently owns the hud + var/datum/weakref/current_hud_owner /datum/component/ammo_hud/Initialize() . = ..() @@ -19,15 +22,17 @@ if(H.is_holding(parent)) if(H.hud_used) hud = H.hud_used.ammo_counter - RegisterSignal(user, COMSIG_QDELETING, PROC_REF(turn_off)) - turn_on() + if(!hud.on) // make sure we're not already turned on + current_hud_owner = WEAKREF(user) + RegisterSignal(user, COMSIG_QDELETING, PROC_REF(turn_off)) + turn_on() else - UnregisterSignal(user, COMSIG_QDELETING) turn_off() /datum/component/ammo_hud/proc/turn_on() SIGNAL_HANDLER + RegisterSignal(hud, COMSIG_QDELETING, PROC_REF(turn_off)) RegisterSignals(parent, list(COMSIG_PREQDELETED, COMSIG_ITEM_DROPPED), PROC_REF(turn_off)) RegisterSignals(parent, list(COMSIG_UPDATE_AMMO_HUD, COMSIG_GUN_CHAMBER_PROCESSED), PROC_REF(update_hud)) @@ -38,11 +43,19 @@ SIGNAL_HANDLER UnregisterSignal(parent, list(COMSIG_PREQDELETED, COMSIG_ITEM_DROPPED, COMSIG_UPDATE_AMMO_HUD, COMSIG_GUN_CHAMBER_PROCESSED)) + var/mob/living/carbon/human/current_owner = current_hud_owner?.resolve() + if(isnull(current_owner)) + current_hud_owner = null + else + UnregisterSignal(current_owner, COMSIG_QDELETING) if(hud) hud.turn_off() + UnregisterSignal(hud, COMSIG_QDELETING) hud = null + current_hud_owner = null + /// Returns get_ammo() with the appropriate args passed to it - some guns like the revolver and bow are special cases /datum/component/ammo_hud/proc/get_accurate_ammo_count(obj/item/gun/ballistic/the_gun) // fucking revolvers indeed - do not count empty or chambered rounds for the display HUD diff --git a/tgstation.dme b/tgstation.dme index 8d3c963e83a..3455690965c 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -6493,6 +6493,7 @@ #include "modular_nova\master_files\code\modules\projectiles\guns\ballistic\bows\bow_quivers.dm" #include "modular_nova\master_files\code\modules\projectiles\guns\ballistic\bows\bow_types.dm" #include "modular_nova\master_files\code\modules\projectiles\guns\energy\kinetic_accelerator.dm" +#include "modular_nova\master_files\code\modules\projectiles\guns\energy\recharge.dm" #include "modular_nova\master_files\code\modules\reagents\bottle.dm" #include "modular_nova\master_files\code\modules\reagents\reagent_containers.dm" #include "modular_nova\master_files\code\modules\reagents\reagent_dispenser.dm"