PartnerSbBaseItemCtrl.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 PartnerSbBaseItemCtrl : UIController<PartnerSbBaseItemVM>
  19. {
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. }
  24. protected override void OnDisable()
  25. {
  26. RemoveUIListenres();
  27. }
  28. #region UI事件
  29. private void AddUIListenres() { }
  30. private void RemoveUIListenres() { }
  31. #endregion
  32. public void ShowUI(int sbId, bool showOther)
  33. {
  34. if (sbId <= 0)
  35. {
  36. VM.PartnerImg.visible = false;
  37. VM.QualityImg.icon = AddressableDefine.SbEmptyDi();
  38. VM.ShowOther.selectedIndex = 1;
  39. VM.LevelTxt.visible = false;
  40. return;
  41. }
  42. var table = PartnerTableRepo.Get(sbId);
  43. if (table == null)
  44. {
  45. Log.Error($"圣兵表不存在id:{sbId}");
  46. return;
  47. }
  48. VM.PartnerImg.visible = true;
  49. VM.ElementLoader.url = AddressableDefine.SbElementTypeRhombus((int)table.Element);
  50. VM.QualityImg.icon = AddressableDefine.SbPzDi((int)table.Quality);
  51. VM.PartnerImg.icon = table.Icon;
  52. VM.ShowOther.selectedIndex = showOther ? 0 : 1;
  53. var partnerData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  54. VM.Have.selectedIndex = partnerData != null ? 0 : 1;
  55. if(partnerData != null)
  56. {
  57. var level = partnerData?.Level ?? 1;
  58. VM.LevelTxt.text = $"LV.{level}";
  59. if (showOther)
  60. {
  61. var starLv = partnerData?.RisingStarLv == null ? 1 : partnerData.RisingStarLv;
  62. ShowStar(starLv);
  63. var starTable = partnerStarUpTableRepo.GetPartnerStarTable(sbId, starLv);
  64. if (starTable == null)
  65. {
  66. Log.Error($"圣兵升星表不存在,id:{sbId},starLv:{starLv}");
  67. return;
  68. }
  69. VM.SpPbar.max = starTable.StarUpCost;
  70. VM.SpPbar.value = ItemData.Instance.GetItemNum(starTable.PetId);
  71. }
  72. }
  73. }
  74. private void ShowStar(int starLv)
  75. {
  76. var curNum = PartnersService.Instance.GetStarLv(starLv);
  77. var curStep = PartnersService.Instance.GetStarStep(starLv);
  78. var list = new List<int>();
  79. for (int i = 0; i < curNum; i++)
  80. {
  81. list.Add(curStep);
  82. }
  83. VM.StarList.BindDatas(list);
  84. }
  85. }
  86. }