if (!_appearanceSystem.TryGetData<bool>(uid, StackVisuals.Hide, out var hidden, args.Component))
hidden = false;
+ if (comp.LayerFunction != StackLayerFunction.None)
+ ApplyLayerFunction((uid, comp), ref actual, ref maxCount);
+
if (comp.IsComposite)
_counterSystem.ProcessCompositeSprite(uid, actual, maxCount, comp.LayerStates, hidden, sprite: args.Sprite);
else
_counterSystem.ProcessOpaqueSprite(uid, comp.BaseLayer, actual, maxCount, comp.LayerStates, hidden, sprite: args.Sprite);
}
+
+ /// <summary>
+ /// Adjusts the actual and maxCount to change how stack amounts are displayed.
+ /// </summary>
+ /// <param name="ent">The entity considered.</param>
+ /// <param name="actual">The actual number of items in the stack. Altered depending on the function to run.</param>
+ /// <param name="maxCount">The maximum number of items in the stack. Altered depending on the function to run.</param>
+ /// <returns>Whether or not a function was applied.</returns>
+ private bool ApplyLayerFunction(Entity<StackComponent> ent, ref int actual, ref int maxCount)
+ {
+ switch (ent.Comp.LayerFunction)
+ {
+ case StackLayerFunction.Threshold:
+ if (TryComp<StackLayerThresholdComponent>(ent, out var threshold))
+ {
+ ApplyThreshold(threshold, ref actual, ref maxCount);
+ return true;
+ }
+ break;
+ }
+ // No function applied.
+ return false;
+ }
+
+ /// <summary>
+ /// Selects which layer a stack applies based on a list of thresholds.
+ /// Each threshold passed results in the next layer being selected.
+ /// </summary>
+ /// <param name="comp">The threshold parameters to apply.</param>
+ /// <param name="actual">The number of items in the stack. Will be set to the index of the layer to use.</param>
+ /// <param name="maxCount">The maximum possible number of items in the stack. Will be set to the number of selectable layers.</param>
+ private static void ApplyThreshold(StackLayerThresholdComponent comp, ref int actual, ref int maxCount)
+ {
+ // We must stop before we run out of thresholds or layers, whichever's smaller.
+ maxCount = Math.Min(comp.Thresholds.Count + 1, maxCount);
+ var newActual = 0;
+ foreach (var threshold in comp.Thresholds)
+ {
+ //If our value exceeds threshold, the next layer should be displayed.
+ //Note: we must ensure actual <= MaxCount.
+ if (actual >= threshold && newActual < maxCount)
+ newActual++;
+ else
+ break;
+ }
+ actual = newActual;
+ }
}
}
[DataField("layerStates")]
[ViewVariables(VVAccess.ReadWrite)]
public List<string> LayerStates = new();
+
+ /// <summary>
+ /// An optional function to convert the amounts used to adjust a stack's appearance.
+ /// Useful for different denominations of cash, for example.
+ /// </summary>
+ [DataField]
+ public StackLayerFunction LayerFunction = StackLayerFunction.None;
}
[Serializable, NetSerializable]
Lingering = lingering;
}
}
+
+ [Serializable, NetSerializable]
+ public enum StackLayerFunction : byte
+ {
+ // <summary>
+ // No operation performed.
+ // </summary>
+ None,
+
+ // <summary>
+ // Arbitrarily thresholds the stack amount for each layer.
+ // Expects entity to have StackLayerThresholdComponent.
+ // </summary>
+ Threshold
+ }
}
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Stacks;
+
+/// <summary>
+/// Denotes an item as having thresholded stack visuals.
+/// StackComponent.LayerFunction should be set to Threshold to use this in practice.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class StackLayerThresholdComponent : Component
+{
+ /// <summary>
+ /// A list of thresholds to check against the number of things in the stack.
+ /// Each exceeded threshold will cause the next layer to be displayed.
+ /// Should be sorted in ascending order.
+ /// </summary>
+ [DataField(required: true)]
+ public List<int> Thresholds = new();
+}
- cash_100
- cash_500
- cash_1000
+ - cash_5000
+ - cash_10000
+ - cash_25000
+ - cash_50000
+ - cash_100000
- cash_1000000
+ layerFunction: Threshold
+ - type: StackLayerThreshold
+ thresholds: [10, 100, 500, 1000, 5000, 10000, 25000, 50000, 100000, 1000000]
- type: Sprite
sprite: Objects/Economy/cash.rsi
state: cash
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
- state: cash_1000
+ state: cash_5000
- type: Stack
count: 5000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
- state: cash_1000
+ state: cash_10000
- type: Stack
count: 10000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
- state: cash_1000
+ state: cash_10000
- type: Stack
count: 20000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
- state: cash_1000
+ state: cash_25000
- type: Stack
count: 30000
{
- "version": 1,
- "size": {
- "x": 32,
- "y": 32
- },
- "license": "CC-BY-NC-SA-3.0",
- "copyright": "Modified by EmoGarbage404 and taken from https://github.com/goonstation/goonstation at commit b951a2c12d967af1295a3e6d33a861e7e1f21299.",
- "states": [
- {
- "name": "cash"
+ "version": 1,
+ "size": {
+ "x": 32,
+ "y": 32
},
- {
- "name": "cash_10"
- },
- {
- "name": "cash_100"
- },
- {
- "name": "cash_500"
- },
- {
- "name": "cash_1000"
- },
- {
- "name": "cash_1000000",
- "delays": [
- [
- 0.2,
- 0.2,
- 0.2,
- 0.2,
- 0.2,
- 0.2,
- 0.2,
- 0.2,
- 0.2,
- 0.2
- ]
- ]
- }
- ]
+ "license": "CC-BY-NC-SA-3.0",
+ "copyright": "Modified by EmoGarbage404 and taken from https://github.com/goonstation/goonstation at commit b951a2c12d967af1295a3e6d33a861e7e1f21299. cash_5k/10k/25k/50k/1M modified by whatston3, cash_100000 modified by Unkn0wnGh0st333.",
+ "states": [
+ {
+ "name": "cash"
+ },
+ {
+ "name": "cash_10"
+ },
+ {
+ "name": "cash_100"
+ },
+ {
+ "name": "cash_500"
+ },
+ {
+ "name": "cash_1000"
+ },
+ {
+ "name": "cash_5000"
+ },
+ {
+ "name": "cash_10000",
+ "delays": [
+ [
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2
+ ]
+ ]
+ },
+ {
+ "name": "cash_25000",
+ "delays": [
+ [
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2
+ ]
+ ]
+ },
+ {
+ "name": "cash_50000",
+ "delays": [
+ [
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2
+ ]
+ ]
+ },
+ {
+ "name": "cash_100000",
+ "delays": [
+ [
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2
+ ]
+ ]
+ },
+ {
+ "name": "cash_1000000",
+ "delays": [
+ [
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2,
+ 0.2
+ ]
+ ]
+ }
+ ]
}