80 lines
2.0 KiB
C#
80 lines
2.0 KiB
C#
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using FairyGUI;
|
|
using Fantasy;
|
|
using UnityEngine;
|
|
using NBC;
|
|
using NBF.Fishing2;
|
|
using UIPanel = NBC.UIPanel;
|
|
|
|
namespace NBF
|
|
{
|
|
public partial class BagSelectPanel : UIPanel
|
|
{
|
|
//context.data
|
|
private static Action<long> _selectCallBack;
|
|
private static ItemType _itemType;
|
|
private List<ItemInfo> _items;
|
|
|
|
public static void Show(ItemType itemType, Action<long> callBack)
|
|
{
|
|
_itemType = itemType;
|
|
_selectCallBack = callBack;
|
|
Show();
|
|
}
|
|
|
|
protected override void OnInit()
|
|
{
|
|
this.AutoAddClick(OnClick);
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
SetList();
|
|
}
|
|
|
|
private void OnClick(GComponent btn)
|
|
{
|
|
if (btn == BtnCancel)
|
|
{
|
|
Hide();
|
|
}
|
|
else if (btn == BtnConfirm)
|
|
{
|
|
var selectIndex = List.selectedIndex;
|
|
if (selectIndex >= 0)
|
|
{
|
|
var itemData = _items[selectIndex];
|
|
_selectCallBack?.Invoke(itemData.Id);
|
|
}
|
|
Hide();
|
|
}
|
|
}
|
|
|
|
private void SetList()
|
|
{
|
|
var role = App.Main.GetComponent<Role>();
|
|
var roleBag = role.GetComponent<RoleBag>();
|
|
|
|
_items = roleBag.GetItemsByType(_itemType);
|
|
|
|
List.RemoveChildrenToPool();
|
|
List.defaultItem = BagItem.URL;
|
|
List.itemRenderer = OnRenderItem;
|
|
List.selectionMode = ListSelectionMode.Single;
|
|
|
|
List.numItems = _items.Count;
|
|
}
|
|
|
|
void OnRenderItem(int index, GObject obj)
|
|
{
|
|
var itemData = _items[index];
|
|
if (obj is BagItem bagItem)
|
|
{
|
|
bagItem.SetData(itemData);
|
|
}
|
|
}
|
|
}
|
|
} |