Bows & arrows (#19771)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Content.Client.Chemistry.Visualizers;
|
||||
|
||||
namespace Content.Client.Storage.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Essentially a version of <see cref="SolutionContainerVisualsComponent"/> fill level handling but for item storage.
|
||||
/// Depending on the fraction of storage that's filled, will change the sprite at <see cref="FillLayer"/> to the nearest
|
||||
/// fill level, up to <see cref="MaxFillLevels"/>.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class StorageContainerVisualsComponent : Component
|
||||
{
|
||||
[DataField("maxFillLevels")]
|
||||
public int MaxFillLevels = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A prefix to use for the fill states., i.e. {FillBaseName}{fill level} for the state
|
||||
/// </summary>
|
||||
[DataField("fillBaseName")]
|
||||
public string? FillBaseName;
|
||||
|
||||
[DataField("layer")]
|
||||
public StorageContainerVisualLayers FillLayer = StorageContainerVisualLayers.Fill;
|
||||
}
|
||||
|
||||
public enum StorageContainerVisualLayers : byte
|
||||
{
|
||||
Fill
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Content.Client.Storage.Components;
|
||||
using Content.Shared.Rounding;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Storage.Systems;
|
||||
|
||||
/// <inheritdoc cref="StorageContainerVisualsComponent"/>
|
||||
public sealed class StorageContainerVisualsSystem : VisualizerSystem<StorageContainerVisualsComponent>
|
||||
{
|
||||
protected override void OnAppearanceChange(EntityUid uid, StorageContainerVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if (!AppearanceSystem.TryGetData<int>(uid, StorageVisuals.StorageUsed, out var used, args.Component))
|
||||
return;
|
||||
|
||||
if (!AppearanceSystem.TryGetData<int>(uid, StorageVisuals.Capacity, out var capacity, args.Component))
|
||||
return;
|
||||
|
||||
var fraction = used / (float) capacity;
|
||||
|
||||
if (!args.Sprite.LayerMapTryGet(component.FillLayer, out var fillLayer))
|
||||
return;
|
||||
|
||||
var closestFillSprite = Math.Min(ContentHelpers.RoundToNearestLevels(fraction, 1, component.MaxFillLevels + 1),
|
||||
component.MaxFillLevels);
|
||||
|
||||
if (closestFillSprite > 0)
|
||||
{
|
||||
if (component.FillBaseName == null)
|
||||
return;
|
||||
|
||||
args.Sprite.LayerSetVisible(fillLayer, true);
|
||||
var stateName = component.FillBaseName + closestFillSprite;
|
||||
args.Sprite.LayerSetState(fillLayer, stateName);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Sprite.LayerSetVisible(fillLayer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user