切换标签

This commit is contained in:
xmac
2025-05-23 11:48:20 +08:00
parent 4b7a6b1dc8
commit 0c44f985ec
31 changed files with 295 additions and 111 deletions

3
Assets/Scripts/Data.meta Normal file
View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 53d4b4ea733e48a3b1324345029f2bc2
timeCreated: 1747967959

View File

@@ -0,0 +1,12 @@
namespace NBF
{
public class ListClassifyData
{
public string Title;
public ListClassifyData(string title)
{
this.Title = title;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: edbbd6c0c6004af8924e5b8f2ec39039
timeCreated: 1747969245

View File

@@ -8,6 +8,7 @@ namespace NBF
{
public static void BindAll()
{
UIObjectFactory.SetPackageItemExtension(ClassifyList.URL, typeof(ClassifyList));
UIObjectFactory.SetPackageItemExtension(CommonMenu.URL, typeof(CommonMenu));
UIObjectFactory.SetPackageItemExtension(ListTitleItem.URL, typeof(ListTitleItem));
}

View File

@@ -0,0 +1,25 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
namespace NBF
{
public partial class ClassifyList
{
public const string URL = "ui://6hgkvlaudrkwh1";
public GList List;
public override void ConstructFromXML(XML xml)
{
base.ConstructFromXML(xml);
List = (GList)GetChild("List");
OnInited();
UILanguage.TrySetComponentLanguage(this);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 75f98daf87c484ef782216da87003f53

View File

@@ -0,0 +1,69 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using System;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
using NBC;
namespace NBF
{
public partial class ClassifyList : GComponent
{
private readonly List<object> _listData = new List<object>();
public event Action<object> OnClickItem;
public int SelectedIndex => List.selectedIndex;
private void OnInited()
{
List.itemProvider = GetListItemResource;
List.itemRenderer = OnRenderItem;
List.onClickItem.Add(OnClickListItem);
}
public void SetListData(List<object> listData)
{
_listData.Clear();
foreach (var obj in listData)
{
_listData.Add(obj);
}
List.numItems = _listData.Count;
List.ScrollToView(0);
}
void OnClickListItem(EventContext context)
{
Debug.Log($"con={context.data} nm={context.sender}");
OnClickItem?.Invoke(null);
}
void OnRenderItem(int index, GObject obj)
{
if (obj is ListItemBase item)
{
item.SetData(_listData[index]);
}
}
//根据索引的不同返回不同的资源URL
string GetListItemResource(int index)
{
var itemData = _listData[index];
if (itemData is ShopGearData shopItem)
{
return ShopGearItem.URL;
}
if (itemData is ListClassifyData item)
{
return ListTitleItem.URL;
}
return List.defaultItem;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ec101ca53ba6849efa2e51492b6310cf

View File

@@ -1,6 +1,7 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using System;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
using NBC;
@@ -14,15 +15,29 @@ namespace NBF
private void OnInited()
{
BtnClose.onClick.Add(OnClickClose);
List.onClickItem.Add(OnClickItem);
}
public void SetTabs()
public void SetTabs(List<TabListData> tabList,int selectIndex = 0)
{
List.RemoveChildrenToPool();
for (int i = 0; i < tabList.Count; i++)
{
var tabData = tabList[i];
var tabItem = List.AddItemFromPool().asButton;
tabItem.title = tabData.TabName;
}
Log.Info($"Set tab index={List.selectedIndex}");
List.selectedIndex = selectIndex;
OnClickItem();
}
private void OnClickItem()
{
OnTabChange?.Invoke(List.selectedIndex);
}
private void OnClickClose()
{
OnClose?.Invoke();

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c64fdab373ea4ce29f82649e8be2a186
timeCreated: 1747969700

View File

@@ -0,0 +1,14 @@
using FairyGUI;
namespace NBF
{
public abstract class ListItemBase : GButton
{
public virtual void SetData(object showData)
{
OnSetData(showData);
}
protected abstract void OnSetData(object showData);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 380c357d667646b69158440a7d7eecd9
timeCreated: 1747969715

View File

@@ -0,0 +1,27 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using UnityEngine;
using FairyGUI;
using NBC;
namespace NBF
{
public partial class ListTitleItem : ListItemBase
{
public ListClassifyData ClassifyData;
private void OnInited()
{
}
protected override void OnSetData(object showData)
{
width = parent.width - 40;
ClassifyData = showData as ListClassifyData;
if (ClassifyData == null)
{
ClassifyData = new ListClassifyData(string.Empty);
}
title = ClassifyData.Title;
}
}
}

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using UnityEngine;
namespace NBF
{
public class TabListData
{
public string TabName;
public bool Selected;
public List<object> ListData;
public void AddTestData(int index)
{
ListData = new List<object>();
TabName = $"标题-{index + 1}";
var count1 = Random.Range(5, 10);
var count2 = Random.Range(10, 30);
for (int i = 0; i < count1; i++)
{
ListData.Add(new ListClassifyData($"Title-{i}"));
for (int j = 0; j < count2; j++)
{
var item = new ShopGearData();
item.title = $"Item {i}-" + j;
ListData.Add(item);
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 47a09808fe3440d59857224bdc01a91f
timeCreated: 1747970638

View File

@@ -1,15 +0,0 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using UnityEngine;
using FairyGUI;
using NBC;
namespace NBF
{
public partial class ListTitleItem : GComponent
{
private void OnInited()
{
}
}
}

View File

@@ -18,7 +18,7 @@ namespace NBF
[AutoFind(Name = "divisionLine")]
public GImage divisionLine;
[AutoFind(Name = "List")]
public GList List;
public ClassifyList List;
public override string[] GetDependPackages(){ return new string[] {"Common"}; }

View File

@@ -7,22 +7,20 @@ using UIPanel = NBC.UIPanel;
namespace NBF
{
public class ListDataBase
public class ShopGearData
{
public string title;
}
public class ShopGearData : ListDataBase
{
}
public partial class FishingShopPanel : UIPanel
{
public override string UIPackName => "Shop";
public override string UIResName => "FishingShopPanel";
private List<ListDataBase> _data = new List<ListDataBase>();
private List<TabListData> _tabList = new List<TabListData>();
protected override void OnInit()
{
base.OnInit();
@@ -31,58 +29,26 @@ namespace NBF
for (int i = 0; i < 10; i++)
{
var data = new ListDataBase();
data.title = "Title" + i;
_data.Add(data);
for (int j = 0; j < 30; j++)
{
var item = new ShopGearData();
item.title = $"Item {i}-" + j;
_data.Add(item);
}
var itemData = new TabListData();
itemData.AddTestData(i);
_tabList.Add(itemData);
}
// List.SetVirtual();
List.itemProvider = GetListItemResource;
List.itemRenderer = OnRenderItem;
List.numItems = _data.Count;
Menu.OnTabChange += ChangeTab;
}
protected override void OnShow()
{
base.OnShow();
Menu.SetTabs(_tabList);
}
void OnRenderItem(int index, GObject obj)
private void ChangeTab(int index)
{
if (obj is ListTitleItem titleItem)
{
titleItem.width = List.width - 60;
titleItem.height = 47;
}
// else
// {
// obj.width = 224;
// obj.height = 320;
// }
}
//根据索引的不同返回不同的资源URL
string GetListItemResource(int index)
{
var itemData = _data[index];
if (itemData is ShopGearData shopItem)
{
return ShopGearItem.URL;
}
if (itemData is ListDataBase item)
{
return ListTitleItem.URL;
}
return List.defaultItem;
Log.Info($"Change tab index={index}");
var listData = _tabList[index];
List.SetListData(listData.ListData);
}
private void OnClick(GComponent btn)

View File

@@ -6,10 +6,18 @@ using NBC;
namespace NBF
{
public partial class ShopGearItem : GButton
public partial class ShopGearItem : ListItemBase
{
public ShopGearData GearData;
private void OnInited()
{
}
protected override void OnSetData(object showData)
{
GearData = showData as ShopGearData;
if(GearData == null) return;
title = GearData.title;
}
}
}

View File

@@ -2,12 +2,14 @@
<component size="100,46" extention="Button">
<controller name="button" pages="2,up,3,down" selected="0"/>
<displayList>
<text id="n3_fcfg" name="title" xy="22,0" size="55,36" fontSize="26" color="#7888a0" align="center" text="标题">
<text id="n3_fcfg" name="title" xy="22,0" size="55,36" fontSize="26" color="#7888a0" align="center" vAlign="middle" text="标题">
<gearColor controller="button" pages="2,3" values="#7888a0,#000000|#ffffff,#000000"/>
</text>
<image id="n4_fcfg" name="n4" src="kryob" fileName="Images/Square.png" xy="33,44" size="33,2">
<gearDisplay controller="button" pages="3"/>
<relation target="" sidePair="bottom-bottom,rightext-right,leftext-left"/>
</image>
</displayList>
<Button mode="Radio"/>
<relation target="n3_fcfg" sidePair="width-width"/>
</component>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<component size="700,430">
<displayList>
<list id="n5_oome" name="List" xy="0,0" size="700,430" layout="flow_hz" selectionMode="multiple" overflow="scroll" scrollBarFlags="4" margin="10,10,0,0" scrollBarRes="ui://6hgkvlauoomej," clipSoftness="10,10" lineGap="30" colGap="30" align="center" autoClearItems="true" foldInvisibleItems="true">
<relation target="" sidePair="width-width,height-height"/>
<item url="ui://6hgkvlauoomea"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://6hgkvlauoomea"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
<item url="ui://146ra2lqoome9"/>
</list>
</displayList>
</component>

View File

@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<component size="638,47">
<component size="638,47" extention="Button">
<displayList>
<image id="n9_oome" name="back" src="kryob" fileName="Images/Square.png" xy="3,45" size="635,2" alpha="0.3">
<relation target="" sidePair="width-width"/>
</image>
<text id="n7_oome" name="n7" xy="0,0" size="51,34" fontSize="24" color="#ffffff" text="标题"/>
<text id="n7_oome" name="title" xy="0,0" size="51,34" fontSize="24" color="#ffffff" text="标题"/>
</displayList>
<Button/>
</component>

View File

@@ -2,11 +2,11 @@
<component size="1920,140" extention="Label" designImage="ui://6hgkvlaufcfgh0" designImageAlpha="0">
<displayList>
<image id="n1_fcfg" name="LongLine" src="kryob" fileName="Images/Square.png" xy="0,137" size="1920,2" alpha="0.3"/>
<list id="n2_fcfg" name="List" xy="220,93" pivot="0.5,0.5" size="1479,46" layout="row" scroll="horizontal" defaultItem="ui://6hgkvlaufcfggs" align="center" vAlign="bottom">
<list id="n2_fcfg" name="List" xy="220,93" pivot="0.5,0.5" size="1479,46" layout="row" scroll="horizontal" defaultItem="ui://6hgkvlaufcfggs" align="center" vAlign="bottom" autoClearItems="true">
<relation target="" sidePair="center-center,bottom-bottom"/>
<item title="标题三"/>
<item/>
<item/>
<item/>
<item title="标题标题标题"/>
<item/>
<item/>
<item/>

View File

@@ -115,6 +115,7 @@
<component id="oomej" name="VerticalroScrollBar.xml" path="/Com/ScrollBar/" exported="true"/>
<component id="oomei" name="VerticalroScrollBar_grip.xml" path="/Com/ScrollBar/"/>
<component id="oomea" name="ListTitleItem.xml" path="/Com/Items/" exported="true"/>
<component id="drkwh1" name="ClassifyList.xml" path="/Com/" exported="true"/>
</resources>
<publish name="" path="../Assets/Resources/Fgui/Common" packageCount="2" genCode="true"/>
</packageDescription>

View File

@@ -10,42 +10,8 @@
<image id="n4_oome" name="divisionLine" src="kryob" fileName="Images/Square.png" pkg="6hgkvlau" xy="355,176" size="2,800" alpha="0.2">
<relation target="" sidePair="left-left,top-top,bottomext-bottom"/>
</image>
<list id="n5_oome" name="List" xy="365,164" size="1534,904" layout="flow_hz" selectionMode="multiple" overflow="scroll" scrollBarFlags="4" margin="10,10,0,0" scrollBarRes="ui://6hgkvlauoomej," clipSoftness="10,10" lineGap="30" colGap="30" defaultItem="ui://146ra2lqoome9" align="center" autoClearItems="true" foldInvisibleItems="true">
<relation target="" sidePair="left-left,top-top,bottom-bottom,rightext-right"/>
<item url="ui://6hgkvlauoomea"/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item url="ui://6hgkvlauoomea"/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
<item/>
</list>
<component id="n6_drkw" name="List" src="drkwh1" fileName="Com/ClassifyList.xml" pkg="6hgkvlau" xy="374,162" size="1532,914">
<relation target="" sidePair="left-left,top-top,rightext-right,bottomext-bottom"/>
</component>
</displayList>
</component>

View File

@@ -0,0 +1 @@
{"url":"ui://6hgkvlaudrkwh1","name":"ClassifyList","scriptType":"component","isCustomName":false,"customName":"","annotation":"","member":{}}