BagBackpackPanelCtrl.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using Codice.CM.Common;
  7. using FairyGUI;
  8. using FL.Data;
  9. using FL.Data.Items;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Net.NetworkInformation;
  13. using XGame.Database;
  14. using XGame.Framework.UI;
  15. namespace FL.FGUI
  16. {
  17. /// <summary>
  18. /// UI逻辑处理类
  19. /// </summary>
  20. /// <typeparam name=""></typeparam>
  21. public partial class BagBackpackPanelCtrl : UIController<BagBackpackPanelVM>
  22. {
  23. private List<Item> _itemDataList;
  24. private List<Item> _matterialDataList;
  25. protected override void OnEnable(object intent)
  26. {
  27. AddUIListenres();
  28. Init();
  29. ShowUI();
  30. }
  31. protected override void OnDisable()
  32. {
  33. RemoveUIListenres();
  34. }
  35. #region UI事件
  36. private void AddUIListenres()
  37. {
  38. VM.ItemPageBtn.onClick.Add(OnClickItemPageBtn);
  39. VM.MaterialPageBtn.onClick.Add(OnClickMaterialPageBtn);
  40. }
  41. private void RemoveUIListenres()
  42. {
  43. VM.ItemPageBtn.onClick.Remove(OnClickItemPageBtn);
  44. VM.MaterialPageBtn.onClick.Remove(OnClickMaterialPageBtn);
  45. }
  46. private void OnClickItemPageBtn(EventContext context)
  47. {
  48. ShowPageUI(0);
  49. }
  50. private void OnClickMaterialPageBtn(EventContext context)
  51. {
  52. ShowPageUI(1);
  53. }
  54. #endregion
  55. private void Init()
  56. {
  57. if (_itemDataList == null) _itemDataList= new List<Item>();
  58. if (_matterialDataList == null) _matterialDataList = new List<Item>();
  59. }
  60. private void ShowUI()
  61. {
  62. GetBackpackData(ItemData.Instance.GetBackpackData());
  63. ShowPageUI(0);
  64. }
  65. private void GetBackpackData(Dictionary<int, BagItemData> bagDataMap)
  66. {
  67. if (bagDataMap == null || bagDataMap.Count == 0) return;
  68. _itemDataList.Clear();
  69. _matterialDataList.Clear();
  70. foreach (var item in bagDataMap)
  71. {
  72. ItemTable itemInfo = ItemTableRepo.Get(item.Value.tableId);
  73. if (itemInfo.Type == (int)EItemType.Gift || itemInfo.Type == (int)EItemType.RedEnvelope || itemInfo.Type == (int)EItemType.Props)
  74. {
  75. Item _item = new Item();
  76. _item.Count = item.Value.num.ToString();
  77. _item.Init(itemInfo, item.Value.id);
  78. if (itemInfo.Type == (int)EItemType.Props)
  79. _matterialDataList.Add(_item);
  80. else
  81. _itemDataList.Add(_item);
  82. }
  83. }
  84. }
  85. private void ShowPageUI(int pageIndex)
  86. {
  87. VM.PageCtrl.selectedIndex = pageIndex;
  88. if (pageIndex == 0)
  89. {
  90. ShowItemsUI(_itemDataList);
  91. }
  92. else
  93. {
  94. ShowItemsUI(_matterialDataList);
  95. }
  96. }
  97. private void ShowItemsUI(List<Item> dataList)
  98. {
  99. VM.ItemsList.BindDatas(dataList);
  100. ShowNum(dataList.Count);
  101. VM.EmptyLabel.visible = dataList.Count == 0;
  102. }
  103. /// <summary>
  104. /// 背包格子数量
  105. /// </summary>
  106. /// <param name="num"></param>
  107. private void ShowNum(int num)
  108. {
  109. VM.NumLabel.text = num.ToString();
  110. }
  111. }
  112. }