From 28fed440dd05ba610bde67cea5bcccb740693765 Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:56:07 +0000 Subject: [PATCH 1/2] Armor style preview Plus a bit of a refactor --- code/modules/client/preferences.dm | 2 + code/modules/clothing/suits/marine_armor.dm | 40 ++++++++++++++----- .../mob/new_player/preferences_setup.dm | 10 +++++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index ad12cb99b50e..8eba4c1894b6 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -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")) diff --git a/code/modules/clothing/suits/marine_armor.dm b/code/modules/clothing/suits/marine_armor.dm index fe37ba86eef2..1974b2d74cc7 100644 --- a/code/modules/clothing/suits/marine_armor.dm +++ b/code/modules/clothing/suits/marine_armor.dm @@ -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( @@ -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) @@ -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" diff --git a/code/modules/mob/new_player/preferences_setup.dm b/code/modules/mob/new_player/preferences_setup.dm index fb4dbac3c160..7e458fc8fb3d 100644 --- a/code/modules/mob/new_player/preferences_setup.dm +++ b/code/modules/mob/new_player/preferences_setup.dm @@ -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) From 21b999254a4589f5da0b0746b63bfa3b63ed1e42 Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Sat, 25 Nov 2023 15:16:51 +0000 Subject: [PATCH 2/2] Comment indentation fix :skull: --- code/modules/clothing/suits/marine_armor.dm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/modules/clothing/suits/marine_armor.dm b/code/modules/clothing/suits/marine_armor.dm index 1974b2d74cc7..6ff6eae8a372 100644 --- a/code/modules/clothing/suits/marine_armor.dm +++ b/code/modules/clothing/suits/marine_armor.dm @@ -217,11 +217,11 @@ 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"`. - */ + * 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+")