From bb0f582fedeb04d441672cb67b51f861a718fa0c Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Tue, 1 Oct 2024 20:53:56 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=20an=20issue=20where=20the=20spell=20Edit?= =?UTF-8?q?or=20could=20not=20remove=20items=20placed=20in=20the=20second?= =?UTF-8?q?=20time.=20=E4=BF=AE=E5=A4=8D=E6=B3=95=E6=9C=AF=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E4=BA=8C=E6=AC=A1=E6=94=BE=E5=85=A5=E7=89=A9?= =?UTF-8?q?=E5=93=81=E6=97=A0=E6=B3=95=E5=8F=96=E5=87=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Config.cs | 9 +++++++++ scripts/furniture/GuiFurniture.cs | 1 + scripts/inventory/ItemSlotNode.cs | 1 + scripts/inventory/PlaceholderItem.cs | 2 -- scripts/inventory/UniversalItemContainer.cs | 15 +++++++++++++++ scripts/loader/uiLoader/SpellEditorUi.cs | 10 ++++++++-- 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/scripts/Config.cs b/scripts/Config.cs index 1943972..ffe96c9 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -216,6 +216,15 @@ public static class Config /// public const string TimeInterval = "TimeInterval"; } + + public class ZIndexManager + { + /// + /// Floating icon + /// 悬浮图标 + /// + public const int FloatingIcon = 1; + } /// /// Item data changes the event type diff --git a/scripts/furniture/GuiFurniture.cs b/scripts/furniture/GuiFurniture.cs index ebb5cc7..e8a585c 100644 --- a/scripts/furniture/GuiFurniture.cs +++ b/scripts/furniture/GuiFurniture.cs @@ -94,6 +94,7 @@ public partial class GuiFurniture : Furniture public override void _PhysicsProcess(double delta) { + base._PhysicsProcess(delta); if (GameSceneDepend.Player == null || !_playerInRange || !_hasMouseOver) { return; diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index 48fa874..d9a58b8 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -49,6 +49,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay textureRect.ExpandMode = _iconTextureRect.ExpandMode; textureRect.Size = _iconTextureRect.Size; textureRect.Texture = _iconTextureRect.Texture; + textureRect.ZIndex = Config.ZIndexManager.FloatingIcon; SetDragPreview(textureRect); return Variant.CreateFrom(this); } diff --git a/scripts/inventory/PlaceholderItem.cs b/scripts/inventory/PlaceholderItem.cs index e7a7f1d..4ae581d 100644 --- a/scripts/inventory/PlaceholderItem.cs +++ b/scripts/inventory/PlaceholderItem.cs @@ -48,11 +48,9 @@ public class PlaceholderItem : IItem public void Use(Node2D? owner, Vector2 targetGlobalPosition) { - throw new System.NotImplementedException(); } public void OnThrow(Vector2 velocity) { - throw new System.NotImplementedException(); } } \ No newline at end of file diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index 97146f3..a4f7d2d 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -257,6 +257,10 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer public bool ClearItem(int index) { + if (!_itemDictionary.TryGetValue(index, out var item)) + { + return false; + } var result = _itemDictionary.Remove(index); if (result) { @@ -268,6 +272,17 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer OldItem = null, Type = Config.ItemDataChangeEventType.Clear }); + if (SupportSelect && index == _selectIndex) + { + item.HideSelf(); + SelectedItemChangeEvent?.Invoke(new SelectedItemChangeEvent() + { + NewIndex = index, + OldIndex = index, + NewItem = null, + OldItem = null + }); + } } return result; } diff --git a/scripts/loader/uiLoader/SpellEditorUi.cs b/scripts/loader/uiLoader/SpellEditorUi.cs index 027a6ec..1091b2d 100644 --- a/scripts/loader/uiLoader/SpellEditorUi.cs +++ b/scripts/loader/uiLoader/SpellEditorUi.cs @@ -21,11 +21,17 @@ public partial class SpellEditorUi : UiLoaderTemplate private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent) { - if (_itemSlot == null) + if (_itemSlot == null || _itemContainer == null) { return; } - _itemSlot.Update(itemDataChangeEvent.NewItem); + var item = itemDataChangeEvent.NewItem; + if (item == null) + { + item = _itemContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex); + } + item.IsSelect = false; + _itemSlot.Update(item); } public override void _ExitTree()