From 274e7c10b99ff2f997a72016c2b4b8203ddc2cbd Mon Sep 17 00:00:00 2001 From: Vero <73014819+vero5123@users.noreply.github.com> Date: Sun, 19 May 2024 17:34:58 -0400 Subject: [PATCH] Fixes light attachments setting and add pref for ammo counter (#6251) # About the pull request Closes #6238, also made the ammo display less spammy. :cl: qol: Toggleable ammo counter, can now cycle between displaying every fifth or single bullet. fix: Light attachments will no longer automatically turn on when the weapon is equipped from suit storage /:cl: --------- Co-authored-by: DOOM Co-authored-by: Drathek <76988376+Drulikar@users.noreply.github.com> --- code/__DEFINES/client_prefs.dm | 1 + code/__DEFINES/traits.dm | 2 +- code/modules/client/client_procs.dm | 1 + code/modules/client/preferences.dm | 2 ++ code/modules/client/preferences_toggles.dm | 7 +++++++ code/modules/projectiles/gun.dm | 13 +++++++++---- code/modules/projectiles/gun_helpers.dm | 10 +++++++++- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/code/__DEFINES/client_prefs.dm b/code/__DEFINES/client_prefs.dm index 5337f64d9e46..56775bea8888 100644 --- a/code/__DEFINES/client_prefs.dm +++ b/code/__DEFINES/client_prefs.dm @@ -24,6 +24,7 @@ #define TOGGLE_START_JOIN_CURRENT_SLOT (1<<16) // Whether joining at roundstart ignores assigned character slot for the job and uses currently selected slot. #define TOGGLE_LATE_JOIN_CURRENT_SLOT (1<<17) //Whether joining during the round ignores assigned character slot for the job and uses currently selected slot. #define TOGGLE_ABILITY_DEACTIVATION_OFF (1<<18) // This toggles whether selecting the same ability again can toggle it off +#define TOGGLE_AMMO_DISPLAY_TYPE (1<<19)/// limit how often the ammo is displayed when using semi-automatic fire #define JOB_SLOT_RANDOMISED_SLOT -1 #define JOB_SLOT_CURRENT_SLOT 0 diff --git a/code/__DEFINES/traits.dm b/code/__DEFINES/traits.dm index 6bf9805c261f..988f82f3b73e 100644 --- a/code/__DEFINES/traits.dm +++ b/code/__DEFINES/traits.dm @@ -267,7 +267,7 @@ #define TRAIT_GUN_BIPODDED "t_gun_bipodded" -#define TRAIT_GUN_LIGHT_DEACTIVATED "t_gun_light_deactivated" +#define TRAIT_GUN_LIGHT_FORCE_DEACTIVATED "t_gun_light_deactivated" /// If this ID belongs to an ERT member #define TRAIT_ERT_ID "ert_id" diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 674e8d281811..59d7764c4193 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -43,6 +43,7 @@ GLOBAL_LIST_INIT(whitelisted_client_procs, list( /client/proc/toggle_auto_eject_to_hand, /client/proc/toggle_eject_to_hand, /client/proc/toggle_automatic_punctuation, + /client/proc/toggle_ammo_display_type, /client/proc/toggle_middle_mouse_click, /client/proc/toggle_ability_deactivation, /client/proc/toggle_clickdrag_override, diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 5a049f72b2b5..46d217ce25d4 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -631,6 +631,8 @@ GLOBAL_LIST_INIT(bgstate_options, list( [toggle_prefs & TOGGLE_MIDDLE_MOUSE_SWAP_HANDS ? "On" : "Off"]
" dat += "Toggle Vendors Vending to Hands: \ [toggle_prefs & TOGGLE_VEND_ITEM_TO_HAND ? "On" : "Off"]
" + dat += "Toggle Semi-Auto Ammo Display Limiter: \ + [toggle_prefs & TOGGLE_AMMO_DISPLAY_TYPE ? "On" : "Off"]
" dat += "Toggle Item Animations Detail Level
" dat += "Toggle Dual Wield Functionality
" if(MENU_SPECIAL) //wart diff --git a/code/modules/client/preferences_toggles.dm b/code/modules/client/preferences_toggles.dm index c4017f172f25..9db140f54958 100644 --- a/code/modules/client/preferences_toggles.dm +++ b/code/modules/client/preferences_toggles.dm @@ -264,6 +264,7 @@ "Toggle Help Intent Safety
", "Toggle Guns Auto-Ejecting Magazines
", "Toggle Guns Auto-Ejecting Magazines to Your Hands
", + "Toggle Semi-Auto Ammo Counter
", "Toggle 'Unload Weapon' Ejecting Magazines to Your Hands
", "Toggle Automatic Punctuation
", "Toggle Middle Mouse Ability Activation
", @@ -315,6 +316,12 @@ to_chat(src, SPAN_BOLDNOTICE("Guns with auto-ejectors will automatically eject their magazines.")) prefs.save_preferences() + +/client/proc/toggle_ammo_display_type() + prefs.toggle_prefs ^= TOGGLE_AMMO_DISPLAY_TYPE + to_chat(usr, SPAN_NOTICE("Guns in semi-automatic mode will now display the ammo on every [SPAN_BOLD(prefs.toggle_prefs & TOGGLE_AMMO_DISPLAY_TYPE ? "fifth bullet and when the mag has less than 15 rounds left" : "single bullet")]")) + prefs.save_preferences() + /client/proc/toggle_auto_eject_to_hand() // Toggle whether guns with auto-ejectors will eject their magazines to your offhand prefs.toggle_prefs ^= TOGGLE_AUTO_EJECT_MAGAZINE_TO_HAND if(prefs.toggle_prefs & TOGGLE_AUTO_EJECT_MAGAZINE_TO_HAND) diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index 71ddc9fb399c..69a458a983d0 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -503,13 +503,15 @@ As sniper rifles have both and weapon mods can change them as well. ..() deals w if(slot in list(WEAR_L_HAND, WEAR_R_HAND)) set_gun_user(user) - if(HAS_TRAIT_FROM_ONLY(src, TRAIT_GUN_LIGHT_DEACTIVATED, WEAKREF(user))) + if(HAS_TRAIT_FROM_ONLY(src, TRAIT_GUN_LIGHT_FORCE_DEACTIVATED, WEAKREF(user))) force_light(on = TRUE) - REMOVE_TRAIT(src, TRAIT_GUN_LIGHT_DEACTIVATED, WEAKREF(user)) + REMOVE_TRAIT(src, TRAIT_GUN_LIGHT_FORCE_DEACTIVATED, WEAKREF(user)) else set_gun_user(null) - force_light(on = FALSE) - ADD_TRAIT(src, TRAIT_GUN_LIGHT_DEACTIVATED, WEAKREF(user)) + // we force the light off and turn it back on again when the gun is equipped. Otherwise bad things happen. + if(light_sources()) + force_light(on = FALSE) + ADD_TRAIT(src, TRAIT_GUN_LIGHT_FORCE_DEACTIVATED, WEAKREF(user)) return ..() @@ -1608,6 +1610,9 @@ not all weapons use normal magazines etc. load_into_chamber() itself is designed user = gun_user if(flags_gun_features & GUN_AMMO_COUNTER && current_mag) + // toggleable spam control. + if(user.client.prefs.toggle_prefs & TOGGLE_AMMO_DISPLAY_TYPE && gun_firemode == GUN_FIREMODE_SEMIAUTO && current_mag.current_rounds % 5 != 0 && current_mag.current_rounds > 15) + return var/chambered = in_chamber ? TRUE : FALSE to_chat(user, SPAN_DANGER("[current_mag.current_rounds][chambered ? "+1" : ""] / [current_mag.max_rounds] ROUNDS REMAINING")) diff --git a/code/modules/projectiles/gun_helpers.dm b/code/modules/projectiles/gun_helpers.dm index ba9ffe897c49..c4cce7c5f996 100644 --- a/code/modules/projectiles/gun_helpers.dm +++ b/code/modules/projectiles/gun_helpers.dm @@ -765,7 +765,6 @@ DEFINES in setup.dm, referenced here. unique_action(usr) - /obj/item/weapon/gun/verb/toggle_gun_safety() set category = "Weapons" set name = "Toggle Gun Safety" @@ -933,6 +932,15 @@ DEFINES in setup.dm, referenced here. return null return params2turf(modifiers["screen-loc"], get_turf(user), user.client) +/// check if the gun contains any light source that is currently turned on. +/obj/item/weapon/gun/proc/light_sources() + var/obj/item/attachable/flashlight/torch + for(var/slot in attachments) + torch = attachments[slot] + if(istype(torch) && torch.light_on == TRUE) + return TRUE // an attachment has light enabled. + return FALSE + /// If this gun has a relevant flashlight attachable attached, (de)activate it /obj/item/weapon/gun/proc/force_light(on) var/obj/item/attachable/flashlight/torch