Re-organize all projects (#4166)
This commit is contained in:
66
Content.Client/Storage/Visualizers/BagOpenCloseVisualizer.cs
Normal file
66
Content.Client/Storage/Visualizers/BagOpenCloseVisualizer.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
#nullable enable
|
||||
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using static Robust.Shared.Utility.SpriteSpecifier;
|
||||
|
||||
namespace Content.Client.Storage.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class BagOpenCloseVisualizer : AppearanceVisualizer, ISerializationHooks
|
||||
{
|
||||
private const string OpenIcon = "openIcon";
|
||||
[DataField(OpenIcon)]
|
||||
private string? _openIcon;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
if(_openIcon == null){
|
||||
Logger.Warning("BagOpenCloseVisualizer is useless with no `openIcon`");
|
||||
}
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
if (_openIcon != null &&
|
||||
entity.TryGetComponent<SpriteComponent>(out var spriteComponent) &&
|
||||
spriteComponent.BaseRSI?.Path != null)
|
||||
{
|
||||
spriteComponent.LayerMapReserveBlank(OpenIcon);
|
||||
spriteComponent.LayerSetSprite(OpenIcon, new Rsi(spriteComponent.BaseRSI.Path, _openIcon));
|
||||
spriteComponent.LayerSetVisible(OpenIcon, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (_openIcon != null
|
||||
&& component.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
|
||||
{
|
||||
if (component.TryGetData<SharedBagState>(SharedBagOpenVisuals.BagState, out var bagState))
|
||||
{
|
||||
switch (bagState)
|
||||
{
|
||||
case SharedBagState.Open:
|
||||
spriteComponent.LayerSetVisible(OpenIcon, true);
|
||||
break;
|
||||
default:
|
||||
spriteComponent.LayerSetVisible(OpenIcon, false);
|
||||
break;
|
||||
}
|
||||
component.SetData(StackVisuals.Hide, bagState == SharedBagState.Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
Content.Client/Storage/Visualizers/StorageVisualizer.cs
Normal file
76
Content.Client/Storage/Visualizers/StorageVisualizer.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Storage.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class StorageVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("state")]
|
||||
private string? _stateBase;
|
||||
[DataField("state_open")]
|
||||
private string? _stateOpen;
|
||||
[DataField("state_closed")]
|
||||
private string? _stateClosed;
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ISpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_stateBase != null)
|
||||
{
|
||||
sprite.LayerSetState(0, _stateBase);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.TryGetData(StorageVisuals.Open, out bool open);
|
||||
var state = open ? _stateOpen ?? $"{_stateBase}_open" : _stateClosed ?? $"{_stateBase}_door";
|
||||
|
||||
sprite.LayerSetState(StorageVisualLayers.Door, state);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (component.TryGetData(StorageVisuals.CanWeld, out bool canWeld) && canWeld)
|
||||
{
|
||||
if (component.TryGetData(StorageVisuals.Welded, out bool weldedVal))
|
||||
{
|
||||
sprite.LayerSetVisible(StorageVisualLayers.Welded, weldedVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum StorageVisualLayers : byte
|
||||
{
|
||||
Door,
|
||||
Welded,
|
||||
Lock
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user