mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 04:25:54 +00:00
Separated ammo and notifications from hud
This commit is contained in:
parent
d644cece7f
commit
46c433e5f7
39 changed files with 258 additions and 86 deletions
|
|
@ -13,39 +13,86 @@ public partial class WeaponAmmoCounter : Container
|
|||
[Export]
|
||||
public TextureRect AmmoIcon { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Label TotalAmmoLabel { get; private set; }
|
||||
[Export]
|
||||
public Label LoadedAmmoLabel { get; private set; }
|
||||
// The actual ammo label
|
||||
[Export] public Label TotalAmmoLabel { get; private set; }
|
||||
|
||||
// Item count label
|
||||
[Export] public Label LoadedAmmoLabel { get; private set; }
|
||||
|
||||
public void Init(LootItem item)
|
||||
{
|
||||
Item = item;
|
||||
|
||||
// If it has icon show it
|
||||
// if it has count show it
|
||||
// if it has ammo show it
|
||||
|
||||
// What's the point of having count and ammo without icon?
|
||||
|
||||
Icon.Texture = item.InventorySprite;
|
||||
|
||||
InventoryManager.Instance.LoadedAmmoChanged += OnInstanceOnLoadedAmmoChanged;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(item.WeaponData.AmmoKey))
|
||||
if (!item.UiType.HasFlag(UiItemType.Icon))
|
||||
{
|
||||
TotalAmmoLabel.Hide();
|
||||
AmmoIcon.Hide();
|
||||
return;
|
||||
Icon.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
Icon.Texture = item.InventorySprite;
|
||||
}
|
||||
|
||||
if (InventoryManager.Instance.TryGetItem(item.WeaponData.AmmoKey, out var ammoItem))
|
||||
if (!item.UiType.HasFlag(UiItemType.Count))
|
||||
{
|
||||
AmmoIcon.Texture = ammoItem.Item.InventorySprite;
|
||||
LoadedAmmoLabel.Hide();
|
||||
}
|
||||
|
||||
if (item.UiType.HasFlag(UiItemType.Ammo))
|
||||
{
|
||||
InventoryManager.Instance.LoadedAmmoChanged += OnInstanceOnLoadedAmmoChanged;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(item.WeaponData?.AmmoKey))
|
||||
{
|
||||
TotalAmmoLabel.Hide();
|
||||
AmmoIcon.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (InventoryManager.Instance.TryGetItem(item.WeaponData?.AmmoKey, out var ammoItem))
|
||||
{
|
||||
AmmoIcon.Texture = ammoItem.Item.InventorySprite;
|
||||
}
|
||||
UpdateAmmoCounter();
|
||||
|
||||
// Register this only if there's ammo
|
||||
InventoryManager.Instance.TotalAmmoChanged += OnInstanceOnTotalAmmoChanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
AmmoIcon.Hide();
|
||||
TotalAmmoLabel.Hide();
|
||||
|
||||
// Here sync the item count if it has no ammo but has count
|
||||
if (item.UiType.HasFlag(UiItemType.Count))
|
||||
{
|
||||
InventoryManager.Instance.ItemAdded += ItemAmountChanged;
|
||||
InventoryManager.Instance.ItemRemoved += ItemAmountRemoved;
|
||||
}
|
||||
|
||||
}
|
||||
//AmmoIcon.Texture = InventoryManager.Instance.
|
||||
|
||||
}
|
||||
|
||||
UpdateCounter();
|
||||
// Register this only if there's ammo
|
||||
InventoryManager.Instance.TotalAmmoChanged += OnInstanceOnTotalAmmoChanged;
|
||||
private void ItemAmountChanged(LootItem item, int currentAmount)
|
||||
{
|
||||
if (item.ItemKey == Item.ItemKey)
|
||||
{
|
||||
LoadedAmmoLabel.Text = currentAmount.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void ItemAmountRemoved(string key, int currentAmount)
|
||||
{
|
||||
if (key == Item.ItemKey)
|
||||
{
|
||||
LoadedAmmoLabel.Text = currentAmount.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInstanceOnLoadedAmmoChanged(StringName weaponKey, int count)
|
||||
|
|
@ -64,10 +111,12 @@ public partial class WeaponAmmoCounter : Container
|
|||
{
|
||||
InventoryManager.Instance.LoadedAmmoChanged -= OnInstanceOnLoadedAmmoChanged;
|
||||
InventoryManager.Instance.TotalAmmoChanged -= OnInstanceOnTotalAmmoChanged;
|
||||
InventoryManager.Instance.ItemAdded -= ItemAmountChanged;
|
||||
InventoryManager.Instance.ItemRemoved -= ItemAmountRemoved;
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
private void UpdateCounter()
|
||||
private void UpdateAmmoCounter()
|
||||
{
|
||||
TotalAmmoLabel.Text = InventoryManager.Instance.GetItemCount(Item.WeaponData.AmmoKey).ToString();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue