From 16e1b9e349f1ad16ad023054c68ec38d23df5e08 Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Sun, 30 Oct 2022 20:06:16 -0400 Subject: [PATCH] Fix female clothing mask (#12217) Co-authored-by: ElectroJr --- .../Clothing/ClientClothingSystem.cs | 54 +++++++++++++++---- .../Humanoid/SharedHumanoidSystem.cs | 15 +----- .../Uniforms/base_clothinguniforms.yml | 4 ++ .../Prototypes/Entities/Mobs/Species/base.yml | 4 +- 4 files changed, 52 insertions(+), 25 deletions(-) diff --git a/Content.Client/Clothing/ClientClothingSystem.cs b/Content.Client/Clothing/ClientClothingSystem.cs index e9a417b5a1..3af58fded4 100644 --- a/Content.Client/Clothing/ClientClothingSystem.cs +++ b/Content.Client/Clothing/ClientClothingSystem.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Client.Inventory; +using Content.Client.Humanoid; using Content.Shared.Clothing; using Content.Shared.Clothing.Components; using Content.Shared.Clothing.EntitySystems; @@ -42,8 +42,9 @@ public sealed class ClientClothingSystem : ClothingSystem {"pocket2", "POCKET2"}, }; - [Dependency] private IResourceCache _cache = default!; - [Dependency] private InventorySystem _inventorySystem = default!; + [Dependency] private readonly IResourceCache _cache = default!; + [Dependency] private readonly InventorySystem _inventorySystem = default!; + [Dependency] private readonly AppearanceSystem _appearance = default!; public override void Initialize() { @@ -53,6 +54,33 @@ public sealed class ClientClothingSystem : ClothingSystem SubscribeLocalEvent(OnVisualsChanged); SubscribeLocalEvent(OnDidUnequip); + SubscribeLocalEvent(OnAppearanceUpdate); + } + + private void OnAppearanceUpdate(EntityUid uid, ClientInventoryComponent component, ref AppearanceChangeEvent args) + { + // May need to update jumpsuit stencils if the sex changed. Also required to properly set the stencil on init + // when sex is first loaded from the profile. + if (!TryComp(uid, out SpriteComponent? sprite) || !sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var layer)) + return; + + if (!args.AppearanceData.TryGetValue(HumanoidVisualizerKey.Key, out object? obj) + || obj is not HumanoidVisualizerData data + || data.Sex != Sex.Female + || !_inventorySystem.TryGetSlotEntity(uid, "jumpsuit", out var suit, component) + || !TryComp(suit, out ClothingComponent? clothing)) + { + sprite.LayerSetVisible(layer, false); + return; + } + + sprite.LayerSetState(layer, clothing.FemaleMask switch + { + FemaleClothingMask.NoMask => "female_none", + FemaleClothingMask.UniformTop => "female_top", + _ => "female_full", + }); + sprite.LayerSetVisible(layer, true); } private void OnGetVisuals(EntityUid uid, ClothingComponent item, GetEquipmentVisualsEvent args) @@ -188,14 +216,22 @@ public sealed class ClientClothingSystem : ClothingSystem if(!Resolve(equipee, ref inventory, ref sprite) || !Resolve(equipment, ref clothingComponent, false)) return; - if (slot == "jumpsuit" && sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out _)) + if (slot == "jumpsuit" && sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var suitLayer)) { - sprite.LayerSetState(HumanoidVisualLayers.StencilMask, clothingComponent.FemaleMask switch + if (_appearance.TryGetData(equipee, HumanoidVisualizerKey.Key, out object? obj) + && obj is HumanoidVisualizerData data + && data.Sex == Sex.Female) { - FemaleClothingMask.NoMask => "female_none", - FemaleClothingMask.UniformTop => "female_top", - _ => "female_full", - }); + sprite.LayerSetState(suitLayer, clothingComponent.FemaleMask switch + { + FemaleClothingMask.NoMask => "female_none", + FemaleClothingMask.UniformTop => "female_top", + _ => "female_full", + }); + sprite.LayerSetVisible(suitLayer, true); + } + else + sprite.LayerSetVisible(suitLayer, false); } if (!_inventorySystem.TryGetSlot(equipee, slot, out var slotDef, inventory)) diff --git a/Content.Shared/Humanoid/SharedHumanoidSystem.cs b/Content.Shared/Humanoid/SharedHumanoidSystem.cs index 423e3e117e..0bdcf19761 100644 --- a/Content.Shared/Humanoid/SharedHumanoidSystem.cs +++ b/Content.Shared/Humanoid/SharedHumanoidSystem.cs @@ -30,19 +30,8 @@ public abstract class SharedHumanoidSystem : EntitySystem { var data = new HumanoidVisualizerData(species, customBaseLayer, skinColor, sex, visLayers, markings); - // Locally raise an event for this, because there might be some systems interested - // in this. - RaiseLocalEvent(uid, new HumanoidAppearanceUpdateEvent(data), true); + // This should raise a HumanoidAppearanceUpdateEvent, but that requires this component to be made networked and + // I cbf doing that atm. _appearance.SetData(uid, HumanoidVisualizerKey.Key, data); } } - -public sealed class HumanoidAppearanceUpdateEvent : EntityEventArgs -{ - public HumanoidVisualizerData Data { get; } - - public HumanoidAppearanceUpdateEvent(HumanoidVisualizerData data) - { - Data = data; - } -} diff --git a/Resources/Prototypes/Entities/Clothing/Uniforms/base_clothinguniforms.yml b/Resources/Prototypes/Entities/Clothing/Uniforms/base_clothinguniforms.yml index ac934f74c3..2adcc212b0 100644 --- a/Resources/Prototypes/Entities/Clothing/Uniforms/base_clothinguniforms.yml +++ b/Resources/Prototypes/Entities/Clothing/Uniforms/base_clothinguniforms.yml @@ -9,6 +9,10 @@ slots: [innerclothing] equipSound: path: /Audio/Items/jumpsuit_equip.ogg + clothingVisuals: + jumpsuit: + - state: equipped-INNERCLOTHING + shader: StencilDraw - type: Butcherable butcheringType: Knife spawned: diff --git a/Resources/Prototypes/Entities/Mobs/Species/base.yml b/Resources/Prototypes/Entities/Mobs/Species/base.yml index dcfb2c7982..1ed322cee0 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/base.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/base.yml @@ -105,7 +105,7 @@ - map: [ "enum.HumanoidVisualLayers.RLeg" ] - map: [ "enum.HumanoidVisualLayers.LLeg" ] - shader: StencilClear - sprite: Mobs/Species/Human/parts.rsi + sprite: Mobs/Species/Human/parts.rsi #PJB on stencil clear being on the left leg: "...this is 'fine'" -https://github.com/space-wizards/space-station-14/pull/12217#issuecomment-1291677115 state: l_leg - shader: StencilMask map: [ "enum.HumanoidVisualLayers.StencilMask" ] @@ -113,7 +113,6 @@ state: female_full visible: false - map: [ "jumpsuit" ] - shader: StencilDraw - map: [ "enum.HumanoidVisualLayers.LHand" ] - map: [ "enum.HumanoidVisualLayers.RHand" ] - map: [ "enum.HumanoidVisualLayers.LFoot" ] @@ -321,7 +320,6 @@ state: female_full visible: false - map: [ "jumpsuit" ] - shader: StencilDraw - map: [ "enum.HumanoidVisualLayers.LHand" ] - map: [ "enum.HumanoidVisualLayers.RHand" ] - map: [ "enum.HumanoidVisualLayers.LFoot" ]