123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /// #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<Item> _itemDataList;
- private List<Item> _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<Item>();
- if (_matterialDataList == null) _matterialDataList = new List<Item>();
- }
- 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.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<Item> 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}";
- }
- }
- }
|