Stacked sprite visualizer (#3096)
* Add Stack Visualizer * Add cigarette pack resources Adds transparent layers for visualizing cigarettes * Add Bag Open/Close Visualizer So storage opened in inventory can have different icons when opened or closed. * Create a component that only enumerates single item Used for creating stuff like matchbox, or cigarettes. As a bonus. It will only update stack visualizer for that particullar item. * Refactoring stuff * Fix other usage of stack in Resources * Add docs * Apply suggestions from code review Apply metalgearsloth suggestions Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Applied suggestions from metalgearsloth * Changed SingleItemStorageComponent to StorageCounterComponent Difference. New component doesn't spawn items, merely counts them. * Refactored StackVisualizer * Fix breakage with master * Update Resources/Prototypes/Entities/Objects/Consumable/fancy.yml Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update with MGS suggestions Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#nullable enable
|
||||
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Storage
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class BagOpenCloseVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private const string OpenIcon = "openIcon";
|
||||
private string? _openIcon;
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
|
||||
if (node.TryGetNode<YamlScalarNode>(OpenIcon, out var openIconNode))
|
||||
{
|
||||
_openIcon = openIconNode.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
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))
|
||||
{
|
||||
var rsiPath = spriteComponent.BaseRSI!.Path!;
|
||||
spriteComponent.LayerMapReserveBlank(OpenIcon);
|
||||
spriteComponent.LayerSetSprite(OpenIcon, new SpriteSpecifier.Rsi(rsiPath, _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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user