Fix female clothing mask (#12217)

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
Rane
2022-10-30 20:06:16 -04:00
committed by GitHub
parent e0ac3307bb
commit 16e1b9e349
4 changed files with 52 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Client.Inventory; using Content.Client.Inventory;
using Content.Client.Humanoid;
using Content.Shared.Clothing; using Content.Shared.Clothing;
using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems; using Content.Shared.Clothing.EntitySystems;
@@ -42,8 +42,9 @@ public sealed class ClientClothingSystem : ClothingSystem
{"pocket2", "POCKET2"}, {"pocket2", "POCKET2"},
}; };
[Dependency] private IResourceCache _cache = default!; [Dependency] private readonly IResourceCache _cache = default!;
[Dependency] private InventorySystem _inventorySystem = default!; [Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -53,6 +54,33 @@ public sealed class ClientClothingSystem : ClothingSystem
SubscribeLocalEvent<ClientInventoryComponent, VisualsChangedEvent>(OnVisualsChanged); SubscribeLocalEvent<ClientInventoryComponent, VisualsChangedEvent>(OnVisualsChanged);
SubscribeLocalEvent<SpriteComponent, DidUnequipEvent>(OnDidUnequip); SubscribeLocalEvent<SpriteComponent, DidUnequipEvent>(OnDidUnequip);
SubscribeLocalEvent<ClientInventoryComponent, AppearanceChangeEvent>(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) 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)) if(!Resolve(equipee, ref inventory, ref sprite) || !Resolve(equipment, ref clothingComponent, false))
return; 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", sprite.LayerSetState(suitLayer, clothingComponent.FemaleMask switch
FemaleClothingMask.UniformTop => "female_top", {
_ => "female_full", 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)) if (!_inventorySystem.TryGetSlot(equipee, slot, out var slotDef, inventory))

View File

@@ -30,19 +30,8 @@ public abstract class SharedHumanoidSystem : EntitySystem
{ {
var data = new HumanoidVisualizerData(species, customBaseLayer, skinColor, sex, visLayers, markings); var data = new HumanoidVisualizerData(species, customBaseLayer, skinColor, sex, visLayers, markings);
// Locally raise an event for this, because there might be some systems interested // This should raise a HumanoidAppearanceUpdateEvent, but that requires this component to be made networked and
// in this. // I cbf doing that atm.
RaiseLocalEvent(uid, new HumanoidAppearanceUpdateEvent(data), true);
_appearance.SetData(uid, HumanoidVisualizerKey.Key, data); _appearance.SetData(uid, HumanoidVisualizerKey.Key, data);
} }
} }
public sealed class HumanoidAppearanceUpdateEvent : EntityEventArgs
{
public HumanoidVisualizerData Data { get; }
public HumanoidAppearanceUpdateEvent(HumanoidVisualizerData data)
{
Data = data;
}
}

View File

@@ -9,6 +9,10 @@
slots: [innerclothing] slots: [innerclothing]
equipSound: equipSound:
path: /Audio/Items/jumpsuit_equip.ogg path: /Audio/Items/jumpsuit_equip.ogg
clothingVisuals:
jumpsuit:
- state: equipped-INNERCLOTHING
shader: StencilDraw
- type: Butcherable - type: Butcherable
butcheringType: Knife butcheringType: Knife
spawned: spawned:

View File

@@ -105,7 +105,7 @@
- map: [ "enum.HumanoidVisualLayers.RLeg" ] - map: [ "enum.HumanoidVisualLayers.RLeg" ]
- map: [ "enum.HumanoidVisualLayers.LLeg" ] - map: [ "enum.HumanoidVisualLayers.LLeg" ]
- shader: StencilClear - 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 state: l_leg
- shader: StencilMask - shader: StencilMask
map: [ "enum.HumanoidVisualLayers.StencilMask" ] map: [ "enum.HumanoidVisualLayers.StencilMask" ]
@@ -113,7 +113,6 @@
state: female_full state: female_full
visible: false visible: false
- map: [ "jumpsuit" ] - map: [ "jumpsuit" ]
shader: StencilDraw
- map: [ "enum.HumanoidVisualLayers.LHand" ] - map: [ "enum.HumanoidVisualLayers.LHand" ]
- map: [ "enum.HumanoidVisualLayers.RHand" ] - map: [ "enum.HumanoidVisualLayers.RHand" ]
- map: [ "enum.HumanoidVisualLayers.LFoot" ] - map: [ "enum.HumanoidVisualLayers.LFoot" ]
@@ -321,7 +320,6 @@
state: female_full state: female_full
visible: false visible: false
- map: [ "jumpsuit" ] - map: [ "jumpsuit" ]
shader: StencilDraw
- map: [ "enum.HumanoidVisualLayers.LHand" ] - map: [ "enum.HumanoidVisualLayers.LHand" ]
- map: [ "enum.HumanoidVisualLayers.RHand" ] - map: [ "enum.HumanoidVisualLayers.RHand" ]
- map: [ "enum.HumanoidVisualLayers.LFoot" ] - map: [ "enum.HumanoidVisualLayers.LFoot" ]