The UI will be automatically closed when the player leaves the range of the furniture. The spell editor is now able to load information about items placed in it.
玩家离开家具的操作范围时会自动关闭UI了。法术编辑器现在能够加载放入的物品信息。
This commit is contained in:
parent
2d7985010d
commit
124c6ce0ba
|
@ -38,10 +38,10 @@ text = "ui_close"
|
|||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_left = 35.0
|
||||
offset_left = 32.0
|
||||
offset_top = 127.0
|
||||
offset_right = -20.0
|
||||
offset_bottom = 446.0
|
||||
offset_bottom = 629.0
|
||||
grow_horizontal = 2
|
||||
mouse_filter = 2
|
||||
|
||||
|
|
|
@ -64,14 +64,7 @@ public partial class GuiFurniture : Furniture
|
|||
{
|
||||
return;
|
||||
}
|
||||
GameSceneDepend.DynamicUiGroup?.ShowControl(Path, control =>
|
||||
{
|
||||
if (control is SpellEditorUi spellEditorUi)
|
||||
{
|
||||
// spellEditorUi.Title = Name;
|
||||
// spellEditorUi.ItemContainer = SelfItemContainer;
|
||||
}
|
||||
});
|
||||
GameSceneDepend.DynamicUiGroup?.ShowControl(Path);
|
||||
}
|
||||
|
||||
public override void _MouseEnter()
|
||||
|
@ -110,6 +103,10 @@ public partial class GuiFurniture : Furniture
|
|||
if (node2D is Player)
|
||||
{
|
||||
_playerInRange = false;
|
||||
if (Path != null)
|
||||
{
|
||||
GameSceneDepend.DynamicUiGroup?.HideControl(Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,5 +9,5 @@ public interface IItemContainerDisplay : IEnumerable<IItemDisplay>
|
|||
/// <para>为物品容器显示器绑定物品容器</para>
|
||||
/// </summary>
|
||||
/// <param name="itemContainer"></param>
|
||||
void BindItemContainer(IItemContainer itemContainer);
|
||||
void BindItemContainer(IItemContainer? itemContainer);
|
||||
}
|
|
@ -10,7 +10,7 @@ public abstract class ItemContainerDisplayTemplate : IItemContainerDisplay
|
|||
protected readonly List<IItemDisplay> ItemDisplayList = [];
|
||||
private IItemContainer? _itemContainer;
|
||||
|
||||
public async void BindItemContainer(IItemContainer itemContainer)
|
||||
public async void BindItemContainer(IItemContainer? itemContainer)
|
||||
{
|
||||
if (_itemContainer == itemContainer)
|
||||
{
|
||||
|
@ -24,8 +24,19 @@ public abstract class ItemContainerDisplayTemplate : IItemContainerDisplay
|
|||
}
|
||||
|
||||
_itemContainer = itemContainer;
|
||||
_itemContainer.SelectedItemChangeEvent += OnSelectedItemChangeEvent;
|
||||
_itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
||||
if (itemContainer == null)
|
||||
{
|
||||
//Set empty items container to hide all ui.
|
||||
//设置空物品容器,隐藏全部ui。
|
||||
foreach (var itemDisplay in ItemDisplayList)
|
||||
{
|
||||
itemDisplay.Update(null);
|
||||
itemDisplay.HideSelf();
|
||||
}
|
||||
return;
|
||||
}
|
||||
itemContainer.SelectedItemChangeEvent += OnSelectedItemChangeEvent;
|
||||
itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
||||
var totalCapacity = itemContainer.GetTotalCapacity();
|
||||
var currentCapacity = ItemDisplayList.Count;
|
||||
var capacityDifference = totalCapacity - currentCapacity;
|
||||
|
@ -102,7 +113,7 @@ public abstract class ItemContainerDisplayTemplate : IItemContainerDisplay
|
|||
{
|
||||
for (var i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
UpdateDataForSingleLocation(itemContainer,i);
|
||||
UpdateDataForSingleLocation(itemContainer, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,42 +4,52 @@ using Godot;
|
|||
|
||||
namespace ColdMint.scripts.loader.uiLoader;
|
||||
|
||||
/// <summary>
|
||||
/// <para>SpellEditorUi</para>
|
||||
/// <para>法术编辑器UI</para>
|
||||
/// </summary>
|
||||
public partial class SpellEditorUi : UiLoaderTemplate
|
||||
{
|
||||
private Button? _exitButton;
|
||||
private IItemContainer? _itemContainer;
|
||||
private IItemContainer? _projectileWeaponContainer;
|
||||
private ItemSlotNode? _itemSlot;
|
||||
private HFlowContainer? _flowContainer;
|
||||
private IItemContainerDisplay? _itemContainerDisplay;
|
||||
|
||||
public override void InitializeUi()
|
||||
{
|
||||
_exitButton = GetNode<Button>("ExitButton");
|
||||
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
|
||||
_itemContainer = new UniversalItemContainer(1);
|
||||
_itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
||||
_itemSlot.Update(_itemContainer.GetPlaceHolderItem(0));
|
||||
_projectileWeaponContainer = new UniversalItemContainer(1);
|
||||
_projectileWeaponContainer.AllowAddingItemByType(Config.ItemType.ProjectileWeapon);
|
||||
_projectileWeaponContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
||||
_itemSlot.Update(_projectileWeaponContainer.GetPlaceHolderItem(0));
|
||||
_flowContainer = GetNode<HFlowContainer>("HFlowContainer");
|
||||
_itemContainerDisplay = new ItemSlotContainerDisplay(_flowContainer);
|
||||
}
|
||||
|
||||
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
|
||||
{
|
||||
if (_itemSlot == null || _itemContainer == null)
|
||||
if (_itemSlot == null || _projectileWeaponContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var item = itemDataChangeEvent.NewItem;
|
||||
if (item == null)
|
||||
{
|
||||
item = _itemContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
|
||||
item = _projectileWeaponContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
|
||||
}
|
||||
item.IsSelect = false;
|
||||
_itemSlot.Update(item);
|
||||
_itemContainerDisplay?.BindItemContainer(item.SelfItemContainer);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
base._ExitTree();
|
||||
if (_itemContainer != null)
|
||||
if (_projectileWeaponContainer != null)
|
||||
{
|
||||
_itemContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
||||
_projectileWeaponContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user