Files
Alexis fb67ef6a5d Cleanup + TGUI Fix for Hair Dye [NOVA PORT] (#5896)
## About The Pull Request
ORIGINAL PR: https://github.com/NovaSector/NovaSector/pull/6818
Cleans up the code for hair dye and fixes the TGUI NtOS bluescreen.
## Why It's Good For The Game
Bugs are bad and maintenance for unmaintained code is good.
## Proof Of Testing
See below.
<details>
<summary>Screenshots/Videos</summary>
<img width="451" height="172" alt="image"
src="https://github.com/user-attachments/assets/36c89512-e375-47f7-9d49-942158acabde"
/>

<img width="767" height="526" alt="image"
src="https://github.com/user-attachments/assets/bb0c5053-437f-4d93-8956-f8164ad9be4d"
/>

</details>

## Changelog
🆑 xPokee, Hardly
fix: Fixes hair dye's gradient dyeing not working
/🆑
2026-07-04 11:44:27 -07:00

120 lines
4.7 KiB
Plaintext

/obj/item/dyespray
name = "hair dye spray"
desc = "A spray to dye your hair any gradients you'd like."
w_class = WEIGHT_CLASS_TINY
icon = 'icons/obj/cosmetic.dmi'
icon_state = "dyespray"
/obj/item/dyespray/attack_self(mob/user)
dye(user, user)
/obj/item/dyespray/pre_attack(atom/target, mob/living/user, list/modifiers, list/attack_modifiers)
dye(target, user)
return ..()
/**
* Applies a gradient and a gradient color to a mob.
*
* Arguments:
* * target - The mob who we will apply the gradient and gradient color to.
*/
/* BUBBER EDIT - REMOVAL - MOVED TO MODULAR (modular_skyrat\master_files\code\game\objects\items\dyekit.dm)
/obj/item/dyespray/proc/dye(mob/target, mob/user)
if(!ishuman(target))
return
var/mob/living/carbon/human/human_target = target
var/list/dyables = list("Hair", "Facial Hair")
for(var/obj/item/organ/organ as anything in human_target.organs)
if(!istype(organ.bodypart_overlay, /datum/bodypart_overlay/mutant))
continue
var/datum/bodypart_overlay/mutant/overlay = organ.bodypart_overlay
if(overlay.dyable && overlay.sprite_datum.color_src)
dyables += list("External Body Parts")
break
var/obj/item/bodypart/head/head = human_target.get_bodypart(BODY_ZONE_HEAD)
if(!head || !(head.head_flags & HEAD_HAIR) || HAS_TRAIT(human_target, TRAIT_BALD))
dyables -= "Hair"
if(!head || !(head.head_flags & HEAD_FACIAL_HAIR) || HAS_TRAIT(human_target, TRAIT_SHAVED))
dyables -= "Facial Hair"
if(!length(dyables))
if(target != user)
to_chat(user, span_warning("[human_target] doesn't have anything that can be dyed."))
else
to_chat(user, span_warning("You have nothing to dye."))
return
var/what_to_dye = tgui_alert(user, "What do you want to dye?", "Character Preference", dyables)
if(!what_to_dye || !user.can_perform_action(src, NEED_DEXTERITY))
return
if(what_to_dye == "External Body Parts")
dye_organ(target, user)
return
var/list/choices = what_to_dye == "Hair" ? SSaccessories.hair_gradients_list : SSaccessories.facial_hair_gradients_list
var/new_grad_style = tgui_input_list(user, "Choose a color pattern", "Character Preference", choices)
if(isnull(new_grad_style))
return
if(!user.can_perform_action(src, NEED_DEXTERITY))
return
var/new_grad_color = tgui_color_picker(user, "Choose a secondary hair color:", "Character Preference", human_target.get_hair_gradient_color())
if(!new_grad_color || !user.can_perform_action(src, NEED_DEXTERITY) || !target.IsReachableBy(user))
return
to_chat(user, span_notice("You start applying the hair dye..."))
if(!do_after(user, 3 SECONDS, target))
return
if(what_to_dye == "Hair")
human_target.set_hair_gradient_style(new_grad_style, update = FALSE)
human_target.set_hair_gradient_color(new_grad_color, update = TRUE)
else
human_target.set_facial_hair_gradient_style(new_grad_style, update = FALSE)
human_target.set_facial_hair_gradient_color(new_grad_color, update = TRUE)
playsound(src, 'sound/effects/spray.ogg', 10, vary = TRUE)
*/
/obj/item/dyespray/proc/dye_organ(mob/living/carbon/human/target, mob/user)
var/list/dyables = list()
var/list/choices = list()
for(var/obj/item/organ/organ as anything in target.organs)
if(!istype(organ.bodypart_overlay, /datum/bodypart_overlay/mutant))
continue
var/datum/bodypart_overlay/mutant/overlay = organ.bodypart_overlay
if(overlay.dyable && overlay.sprite_datum.color_src)
var/choice_name = full_capitalize(organ.name)
dyables[choice_name] = organ
choices += choice_name
if(!length(choices))
return
var/what_to_dye = tgui_alert(user, "What do you want to dye?", "Character Preference", choices)
if(!what_to_dye || !user.can_perform_action(src, NEED_DEXTERITY))
return
var/obj/item/organ/selected = dyables[what_to_dye]
if(QDELETED(selected) || !(selected in target.organs))
return
var/datum/bodypart_overlay/mutant/overlay = selected.bodypart_overlay
if(overlay.dye_color)
var/remove_dye = tgui_alert(user, "Do you want to un-dye [selected]?", "Character Preference", list("Yes", "No"))
if(isnull(remove_dye) || !user.can_perform_action(src, NEED_DEXTERITY))
return
if(QDELETED(selected) || !(selected in target.organs))
return
if(remove_dye == "Yes")
overlay.set_dye_color(null, selected)
return
var/default_color = overlay.dye_color || overlay.draw_color
var/new_color = tgui_color_picker(user, "Choose a color for [selected]:", "Character Preference", default_color)
if(isnull(new_color) || new_color == default_color || !user.can_perform_action(src, NEED_DEXTERITY))
return
if(QDELETED(selected) || !(selected in target.organs))
return
if(!do_after(user, 4.5 SECONDS, target))
return
if(QDELETED(selected) || !(selected in target.organs))
return
overlay.set_dye_color(new_color, selected)