diff --git a/Content.Client/Stack/StackSystem.cs b/Content.Client/Stack/StackSystem.cs index 7e681aeba3..17e502675c 100644 --- a/Content.Client/Stack/StackSystem.cs +++ b/Content.Client/Stack/StackSystem.cs @@ -66,10 +66,60 @@ namespace Content.Client.Stack if (!_appearanceSystem.TryGetData(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); } + + /// + /// Adjusts the actual and maxCount to change how stack amounts are displayed. + /// + /// The entity considered. + /// The actual number of items in the stack. Altered depending on the function to run. + /// The maximum number of items in the stack. Altered depending on the function to run. + /// Whether or not a function was applied. + private bool ApplyLayerFunction(Entity ent, ref int actual, ref int maxCount) + { + switch (ent.Comp.LayerFunction) + { + case StackLayerFunction.Threshold: + if (TryComp(ent, out var threshold)) + { + ApplyThreshold(threshold, ref actual, ref maxCount); + return true; + } + break; + } + // No function applied. + return false; + } + + /// + /// Selects which layer a stack applies based on a list of thresholds. + /// Each threshold passed results in the next layer being selected. + /// + /// The threshold parameters to apply. + /// The number of items in the stack. Will be set to the index of the layer to use. + /// The maximum possible number of items in the stack. Will be set to the number of selectable layers. + 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; + } } } diff --git a/Content.Shared/Stacks/StackComponent.cs b/Content.Shared/Stacks/StackComponent.cs index 7137f8c0c2..356b888606 100644 --- a/Content.Shared/Stacks/StackComponent.cs +++ b/Content.Shared/Stacks/StackComponent.cs @@ -78,6 +78,13 @@ namespace Content.Shared.Stacks [DataField("layerStates")] [ViewVariables(VVAccess.ReadWrite)] public List LayerStates = new(); + + /// + /// An optional function to convert the amounts used to adjust a stack's appearance. + /// Useful for different denominations of cash, for example. + /// + [DataField] + public StackLayerFunction LayerFunction = StackLayerFunction.None; } [Serializable, NetSerializable] @@ -95,4 +102,19 @@ namespace Content.Shared.Stacks Lingering = lingering; } } + + [Serializable, NetSerializable] + public enum StackLayerFunction : byte + { + // + // No operation performed. + // + None, + + // + // Arbitrarily thresholds the stack amount for each layer. + // Expects entity to have StackLayerThresholdComponent. + // + Threshold + } } diff --git a/Content.Shared/Stacks/StackThresholdComponent.cs b/Content.Shared/Stacks/StackThresholdComponent.cs new file mode 100644 index 0000000000..5d142b5774 --- /dev/null +++ b/Content.Shared/Stacks/StackThresholdComponent.cs @@ -0,0 +1,19 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Stacks; + +/// +/// Denotes an item as having thresholded stack visuals. +/// StackComponent.LayerFunction should be set to Threshold to use this in practice. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class StackLayerThresholdComponent : Component +{ + /// + /// 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. + /// + [DataField(required: true)] + public List Thresholds = new(); +} diff --git a/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml b/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml index 57dfb40098..db08a70202 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml @@ -25,7 +25,15 @@ - 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 @@ -121,7 +129,7 @@ components: - type: Icon sprite: Objects/Economy/cash.rsi - state: cash_1000 + state: cash_5000 - type: Stack count: 5000 @@ -132,7 +140,7 @@ components: - type: Icon sprite: Objects/Economy/cash.rsi - state: cash_1000 + state: cash_10000 - type: Stack count: 10000 @@ -143,7 +151,7 @@ components: - type: Icon sprite: Objects/Economy/cash.rsi - state: cash_1000 + state: cash_10000 - type: Stack count: 20000 @@ -154,7 +162,7 @@ components: - type: Icon sprite: Objects/Economy/cash.rsi - state: cash_1000 + state: cash_25000 - type: Stack count: 30000 diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash.png b/Resources/Textures/Objects/Economy/cash.rsi/cash.png index 42e7b863e6..7ce8d6fd7b 100644 Binary files a/Resources/Textures/Objects/Economy/cash.rsi/cash.png and b/Resources/Textures/Objects/Economy/cash.rsi/cash.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_10.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_10.png index 05c4775016..98b572646a 100644 Binary files a/Resources/Textures/Objects/Economy/cash.rsi/cash_10.png and b/Resources/Textures/Objects/Economy/cash.rsi/cash_10.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_100.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_100.png index 5862df6791..bd1586a7b5 100644 Binary files a/Resources/Textures/Objects/Economy/cash.rsi/cash_100.png and b/Resources/Textures/Objects/Economy/cash.rsi/cash_100.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_1000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_1000.png index 6a5688cd86..6271c90e99 100644 Binary files a/Resources/Textures/Objects/Economy/cash.rsi/cash_1000.png and b/Resources/Textures/Objects/Economy/cash.rsi/cash_1000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_10000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_10000.png new file mode 100644 index 0000000000..8038bb576f Binary files /dev/null and b/Resources/Textures/Objects/Economy/cash.rsi/cash_10000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_100000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_100000.png new file mode 100644 index 0000000000..26b4e80b1f Binary files /dev/null and b/Resources/Textures/Objects/Economy/cash.rsi/cash_100000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_1000000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_1000000.png index 389f00ce15..7077bf99f8 100644 Binary files a/Resources/Textures/Objects/Economy/cash.rsi/cash_1000000.png and b/Resources/Textures/Objects/Economy/cash.rsi/cash_1000000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_25000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_25000.png new file mode 100644 index 0000000000..b0f705a34f Binary files /dev/null and b/Resources/Textures/Objects/Economy/cash.rsi/cash_25000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_500.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_500.png index 5d68d914bf..ff3644af85 100644 Binary files a/Resources/Textures/Objects/Economy/cash.rsi/cash_500.png and b/Resources/Textures/Objects/Economy/cash.rsi/cash_500.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_5000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_5000.png new file mode 100644 index 0000000000..ba5aeaa27e Binary files /dev/null and b/Resources/Textures/Objects/Economy/cash.rsi/cash_5000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/cash_50000.png b/Resources/Textures/Objects/Economy/cash.rsi/cash_50000.png new file mode 100644 index 0000000000..160e07af5b Binary files /dev/null and b/Resources/Textures/Objects/Economy/cash.rsi/cash_50000.png differ diff --git a/Resources/Textures/Objects/Economy/cash.rsi/meta.json b/Resources/Textures/Objects/Economy/cash.rsi/meta.json index bd7b30e211..11f8b13b16 100644 --- a/Resources/Textures/Objects/Economy/cash.rsi/meta.json +++ b/Resources/Textures/Objects/Economy/cash.rsi/meta.json @@ -1,43 +1,136 @@ { - "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 + ] + ] + } + ] }