CatStation/Content.Client/Weapons/Ranged/Systems/GunSystem.CustomAmmoCounter.cs
Samuka 3672a6ed62
Custom icon ammo counter (#44368)
* CustomBulletRenderer

* CustomIconStatusControl

* custom ammo counter system

* custom sprite ammo counter comp

* client custom ammo counter system

* need to register the component

* have tiles show in the ammo counter for the tile gun

* comment

* more sprites

* dont try to make 2 controls

* update mini tile sprite

* add horizontal mult

* remove horizontal mult and fix the math

* ensure there is no errors

* replace magical number

* simpler to understand

* remove unecessary stuff

* remove HasComp<CustomSpriteAmmoCounterComponent

* forgot those

* add important stuff back

* explanation

* damn, so simple

* make it better

* use item instead of icon

* remove useless comment

* set number of rows

* fix odd number

* component to hide the name

* update ammo capacity

* set the aligment to vertical

* add 2 px of margin

* move the margin up (that fixes things somehow)

* comment good
2026-07-02 20:31:20 +00:00

30 lines
1.1 KiB
C#

using Content.Shared.Weapons.Ranged.Components;
namespace Content.Client.Weapons.Ranged.Systems;
public sealed partial class GunSystem
{
protected override void InitializeCustomAmmoCounter()
{
base.InitializeCustomAmmoCounter();
SubscribeLocalEvent<CustomSpriteAmmoCounterComponent, UpdateAmmoCounterEvent>(OnAmmoCountUpdate);
SubscribeLocalEvent<CustomSpriteAmmoCounterComponent, AmmoCounterControlEvent>(OnControl);
}
private void OnAmmoCountUpdate(Entity<CustomSpriteAmmoCounterComponent> ent, ref UpdateAmmoCounterEvent args)
{
if (args.Control is not CustomIconStatusControl customIcon)
return;
customIcon.Update(GetAmmoCount(ent), GetAmmoCapacity(ent));
}
private void OnControl(Entity<CustomSpriteAmmoCounterComponent> ent, ref AmmoCounterControlEvent args)
{
var loadedTexture = _sprite.GetFrame(ent.Comp.LoadedAmmoSprite, TimeSpan.Zero);
var spentTexture = _sprite.GetFrame(ent.Comp.SpentAmmoSprite, TimeSpan.Zero);
args.Control = new CustomIconStatusControl(loadedTexture, spentTexture, ent.Comp.NumberOfRows);
}
}