From 1f66376857c54357ba3213d6c84dbeb118b18c05 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Fri, 18 Oct 2024 14:56:58 +0800 Subject: [PATCH] =?UTF-8?q?Items=20held=20by=20the=20player=20upon=20death?= =?UTF-8?q?=20are=20also=20destroyed.=20=E7=8E=A9=E5=AE=B6=E6=AD=BB?= =?UTF-8?q?=E4=BA=A1=E5=90=8E=E6=8C=81=E6=9C=89=E7=9A=84=E7=89=A9=E5=93=81?= =?UTF-8?q?=E4=B9=9F=E4=BC=9A=E8=A2=AB=E9=94=80=E6=AF=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/mainMenu.tscn | 1 + scripts/inventory/IItemContainer.cs | 7 ++- scripts/inventory/UniversalItemContainer.cs | 48 ++++++++++++--------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/scenes/mainMenu.tscn b/scenes/mainMenu.tscn index 55186b5..3fdf717 100644 --- a/scenes/mainMenu.tscn +++ b/scenes/mainMenu.tscn @@ -35,6 +35,7 @@ offset_top = 215.0 offset_right = 50.5 offset_bottom = 248.0 grow_horizontal = 2 +disabled = true text = "ui_settings" [node name="levelGraphEditorButton" type="Button" parent="."] diff --git a/scripts/inventory/IItemContainer.cs b/scripts/inventory/IItemContainer.cs index 732294a..9e2f55c 100644 --- a/scripts/inventory/IItemContainer.cs +++ b/scripts/inventory/IItemContainer.cs @@ -120,8 +120,11 @@ public interface IItemContainer /// 清理物品 /// /// - /// - bool ClearItem(int index); + /// + ///Returns the item to be cleaned, or null if the item to be cleaned cannot be found + ///返回要清理的物品,如果找不到要清理的物品则返回null + /// + IItem? ClearItem(int index); /// /// ClearAllItems diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index 7f0f49a..019928b 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -304,43 +304,49 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer } - public bool ClearItem(int index) + public IItem? ClearItem(int index) { if (!_itemDictionary.TryGetValue(index, out var item)) { - return false; + return null; } - var result = _itemDictionary.Remove(index); - if (result) + if (!_itemDictionary.Remove(index)) { - ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent + return null; + } + ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent + { + NewItem = null, + NewIndex = index, + OldIndex = index, + OldItem = null, + Type = Config.ItemDataChangeEventType.Clear + }); + if (SupportSelect && index == _selectIndex) + { + item.HideSelf(); + SelectedItemChangeEvent?.Invoke(new SelectedItemChangeEvent { - NewItem = null, NewIndex = index, OldIndex = index, - OldItem = null, - Type = Config.ItemDataChangeEventType.Clear + NewItem = null, + OldItem = null }); - if (SupportSelect && index == _selectIndex) - { - item.HideSelf(); - SelectedItemChangeEvent?.Invoke(new SelectedItemChangeEvent - { - NewIndex = index, - OldIndex = index, - NewItem = null, - OldItem = null - }); - } } - return result; + return item; } public void ClearAllItems() { foreach (var itemDictionaryKey in _itemDictionary.Keys) { - ClearItem(itemDictionaryKey); + var item = ClearItem(itemDictionaryKey); + if (item == null) + { + continue; + } + item.SelfItemContainer?.ClearAllItems(); + item.QueueFreeSelf(); } }