Skip to content

Commit

Permalink
Armor style preview
Browse files Browse the repository at this point in the history
Plus a bit of a refactor
  • Loading branch information
SabreML committed Nov 25, 2023
1 parent 7ce5c3e commit 28fed44
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 @@ var/const/MAX_SAVE_SLOTS = 10
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 28fed44

Please sign in to comment.