Skip to content

Commit

Permalink
Body zone targeting keybinds refactor and a fix (#5943)
Browse files Browse the repository at this point in the history
# About the pull request

Refactors the bodypart selection keybinds to be a bit more
"object-oriented", and to fix a bug when it tries to find the UI
element.

# Explain why it's good for the game

Makes the code very slightly cleaner, and a bit less prone to error.

# 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 bodypart selection keybinds.
fix: Fixed a bug where selecting a new body zone would sometimes modify
the wrong HUD element.
/:cl:
  • Loading branch information
SabreML authored Mar 25, 2024
1 parent 8cc1e5e commit 2b76472
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 126 deletions.
2 changes: 1 addition & 1 deletion code/_onclick/hud/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
var/atom/movable/screen/toggle_burst
var/atom/movable/screen/unique_action

var/atom/movable/screen/zone_sel
var/atom/movable/screen/zone_sel/zone_sel
var/atom/movable/screen/pull_icon
var/atom/movable/screen/throw_icon
var/atom/movable/screen/oxygen_icon
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
/atom/movable/screen/zone_sel/update_icon(mob/living/user)
overlays.Cut()
overlays += image('icons/mob/hud/zone_sel.dmi', "[selecting]")
user.zone_selected = selecting

/atom/movable/screen/zone_sel/clicked(mob/user, list/mods)
if (..())
Expand Down Expand Up @@ -210,6 +209,7 @@
selecting = "eyes"

if(old_selecting != selecting)
user.zone_selected = selecting
update_icon(user)
return 1

Expand Down
119 changes: 56 additions & 63 deletions code/datums/keybinding/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,140 +73,133 @@
user.mob.drop_held_item(I)
return TRUE

/datum/keybinding/mob/target_head_cycle
// Parent type of the bodypart targeting keybinds
/datum/keybinding/mob/target

/datum/keybinding/mob/target/down(client/user)
. = ..()
if(. || !user.mob)
return

user.mob.select_body_zone(get_target_zone(user))
return TRUE

/// Returns the body zone which should be targeted when pressing this keybind.
/datum/keybinding/mob/target/proc/get_target_zone(client/user)
return

/datum/keybinding/mob/target/head_cycle
hotkey_keys = list("Numpad8")
classic_keys = list("Numpad8")
name = "target_head_cycle"
full_name = "Target: Cycle Head"
description = "Pressing this key targets the head, and continued presses will cycle to the eyes and mouth. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETCYCLEHEAD_DOWN

/datum/keybinding/mob/target_head_cycle/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("head", user)
return TRUE
/datum/keybinding/mob/target/head_cycle/get_target_zone(client/user)
switch(user.mob.zone_selected)
if("head")
return "eyes"
if("eyes")
return "mouth"
else // including if("mouth")
return "head"

/datum/keybinding/mob/target_r_arm
/datum/keybinding/mob/target/r_arm
hotkey_keys = list("Numpad4")
classic_keys = list("Numpad4")
name = "target_r_arm"
full_name = "Target: right arm"
description = "Pressing this key targets the right arm. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETRIGHTARM_DOWN

/datum/keybinding/mob/target_r_arm/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("rarm", user)
return TRUE
/datum/keybinding/mob/target/r_arm/get_target_zone(client/user)
if(user.mob.zone_selected == "r_arm")
return "r_hand"
return "r_arm"

/datum/keybinding/mob/target_body_chest
/datum/keybinding/mob/target/body_chest
hotkey_keys = list("Numpad5")
classic_keys = list("Numpad5")
name = "target_body_chest"
full_name = "Target: Body"
description = "Pressing this key targets the body. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETBODYCHEST_DOWN

/datum/keybinding/mob/target_body_chest/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("chest", user)
return TRUE
/datum/keybinding/mob/target/body_chest/get_target_zone(client/user)
return "chest"

/datum/keybinding/mob/target_left_arm
/datum/keybinding/mob/target/left_arm
hotkey_keys = list("Numpad6")
classic_keys = list("Numpad6")
name = "target_left_arm"
full_name = "Target: left arm"
description = "Pressing this key targets the body. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETLEFTARM_DOWN

/datum/keybinding/mob/target_left_arm/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("larm", user)
return TRUE
/datum/keybinding/mob/target/left_arm/get_target_zone(client/user)
if(user.mob.zone_selected == "l_arm")
return "l_hand"
return "l_arm"

/datum/keybinding/mob/target_right_leg
/datum/keybinding/mob/target/right_leg
hotkey_keys = list("Numpad1")
classic_keys = list("Numpad1")
name = "target_right_leg"
full_name = "Target: Right leg"
description = "Pressing this key targets the right leg. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETRIGHTLEG_DOWN

/datum/keybinding/mob/target_right_leg/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("rleg", user)
return TRUE
/datum/keybinding/mob/target/right_leg/get_target_zone(client/user)
if(user.mob.zone_selected == "r_leg")
return "r_foot"
return "r_leg"

/datum/keybinding/mob/target_body_groin
/datum/keybinding/mob/target/body_groin
hotkey_keys = list("Numpad2")
classic_keys = list("Numpad2")
name = "target_body_groin"
full_name = "Target: Groin"
description = "Pressing this key targets the groin. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETBODYGROIN_DOWN

/datum/keybinding/mob/target_body_groin/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("groin", user)
return TRUE
/datum/keybinding/mob/target/body_groin/get_target_zone(client/user)
return "groin"

/datum/keybinding/mob/target_left_leg
/datum/keybinding/mob/target/left_leg
hotkey_keys = list("Numpad3")
classic_keys = list("Numpad3")
name = "target_left_leg"
full_name = "Target: left leg"
description = "Pressing this key targets the left leg. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETLEFTLEG_DOWN

/datum/keybinding/mob/target_left_leg/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("lleg", user)
return TRUE
/datum/keybinding/mob/target/left_leg/get_target_zone(client/user)
if(user.mob.zone_selected == "l_leg")
return "l_foot"
return "l_leg"

/datum/keybinding/mob/target_next
/datum/keybinding/mob/target/next
hotkey_keys = list("Numpad7")
classic_keys = list("Numpad7")
name = "target_next"
full_name = "Target: next"
description = "Pressing this key targets the next body part, cycling forward through all of them. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETNEXT_DOWN

/datum/keybinding/mob/target_next/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("next", user)
return TRUE
/datum/keybinding/mob/target/next/get_target_zone(client/user)
return next_in_list(user.mob.zone_selected, DEFENSE_ZONES_LIVING)

/datum/keybinding/mob/target_prev
/datum/keybinding/mob/target/prev
hotkey_keys = list("Numpad9")
classic_keys = list("Numpad9")
name = "target_prev"
full_name = "Target: previous"
description = "Pressing this key targets the previous body part, cycling backward through all of them. This will impact where you hit people, and can be used for surgery."
keybind_signal = COMSIG_KB_MOB_TARGETPREV_DOWN

/datum/keybinding/mob/target_prev/down(client/user)
. = ..()
if(.)
return
user.mob.a_select_zone("prev", user)
return TRUE
/datum/keybinding/mob/target/prev/get_target_zone(client/user)
return prev_in_list(user.mob.zone_selected, DEFENSE_ZONES_LIVING)

/datum/keybinding/mob/prevent_movement
hotkey_keys = list("Ctrl", "Alt")
Expand Down
69 changes: 8 additions & 61 deletions code/modules/mob/mob_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -386,68 +386,16 @@ GLOBAL_LIST_INIT(limb_types_by_name, list(
/mob/proc/get_eye_protection()
return EYE_PROTECTION_NONE

/mob/proc/a_select_zone(input, client/user)
var/atom/movable/screen/zone_sel/zone

for(var/A in user.screen)
if(istype(A, /atom/movable/screen/zone_sel))
zone = A

if(!zone)
/// Change the mob's selected body zone to `target_zone`.
/mob/proc/select_body_zone(target_zone)
if(!target_zone || !hud_used?.zone_sel)
return

switch(input)
if("head")
switch(usr.zone_selected)
if("head")
zone.selecting = "eyes"
if("eyes")
zone.selecting = "mouth"
if("mouth")
zone.selecting = "head"
else
zone.selecting = "head"
if("chest")
zone.selecting = "chest"
if("groin")
zone.selecting = "groin"
if("rarm")
switch(usr.zone_selected)
if("r_arm")
zone.selecting = "r_hand"
if("r_hand")
zone.selecting = "r_arm"
else
zone.selecting = "r_arm"
if("larm")
switch(usr.zone_selected)
if("l_arm")
zone.selecting = "l_hand"
if("l_hand")
zone.selecting = "l_arm"
else
zone.selecting = "l_arm"
if("rleg")
switch(usr.zone_selected)
if("r_leg")
zone.selecting = "r_foot"
if("r_foot")
zone.selecting = "r_leg"
else
zone.selecting = "r_leg"
if("lleg")
switch(usr.zone_selected)
if("l_leg")
zone.selecting = "l_foot"
if("l_foot")
zone.selecting = "l_leg"
else
zone.selecting = "l_leg"
if("next")
zone.selecting = next_in_list(usr.zone_selected, DEFENSE_ZONES_LIVING)
if("prev")
zone.selecting = prev_in_list(usr.zone_selected, DEFENSE_ZONES_LIVING)
zone.update_icon(usr)
// Update the mob's selected zone.
zone_selected = target_zone
// Update the HUD's selected zone.
hud_used.zone_sel.selecting = target_zone
hud_used.zone_sel.update_icon()

#define DURATION_MULTIPLIER_TIER_1 0.75
#define DURATION_MULTIPLIER_TIER_2 0.5
Expand Down Expand Up @@ -665,4 +613,3 @@ GLOBAL_LIST_INIT(limb_types_by_name, list(

lighting_alpha = LIGHTING_PLANE_ALPHA_VISIBLE
sync_lighting_plane_alpha()

0 comments on commit 2b76472

Please sign in to comment.