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,19 @@
#nullable enable
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components
{
[Serializable, NetSerializable]
public enum SharedBagOpenVisuals : byte
{
BagState,
}
[Serializable, NetSerializable]
public enum SharedBagState : byte
{
Open,
Close,
}
}

View File

@@ -0,0 +1,21 @@
#nullable enable
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components
{
[Serializable, NetSerializable]
public enum StackVisuals : byte
{
/// <summary>
/// The amount of elements in the stack
/// </summary>
Actual,
/// <summary>
/// The total amount of elements in the stack. If unspecified, the visualizer assumes
/// its
/// </summary>
MaxCount,
Hide
}
}

View File

@@ -25,14 +25,17 @@ namespace Content.Shared.Utility
{
throw new ArgumentException("Levels must be greater than 0.", nameof(levels));
}
if (actual >= max)
{
return levels - 1;
}
if (actual <= 0)
{
return 0;
}
var toOne = actual / max;
double threshold;
if (levels % 2 == 0)
@@ -49,11 +52,11 @@ namespace Content.Shared.Utility
var preround = toOne * (levels - 1);
if (toOne <= threshold || levels <= 2)
{
return (int)Math.Ceiling(preround);
return (int) Math.Ceiling(preround);
}
else
{
return (int)Math.Floor(preround);
return (int) Math.Floor(preround);
}
}
@@ -81,28 +84,18 @@ namespace Content.Shared.Utility
{
throw new ArgumentException("Levels must be greater than 1.", nameof(levels));
}
if (actual >= max)
{
return levels;
}
if (actual <= 0)
{
return 0;
}
double step = max / levels;
int nearest = 0;
double nearestDiff = actual;
for (var i = 1; i <= levels; i++)
{
var diff = Math.Abs(actual - i * step);
if (diff < nearestDiff)
{
nearestDiff = diff;
nearest = i;
}
}
return nearest;
return (int) Math.Round(actual / max * levels, MidpointRounding.AwayFromZero);
}
}
}