From 19da648f627b38d105677fe7f8e0a618b414e48e Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 8 May 2025 11:07:23 +0200 Subject: [PATCH] Weapon hud fix --- .../Components/Actors/PlayerWeaponProvider.cs | 2 ++ Scripts/GameManager.cs | 2 +- Scripts/InventoryManager.cs | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Scripts/Components/Actors/PlayerWeaponProvider.cs b/Scripts/Components/Actors/PlayerWeaponProvider.cs index 76227e0d..ac966990 100644 --- a/Scripts/Components/Actors/PlayerWeaponProvider.cs +++ b/Scripts/Components/Actors/PlayerWeaponProvider.cs @@ -152,6 +152,8 @@ public partial class PlayerWeaponProvider : Node2D _switching = true; _switchCooldown = 0d; + + InventoryManager.Instance.UpdateEquippedWeapon(weapon.WeaponData.ItemKey); } public void NextWeapon() diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index f403e53e..97f03b5d 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -123,7 +123,7 @@ public partial class GameManager : Node2D //_inventoryManager.ItemAdded += (item, currentAmount) => _hud.AddInventoryItem(item, currentAmount); //_inventoryManager.ItemRemoved += (item, currentAmount) => _hud.RemoveInventoryItem(item, currentAmount); - _inventoryManager.WeaponEquip += key => _hud.EquipWeapon(key); + _inventoryManager.WeaponUpdate += key => _hud.EquipWeapon(key); } PlayerRespawned += OnPlayerRespawned; diff --git a/Scripts/InventoryManager.cs b/Scripts/InventoryManager.cs index 80ea1435..34e92fc5 100644 --- a/Scripts/InventoryManager.cs +++ b/Scripts/InventoryManager.cs @@ -23,8 +23,15 @@ public partial class InventoryManager : Node2D [Signal] public delegate void ItemRemovedEventHandler(string itemKey, int currentAmount); - [Signal] - public delegate void WeaponEquipEventHandler(string itemKey); + /// + /// Use when equipping a weapon from the inventory screen + /// + [Signal] public delegate void WeaponEquipEventHandler(string itemKey); + + /// + /// Use when updating the weapon shown on the hud + /// + [Signal] public delegate void WeaponUpdateEventHandler(string itemKey); [Signal] public delegate void ItemUsedEventHandler(LootItem itemKey, int totalCount); @@ -208,6 +215,11 @@ public partial class InventoryManager : Node2D GD.Print($"Items after loading: {_itemsDict.Count}"); } + + public void UpdateEquippedWeapon(string itemKey) + { + EmitSignalWeaponUpdate(itemKey); + } } public class ItemContainer