/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using Codice.CM.Common; using FairyGUI; using FL.Data; using FL.Data.Items; using System; using System.Collections.Generic; using System.Net.NetworkInformation; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class BagBackpackPanelCtrl : UIController { private List _itemDataList; private List _matterialDataList; protected override void OnEnable(object intent) { AddUIListenres(); Init(); ShowUI(); } protected override void OnDisable() { RemoveUIListenres(); } #region UI事件 private void AddUIListenres() { VM.ItemPageBtn.onClick.Add(OnClickItemPageBtn); VM.MaterialPageBtn.onClick.Add(OnClickMaterialPageBtn); } private void RemoveUIListenres() { VM.ItemPageBtn.onClick.Remove(OnClickItemPageBtn); VM.MaterialPageBtn.onClick.Remove(OnClickMaterialPageBtn); } private void OnClickItemPageBtn(EventContext context) { ShowPageUI(0); } private void OnClickMaterialPageBtn(EventContext context) { ShowPageUI(1); } #endregion private void Init() { if (_itemDataList == null) _itemDataList= new List(); if (_matterialDataList == null) _matterialDataList = new List(); } private void ShowUI() { GetBackpackData(ItemData.Instance.GetBackpackData()); ShowPageUI(0); } private void GetBackpackData(Dictionary bagDataMap) { if (bagDataMap == null || bagDataMap.Count == 0) return; _itemDataList.Clear(); _matterialDataList.Clear(); foreach (var item in bagDataMap) { ItemTable itemInfo = ItemTableRepo.Get(item.Value.tableId); if (itemInfo.Type == (int)EItemType.Gift || itemInfo.Type == (int)EItemType.RedEnvelope || itemInfo.Type == (int)EItemType.Props) { Item _item = new Item(); _item.Count = item.Value.num.ToString(); _item.Init(itemInfo, item.Value.id); if (itemInfo.Type == (int)EItemType.Props) _matterialDataList.Add(_item); else _itemDataList.Add(_item); } } } private void ShowPageUI(int pageIndex) { VM.PageCtrl.selectedIndex = pageIndex; if (pageIndex == 0) { ShowItemsUI(_itemDataList); } else { ShowItemsUI(_matterialDataList); } } private void ShowItemsUI(List dataList) { VM.ItemsList.BindDatas(dataList); ShowNum(dataList.Count); VM.EmptyLabel.visible = dataList.Count == 0; } /// /// 背包格子数量 /// /// private void ShowNum(int num) { VM.NumLabel.text = num.ToString(); } } }