PartnerSbDetailNestedCtrl.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using FL.Data;
  8. using XGame.Database;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. /// <summary>
  13. /// UI逻辑处理类
  14. /// </summary>
  15. /// <typeparam name=""></typeparam>
  16. public partial class PartnerSbDetailNestedCtrl : UIController<PartnerSbDetailNestedVM>
  17. {
  18. protected override void OnEnable(object intent)
  19. {
  20. AddUIListenres();
  21. }
  22. protected override void OnDisable()
  23. {
  24. RemoveUIListenres();
  25. }
  26. #region UI事件
  27. private void AddUIListenres() { }
  28. private void RemoveUIListenres() { }
  29. #endregion
  30. private int _sbId;
  31. public void ShowUI(int id)
  32. {
  33. _sbId = id;
  34. if (_sbId == 0)
  35. {
  36. VM.ItemBase.Disable();
  37. VM.IsEmpty.selectedIndex = 1;
  38. return;
  39. }
  40. VM.ItemBase.Enable(null);
  41. VM.IsEmpty.selectedIndex = 0;
  42. var table = PartnerTableRepo.Get(_sbId);
  43. XGame.Framework.Assert.IsNotNull(table, $"圣兵表不存在,id:{_sbId}");
  44. VM.NameLabel.text = table.Name;
  45. var attr = PartnersData.Instance.GetPartnerAttrByTableId(_sbId);
  46. var level = attr?.Level ?? 1;
  47. var star = attr?.RisingStarLv ?? 1;
  48. var upStarTable = partnerStarUpTableRepo.GetPartnerStarTable(_sbId, star);
  49. XGame.Framework.Assert.IsNotNull(
  50. upStarTable,
  51. $"圣兵升星表不存在,id:{_sbId},level:{star}"
  52. );
  53. VM.SpPbar.max = upStarTable.StarUpCost;
  54. VM.SpPbar.value = ItemData.Instance.GetItemNum(upStarTable.PetId);
  55. //
  56. ShowStar(star);
  57. //
  58. ShowSkillBaseInfo(table.Skill[0]);
  59. //
  60. ShowAttr(level);
  61. //
  62. VM.ElementLoader.url = AddressableDefine.SbElementType(((int)table.Element));
  63. VM.TypeLoader.url = AddressableDefine.SbTypeIcon(table.Type);
  64. //
  65. VM.AttrLabel.text = $"+{table.Own_attr[1] / 100f}%";
  66. var item = ItemBase.Create(_sbId);
  67. VM.ItemBase.Ctrl.ShowUI(item);
  68. }
  69. private void ShowStar(int star)
  70. {
  71. var starStep = PartnersService.Instance.GetStarStep(star);
  72. var starLv = PartnersService.Instance.GetStarLv(star);
  73. var list = new List<int>();
  74. for (int i = 0; i < starLv; i++)
  75. {
  76. list.Add(starStep);
  77. }
  78. VM.StarList.BindDatas(list);
  79. }
  80. private void ShowAttr(int level)
  81. {
  82. var lvTable = partnerLvUpAttrTableRepo.GetPartnerLvUpAttrTable(_sbId, level);
  83. XGame.Framework.Assert.IsNotNull(lvTable, $"圣兵等级不存在,id:{_sbId},level:{level}");
  84. var partnerTable = PartnerTableRepo.Get(_sbId);
  85. XGame.Framework.Assert.IsNotNull(partnerTable, $"圣兵表不存在,id:{_sbId}");
  86. var map = new Dictionary<int, int>();
  87. for (int i = 0; i < partnerTable.Base_attr.Length; i += 2)
  88. {
  89. map.Add(partnerTable.Base_attr[i], partnerTable.Base_attr[i + 1]);
  90. }
  91. var atkVal = map.GetValueOrDefault((int)EAttributeType.PetDmg, 0);
  92. var atkSpeed = map.GetValueOrDefault((int)EAttributeType.PetSpeed, 0);
  93. for (int i = 0; i < lvTable.Attr.Length; i += 2)
  94. {
  95. var type = lvTable.Attr[i];
  96. if (type == (int)EAttributeType.PetDmg)
  97. {
  98. atkVal += lvTable.Attr[i + 1];
  99. }
  100. else if (type == (int)EAttributeType.PetSpeed)
  101. {
  102. atkSpeed += lvTable.Attr[i + 1];
  103. }
  104. }
  105. //var attributeInfo = AttrDescTableRepo.Get(attrType);
  106. string descAtk = atkVal > 0 ? atkVal.ToRealFloat().ToString("F1") : "0";
  107. VM.AtkValLabel.text = descAtk;
  108. string descSpeed = atkSpeed > 0 ? atkSpeed.ToRealFloat().ToString("F1") : "0";
  109. VM.SpeedValLabel.text = descSpeed;
  110. }
  111. /// <summary>
  112. /// 基础技能描述
  113. /// </summary>
  114. /// <param name="skillId"></param>
  115. private void ShowSkillBaseInfo(int skillId)
  116. {
  117. var skillInfo = SkillTableRepo.Get(skillId);
  118. XGame.Framework.Assert.IsNotNull(skillInfo, $"技能表不存在,id{skillId}");
  119. VM.DescLabel.text = skillInfo.Desc;
  120. }
  121. }
  122. }