forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove obsoletion warnings from StackVisualizer
This is a combination of 4 commits. This is the 1st commit message: Move StackVisualizer to Content.Shared.StackVisualizerComponent (temporarily), update content. Visualizer disabled for now. This is the commit message space-wizards#2: Convert StackVisualizer from AppearanceVisualizer to VisualizerSystem This is the commit message space-wizards#3: Split StackVisualizerComponent into seperate file, add some comments Intention had been to merge StackVisualizerComponent and StackComponent, but there are some prototypes which use StackVisualizerComponent without StackComponent (to great effect) This is the commit message space-wizards#4: Don't netsync stack visualizer components
- Loading branch information
1 parent
d1a64c9
commit 413c824
Showing
19 changed files
with
441 additions
and
390 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using Content.Shared.Rounding; | ||
using Content.Shared.Stacks; | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.Stack | ||
{ | ||
/// <summary> | ||
/// Visualizer for items that come in stacks and have different appearance | ||
/// depending on the size of the stack. Visualizer can work by switching between different | ||
/// icons in <c>_spriteLayers</c> or if the sprite layers are supposed to be composed as transparent layers. | ||
/// The former behavior is default and the latter behavior can be defined in prototypes. | ||
/// | ||
/// <example> | ||
/// <para>To define a Stack Visualizer prototype insert the following | ||
/// snippet (you can skip Appearance if already defined) | ||
/// </para> | ||
/// <code> | ||
/// - type: StackVisualizer | ||
/// stackLayers: | ||
/// - goldbar_10 | ||
/// - goldbar_20 | ||
/// - goldbar_30 | ||
/// </code> | ||
/// </example> | ||
/// <example> | ||
/// <para>Defining a stack visualizer with composable transparent layers</para> | ||
/// <code> | ||
/// - type: StackVisualizer | ||
/// composite: true | ||
/// stackLayers: | ||
/// - cigarette_1 | ||
/// - cigarette_2 | ||
/// - cigarette_3 | ||
/// - cigarette_4 | ||
/// - cigarette_5 | ||
/// - cigarette_6 | ||
/// </code> | ||
/// </example> | ||
/// <seealso cref="_spriteLayers"/> | ||
/// </summary> | ||
public sealed class StackVisualizerSystem : VisualizerSystem<StackVisualizerComponent> | ||
{ | ||
/// <summary> | ||
/// Default IconLayer stack. | ||
/// </summary> | ||
private const int IconLayer = 0; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<StackVisualizerComponent, ComponentInit>(OnComponentInit); | ||
} | ||
|
||
private void OnComponentInit(EntityUid uid, StackVisualizerComponent stackComponent, ComponentInit args) | ||
{ | ||
if (stackComponent._isComposite | ||
&& stackComponent._spriteLayers.Count > 0 | ||
&& IoCManager.Resolve<IEntityManager>().TryGetComponent<ISpriteComponent?>(uid, | ||
out var spriteComponent)) | ||
{ | ||
var spritePath = stackComponent._spritePath ?? spriteComponent.BaseRSI!.Path!; | ||
|
||
foreach (var sprite in stackComponent._spriteLayers) | ||
{ | ||
spriteComponent.LayerMapReserveBlank(sprite); | ||
spriteComponent.LayerSetSprite(sprite, new SpriteSpecifier.Rsi(spritePath, sprite)); | ||
spriteComponent.LayerSetVisible(sprite, false); | ||
} | ||
} | ||
} | ||
|
||
protected override void OnAppearanceChange(EntityUid uid, StackVisualizerComponent stackComponent, ref AppearanceChangeEvent args) | ||
{ | ||
var entities = IoCManager.Resolve<IEntityManager>(); | ||
if (entities.TryGetComponent(stackComponent.Owner, out ISpriteComponent? spriteComponent)) | ||
{ | ||
if (stackComponent._isComposite) | ||
{ | ||
ProcessCompositeSprites(uid, stackComponent, spriteComponent); | ||
} | ||
else | ||
{ | ||
ProcessOpaqueSprites(uid, stackComponent, spriteComponent); | ||
} | ||
} | ||
} | ||
|
||
private void ProcessOpaqueSprites(EntityUid uid, StackVisualizerComponent stackComponent, ISpriteComponent spriteComponent) | ||
{ | ||
// Skip processing if no actual | ||
if (!AppearanceSystem.TryGetData<int>(uid, StackVisuals.Actual, out var actual)) return; | ||
if (!AppearanceSystem.TryGetData<int>(uid, StackVisuals.MaxCount, out var maxCount)) | ||
{ | ||
maxCount = stackComponent._spriteLayers.Count; | ||
} | ||
|
||
var activeLayer = ContentHelpers.RoundToEqualLevels(actual, maxCount, stackComponent._spriteLayers.Count); | ||
spriteComponent.LayerSetState(IconLayer, stackComponent._spriteLayers[activeLayer]); | ||
} | ||
|
||
private void ProcessCompositeSprites(EntityUid uid, StackVisualizerComponent stackComponent, ISpriteComponent spriteComponent) | ||
{ | ||
// If hidden, don't render any sprites | ||
if (AppearanceSystem.TryGetData<bool>(uid, StackVisuals.Hide, out var hide) | ||
&& hide) | ||
{ | ||
foreach (var transparentSprite in stackComponent._spriteLayers) | ||
{ | ||
spriteComponent.LayerSetVisible(transparentSprite, false); | ||
} | ||
|
||
return; | ||
} | ||
|
||
// Skip processing if no actual/maxCount | ||
if (!AppearanceSystem.TryGetData<int>(uid, StackVisuals.Actual, out var actual)) return; | ||
if (!AppearanceSystem.TryGetData<int>(uid, StackVisuals.MaxCount, out var maxCount)) | ||
{ | ||
maxCount = stackComponent._spriteLayers.Count; | ||
} | ||
|
||
|
||
var activeTill = ContentHelpers.RoundToNearestLevels(actual, maxCount, stackComponent._spriteLayers.Count); | ||
for (var i = 0; i < stackComponent._spriteLayers.Count; i++) | ||
{ | ||
spriteComponent.LayerSetVisible(stackComponent._spriteLayers[i], i < activeTill); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Shared.Stacks | ||
{ | ||
/// | ||
/// <summary> | ||
/// Visualizer for items that come in stacks and have different appearance | ||
/// depending on the size of the stack. The visualizer can work by switching between different icons | ||
/// in <c>_spriteLayers</c> or if the sprite layers are supposed to be composed as transparent layers. | ||
/// The former behavior is default and the latter behavior can be defined in prototypes. | ||
/// | ||
/// Note, the entity doesn't necessarily need to have a StackComponent for this to work. | ||
/// Some prototypes (e.g. CigPackBase) use this to visualize how full a Storage is. | ||
/// | ||
/// <example> | ||
/// <para>To define a Stack Visualizer prototype insert the following | ||
/// snippet (you can skip Appearance if already defined) | ||
/// </para> | ||
/// <code> | ||
/// - type: Appearance | ||
/// visuals: | ||
/// - type: StackVisualizer | ||
/// stackLayers: | ||
/// - goldbar_10 | ||
/// - goldbar_20 | ||
/// - goldbar_30 | ||
/// </code> | ||
/// </example> | ||
/// <example> | ||
/// <para>Defining a stack visualizer with composable transparent layers</para> | ||
/// <code> | ||
/// - type: StackVisualizer | ||
/// composite: true | ||
/// stackLayers: | ||
/// - cigarette_1 | ||
/// - cigarette_2 | ||
/// - cigarette_3 | ||
/// - cigarette_4 | ||
/// - cigarette_5 | ||
/// - cigarette_6 | ||
/// </code> | ||
/// </example> | ||
/// <seealso cref="_spriteLayers"/> | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed class StackVisualizerComponent : Component | ||
{ | ||
/// <summary> | ||
/// Sprite layers used in stack visualizer. Sprites first in layer correspond to lower stack states | ||
/// e.g. <code>_spriteLayers[0]</code> is lower stack level than <code>_spriteLayers[1]</code>. | ||
/// </summary> | ||
[DataField("stackLayers")] public readonly List<string> _spriteLayers = new(); | ||
|
||
/// <summary> | ||
/// Determines if the visualizer uses composite or non-composite layers for icons. Defaults to false. | ||
/// | ||
/// <list type="bullet"> | ||
/// <item> | ||
/// <description>false: they are opaque and mutually exclusive (e.g. sprites in a cable coil). <b>Default value</b></description> | ||
/// </item> | ||
/// <item> | ||
/// <description>true: they are transparent and thus layered one over another in ascending order first</description> | ||
/// </item> | ||
/// </list> | ||
/// | ||
/// </summary> | ||
[DataField("composite")] public bool _isComposite; | ||
|
||
/// <summary> | ||
/// Optional RSI path to use for the <code>stackLayers<code>. If not specified, will look in the entity's sprite. | ||
/// </summary> | ||
[DataField("sprite")] public ResourcePath? _spritePath; | ||
} | ||
} |
Oops, something went wrong.