mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Extensions count in inventory
This commit is contained in:
parent
08a3f9acd1
commit
8f9e4f0bb9
6 changed files with 61 additions and 11 deletions
47
Scripts/UI/StatusMenu.cs
Normal file
47
Scripts/UI/StatusMenu.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class StatusMenu : PanelContainer
|
||||
{
|
||||
[Export] public StringName HealthExpansionName { get; private set; }
|
||||
|
||||
[Export] public StringName ShieldExpansionName { get; private set; }
|
||||
|
||||
[Export] public Button HealthExpansionCounter { get; private set; }
|
||||
|
||||
[Export] public Button ShieldExpansionCounter { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CallDeferred(MethodName.InitializeDeferred);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryManager.Instance.ItemAdded -= InstanceOnItemAdded;
|
||||
}
|
||||
|
||||
private void InitializeDeferred()
|
||||
{
|
||||
var healthExpansions = InventoryManager.Instance.GetItemCount(HealthExpansionName);
|
||||
var shieldExpansions = InventoryManager.Instance.GetItemCount(ShieldExpansionName);
|
||||
|
||||
HealthExpansionCounter.Text = $"x{healthExpansions}";
|
||||
ShieldExpansionCounter.Text = $"x{shieldExpansions}";
|
||||
|
||||
InventoryManager.Instance.ItemAdded += InstanceOnItemAdded;
|
||||
}
|
||||
|
||||
private void InstanceOnItemAdded(LootItem item, int currentamount)
|
||||
{
|
||||
if (item.ItemKey == HealthExpansionName)
|
||||
{
|
||||
HealthExpansionCounter.Text = $"x{currentamount}";
|
||||
}
|
||||
else if (item.ItemKey == ShieldExpansionName)
|
||||
{
|
||||
ShieldExpansionCounter.Text = $"x{currentamount}";
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/UI/StatusMenu.cs.uid
Normal file
1
Scripts/UI/StatusMenu.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bv1fkn7qiyyr1
|
||||
Loading…
Add table
Add a link
Reference in a new issue