mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:05:34 +00:00
Ammo UI system
This commit is contained in:
parent
70c514f1a9
commit
5eb7b578bc
22 changed files with 238 additions and 87 deletions
|
|
@ -9,8 +9,6 @@ public partial class InventoryManager : Node2D
|
|||
{
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
private List<LootItem> _items = new List<LootItem>();
|
||||
|
||||
private Dictionary<string, ItemContainer> _itemsDict = new Dictionary<string, ItemContainer>();
|
||||
|
||||
public Dictionary<string, ItemContainer> Items => _itemsDict;
|
||||
|
|
@ -19,7 +17,7 @@ public partial class InventoryManager : Node2D
|
|||
public delegate void ItemAddedEventHandler(LootItem item, int currentAmount);
|
||||
|
||||
[Signal]
|
||||
public delegate void ItemRemovedEventHandler(LootItem item, int currentAmount);
|
||||
public delegate void ItemRemovedEventHandler(string itemKey, int currentAmount);
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
|
|
@ -30,38 +28,34 @@ public partial class InventoryManager : Node2D
|
|||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public bool HasItems(List<ItemTypes> items)
|
||||
|
||||
public bool HasItems(List<string> itemKeys)
|
||||
{
|
||||
return items.Aggregate(false, (current, item) => current || HasItem(item));
|
||||
return itemKeys.Aggregate(false, (current, item) => current || GetItemCount(item) > 0);
|
||||
}
|
||||
|
||||
public bool HasItem(ItemTypes type)
|
||||
public int GetItemCount(string itemKey)
|
||||
{
|
||||
return _items.Any(x => x.Item == type && x.Amount > 0);
|
||||
return _itemsDict.TryGetValue(itemKey, out var itm) ? itm.Count : 0;
|
||||
}
|
||||
|
||||
public int RemoveItem(LootItem item, int amount)
|
||||
public int RemoveItem(string itemKey, int amount)
|
||||
{
|
||||
if (_itemsDict.ContainsKey(item.ItemKey))
|
||||
if (!_itemsDict.TryGetValue(itemKey, out var itm)) return 0;
|
||||
|
||||
int removed = Math.Min(itm.Count, amount);
|
||||
|
||||
itm.Count -= amount;
|
||||
|
||||
if (itm.Count <= 0)
|
||||
{
|
||||
var itm = _itemsDict[item.ItemKey];
|
||||
|
||||
int removed = 0;
|
||||
|
||||
itm.Count -= amount;
|
||||
|
||||
if (itm.Count <= 0)
|
||||
{
|
||||
_itemsDict.Remove(item.ItemKey);
|
||||
}
|
||||
|
||||
EmitSignal(nameof(ItemRemoved), item, item.Amount);
|
||||
|
||||
return itm.Count;
|
||||
_itemsDict.Remove(itemKey);
|
||||
}
|
||||
|
||||
EmitSignal(nameof(ItemRemoved), itemKey, itm.Count);
|
||||
|
||||
return removed;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public bool AddItem(LootItem item)
|
||||
|
|
@ -81,7 +75,7 @@ public partial class InventoryManager : Node2D
|
|||
}
|
||||
else
|
||||
{
|
||||
if (itm.Count < item.Amount)
|
||||
if (itm.Count < item.Max)
|
||||
{
|
||||
itm.Count += item.Amount;
|
||||
}
|
||||
|
|
@ -96,7 +90,7 @@ public partial class InventoryManager : Node2D
|
|||
return false;
|
||||
}
|
||||
}
|
||||
EmitSignal(nameof(ItemAdded), item, itm.Count, item.Amount);
|
||||
EmitSignal(nameof(ItemAdded), item, itm.Count);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue