123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class BagBackpackPanelCtrl : UIController<BagBackpackPanelVM>
- {
- private List<ItemBase> _itemDataList;
- private List<ItemBase> _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);
- }
- /// <summary>
- /// 点击的被动技能项
- /// </summary>
- /// <param name="index"></param>
- 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<ItemBase>();
- if (_matterialDataList == null) _matterialDataList = new List<ItemBase>();
- }
- private void ShowUI()
- {
- GetBackpackData(ItemData.Instance.GetBackpackData());
- ShowPageUI(0);
- }
- private void GetBackpackData(Dictionary<int, BagItemData> 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<ItemBase> dataList)
- {
- VM.ItemsList.BindDatas(dataList);
- ShowNum(dataList.Count);
- VM.EmptyLabel.visible = dataList.Count == 0;
- }
- /// <summary>
- /// 背包格子数量
- /// </summary>
- /// <param name="num"></param>
- private void ShowNum(int num)
- {
- VM.NumLabel.text = $"{num}/{KeyValue.boxMax}";
- }
- }
- }
|