Skip to content

Commit

Permalink
Fix ammo counter HUD not updating properly, and some hard dels (#555)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vinylspiders authored and FFMirrorBot committed Jan 22, 2024
1 parent 17d9562 commit a133c8c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions code/_onclick/hud/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions modular_nova/modules/gunhud/code/gun_hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
19 changes: 16 additions & 3 deletions modular_nova/modules/gunhud/code/gun_hud_component.dm
Original file line number Diff line number Diff line change
@@ -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()
. = ..()
Expand All @@ -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))

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a133c8c

Please sign in to comment.