TemporaryEquipBagPanelCtrl.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using FL.Data.Items;
  9. using System;
  10. using System.Collections.Generic;
  11. using XGame.Database;
  12. using XGame.Framework.UI;
  13. namespace FL.FGUI
  14. {
  15. /// <summary>
  16. /// UI逻辑处理类
  17. /// </summary>
  18. /// <typeparam name=""></typeparam>
  19. public partial class TemporaryEquipBagPanelCtrl : UIController<TemporaryEquipBagPanelVM>
  20. {
  21. private const int MaxRow = 6;// 最大行数
  22. protected override void OnEnable(object intent)
  23. {
  24. AddUIListenres();
  25. EventSingle.Instance.AddListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip);
  26. ShowUI();
  27. }
  28. protected override void OnDisable()
  29. {
  30. RemoveUIListenres();
  31. EventSingle.Instance.RemoveListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip);
  32. }
  33. #region UI事件
  34. private void AddUIListenres()
  35. {
  36. VM.SellBtn.onClick.Add(OnClickSellBtn);
  37. }
  38. private void RemoveUIListenres()
  39. {
  40. VM.SellBtn.onClick.Remove(OnClickSellBtn);
  41. }
  42. /// <summary>
  43. /// 一键出售按钮
  44. /// </summary>
  45. /// <param name="context"></param>
  46. private void OnClickSellBtn(EventContext context)
  47. {
  48. Context.ClosePanel();
  49. DragonEggService.Instance.SendToSellAllBagEquips();
  50. }
  51. #endregion
  52. private void ShowUI()
  53. {
  54. bool bEmpty = EquipData.Instance.IsEquipbagEmpty();
  55. VM.EmptyCtrl.selectedIndex = bEmpty ? 1 : 0;
  56. if (bEmpty)
  57. {
  58. return;
  59. }
  60. var equipDataList = new List<EquipItem>();
  61. EquipData.Instance.GetBagEquipList(ref equipDataList);
  62. OnSortEquipDataList(ref equipDataList);
  63. VM.EquipList.BindDatas(equipDataList);
  64. int num = (int)Math.Ceiling(equipDataList.Count / 5.0f);
  65. int addHeight = (Math.Min(num, MaxRow)-1) * 140 -32;
  66. VM.EquipList.height = 140 + addHeight;
  67. VM.ListBG.height = 425 + addHeight;
  68. VM.UIGroup.height = 462 + addHeight;
  69. }
  70. private void OnSortEquipDataList(ref List<EquipItem> equipDataList)
  71. {
  72. equipDataList.Sort((a, b) =>
  73. {
  74. var aHighPower = GetCompareValue(a);
  75. var bHighPower = GetCompareValue(b);
  76. if (aHighPower == bHighPower)
  77. {
  78. if (a.FightingPower == b.FightingPower)
  79. {
  80. return a.Id.CompareTo(b.Id); // 升序
  81. }
  82. return b.FightingPower.CompareTo(a.FightingPower); //降序
  83. }
  84. else
  85. return bHighPower.CompareTo(aHighPower);
  86. });
  87. }
  88. private int GetCompareValue(EquipItem equipData)
  89. {
  90. int compareFlag = 0;
  91. if (equipData?.Table?.Part > 0)
  92. {
  93. long compareFightingPower = equipData?.FightingPower ?? 0;
  94. var equipItem = EquipData.Instance.GetWearEquipData(equipData.Table.Part);
  95. long wearFightingPower = equipItem?.FightingPower ?? 0;
  96. if (compareFightingPower > wearFightingPower)
  97. compareFlag = 1;
  98. }
  99. return compareFlag;
  100. }
  101. /// <summary>
  102. /// 刷新临时装备背包
  103. /// </summary>
  104. /// <param name="eventId"></param>
  105. /// <param name="args"></param>
  106. private void RefreshTemporaryEquip(int eventId, object args)
  107. {
  108. var equipDataList = new List<EquipItem>();
  109. EquipData.Instance.GetBagEquipList(ref equipDataList);
  110. OnSortEquipDataList(ref equipDataList);
  111. VM.EquipList.BindDatas(equipDataList);
  112. }
  113. }
  114. }