From 4aff26d7bc042f3fc040f179c4bb0e839ea271b3 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Wed, 3 Jul 2024 23:31:31 +0800 Subject: [PATCH] =?UTF-8?q?Added=20drag=20and=20drop=20to=20backpack=20for?= =?UTF-8?q?=20quick=20storage.=20=E6=B7=BB=E5=8A=A0=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E5=88=B0=E8=83=8C=E5=8C=85=E5=BF=AB=E9=80=9F=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/Log.csv | 9 ++- scripts/inventory/ItemSlotNode.cs | 72 ++++++++++++++++++++++- scripts/loader/uiLoader/MainMenuLoader.cs | 2 + 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/locals/Log.csv b/locals/Log.csv index d2e9058..74ae339 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -52,4 +52,11 @@ log_no_points,巡逻路径没有点。,The patrol path has no points.,巡回路 log_patrol_to_next_point,下一个点{0},当前位置{1},偏移量{2},距离为{3}。,"Next point {0}, current position {1}, offset {2}, distance {3}.",次のポイント{0}、現在の位置{1}、オフセット{2}、距離{3}。 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.,初期パスを空中に設定できません。 \ No newline at end of file +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_item_slot_is_selected_and_not_allowed,已选择物品槽,不允许添加。,"Item slot is selected, not allowed to add.",アイテムスロットが選択されており、追加は許可されていません。 \ No newline at end of file diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index 7dbd69c..a8ad4ec 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -1,4 +1,5 @@ using System; +using ColdMint.scripts.debug; using ColdMint.scripts.utils; using Godot; @@ -62,6 +63,14 @@ public partial class ItemSlotNode : MarginContainer public override bool _CanDropData(Vector2 atPosition, Variant data) { + if (_isSelect) + { + //Do not place items in the selected item slot, even if the item slot is empty. + //禁止在已选中的物品槽内放置物品,即使物品槽是空的。 + LogCat.Log("item_slot_is_selected_and_not_allowed"); + return false; + } + //If the preplaced slot does not have an icon, the preplaced slot is not allowed. //如果预放置的槽位没有图标,那么不允许放置。 if (_iconTextureRect == null) @@ -86,6 +95,35 @@ public partial class ItemSlotNode : MarginContainer 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); } @@ -194,16 +232,40 @@ public partial class ItemSlotNode : MarginContainer } var itemSlotNode = data.As(); - var item = itemSlotNode.GetItem(); - if (item == null) + var sourceItem = itemSlotNode.GetItem(); + 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); - AddItem(item); } /// @@ -337,6 +399,7 @@ public partial class ItemSlotNode : MarginContainer if (!BackpackAllowed && item is Packsack) { //如果禁止放置背包,且新物品是背包 + LogCat.Log("backpack_not_allowed"); return false; } @@ -344,6 +407,7 @@ public partial class ItemSlotNode : MarginContainer { //If there is no item in the current item slot, it is allowed to add. //如果当前物品槽内没物品,那么允许添加。 + LogCat.Log("item_is_null"); return true; } @@ -351,6 +415,7 @@ public partial class ItemSlotNode : MarginContainer { //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; } @@ -359,6 +424,7 @@ public partial class ItemSlotNode : MarginContainer { //The maximum number is exceeded and items cannot be added. //超过了最大数量,无法添加物品。 + LogCat.Log("max_quantity_exceeded"); return false; } diff --git a/scripts/loader/uiLoader/MainMenuLoader.cs b/scripts/loader/uiLoader/MainMenuLoader.cs index b6bb916..a547240 100644 --- a/scripts/loader/uiLoader/MainMenuLoader.cs +++ b/scripts/loader/uiLoader/MainMenuLoader.cs @@ -45,6 +45,8 @@ public partial class MainMenuLoader : UiLoaderTemplate //在发行版禁用所有日志。 LogCat.MinLogLevel = LogCat.DisableAllLogLevel; } + + LogCat.DisableLogLabel(LogCat.LogLabel.PatrolStateProcessor); ContributorDataManager.RegisterAllContributorData(); DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());