Skip to content

Commit

Permalink
Character creation 'Preferred Armor' preview (#5033)
Browse files Browse the repository at this point in the history
# About the pull request

Makes the armour worn by the preview dummy in the character creation
menu show the user's 'Preferred Armor' setting.

Also fixes a bug I found where the 'Padded' armour type would have its
sprite replaced with the user's preferred style when vended.
This specifically affected the 'Padded' variant because that has the
icon states of `L1`/`1`/`H1` for Light/Medium/Heavy, and
`post_vendor_spawn_hook()` worked by replacing any `1`s in the
`icon_state` with the user's preference.
(`post_vendor_spawn_hook()` now checks if the armour has style variants
before anything else.)

# Explain why it's good for the game

The 'Preferred Armor' setting can be a bit confusing if you don't
actually know what each armour style looks like. (Which I personally
didn't until making this PR.)

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>

**Character creation preview:**


https://github.com/cmss13-devs/cmss13/assets/57483089/e2ac29ea-c290-447f-b234-a3ca82397e23
<hr>

**Padded armour bug before:** (Preferred Armor set to 'Skull')


https://github.com/cmss13-devs/cmss13/assets/57483089/ba0bc7d0-2ea0-4d07-8185-3d8920790463

**Padded armour bug after:** (Preferred Armor set to 'Skull')


https://github.com/cmss13-devs/cmss13/assets/57483089/397ad4b4-a7e5-4433-84b5-196ce5df7ded
</details>


# Changelog
:cl:
add: Made the character preview in the character creation menu show the
'Preferred Armor' setting.
fix: Fixed 'Padded' armour being replaced by the user's armour style
preference when vended.
/:cl:
  • Loading branch information
SabreML authored Nov 26, 2023
1 parent 9692c43 commit 8112b59
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,8 @@ GLOBAL_LIST_INIT(bgstate_options, list(
var/new_pref_armor = tgui_input_list(user, "Choose your character's default style of armor:", "Character Preferences", GLOB.armor_style_list)
if(new_pref_armor)
preferred_armor = new_pref_armor
// Update the dummy with the new armor style.
update_preview_icon()

if("limbs")
var/limb_name = tgui_input_list(user, "Which limb do you want to change?", list("Left Leg","Right Leg","Left Arm","Right Arm","Left Foot","Right Foot","Left Hand","Right Hand"))
Expand Down
40 changes: 29 additions & 11 deletions code/modules/clothing/suits/marine_armor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
select_gamemode_skin(type)
armor_overlays = list("lamp") //Just one for now, can add more later.
if(armor_variation && mapload)
post_vendor_spawn_hook()
set_armor_style("Random")
update_icon()
pockets.max_w_class = SIZE_SMALL //Can contain small items AND rifle magazines.
pockets.bypass_w_limit = list(
Expand Down Expand Up @@ -149,18 +149,15 @@


/obj/item/clothing/suit/storage/marine/post_vendor_spawn_hook(mob/living/carbon/human/user) //used for randomizing/selecting a variant for armors.
var/new_look //used for the icon_state text replacement.

if(!user?.client?.prefs)
new_look = rand(1,armor_variation)

else if(user.client.prefs.preferred_armor == "Random")
new_look = rand(1,armor_variation)
if(!armor_variation)
return

if(user?.client?.prefs)
// Set the armor style to the user's preference.
set_armor_style(user.client.prefs.preferred_armor)
else
new_look = GLOB.armor_style_list[user.client.prefs.preferred_armor]

icon_state = replacetext(icon_state,"1","[new_look]")
// Or if that isn't possible, just pick a random one.
set_armor_style("Random")
update_icon(user)

/obj/item/clothing/suit/storage/marine/attack_self(mob/user)
Expand Down Expand Up @@ -219,6 +216,27 @@
M.visible_message(SPAN_DANGER("Your programming prevents you from wearing this!"))
return 0

/**
* Updates the armor's `icon_state` to the style represented by `new_style`.
*
* Arguments:
* * new_style - The new armor style. May only be one of `GLOB.armor_style_list`'s keys, or `"Random"`.
*/
/obj/item/clothing/suit/storage/marine/proc/set_armor_style(new_style)
// Regex to match one or more digits.
var/static/regex/digits = new("\\d+")
// Integer for the new armor style's `icon_state`.
var/new_look

if(new_style == "Random")
// The style icon states are all numbers between 1 and `armor_variation`, so this picks a random one.
new_look = rand(1, armor_variation)
else
new_look = GLOB.armor_style_list[new_style]

// Replace the digits in the current icon state with `new_look`. (E.g. "L6" -> "L2")
icon_state = digits.Replace(icon_state, new_look)

/obj/item/clothing/suit/storage/marine/padded
name = "M3 pattern padded marine armor"
icon_state = "1"
Expand Down
10 changes: 10 additions & 0 deletions code/modules/mob/new_player/preferences_setup.dm
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@

arm_equipment(preview_dummy, J, FALSE, FALSE, owner, show_job_gear)

// If the dummy was equipped with marine armor.
var/jacket = preview_dummy.get_item_by_slot(WEAR_JACKET)
if(istype(jacket, /obj/item/clothing/suit/storage/marine))
var/obj/item/clothing/suit/storage/marine/armor = jacket
// If the armor has different sprite variants.
if(armor.armor_variation)
// Set its `icon_state` to the style the player picked as their 'Preferred Armor'.
armor.set_armor_style(preferred_armor)
armor.update_icon(preview_dummy)

if(isnull(preview_front))
preview_front = new()
owner.add_to_screen(preview_front)
Expand Down

0 comments on commit 8112b59

Please sign in to comment.