101 lines
2.3 KiB
C#
101 lines
2.3 KiB
C#
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
|
|
|
using System.Collections.Generic;
|
|
using FairyGUI;
|
|
using Fantasy;
|
|
using UnityEngine;
|
|
using NBC;
|
|
using NBF.Fishing2;
|
|
using UIPanel = NBC.UIPanel;
|
|
|
|
namespace NBF
|
|
{
|
|
public partial class BagSlotPanel : UIPanel
|
|
{
|
|
private List<ItemInfo> _items = new List<ItemInfo>();
|
|
|
|
private RoleBag _roleBag;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
var role = App.Main.GetComponent<Role>();
|
|
_roleBag = role.GetComponent<RoleBag>();
|
|
SetList();
|
|
SetSlotList();
|
|
}
|
|
|
|
#region 物品列表
|
|
|
|
private void SetList()
|
|
{
|
|
_items.Clear();
|
|
foreach (var roleBagItem in _roleBag.Items)
|
|
{
|
|
if (CanShow(roleBagItem))
|
|
{
|
|
_items.Add(roleBagItem);
|
|
}
|
|
}
|
|
|
|
List.RemoveChildrenToPool();
|
|
List.itemRenderer = OnRenderItem;
|
|
|
|
List.numItems = _items.Count;
|
|
}
|
|
|
|
void OnRenderItem(int index, GObject obj)
|
|
{
|
|
var itemData = _items[index];
|
|
if (obj is BagItem bagItem)
|
|
{
|
|
bagItem.SetData(itemData);
|
|
bagItem.draggable = true;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 快速选择列表
|
|
|
|
private void SetSlotList()
|
|
{
|
|
SlotList.RemoveChildrenToPool();
|
|
for (int index = 0; index < 7; index++)
|
|
{
|
|
if (SlotList.AddItemFromPool() is BagSlotItem slotItem)
|
|
{
|
|
slotItem.SetData(index, _roleBag.GetSlotItem(index));
|
|
slotItem.OnChangeSlot = OnChangeSlotItem;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void OnChangeSlotItem(int index, long id)
|
|
{
|
|
_roleBag.SetSlot(index, id).OnCompleted(OnChangeSlotItemDone);
|
|
}
|
|
|
|
private void OnChangeSlotItemDone()
|
|
{
|
|
SetSlotList();
|
|
// SlotList.RefreshVirtualList();
|
|
}
|
|
|
|
#endregion
|
|
|
|
private bool CanShow(ItemInfo itemInfo)
|
|
{
|
|
if (itemInfo.ItemType == ItemType.Rod)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |