2021-12-05 18:09:01 +01:00
|
|
|
|
using Content.Shared.Storage.Components;
|
2021-02-17 14:02:36 +01:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-02-17 14:02:36 +01:00
|
|
|
|
using Robust.Shared.Log;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-02-22 14:39:39 +01:00
|
|
|
|
using static Robust.Shared.Utility.SpriteSpecifier;
|
2021-02-17 14:02:36 +01:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Storage.Visualizers
|
2021-02-17 14:02:36 +01:00
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class BagOpenCloseVisualizer : AppearanceVisualizer, ISerializationHooks
|
2021-02-17 14:02:36 +01:00
|
|
|
|
{
|
|
|
|
|
|
private const string OpenIcon = "openIcon";
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField(OpenIcon)]
|
2021-02-17 14:02:36 +01:00
|
|
|
|
private string? _openIcon;
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
void ISerializationHooks.AfterDeserialization()
|
2021-02-17 14:02:36 +01:00
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
if(_openIcon == null){
|
2021-02-17 14:02:36 +01:00
|
|
|
|
Logger.Warning("BagOpenCloseVisualizer is useless with no `openIcon`");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
public override void InitializeEntity(EntityUid entity)
|
2021-02-17 14:02:36 +01:00
|
|
|
|
{
|
|
|
|
|
|
base.InitializeEntity(entity);
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
2021-02-22 14:39:39 +01:00
|
|
|
|
if (_openIcon != null &&
|
2021-12-05 18:09:01 +01:00
|
|
|
|
entities.TryGetComponent<SpriteComponent?>(entity, out var spriteComponent) &&
|
2022-03-04 22:59:53 +01:00
|
|
|
|
spriteComponent.BaseRSI?.Path is { } path)
|
2021-02-17 14:02:36 +01:00
|
|
|
|
{
|
|
|
|
|
|
spriteComponent.LayerMapReserveBlank(OpenIcon);
|
2022-03-04 22:59:53 +01:00
|
|
|
|
spriteComponent.LayerSetSprite(OpenIcon, new Rsi(path, _openIcon));
|
2021-02-17 14:02:36 +01:00
|
|
|
|
spriteComponent.LayerSetVisible(OpenIcon, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
|
|
|
|
|
if (_openIcon == null ||
|
|
|
|
|
|
!entities.TryGetComponent(component.Owner, out SpriteComponent spriteComponent))
|
|
|
|
|
|
return;
|
2021-09-04 19:42:32 +02:00
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (!component.TryGetData<SharedBagState>(SharedBagOpenVisuals.BagState, out var bagState))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
switch (bagState)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SharedBagState.Open:
|
|
|
|
|
|
spriteComponent.LayerSetVisible(OpenIcon, true);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
spriteComponent.LayerSetVisible(OpenIcon, false);
|
|
|
|
|
|
break;
|
2021-02-17 14:02:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|