2024-09-23 15:17:57 +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-29 14:12:54 +00:00
|
|
|
public override bool CanContainItems { get; set; } = true;
|
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;
|
2024-09-28 14:59:25 +00:00
|
|
|
packsackUi.ItemContainer = SelfItemContainer;
|
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-09-28 14:59:25 +00:00
|
|
|
public override void CopyAttributes(Node node)
|
|
|
|
{
|
|
|
|
base.CopyAttributes(node);
|
|
|
|
if (node is Packsack packsack)
|
|
|
|
{
|
|
|
|
SelfItemContainer = packsack.SelfItemContainer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IItemContainer? SelfItemContainer { get; set; }
|
2024-06-14 04:22:44 +00:00
|
|
|
|
|
|
|
public override void _Ready()
|
2024-06-12 15:42:35 +00:00
|
|
|
{
|
2024-06-14 04:22:44 +00:00
|
|
|
base._Ready();
|
2024-09-28 14:59:25 +00:00
|
|
|
if (SelfItemContainer == null)
|
|
|
|
{
|
|
|
|
SelfItemContainer = new UniversalItemContainer(NumberSlots);
|
|
|
|
SelfItemContainer.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
|
|
|
}
|
|
|
|
}
|