Fixed an issue where the spell Editor could not remove items placed in the second time.

修复法术编辑器二次放入物品无法取出的问题。
This commit is contained in:
Cold-Mint 2024-10-01 20:53:56 +08:00
parent 81344faa3e
commit bb0f582fed
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
6 changed files with 34 additions and 4 deletions

View File

@ -216,6 +216,15 @@ public static class Config
/// </summary>
public const string TimeInterval = "TimeInterval";
}
public class ZIndexManager
{
/// <summary>
/// <para>Floating icon</para>
/// <para>悬浮图标</para>
/// </summary>
public const int FloatingIcon = 1;
}
/// <summary>
/// <para>Item data changes the event type</para>

View File

@ -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;

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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()