mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Inventory Menu
This commit is contained in:
parent
2d6bcc5f00
commit
0c0174e0ab
14 changed files with 126 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ namespace Cirno.Scripts.Resources;
|
|||
public partial class LootItem : Resource
|
||||
{
|
||||
[Export] public string ItemName { get; set; }
|
||||
[Export] public string ItemDescription { get; set; }
|
||||
[Export] public string ItemKey { get; set; }
|
||||
[Export] public ItemTypes Item;
|
||||
[Export] public WeaponResource WeaponData { get; set; }
|
||||
|
|
@ -14,7 +15,7 @@ public partial class LootItem : Resource
|
|||
[Export] public bool PickupIfMaxed;
|
||||
[Export] public bool ConsumeOnUse;
|
||||
[Export] public UiItemType UiType;
|
||||
|
||||
[Export] public bool Selectable;
|
||||
[Export] public Texture2D InventorySprite;
|
||||
[Export] public SpriteFrames WorldSprite;
|
||||
[Export] public PackedScene HudItemScene;
|
||||
|
|
|
|||
72
Scripts/UI/ItemsMenu.cs
Normal file
72
Scripts/UI/ItemsMenu.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class ItemsMenu : ItemList
|
||||
{
|
||||
private InventoryManager _inventoryManager;
|
||||
private Dictionary<long, string> _itemsDic = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CallDeferred(MethodName.DeferredInitialize);
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("inventory"))
|
||||
{
|
||||
if (!Visible)
|
||||
{
|
||||
ShowInventory();
|
||||
}
|
||||
else
|
||||
{
|
||||
HideInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeferredInitialize()
|
||||
{
|
||||
_inventoryManager = GameManager.Instance.GetInventoryManager();
|
||||
|
||||
ItemSelected += OnItemSelected;
|
||||
Clear();
|
||||
|
||||
ItemActivated += OnItemSelected;
|
||||
}
|
||||
|
||||
private void OnItemSelected(long index)
|
||||
{
|
||||
var item = _itemsDic[index];
|
||||
GD.Print("Item: " + item);
|
||||
|
||||
HideInventory();
|
||||
}
|
||||
|
||||
public void HideInventory()
|
||||
{
|
||||
this.Hide();
|
||||
Clear();
|
||||
_itemsDic.Clear();
|
||||
}
|
||||
|
||||
public void ShowInventory()
|
||||
{
|
||||
this.Show();
|
||||
foreach (var itm in _inventoryManager.Items)
|
||||
{
|
||||
var item = itm.Value;
|
||||
var index = this.AddItem($"{item.Item.ItemName} x{item.Count}", item.Item.InventorySprite,
|
||||
item.Item.Selectable);
|
||||
|
||||
this.SetItemTooltip(index, item.Item.ItemDescription);
|
||||
|
||||
_itemsDic.Add(index, item.Item.ItemKey);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/UI/ItemsMenu.cs.uid
Normal file
1
Scripts/UI/ItemsMenu.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bobo5f4ud60qw
|
||||
Loading…
Add table
Add a link
Reference in a new issue