TreasureChestIncomeListItemCtrl.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 XGame.Database;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. public struct TreasureChestIncome
  13. {
  14. public int dropId; // 当前等级掉落id
  15. public int nextLvDropId; // 下一级的掉落id
  16. }
  17. /// <summary>
  18. /// UI逻辑处理类
  19. /// </summary>
  20. /// <typeparam name=""></typeparam>
  21. public partial class TreasureChestIncomeListItemCtrl : UIController<TreasureChestIncomeListItemVM>
  22. {
  23. protected override void OnEnable(object intent)
  24. {
  25. AddUIListenres();
  26. }
  27. protected override void OnDisable()
  28. {
  29. RemoveUIListenres();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.InfoBtn.onClick.Add(OnClickInfoBtn);
  35. }
  36. private void RemoveUIListenres()
  37. {
  38. VM.InfoBtn.onClick.Remove(OnClickInfoBtn);
  39. }
  40. private void OnClickInfoBtn(EventContext context)
  41. {
  42. EventSingle.Instance.Notify(EventDefine.ShowEquipQualityProbability);
  43. }
  44. #endregion
  45. public void OnRefresh(int index, TreasureChestIncome dropData)
  46. {
  47. VM.HideLineCtrl.selectedIndex = index < 4 ? 0 : 1;
  48. bool bEquip = index == 2;
  49. VM.EquipCtrl.selectedIndex = bEquip ? 1 : 0; // 第3个宝箱产出装备
  50. bool bMaxLv = dropData.nextLvDropId == 0;
  51. VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0;
  52. var curDropInfo = DropTableRepo.Get(dropData.dropId);
  53. if (curDropInfo?.Group[0] > 0)
  54. {
  55. VM.ItemIcon1.icon = GetItemIcon(curDropInfo.Group[0]);
  56. VM.CurLvNumLabel.text = curDropInfo?.Group[1].ToString();
  57. }
  58. if (!bMaxLv)
  59. {
  60. var nextDropInfo = DropTableRepo.Get(dropData.nextLvDropId);
  61. if (nextDropInfo?.Group[0] > 0)
  62. {
  63. VM.ItemIcon2.icon = GetItemIcon(nextDropInfo.Group[0]);
  64. VM.NextLvNumLabel.text = nextDropInfo?.Group[1].ToString();
  65. }
  66. }
  67. ShowTreasureBoxIcon(index);
  68. if (bEquip)
  69. {
  70. ShowMaxEquipQuality(bMaxLv);
  71. }
  72. }
  73. private string GetItemIcon(int itemId)
  74. {
  75. var itemInfo = ItemTableRepo.Get(itemId);
  76. return itemInfo?.Icon;
  77. }
  78. /// <summary>
  79. /// 当前宝箱等级可以产出的最高装备品质描述
  80. /// </summary>
  81. private void ShowMaxEquipQuality(bool bMaxLv)
  82. {
  83. var curTreasure = treasureTableRepo.Get(DragonEggData.Instance.Level);
  84. if (curTreasure != null)
  85. {
  86. int maxQuality = 1;
  87. for (int i = 0; i < curTreasure.EquipmentProbability.Length; i += 2)
  88. {
  89. if (curTreasure.EquipmentProbability[i + 1] > 0 && curTreasure.EquipmentProbability[i] > maxQuality)
  90. {
  91. maxQuality = curTreasure.EquipmentProbability[i];
  92. }
  93. }
  94. EQualityLevel quality = (EQualityLevel)maxQuality;
  95. string nextQualityStr = bMaxLv ? string.Empty : GetNextLvEquipQuality(DragonEggData.Instance.Level + 1, maxQuality);
  96. VM.ProduceLabel.text = string.Format(StringDefine.maxEquipQuality, ColorDefine.GetQualityColor(quality), StringDefine.equipQualityNameList[maxQuality - 1], nextQualityStr);
  97. }
  98. }
  99. /// <summary>
  100. /// 判断升级后是否会开启新的品质装备
  101. /// </summary>
  102. /// <param name="level"></param>
  103. /// <param name="curQuality"></param>
  104. /// <returns></returns>
  105. private string GetNextLvEquipQuality(int level, int curQuality)
  106. {
  107. int maxQuality = curQuality;
  108. var treasureInfo = treasureTableRepo.Get(DragonEggData.Instance.Level);
  109. if (treasureInfo != null)
  110. {
  111. for (int i = 0; i < treasureInfo.EquipmentProbability.Length; i += 2)
  112. {
  113. if (treasureInfo.EquipmentProbability[i + 1] > 0 && treasureInfo.EquipmentProbability[i] > maxQuality)
  114. {
  115. maxQuality = treasureInfo.EquipmentProbability[i];
  116. }
  117. }
  118. }
  119. if (maxQuality > curQuality)
  120. {
  121. return string.Format(StringDefine.nextLvEquipQuality, ColorDefine.GetQualityColor((EQualityLevel)maxQuality), StringDefine.equipQualityNameList[maxQuality - 1]);
  122. }
  123. return string.Empty;
  124. }
  125. /// <summary>
  126. /// (品质)宝箱的icon
  127. /// </summary>
  128. /// <param name="index"></param>
  129. private void ShowTreasureBoxIcon(int index)
  130. {
  131. VM.DragonIcon.icon = AddressableDefine.DragonIcon(index + 1);
  132. }
  133. }
  134. }