/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data; using FL.Data.Items; using System.Collections.Generic; 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); VM.ItemsList.ItemClickEvent += OnClcikPropsItem; } private void RemoveUIListenres() { VM.ItemPageBtn.onClick.Remove(OnClickItemPageBtn); VM.MaterialPageBtn.onClick.Remove(OnClickMaterialPageBtn); VM.ItemsList.ItemClickEvent -= OnClcikPropsItem; } private void OnClickItemPageBtn(EventContext context) { ShowPageUI(0); } private void OnClickMaterialPageBtn(EventContext context) { ShowPageUI(1); } /// /// 点击的被动技能项 /// /// private void OnClcikPropsItem(int index) { var data = VM.PageCtrl.selectedIndex == 0 ? _itemDataList[index] : _matterialDataList[index]; if (data == null) return; Context.UI.OpenAsync( UIKeys.BagSourceOfPropsPanel, data ); } #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 != null &&(itemInfo.Type == (int)EItemType.Gift || itemInfo.Type == (int)EItemType.RedEnvelope || itemInfo.Type == (int)EItemType.Props)) { ItemBase itemBase = new ItemBase(); itemBase.Init(itemInfo.Id, item.Value.num); if (itemInfo.Type == (int)EItemType.Props) _matterialDataList.Add(itemBase); else _itemDataList.Add(itemBase); } } } 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}/{KeyValue.boxMax}"; } } }