CatStation/Content.Client/Humanoid/HideableHumanoidLayersSystem.cs
pathetic meowmeow 8cf744ec55
Visual nubody (humanoid appearance refactor) (#42476)
* initial visual nubody

* oops overlay

* im so pheeming rn

* conversion...

* tests

* comeback of the underwear

* oops eyes

* blabbl

* zeds

* yaml linted

* search and visible count constraints

* reordering

* preserve previously selected markings colors

* fix test

* some ui niceties

* ordering

* make DB changes backwards-compatible/downgrade-friendly

* fix things again

* fix migration

* vulpkanin markings limit increase

* wrapping

* code cleanup and more code cleanup and more code cleanup and more code cleanup and

* fix slop ports

* better sampling API

* make filter work + use the method i made for its intended purpose

* fix test fails real quick

* magic mirror cleanup, remove TODO

* don't 0-init the organ profile data

* remove deltastates

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-01-20 07:07:53 +00:00

74 lines
2.3 KiB
C#

using Content.Shared.Humanoid;
using Content.Shared.Inventory;
using Robust.Client.GameObjects;
namespace Content.Client.Humanoid;
public sealed class HideableHumanoidLayersSystem : SharedHideableHumanoidLayersSystem
{
[Dependency] private readonly SpriteSystem _sprite = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HideableHumanoidLayersComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<HideableHumanoidLayersComponent, AfterAutoHandleStateEvent>(OnHandleState);
}
private void OnComponentInit(Entity<HideableHumanoidLayersComponent> ent, ref ComponentInit args)
{
UpdateSprite(ent);
}
private void OnHandleState(Entity<HideableHumanoidLayersComponent> ent, ref AfterAutoHandleStateEvent args)
{
UpdateSprite(ent);
}
public override void SetLayerVisibility(
Entity<HideableHumanoidLayersComponent?> ent,
HumanoidVisualLayers layer,
bool visible,
SlotFlags source)
{
base.SetLayerVisibility(ent, layer, visible, source);
if (Resolve(ent, ref ent.Comp))
UpdateSprite((ent, ent.Comp));
}
private void UpdateSprite(Entity<HideableHumanoidLayersComponent> ent)
{
foreach (var item in ent.Comp.LastHiddenLayers)
{
if (ent.Comp.HiddenLayers.ContainsKey(item))
continue;
var evt = new HumanoidLayerVisibilityChangedEvent(item, true);
RaiseLocalEvent(ent, ref evt);
if (!_sprite.LayerMapTryGet(ent.Owner, item, out var index, true))
continue;
_sprite.LayerSetVisible(ent.Owner, index, true);
}
foreach (var item in ent.Comp.HiddenLayers.Keys)
{
if (ent.Comp.LastHiddenLayers.Contains(item))
continue;
var evt = new HumanoidLayerVisibilityChangedEvent(item, false);
RaiseLocalEvent(ent, ref evt);
if (!_sprite.LayerMapTryGet(ent.Owner, item, out var index, true))
continue;
_sprite.LayerSetVisible(ent.Owner, index, false);
}
ent.Comp.LastHiddenLayers.Clear();
ent.Comp.LastHiddenLayers.UnionWith(ent.Comp.HiddenLayers.Keys);
}
}