PartnerPartnerBaseItemCtrl.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using FairyGUI;
  8. using FL.Data;
  9. using XGame;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. /// <summary>
  15. /// UI逻辑处理类
  16. /// </summary>
  17. /// <typeparam name=""></typeparam>
  18. public partial class PartnerPartnerBaseItemCtrl : UIController<PartnerPartnerBaseItemVM>
  19. {
  20. private List<GLoader> _starIconList;
  21. protected override void OnEnable(object intent)
  22. {
  23. AddUIListenres();
  24. }
  25. protected override void OnDisable()
  26. {
  27. RemoveUIListenres();
  28. ClearStar();
  29. }
  30. #region UI事件
  31. private void AddUIListenres() { }
  32. private void RemoveUIListenres() { }
  33. #endregion
  34. public void ShowUI(int id, bool showOther)
  35. {
  36. if (id <= 0)
  37. {
  38. VM.PartnerImg.visible = false;
  39. VM.QualityImg.icon = AddressableDefine.PartnerEmptyDi();
  40. VM.ShowOther.selectedIndex = 1;
  41. VM.LevelTxt.visible = false;
  42. return;
  43. }
  44. var table = PartnerTableRepo.Get(id);
  45. if (table == null)
  46. {
  47. Log.Error($"圣兵表不存在id:{id}");
  48. return;
  49. }
  50. VM.PartnerImg.visible = true;
  51. VM.QualityImg.icon = AddressableDefine.PartnerQualityFrame((int)table.Quality);
  52. VM.PartnerImg.icon = table.Icon;
  53. var partnerData = PartnersData.Instance.GetPartnerAttrByTableId(id);
  54. var level = partnerData?.Level ?? 0;
  55. bool bShowLevel = level > 0;
  56. VM.LevelTxt.visible = bShowLevel;
  57. if (bShowLevel)
  58. {
  59. VM.LevelTxt.text = $"LV.{level}";
  60. }
  61. VM.ShowOther.selectedIndex = showOther ? 0 : 1;
  62. if (showOther)
  63. {
  64. var starLv = partnerData?.RisingStarLv == null ? 0 : partnerData.RisingStarLv;
  65. ShowStarUI(starLv);
  66. var starTable = partnerStarUpTableRepo.GetPartnerStarTable(id, starLv);
  67. if (starTable == null)
  68. {
  69. VM.SpPbar.visible = false;
  70. }
  71. else
  72. {
  73. VM.SpPbar.GetChild("icon").asLoader.url = AddressableDefine.PartnerSpProgressDi((int)table.Quality);
  74. VM.SpPbar.max = starTable.StarUpCost;
  75. VM.SpPbar.value = ItemData.Instance.GetItemNum(starTable.PetId);
  76. VM.SpPbar.visible = true;
  77. }
  78. }
  79. }
  80. private void ShowStarUI(int starLv)
  81. {
  82. InitStarList();
  83. int starNum = starLv == 0 ? 0 : starLv % PartnersData.MaxStarNum;
  84. if (starLv > 0 && starNum == 0)
  85. starNum = PartnersData.MaxStarNum;
  86. VM.StarRating.GetController("StarNumCtrl").selectedIndex = starNum;
  87. ShowStarIcon(starNum, starLv);
  88. }
  89. private void ClearStar()
  90. {
  91. if (_starIconList != null)
  92. {
  93. _starIconList.Clear();
  94. _starIconList = null;
  95. }
  96. }
  97. private void InitStarList()
  98. {
  99. if (_starIconList == null)
  100. {
  101. _starIconList = new List<GLoader>()
  102. {
  103. VM.StarRating.GetChild("Star1").asLoader,
  104. VM.StarRating.GetChild("Star2").asLoader,
  105. VM.StarRating.GetChild("Star3").asLoader,
  106. VM.StarRating.GetChild("Star4").asLoader,
  107. VM.StarRating.GetChild("Star5").asLoader,
  108. };
  109. }
  110. foreach (var item in _starIconList)
  111. {
  112. item.visible = false;
  113. }
  114. }
  115. private void ShowStarIcon(int count, int starLv)
  116. {
  117. if (count > 0)
  118. {
  119. int starStep = PartnersData.Instance.GetStarStep(starLv);
  120. for (int i = 0; i < count; i++)
  121. {
  122. if (_starIconList[i] != null)
  123. {
  124. _starIconList[i].visible = true;
  125. _starIconList[i].icon = AddressableDefine.PartnerStarIconName(starStep);
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }