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-09-18 15:19:38 +00:00
|
|
|
|
private const string Path = "res://prefab/ui/packsackUI.tscn";
|
2024-06-24 14:19:12 +00:00
|
|
|
|
[Export] public int NumberSlots { get; set; }
|
2024-09-14 15:38:57 +00:00
|
|
|
|
|
2024-06-27 15:38:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Whether to allow backpacks</para>
|
|
|
|
|
/// <para>是否允许放置背包</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
///<para>Can a new backpack be placed in the slot of the backpack?</para>
|
|
|
|
|
///<para>即此背包的槽位内是否可以再放置新的背包?</para>
|
|
|
|
|
/// </remarks>
|
2024-09-14 15:38:57 +00:00
|
|
|
|
[Export]
|
|
|
|
|
public bool BackpackAllowed { 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-09-18 15:19:38 +00:00
|
|
|
|
GameSceneDepend.DynamicUiGroup?.ShowControl(Path, control =>
|
2024-06-16 07:28:16 +00:00
|
|
|
|
{
|
2024-09-18 15:19:38 +00:00
|
|
|
|
if (control is PacksackUi packsackUi)
|
2024-06-16 12:18:44 +00:00
|
|
|
|
{
|
2024-09-18 15:19:38 +00:00
|
|
|
|
packsackUi.Title = Name;
|
|
|
|
|
packsackUi.ItemContainer = ItemContainer;
|
2024-06-16 12:18:44 +00:00
|
|
|
|
}
|
2024-09-18 15:19:38 +00:00
|
|
|
|
});
|
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();
|
2024-09-22 08:51:42 +00:00
|
|
|
|
ItemContainer = new UniversalItemContainer(NumberSlots);
|
2024-06-19 14:33:00 +00:00
|
|
|
|
ItemContainer.SupportSelect = false;
|
2024-09-18 15:19:38 +00:00
|
|
|
|
GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () =>
|
|
|
|
|
{
|
|
|
|
|
var packedScene = GD.Load<PackedScene>(Path);
|
|
|
|
|
return NodeUtils.InstantiatePackedScene<PacksackUi>(packedScene);
|
|
|
|
|
});
|
2024-06-12 15:42:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|