2021-07-30 19:22:06 +02:00
|
|
|
using Content.Shared.Storage;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2019-05-05 18:52:06 +02:00
|
|
|
using Robust.Client.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:05:23 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Storage.Visualizers
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2020-07-23 00:56:53 +02:00
|
|
|
public sealed class StorageVisualizer : AppearanceVisualizer
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2021-12-29 15:57:20 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the base sprite to this layer. Exists to make the inheritance tree less boilerplate-y.
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("state")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateBase;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("state_open")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateOpen;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("state_closed")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateClosed;
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public override void InitializeEntity(EntityUid entity)
|
2020-05-22 15:44:49 +02:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ISpriteComponent? sprite))
|
2020-05-22 15:44:49 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_stateBase != null)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(0, _stateBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-05 18:52:06 +02:00
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
if (!entities.TryGetComponent(component.Owner, out ISpriteComponent? sprite))
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component.TryGetData(StorageVisuals.Open, out bool open);
|
2020-11-14 01:08:00 +11:00
|
|
|
|
2021-12-29 15:57:20 +11:00
|
|
|
if (sprite.LayerMapTryGet(StorageVisualLayers.Door, out _))
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetVisible(StorageVisualLayers.Door, true);
|
|
|
|
|
|
|
|
|
|
if (open && _stateOpen != null)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(StorageVisualLayers.Door, _stateOpen);
|
|
|
|
|
}
|
|
|
|
|
else if (!open && _stateClosed != null)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(StorageVisualLayers.Door, _stateClosed);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetVisible(StorageVisualLayers.Door, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-25 13:58:56 +02:00
|
|
|
|
|
|
|
|
if (component.TryGetData(StorageVisuals.CanLock, out bool canLock) && canLock)
|
|
|
|
|
{
|
|
|
|
|
if (!component.TryGetData(StorageVisuals.Locked, out bool locked))
|
|
|
|
|
{
|
|
|
|
|
locked = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sprite.LayerSetVisible(StorageVisualLayers.Lock, !open);
|
|
|
|
|
if (!open)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(StorageVisualLayers.Lock, locked ? "locked" : "unlocked");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
if (component.TryGetData(StorageVisuals.CanWeld, out bool canWeld) && canWeld)
|
2020-05-25 13:58:56 +02:00
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
if (component.TryGetData(StorageVisuals.Welded, out bool weldedVal))
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetVisible(StorageVisualLayers.Welded, weldedVal);
|
|
|
|
|
}
|
2020-05-25 13:58:56 +02:00
|
|
|
}
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 11:57:33 +01:00
|
|
|
public enum StorageVisualLayers : byte
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
Door,
|
|
|
|
|
Welded,
|
|
|
|
|
Lock
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
|
|
|
|
}
|