Update Weapon in status

This commit is contained in:
Marco 2025-03-28 10:29:04 +01:00
commit 83d3cc7835
10 changed files with 45 additions and 15 deletions

View file

@ -1,4 +1,5 @@
using Godot;
using System.Linq;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Resources;
@ -8,4 +9,9 @@ public partial class ItemsDatabase : Resource
{
[Export]
public Array<LootItem> LootItems { get; set; } = new();
public LootItem GetLootItem(string itemName)
{
return LootItems.FirstOrDefault(x => x.ItemKey == itemName);
}
}

View file

@ -7,6 +7,7 @@ namespace Cirno.Scripts.Resources;
public partial class LootItem : Resource
{
[Export] public StringName ItemName { get; set; }
[Export] public StringName ShortName { get; set; }
[Export] public StringName ItemDescription { get; set; }
[Export] public StringName ItemKey { get; set; }
[Export] public ItemTypes Item;
@ -19,8 +20,8 @@ public partial class LootItem : Resource
[Export] public UiItemType UiType;
[Export] public bool Selectable;
[Export] public Texture2D InventorySprite;
[Export] public SpriteFrames WorldSprite;
[Export] public PackedScene HudItemScene;
//[Export] public SpriteFrames WorldSprite;
//[Export] public PackedScene HudItemScene;
[Export(PropertyHint.File)] public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
}

View file

@ -1,5 +1,6 @@
using Godot;
using System;
using System.Linq;
using Cirno.Scripts.Resources;
public partial class StatusMenu : PanelContainer
@ -7,11 +8,15 @@ public partial class StatusMenu : PanelContainer
[Export] public StringName HealthExpansionName { get; private set; }
[Export] public StringName ShieldExpansionName { get; private set; }
//[Export] public ItemsDatabase ItemsDatabase { get; private set; }
[Export] public Button HealthExpansionCounter { get; private set; }
[Export] public Button ShieldExpansionCounter { get; private set; }
[Export] public Button WeaponButton { get; private set; }
public override void _Ready()
{
CallDeferred(MethodName.InitializeDeferred);
@ -31,6 +36,23 @@ public partial class StatusMenu : PanelContainer
ShieldExpansionCounter.Text = $"x{shieldExpansions}";
InventoryManager.Instance.ItemAdded += InstanceOnItemAdded;
InventoryManager.Instance.WeaponEquip += InstanceOnWeaponEquip;
}
private void InstanceOnWeaponEquip(string itemKey)
{
//var weaponData = ItemsDatabase.GetLootItem(itemKey);
var succ = InventoryManager.Instance.TryGetItem(itemKey, out var item);
if (!succ)
{
GD.Print($"Could not get item {itemKey}");
return;
}
WeaponButton.Text = item.Item.ShortName;
WeaponButton.Icon = item.Item.InventorySprite;
}
private void InstanceOnItemAdded(LootItem item, int currentamount)