Add "fill levels" to spear in-hand/wielded/equipped sprites (#28865)

* Add fill level sprite support for equipped items

* Add fill sprites for held/equipped spears
This commit is contained in:
Tayrtahn
2024-08-02 03:18:59 -04:00
committed by GitHub
parent 029771d672
commit ed4ae1628c
38 changed files with 217 additions and 40 deletions

View File

@@ -2,6 +2,8 @@ using Content.Client.Items.Systems;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Clothing;
using Content.Shared.Clothing.Components;
using Content.Shared.Hands;
using Content.Shared.Item;
using Content.Shared.Rounding;
@@ -20,6 +22,7 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
base.Initialize();
SubscribeLocalEvent<SolutionContainerVisualsComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<SolutionContainerVisualsComponent, GetInhandVisualsEvent>(OnGetHeldVisuals);
SubscribeLocalEvent<SolutionContainerVisualsComponent, GetEquipmentVisualsEvent>(OnGetClothingVisuals);
}
private void OnMapInit(EntityUid uid, SolutionContainerVisualsComponent component, MapInitEvent args)
@@ -174,4 +177,41 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
args.Layers.Add((key, layer));
}
}
private void OnGetClothingVisuals(Entity<SolutionContainerVisualsComponent> ent, ref GetEquipmentVisualsEvent args)
{
if (ent.Comp.EquippedFillBaseName == null)
return;
if (!TryComp<AppearanceComponent>(ent, out var appearance))
return;
if (!TryComp<ClothingComponent>(ent, out var clothing))
return;
if (!AppearanceSystem.TryGetData<float>(ent, SolutionContainerVisuals.FillFraction, out var fraction, appearance))
return;
var closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, ent.Comp.EquippedMaxFillLevels + 1);
if (closestFillSprite > 0)
{
var layer = new PrototypeLayerData();
var equippedPrefix = clothing.EquippedPrefix == null ? $"equipped-{args.Slot}" : $" {clothing.EquippedPrefix}-equipped-{args.Slot}";
var key = equippedPrefix + ent.Comp.EquippedFillBaseName + closestFillSprite;
// Make sure the sprite state is valid so we don't show a big red error message
// This saves us from having to make fill level sprites for every possible slot the item could be in (including pockets).
if (!TryComp<SpriteComponent>(ent, out var sprite) || sprite.BaseRSI == null || !sprite.BaseRSI.TryGetState(key, out _))
return;
layer.State = key;
if (ent.Comp.ChangeColor && AppearanceSystem.TryGetData<Color>(ent, SolutionContainerVisuals.Color, out var color, appearance))
layer.Color = color;
args.Layers.Add((key, layer));
}
}
}

View File

@@ -53,5 +53,17 @@ namespace Content.Shared.Chemistry.Components
/// </summary>
[DataField]
public int InHandsMaxFillLevels = 0;
/// <summary>
/// Optional equipped visuals to show someone is wearing a something with a filled container.
/// </summary>
[DataField]
public string? EquippedFillBaseName = null;
/// <summary>
/// A separate max fill levels for equipped items (to reduce number of sprites needed)
/// </summary>
[DataField]
public int EquippedMaxFillLevels = 0;
}
}

View File

@@ -112,6 +112,11 @@
- type: SolutionContainerVisuals
maxFillLevels: 1
fillBaseName: spear
inHandsFillBaseName: -fill-
inHandsMaxFillLevels: 1
equippedFillBaseName: -fill-
equippedMaxFillLevels: 1
- type: entity
name: reinforced spear

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@@ -17,25 +17,49 @@
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-left-fill-1",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
},
{
"name": "inhand-right-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-left",
"directions": 4
},
{
"name": "wielded-inhand-left-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-right",
"directions": 4
},
{
"name": "wielded-inhand-right-fill-1",
"directions": 4
},
{
"name": "equipped-BACKPACK",
"directions": 4
},
{
"name": "equipped-back-fill-1",
"directions": 4
},
{
"name": "equipped-SUITSTORAGE",
"directions": 4
},
{
"name": "equipped-suitstorage-fill-1",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@@ -17,25 +17,49 @@
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-left-fill-1",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
},
{
"name": "inhand-right-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-left",
"directions": 4
},
{
"name": "wielded-inhand-left-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-right",
"directions": 4
},
{
"name": "wielded-inhand-right-fill-1",
"directions": 4
},
{
"name": "equipped-BACKPACK",
"directions": 4
},
{
"name": "equipped-back-fill-1",
"directions": 4
},
{
"name": "equipped-SUITSTORAGE",
"directions": 4
},
{
"name": "equipped-suitstorage-fill-1",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@@ -17,25 +17,49 @@
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-left-fill-1",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
},
{
"name": "inhand-right-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-left",
"directions": 4
},
{
"name": "wielded-inhand-left-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-right",
"directions": 4
},
{
"name": "wielded-inhand-right-fill-1",
"directions": 4
},
{
"name": "equipped-BACKPACK",
"directions": 4
},
{
"name": "equipped-back-fill-1",
"directions": 4
},
{
"name": "equipped-SUITSTORAGE",
"directions": 4
},
{
"name": "equipped-suitstorage-fill-1",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@@ -17,25 +17,49 @@
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-left-fill-1",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
},
{
"name": "inhand-right-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-left",
"directions": 4
},
{
"name": "wielded-inhand-left-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-right",
"directions": 4
},
{
"name": "wielded-inhand-right-fill-1",
"directions": 4
},
{
"name": "equipped-BACKPACK",
"directions": 4
},
{
"name": "equipped-back-fill-1",
"directions": 4
},
{
"name": "equipped-SUITSTORAGE",
"directions": 4
},
{
"name": "equipped-suitstorage-fill-1",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@@ -17,25 +17,49 @@
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-left-fill-1",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
},
{
"name": "inhand-right-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-left",
"directions": 4
},
{
"name": "wielded-inhand-left-fill-1",
"directions": 4
},
{
"name": "wielded-inhand-right",
"directions": 4
},
{
"name": "wielded-inhand-right-fill-1",
"directions": 4
},
{
"name": "equipped-BACKPACK",
"directions": 4
},
{
"name": "equipped-back-fill-1",
"directions": 4
},
{
"name": "equipped-SUITSTORAGE",
"directions": 4
},
{
"name": "equipped-suitstorage-fill-1",
"directions": 4
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B