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