diff --git a/locals/Log.csv b/locals/Log.csv index 35fb472..4ccf893 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -51,12 +51,7 @@ log_patrol_to_next_point,下一个点{0},当前位置{1},偏移量{2},距 log_patrol_arrival_point,到达巡逻点{0}。,Arrival at patrol point {0}.,巡回ポイント{0}に到着します。 log_patrol_origin_position,巡逻路径的起始位置是{0}。,The starting position of the patrol path is {0}.,巡回路の開始位置は{0}です。 log_patrol_not_on_floor,不能将初始路径设置在空中。,The initial path cannot be set in the air.,初期パスを空中に設定できません。 -log_item_container_is_null,物品容器为空。,Item container is null.,アイテム・コンテナが空です。 log_can_add_item,可以添加物品{0}。,Can add item {0}.,アイテム{0}を追加できます。 -log_backpack_not_allowed,不允许添加到背包。,Not allowed to add to backpack.,バックパックに追加することは許可されていません。 -log_item_is_null,物品为空。,Item is null.,アイテムが空です。 -log_item_id_not_same,物品ID不同。,Item ID is different.,アイテムIDが異なります。 -log_max_quantity_exceeded,超过最大数量。,Exceeded maximum quantity.,最大数量を超えました。 log_patrol_enemy_detected,检测到敌人。,Enemy detected.,敵を検出しました。 log_attacker_or_target_is_null,攻击者或目标为空。,Attacker or target is null.,攻撃者またはターゲットが空です。 log_in_the_same_camp,在同一阵营。,In the same camp.,同じ陣営です。 diff --git a/scripts/inventory/IItemDisplay.cs b/scripts/inventory/IItemDisplay.cs index 272c2d2..6698695 100644 --- a/scripts/inventory/IItemDisplay.cs +++ b/scripts/inventory/IItemDisplay.cs @@ -6,7 +6,7 @@ namespace ColdMint.scripts.inventory; /// public interface IItemDisplay { - + /// /// Call this method to refresh the display when the item's information changes /// 物品的信息发生变更时,调用此方法刷新显示器 @@ -19,12 +19,18 @@ public interface IItemDisplay /// void Update(IItem? item); + /// + /// Gets the item that is being displayed + /// 获取正在显示的物品 + /// + IItem? Item { get; } + /// /// Show item Display /// 显示物品显示器 /// void ShowSelf(); - + /// /// Hide item Display /// 隐藏物品显示器 diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index 7ef5566..f1f3db9 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -1,4 +1,3 @@ -using ColdMint.scripts.debug; using ColdMint.scripts.utils; using Godot; @@ -16,7 +15,8 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay private Control? _control; private Texture2D? _backgroundTexture; private Texture2D? _backgroundTextureWhenSelect; - private IItem? _item; + public IItem? Item { get; private set; } + public override void _Ready() { @@ -47,83 +47,19 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay public override bool _CanDropData(Vector2 atPosition, Variant data) { - //If the preplaced slot does not have an icon, the preplaced slot is not allowed. - //如果预放置的槽位没有图标,那么不允许放置。 - if (_iconTextureRect == null) + if (Item == null) { return false; } - - var type = data.VariantType; - if (type == Variant.Type.Nil) + if (Item is PlaceholderItem) { - //The preplaced data is null. - //预放置的数据为null。 return false; } - - var itemSlotNode = data.As(); - var item = itemSlotNode.GetItem(); - if (item == null) - { - //Return null when trying to get the source item. - //尝试获取源物品时返回null。 - return false; - } - - if (item is Packsack packsack) - { - if (_item == null) - { - //If the dragged item is a backpack and there are no items in the current slot, return whether the backpack is allowed. - //如果拖拽的物品是背包,且当前槽位没有物品,那么返回是否允许放置背包。 - return BackpackAllowed; - } - - if (packsack.ItemContainer == null) - { - LogCat.Log("item_container_is_null"); - return false; - } - - return packsack.ItemContainer.CanAddItem(_item); - } - - if (_item is Packsack currentPacksack) - { - if (currentPacksack.ItemContainer == null) - { - LogCat.Log("item_container_is_null"); - return false; - } - - return currentPacksack.ItemContainer.CanAddItem(item); - } - - return CanAddItem(item); + return true; } - /// - /// Get the items in the item container - /// 获取物品容器内的物品 - /// - /// - ///There may be multiple quantities - ///数量可能有多个 - /// - public IItem? GetItem() - { - return _item; - } - - public override void _DropData(Vector2 atPosition, Variant data) { - if (_iconTextureRect == null) - { - return; - } - var type = data.VariantType; if (type == Variant.Type.Nil) { @@ -131,42 +67,14 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay //传入的变量为null。 return; } - var itemSlotNode = data.As(); - var sourceItem = itemSlotNode.GetItem(); + var sourceItem = itemSlotNode.Item; if (sourceItem == null) { //Return null when trying to get the source item. //尝试获取源物品时返回null。 return; } - - if (sourceItem is Packsack packsack) - { - //If the source item is a backpack. - //如果源物品是背包。 - if (packsack.ItemContainer != null && _item != null) - { - packsack.ItemContainer.AddItem(_item); - // ClearItem(false); - return; - } - } - - if (_item is Packsack customPacksack) - { - if (customPacksack.ItemContainer == null) - { - return; - } - - customPacksack.ItemContainer.AddItem(sourceItem); - // itemSlotNode.ClearItem(false); - return; - } - - // AddItem(sourceItem); - // itemSlotNode.ClearItem(false); } /// @@ -206,7 +114,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay /// private void UpdateTooltipText() { - if (_item == null) + if (Item == null) { TooltipText = null; return; @@ -217,16 +125,16 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay var debugText = TranslationServerUtils.Translate("item_prompt_debug"); if (debugText != null) { - TooltipText = string.Format(debugText, _item.Id, - TranslationServerUtils.Translate(_item.Name), - _item.Quantity, _item.MaxQuantity, _item.GetType().Name, - TranslationServerUtils.Translate(_item.Description)); + TooltipText = string.Format(debugText, Item.Id, + TranslationServerUtils.Translate(Item.Name), + Item.Quantity, Item.MaxQuantity, Item.GetType().Name, + TranslationServerUtils.Translate(Item.Description)); } } else { - TooltipText = TranslationServerUtils.Translate(_item.Name) + "\n" + - TranslationServerUtils.Translate(_item.Description); + TooltipText = TranslationServerUtils.Translate(Item.Name) + "\n" + + TranslationServerUtils.Translate(Item.Description); } } @@ -241,7 +149,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay return; } - switch (_item?.Quantity) + switch (Item?.Quantity) { case null or 1: _quantityLabel.Hide(); @@ -249,7 +157,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay default: //When the quantity is not null or 1, we display the quantity. //当数量不为null或1时,我们显示数量 - _quantityLabel.Text = _item?.Quantity.ToString(); + _quantityLabel.Text = Item?.Quantity.ToString(); _quantityLabel.Show(); break; } @@ -264,53 +172,15 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay { if (_iconTextureRect != null) { - _iconTextureRect.Texture = _item?.Icon; + _iconTextureRect.Texture = Item?.Icon; } } - public bool CanAddItem(IItem item) - { - if (!BackpackAllowed && item is Packsack) - { - //如果禁止放置背包,且新物品是背包 - LogCat.Log("backpack_not_allowed"); - return false; - } - - if (_item == null) - { - //If there is no item in the current item slot, it is allowed to add. - //如果当前物品槽内没物品,那么允许添加。 - LogCat.Log("item_is_null"); - return true; - } - - if (item.Id != _item.Id) - { - //If the item ID you want to add is different from the current item ID, disable. - //如果要添加的物品ID和当前的物品ID不一样,那么禁止。 - LogCat.Log("item_id_not_same"); - return false; - } - - var newQuantity = item.Quantity + _item.Quantity; - if (newQuantity > _item.MaxQuantity) - { - //The maximum number is exceeded and items cannot be added. - //超过了最大数量,无法添加物品。 - LogCat.Log("max_quantity_exceeded"); - return false; - } - - return true; - } - - public void Update(IItem? item) { if (item is not PlaceholderItem) { - _item = item; + Item = item; UpdateAllDisplay(); } UpdateBackground(item is { IsSelect: true });