Traveller/scripts/item/Packsack.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2024-06-13 06:18:11 +00:00
using ColdMint.scripts.inventory;
using ColdMint.scripts.pickable;
using ColdMint.scripts.utils;
2024-06-16 10:41:26 +00:00
using Godot;
using PacksackUi = ColdMint.scripts.loader.uiLoader.PacksackUi;
2024-06-13 06:18:11 +00:00
namespace ColdMint.scripts.item;
/// <summary>
/// <para>packsack</para>
/// <para>背包</para>
/// </summary>
public partial class Packsack : PickAbleTemplate
{
private PackedScene? _packedScene;
private PacksackUi? _packsackUi;
[Export]
public int NumberSlots { get; set; }
2024-06-13 03:04:51 +00:00
2024-06-16 10:41:26 +00:00
public override bool CanPutInPack => false;
public override void Use(Node2D? owner, Vector2 targetGlobalPosition)
{
if (_packedScene == null)
{
return;
}
2024-06-16 10:41:26 +00:00
if (_packsackUi == null)
{
_packsackUi = NodeUtils.InstantiatePackedScene<PacksackUi>(_packedScene,this);
if (_packsackUi != null)
{
_packsackUi.Title = Name;
_packsackUi.ItemContainer = ItemContainer;
}
}
GameSceneNodeHolder.BackpackUiContainer?.Show();
_packsackUi?.Show();
}
public IItemContainer? ItemContainer { get; private set; }
public override void _Ready()
{
base._Ready();
ItemContainer = new UniversalItemContainer();
ItemContainer.SupportSelect = false;
//When the backpack is created, the item slot is generated.
//当背包被创建时,物品槽就被生成出来了。
for (var i = 0; i < NumberSlots; i++)
{
ItemContainer.AddItemSlot(this)?.Hide();
}
_packedScene = GD.Load<PackedScene>("res://prefab/ui/packsackUI.tscn");
}
}