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
|
layout_mode = 1
|
||||||
anchors_preset = 10
|
anchors_preset = 10
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
offset_left = 35.0
|
offset_left = 32.0
|
||||||
offset_top = 127.0
|
offset_top = 127.0
|
||||||
offset_right = -20.0
|
offset_right = -20.0
|
||||||
offset_bottom = 446.0
|
offset_bottom = 629.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
|
|
||||||
|
|
|
@ -64,14 +64,7 @@ public partial class GuiFurniture : Furniture
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GameSceneDepend.DynamicUiGroup?.ShowControl(Path, control =>
|
GameSceneDepend.DynamicUiGroup?.ShowControl(Path);
|
||||||
{
|
|
||||||
if (control is SpellEditorUi spellEditorUi)
|
|
||||||
{
|
|
||||||
// spellEditorUi.Title = Name;
|
|
||||||
// spellEditorUi.ItemContainer = SelfItemContainer;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _MouseEnter()
|
public override void _MouseEnter()
|
||||||
|
@ -110,6 +103,10 @@ public partial class GuiFurniture : Furniture
|
||||||
if (node2D is Player)
|
if (node2D is Player)
|
||||||
{
|
{
|
||||||
_playerInRange = false;
|
_playerInRange = false;
|
||||||
|
if (Path != null)
|
||||||
|
{
|
||||||
|
GameSceneDepend.DynamicUiGroup?.HideControl(Path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,5 +9,5 @@ public interface IItemContainerDisplay : IEnumerable<IItemDisplay>
|
||||||
/// <para>为物品容器显示器绑定物品容器</para>
|
/// <para>为物品容器显示器绑定物品容器</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="itemContainer"></param>
|
/// <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 = [];
|
protected readonly List<IItemDisplay> ItemDisplayList = [];
|
||||||
private IItemContainer? _itemContainer;
|
private IItemContainer? _itemContainer;
|
||||||
|
|
||||||
public async void BindItemContainer(IItemContainer itemContainer)
|
public async void BindItemContainer(IItemContainer? itemContainer)
|
||||||
{
|
{
|
||||||
if (_itemContainer == itemContainer)
|
if (_itemContainer == itemContainer)
|
||||||
{
|
{
|
||||||
|
@ -24,8 +24,19 @@ public abstract class ItemContainerDisplayTemplate : IItemContainerDisplay
|
||||||
}
|
}
|
||||||
|
|
||||||
_itemContainer = itemContainer;
|
_itemContainer = itemContainer;
|
||||||
_itemContainer.SelectedItemChangeEvent += OnSelectedItemChangeEvent;
|
if (itemContainer == null)
|
||||||
_itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
{
|
||||||
|
//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 totalCapacity = itemContainer.GetTotalCapacity();
|
||||||
var currentCapacity = ItemDisplayList.Count;
|
var currentCapacity = ItemDisplayList.Count;
|
||||||
var capacityDifference = totalCapacity - currentCapacity;
|
var capacityDifference = totalCapacity - currentCapacity;
|
||||||
|
|
|
@ -4,42 +4,52 @@ using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.loader.uiLoader;
|
namespace ColdMint.scripts.loader.uiLoader;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>SpellEditorUi</para>
|
||||||
|
/// <para>法术编辑器UI</para>
|
||||||
|
/// </summary>
|
||||||
public partial class SpellEditorUi : UiLoaderTemplate
|
public partial class SpellEditorUi : UiLoaderTemplate
|
||||||
{
|
{
|
||||||
private Button? _exitButton;
|
private Button? _exitButton;
|
||||||
private IItemContainer? _itemContainer;
|
private IItemContainer? _projectileWeaponContainer;
|
||||||
private ItemSlotNode? _itemSlot;
|
private ItemSlotNode? _itemSlot;
|
||||||
|
private HFlowContainer? _flowContainer;
|
||||||
|
private IItemContainerDisplay? _itemContainerDisplay;
|
||||||
|
|
||||||
public override void InitializeUi()
|
public override void InitializeUi()
|
||||||
{
|
{
|
||||||
_exitButton = GetNode<Button>("ExitButton");
|
_exitButton = GetNode<Button>("ExitButton");
|
||||||
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
|
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
|
||||||
_itemContainer = new UniversalItemContainer(1);
|
_projectileWeaponContainer = new UniversalItemContainer(1);
|
||||||
_itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
_projectileWeaponContainer.AllowAddingItemByType(Config.ItemType.ProjectileWeapon);
|
||||||
_itemSlot.Update(_itemContainer.GetPlaceHolderItem(0));
|
_projectileWeaponContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
||||||
|
_itemSlot.Update(_projectileWeaponContainer.GetPlaceHolderItem(0));
|
||||||
|
_flowContainer = GetNode<HFlowContainer>("HFlowContainer");
|
||||||
|
_itemContainerDisplay = new ItemSlotContainerDisplay(_flowContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
|
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
|
||||||
{
|
{
|
||||||
if (_itemSlot == null || _itemContainer == null)
|
if (_itemSlot == null || _projectileWeaponContainer == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var item = itemDataChangeEvent.NewItem;
|
var item = itemDataChangeEvent.NewItem;
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
item = _itemContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
|
item = _projectileWeaponContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
|
||||||
}
|
}
|
||||||
item.IsSelect = false;
|
item.IsSelect = false;
|
||||||
_itemSlot.Update(item);
|
_itemSlot.Update(item);
|
||||||
|
_itemContainerDisplay?.BindItemContainer(item.SelfItemContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
{
|
{
|
||||||
base._ExitTree();
|
base._ExitTree();
|
||||||
if (_itemContainer != null)
|
if (_projectileWeaponContainer != null)
|
||||||
{
|
{
|
||||||
_itemContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
_projectileWeaponContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user