新增菜单all和列表标题功能
This commit is contained in:
@@ -8,6 +8,11 @@ using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class ClassifyListTitleData
|
||||
{
|
||||
public string Title;
|
||||
}
|
||||
|
||||
public partial class ClassifyList : GComponent
|
||||
{
|
||||
private readonly List<object> _listData = new List<object>();
|
||||
@@ -19,6 +24,10 @@ namespace NBF
|
||||
private void OnInited()
|
||||
{
|
||||
Game.Input.OnUICanceled += OnUICanceled;
|
||||
List.defaultItem = ListTitleItem.URL;
|
||||
List.itemProvider = GetListItemResource;
|
||||
List.itemRenderer = OnRenderItem;
|
||||
List.onClickItem.Add(OnClickListItem);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -67,18 +76,13 @@ namespace NBF
|
||||
ListSelectionMode selectionMode = ListSelectionMode.Single)
|
||||
{
|
||||
List.selectedIndex = -1;
|
||||
List.defaultItem = ListTitleItem.URL;
|
||||
List.itemProvider = GetListItemResource;
|
||||
List.itemRenderer = OnRenderItem;
|
||||
List.onClickItem.Add(OnClickListItem);
|
||||
// List.SetVirtual();
|
||||
_listData.Clear();
|
||||
|
||||
foreach (var obj in listData)
|
||||
{
|
||||
_listData.Add(obj);
|
||||
}
|
||||
|
||||
List.RemoveChildrenToPool();
|
||||
List.selectionMode = selectionMode;
|
||||
List.numItems = _listData.Count;
|
||||
List.ScrollToView(0);
|
||||
@@ -92,17 +96,19 @@ namespace NBF
|
||||
|
||||
void OnRenderItem(int index, GObject obj)
|
||||
{
|
||||
var itemData = _listData[index];
|
||||
if (obj is ListItemBase item)
|
||||
{
|
||||
item.SetData(_listData[index]);
|
||||
item.SetData(itemData);
|
||||
obj.SetSize(350, 300);
|
||||
}
|
||||
else if (obj is ListTitleItem titleItem)
|
||||
{
|
||||
titleItem.SetData(itemData);
|
||||
titleItem.SetSize(List.width, 32);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//根据索引的不同,返回不同的资源URL
|
||||
string GetListItemResource(int index)
|
||||
@@ -114,7 +120,7 @@ namespace NBF
|
||||
return ShopGearItem.URL;
|
||||
}
|
||||
|
||||
if (itemData is string title)
|
||||
if (itemData is ClassifyListTitleData titleData)
|
||||
{
|
||||
return ListTitleItem.URL;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
@@ -27,22 +28,29 @@ namespace NBF
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public void SetData<T>(List<T> list) where T : class
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tabItemList"></param>
|
||||
/// <param name="showAll">是否显示全部页签</param>
|
||||
/// <param name="showListTitle">是否列表页显示分类标题</param>
|
||||
public void SetData(List<TabItemData> tabItemList, bool showAll = false, bool showListTitle = true)
|
||||
{
|
||||
_tabList.Clear();
|
||||
_currentTab = null;
|
||||
var tabList = ItemDataHelper.GetItemTabDataList(list);
|
||||
style.selectedIndex = 0; //一级菜单
|
||||
foreach (var tabItemData in tabList)
|
||||
if (tabItemList.Any(tabItem => tabItem.Children.Count > 0))
|
||||
{
|
||||
if (tabItemData.Children.Count > 0)
|
||||
{
|
||||
style.selectedIndex = 1; //有二级菜单
|
||||
break;
|
||||
}
|
||||
style.selectedIndex = 1; //有二级菜单
|
||||
}
|
||||
|
||||
_tabList.AddRange(tabList);
|
||||
_tabList.AddRange(tabItemList);
|
||||
if (showAll)
|
||||
{
|
||||
_tabList.AddAllTabItem(showListTitle);
|
||||
}
|
||||
|
||||
Menu.SetTabs(_tabList);
|
||||
}
|
||||
|
||||
private void ChangeTab(int index)
|
||||
|
||||
Reference in New Issue
Block a user