mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-05 17:05:55 +00:00
Visualization for ammo
This commit is contained in:
parent
ed6e659d23
commit
07ab64a0bf
12 changed files with 252 additions and 102 deletions
51
Scripts/UI/WeaponAmmoCounter.cs
Normal file
51
Scripts/UI/WeaponAmmoCounter.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class WeaponAmmoCounter : Control
|
||||
{
|
||||
public LootItem Item { get; private set; }
|
||||
|
||||
[Export]
|
||||
public TextureRect Icon { get; private set; }
|
||||
|
||||
[Export]
|
||||
public TextureRect AmmoIcon { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Label TotalAmmoLabel { get; private set; }
|
||||
[Export]
|
||||
public Label LoadedAmmoLabel { get; private set; }
|
||||
|
||||
public void Init(LootItem item)
|
||||
{
|
||||
Item = item;
|
||||
|
||||
InventoryManager.Instance.LoadedAmmoChanged += (weaponKey, count) =>
|
||||
{
|
||||
if (weaponKey != Item.WeaponData.ItemKey) return;
|
||||
LoadedAmmoLabel.Text = count.ToString();
|
||||
};
|
||||
|
||||
if (string.IsNullOrWhiteSpace(item.WeaponData.AmmoKey))
|
||||
{
|
||||
TotalAmmoLabel.Hide();
|
||||
AmmoIcon.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateCounter();
|
||||
// Register this only if there's ammo
|
||||
InventoryManager.Instance.TotalAmmoChanged += (ammoKey, count) =>
|
||||
{
|
||||
if (ammoKey != Item.WeaponData.AmmoKey) return;
|
||||
TotalAmmoLabel.Text = count.ToString();
|
||||
};
|
||||
}
|
||||
|
||||
private void UpdateCounter()
|
||||
{
|
||||
TotalAmmoLabel.Text = InventoryManager.Instance.GetItemCount(Item.WeaponData.AmmoKey).ToString();
|
||||
}
|
||||
}
|
||||
1
Scripts/UI/WeaponAmmoCounter.cs.uid
Normal file
1
Scripts/UI/WeaponAmmoCounter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://chqjrv7wqk6ej
|
||||
Loading…
Add table
Add a link
Reference in a new issue