mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Fix tail wag visibility * SPACE * use logical or, not bitwise or * wow, new struct, so cool * little cleanup, modernization, few fixes, organ ev * ShouldHide, unconditional clear * Back to HashSet, unindent comments
95 lines
3 KiB
C#
95 lines
3 KiB
C#
using Content.Shared.Body;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Inventory;
|
|
using Robust.Client.GameObjects;
|
|
|
|
namespace Content.Client.Humanoid;
|
|
|
|
/// <inheritdoc />
|
|
public sealed partial class HideableHumanoidLayersSystem : SharedHideableHumanoidLayersSystem
|
|
{
|
|
[Dependency] private SpriteSystem _sprite = default!;
|
|
|
|
[Dependency] private EntityQuery<VisualOrganComponent> _visualOrganQuery = default!;
|
|
|
|
/// <inheritdoc />
|
|
public override void SetLayerOcclusion(
|
|
Entity<HideableHumanoidLayersComponent?> ent,
|
|
HumanoidVisualLayers layer,
|
|
bool visible,
|
|
SlotFlags source)
|
|
{
|
|
base.SetLayerOcclusion(ent, layer, visible, source);
|
|
|
|
if (Resolve(ent, ref ent.Comp))
|
|
UpdateSprite((ent, ent.Comp));
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnComponentStartup(Entity<HideableHumanoidLayersComponent> ent, ref ComponentStartup args)
|
|
{
|
|
UpdateSprite(ent);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnOrganInserted(Entity<HideableHumanoidLayersComponent> ent, ref OrganInsertedIntoEvent args)
|
|
{
|
|
if (_visualOrganQuery.HasComp(args.Organ))
|
|
UpdateSprite(ent);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnOrganRemoved(Entity<HideableHumanoidLayersComponent> ent, ref OrganRemovedFromEvent args)
|
|
{
|
|
if (_visualOrganQuery.HasComp(args.Organ))
|
|
UpdateSprite(ent);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnHandleState(Entity<HideableHumanoidLayersComponent> ent, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
UpdateSprite(ent);
|
|
}
|
|
|
|
private void UpdateSprite(Entity<HideableHumanoidLayersComponent> ent)
|
|
{
|
|
// Reset old hidden layers if they aren't in our new set.
|
|
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);
|
|
}
|
|
|
|
// Accumulate new hidden set in here.
|
|
var actualHiddenLayers = new HashSet<HumanoidVisualLayers>(ent.Comp.HiddenLayers.Count);
|
|
|
|
// Handle hiding our new layers - handlers must set ShouldHide true to hide the layer.
|
|
foreach (var item in ent.Comp.HiddenLayers.Keys)
|
|
{
|
|
if (ent.Comp.LastHiddenLayers.Contains(item))
|
|
{
|
|
actualHiddenLayers.Add(item);
|
|
continue;
|
|
}
|
|
|
|
var evt = new HumanoidLayerVisibilityChangedEvent(item, false);
|
|
RaiseLocalEvent(ent, ref evt);
|
|
|
|
if (!evt.ShouldHide || !_sprite.LayerMapTryGet(ent.Owner, item, out var index, true))
|
|
continue;
|
|
|
|
_sprite.LayerSetVisible(ent.Owner, index, false);
|
|
actualHiddenLayers.Add(item);
|
|
}
|
|
|
|
ent.Comp.LastHiddenLayers = actualHiddenLayers;
|
|
}
|
|
}
|