Skip to content

Commit

Permalink
Fixes light attachments setting and add pref for ammo counter (#6251)
Browse files Browse the repository at this point in the history
# 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 <N/A>
Co-authored-by: Drathek <[email protected]>
  • Loading branch information
vero5123 and Drulikar committed May 19, 2024
1 parent 9bbb153 commit 274e7c1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/client_prefs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/__DEFINES/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ GLOBAL_LIST_INIT(bgstate_options, list(
</b> <a href='?_src_=prefs;preference=toggle_prefs;flag=[TOGGLE_MIDDLE_MOUSE_SWAP_HANDS]'><b>[toggle_prefs & TOGGLE_MIDDLE_MOUSE_SWAP_HANDS ? "On" : "Off"]</b></a><br>"
dat += "<b>Toggle Vendors Vending to Hands: \
</b> <a href='?_src_=prefs;preference=toggle_prefs;flag=[TOGGLE_VEND_ITEM_TO_HAND]'><b>[toggle_prefs & TOGGLE_VEND_ITEM_TO_HAND ? "On" : "Off"]</b></a><br>"
dat += "<b>Toggle Semi-Auto Ammo Display Limiter: \
</b> <a href='?_src_=prefs;preference=toggle_prefs;flag=[TOGGLE_AMMO_DISPLAY_TYPE]'><b>[toggle_prefs & TOGGLE_AMMO_DISPLAY_TYPE ? "On" : "Off"]</b></a><br>"
dat += "<a href='?src=\ref[src];action=proccall;procpath=/client/proc/switch_item_animations'>Toggle Item Animations Detail Level</a><br>"
dat += "<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_dualwield'>Toggle Dual Wield Functionality</a><br>"
if(MENU_SPECIAL) //wart
Expand Down
7 changes: 7 additions & 0 deletions code/modules/client/preferences_toggles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_help_intent_safety'>Toggle Help Intent Safety</a><br>",
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_auto_eject'>Toggle Guns Auto-Ejecting Magazines</a><br>",
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_auto_eject_to_hand'>Toggle Guns Auto-Ejecting Magazines to Your Hands</a><br>",
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_ammo_display_type'>Toggle Semi-Auto Ammo Counter</a><br>",
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_eject_to_hand'>Toggle 'Unload Weapon' Ejecting Magazines to Your Hands</a><br>",
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_automatic_punctuation'>Toggle Automatic Punctuation</a><br>",
"<a href='?src=\ref[src];action=proccall;procpath=/client/proc/toggle_middle_mouse_click'>Toggle Middle Mouse Ability Activation</a><br>",
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..()

Expand Down Expand Up @@ -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"))

Expand Down
10 changes: 9 additions & 1 deletion code/modules/projectiles/gun_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 274e7c1

Please sign in to comment.