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:
Ygg01
2021-02-17 14:02:36 +01:00
committed by GitHub
parent 83f102ea75
commit 55d65889ae
20 changed files with 655 additions and 134 deletions

View File

@@ -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;
}
}
}
}
}
}

View File

@@ -1,8 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.Animations;
using Content.Client.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Storage;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Client.GameObjects;
@@ -29,9 +30,18 @@ namespace Content.Client.GameObjects.Components.Storage
private int StorageSizeUsed;
private int StorageCapacityMax;
private StorageWindow Window;
private SharedBagState _bagState;
public override IReadOnlyList<IEntity> StoredEntities => _storedEntities;
public override void Initialize()
{
base.Initialize();
// Hide stackVisualizer on start
_bagState = SharedBagState.Close;
}
public override void OnAdd()
{
base.OnAdd();
@@ -69,12 +79,15 @@ namespace Content.Client.GameObjects.Components.Storage
//Updates what we are storing for the UI
case StorageHeldItemsMessage msg:
HandleStorageMessage(msg);
ChangeStorageVisualization(_bagState);
break;
//Opens the UI
case OpenStorageUIMessage _:
ChangeStorageVisualization(SharedBagState.Open);
ToggleUI();
break;
case CloseStorageUIMessage _:
ChangeStorageVisualization(SharedBagState.Close);
CloseUI();
break;
case AnimateInsertingEntitiesMessage msg:
@@ -119,6 +132,7 @@ namespace Content.Client.GameObjects.Components.Storage
private void ToggleUI()
{
if (Window.IsOpen)
Window.Close();
else
Window.Open();
@@ -128,6 +142,16 @@ namespace Content.Client.GameObjects.Components.Storage
{
Window.Close();
}
private void ChangeStorageVisualization(SharedBagState state)
{
_bagState = state;
if (Owner.TryGetComponent<AppearanceComponent>(out var appearanceComponent))
{
appearanceComponent.SetData(SharedBagOpenVisuals.BagState, state);
appearanceComponent.SetData(StackVisuals.Hide, state == SharedBagState.Close);
}
}
/// <summary>
/// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity