Files
tbd-station-14/Content.Shared/Humanoid/HumanoidAppearanceComponent.cs
paige404 2e7f01b99e Fix broken layer hiding on clothes with multiple equipment slots (#34080)
* Fix broken layer hiding on clothes with multiple equipment slots

* Refactor ToggleVisualLayers, HideLayerClothingComponent, and ClothingComponent to allow more
precise layer hide behavior and more CPU efficient layer toggling.

* Adjust HumanoidAppearaceSystem to track which slots are hiding a given layer (e.g. gas mask and welding mask)
Add documentation
Change gas masks to use the new HideLayerClothingComponent structure as an example of its usage

* Fix the delayed snout bug

* Misc cleanup

* Make `bool permanent` implicit from SlotFlags

any non-permanent visibility toggle with `SlotFlags.None` isn't supported with how its set up. And similarly, the slot flags argument does nothing if permanent = true. So IMO it makes more sense to infer it from a nullable arg.

* Split into separate system

Too much pasta

* Remove (hopefully unnecessary) refresh

* Fisk mask networking

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

* Keep old behaviour, use clearer names?

I'm just guessing at what this was meant to do

* english

* Separate slot name & flag

* dirty = true

* fix comment

* Improved SetLayerVisibility with dirtying logic suggested by @ElectroJr

* Only set mask toggled if DisableOnFold is true

* FoldableClothingSystem fixes

* fix bandana state

* Better comment

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2025-03-21 00:30:47 +11:00

127 lines
4.3 KiB
C#

using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Inventory;
using Robust.Shared.Enums;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Humanoid;
[NetworkedComponent, RegisterComponent, AutoGenerateComponentState(true)]
public sealed partial class HumanoidAppearanceComponent : Component
{
public MarkingSet ClientOldMarkings = new();
[DataField, AutoNetworkedField]
public MarkingSet MarkingSet = new();
[DataField]
public Dictionary<HumanoidVisualLayers, HumanoidSpeciesSpriteLayer> BaseLayers = new();
[DataField, AutoNetworkedField]
public HashSet<HumanoidVisualLayers> PermanentlyHidden = new();
// Couldn't these be somewhere else?
[DataField, AutoNetworkedField]
public Gender Gender;
[DataField, AutoNetworkedField]
public int Age = 18;
/// <summary>
/// Any custom base layers this humanoid might have. See:
/// limb transplants (potentially), robotic arms, etc.
/// Stored on the server, this is merged in the client into
/// all layer settings.
/// </summary>
[DataField, AutoNetworkedField]
public Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo> CustomBaseLayers = new();
/// <summary>
/// Current species. Dictates things like base body sprites,
/// base humanoid to spawn, etc.
/// </summary>
[DataField(required: true), AutoNetworkedField]
public ProtoId<SpeciesPrototype> Species { get; set; }
/// <summary>
/// The initial profile and base layers to apply to this humanoid.
/// </summary>
[DataField]
public ProtoId<HumanoidProfilePrototype>? Initial { get; private set; }
/// <summary>
/// Skin color of this humanoid.
/// </summary>
[DataField, AutoNetworkedField]
public Color SkinColor { get; set; } = Color.FromHex("#C0967F");
/// <summary>
/// A map of the visual layers currently hidden to the equipment
/// slots that are currently hiding them. This will affect the base
/// sprite on this humanoid layer, and any markings that sit above it.
/// </summary>
[DataField, AutoNetworkedField]
public Dictionary<HumanoidVisualLayers, SlotFlags> HiddenLayers = new();
[DataField, AutoNetworkedField]
public Sex Sex = Sex.Male;
[DataField, AutoNetworkedField]
public Color EyeColor = Color.Brown;
/// <summary>
/// Hair color of this humanoid. Used to avoid looping through all markings
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public Color? CachedHairColor;
/// <summary>
/// Facial Hair color of this humanoid. Used to avoid looping through all markings
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public Color? CachedFacialHairColor;
/// <summary>
/// Which layers of this humanoid that should be hidden on equipping a corresponding item..
/// </summary>
[DataField]
public HashSet<HumanoidVisualLayers> HideLayersOnEquip = [HumanoidVisualLayers.Hair];
/// <summary>
/// Which markings the humanoid defaults to when nudity is toggled off.
/// </summary>
[DataField]
public ProtoId<MarkingPrototype>? UndergarmentTop = new ProtoId<MarkingPrototype>("UndergarmentTopTanktop");
[DataField]
public ProtoId<MarkingPrototype>? UndergarmentBottom = new ProtoId<MarkingPrototype>("UndergarmentBottomBoxers");
}
[DataDefinition]
[Serializable, NetSerializable]
public readonly partial struct CustomBaseLayerInfo
{
public CustomBaseLayerInfo(string? id, Color? color = null)
{
DebugTools.Assert(id == null || IoCManager.Resolve<IPrototypeManager>().HasIndex<HumanoidSpeciesSpriteLayer>(id));
Id = id;
Color = color;
}
/// <summary>
/// ID of this custom base layer. Must be a <see cref="HumanoidSpeciesSpriteLayer"/>.
/// </summary>
[DataField]
public ProtoId<HumanoidSpeciesSpriteLayer>? Id { get; init; }
/// <summary>
/// Color of this custom base layer. Null implies skin colour if the corresponding <see cref="HumanoidSpeciesSpriteLayer"/> is set to match skin.
/// </summary>
[DataField]
public Color? Color { get; init; }
}