新增菜单all和列表标题功能
This commit is contained in:
4
Assets/Scripts/UI/Bag/BagPanel.Designer.cs
generated
4
Assets/Scripts/UI/Bag/BagPanel.Designer.cs
generated
@@ -16,10 +16,10 @@ namespace NBF
|
||||
|
||||
[AutoFind(Name = "back")]
|
||||
public GImage back;
|
||||
[AutoFind(Name = "Menu")]
|
||||
public CommonMenu Menu;
|
||||
[AutoFind(Name = "BottomMenu")]
|
||||
public BottomMenu BottomMenu;
|
||||
[AutoFind(Name = "ItemList")]
|
||||
public CommonItemList ItemList;
|
||||
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
|
||||
|
||||
public static void Show(object param = null){ App.UI.OpenUI<BagPanel>(param); }
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace NBF
|
||||
protected override void OnInit()
|
||||
{
|
||||
base.OnInit();
|
||||
Menu.OnTabChange += ChangeTab;
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
@@ -36,12 +35,6 @@ namespace NBF
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeTab(int index)
|
||||
{
|
||||
if (index < 0) return;
|
||||
Log.Info($"Change tab index={index}");
|
||||
}
|
||||
|
||||
private void UseBottomMenu()
|
||||
{
|
||||
BottomMenu.Use(this);
|
||||
|
||||
3
Assets/Scripts/UI/Common/Extensions.meta
Normal file
3
Assets/Scripts/UI/Common/Extensions.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 688374f241004942b3ef3af4086c983e
|
||||
timeCreated: 1760344663
|
||||
73
Assets/Scripts/UI/Common/Extensions/TabItemDataExtensions.cs
Normal file
73
Assets/Scripts/UI/Common/Extensions/TabItemDataExtensions.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class TabItemDataExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 为TabItemData列表添加"全部"选项卡
|
||||
/// </summary>
|
||||
/// <param name="tabItems">原始选项卡列表</param>
|
||||
/// <param name="addListTitle"></param>
|
||||
/// <returns>包含"全部"选项卡的新列表</returns>
|
||||
public static void AddAllTabItem(this List<TabItemData> tabItems, bool addListTitle = false)
|
||||
{
|
||||
//判断是否存在二级目录,有二级目录则只在二级目录有"全部"选项卡
|
||||
if (tabItems.Any(tabItem => tabItem.Children.Count > 0))
|
||||
{
|
||||
foreach (var tabItemData in tabItems)
|
||||
{
|
||||
if (tabItemData.Children.Count > 0)
|
||||
{
|
||||
var allTab = new TabItemData
|
||||
{
|
||||
Id = 0,
|
||||
Key = "All",
|
||||
Icon = "All",
|
||||
IsAll = true,
|
||||
Items = GetAllItemsFromTabs(tabItemData.Children, addListTitle)
|
||||
};
|
||||
tabItemData.Children.Insert(0, allTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var allTab = new TabItemData
|
||||
{
|
||||
Id = 0,
|
||||
Key = "All",
|
||||
Icon = "All",
|
||||
IsAll = true,
|
||||
Items = GetAllItemsFromTabs(tabItems, addListTitle)
|
||||
};
|
||||
tabItems.Insert(0, allTab);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归获取所有选项卡中的项目(去重)
|
||||
/// </summary>
|
||||
private static List<object> GetAllItemsFromTabs(List<TabItemData> tabs, bool addListTitle = false)
|
||||
{
|
||||
var allItems = new List<object>();
|
||||
|
||||
foreach (var tab in tabs)
|
||||
{
|
||||
allItems.Add(new ClassifyListTitleData()
|
||||
{
|
||||
Title = tab.Key
|
||||
});
|
||||
// 添加当前选项卡的项目
|
||||
if (tab.Items != null)
|
||||
{
|
||||
allItems.AddRange(tab.Items);
|
||||
}
|
||||
}
|
||||
|
||||
// 去重处理(基于引用相等,如果需要基于内容去重需要重写Equals方法)
|
||||
return allItems.Distinct().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab38f91a1c10449ea1d908bdffc5111a
|
||||
timeCreated: 1760344665
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class ItemDataHelper
|
||||
{
|
||||
public static List<TabItemData> GetItemTabDataList<T>(List<T> list) where T : class
|
||||
{
|
||||
List<TabItemData> ret = new List<TabItemData>();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea59c591744a47729f78e4984cea1675
|
||||
timeCreated: 1760170968
|
||||
@@ -11,5 +11,13 @@ namespace NBF
|
||||
private void OnInited()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void SetData(object showData)
|
||||
{
|
||||
if (showData is ClassifyListTitleData listTitleData)
|
||||
{
|
||||
this.SetLanguage(listTitleData.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace NBF
|
||||
{
|
||||
var tab = new TabItemData
|
||||
{
|
||||
Name = group
|
||||
// Name = group
|
||||
};
|
||||
tabList.Add(tab);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UIPanel = NBC.UIPanel;
|
||||
|
||||
namespace NBF
|
||||
@@ -11,8 +12,6 @@ namespace NBF
|
||||
public class ShopGearData
|
||||
{
|
||||
public string title;
|
||||
public int type;
|
||||
public int subType;
|
||||
}
|
||||
|
||||
public partial class FishingShopPanel : UIPanel
|
||||
@@ -23,21 +22,32 @@ namespace NBF
|
||||
this.AutoAddClick(OnClick);
|
||||
IsShowCursor = true;
|
||||
|
||||
var testData = new List<ShopGearData>();
|
||||
List<TabItemData> tabItemList = new List<TabItemData>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int j = 20; j < 25; j++)
|
||||
TabItemData tabItem = new TabItemData();
|
||||
tabItem.Key = $"Tab_{i}";
|
||||
for (int j = 0; j < 5; j++)
|
||||
{
|
||||
var item = new ShopGearData
|
||||
TabItemData tabSubItem = new TabItemData();
|
||||
tabSubItem.Key = $"SubTab_{j}";
|
||||
var count = Random.Range(2, 5);
|
||||
for (int k = 0; k < count; k++)
|
||||
{
|
||||
type = i,
|
||||
subType = j
|
||||
};
|
||||
testData.Add(item);
|
||||
var item = new ShopGearData
|
||||
{
|
||||
title = $"Item:{i}-{j}-{k}"
|
||||
};
|
||||
tabSubItem.Items.Add(item);
|
||||
}
|
||||
|
||||
tabItem.Children.Add(tabSubItem);
|
||||
}
|
||||
|
||||
tabItemList.Add(tabItem);
|
||||
}
|
||||
|
||||
ItemList.SetData(testData);
|
||||
ItemList.SetData(tabItemList, true, true);
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
|
||||
Reference in New Issue
Block a user