PartnerSbDetailNoIconNestedCtrl.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class PartnerSbDetailNoIconNestedCtrl
  18. : UIController<PartnerSbDetailNoIconNestedVM>
  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. private int _sbId;
  33. public void ShowUI(int sbId)
  34. {
  35. _sbId = sbId;
  36. var table = PartnerTableRepo.Get(_sbId);
  37. XGame.Framework.Assert.IsNotNull(table, $"圣兵表不存在,id:{_sbId}");
  38. var attr = PartnersData.Instance.GetPartnerAttrByTableId(_sbId);
  39. var level = attr?.Level ?? 1;
  40. var star = attr?.RisingStarLv ?? 1;
  41. VM.AttrLabel.text = $"+{table.Own_attr[1] / 100f}%";
  42. //
  43. ShowSkillBaseInfo(table.Skill[0]);
  44. //
  45. ShowAttr(level);
  46. //
  47. VM.ElementLoader.url = AddressableDefine.SbElementType(((int)table.Element));
  48. VM.TypeLoader.url = AddressableDefine.SbTypeIcon(table.Type);
  49. ShowBuff(star);
  50. //
  51. var pos = PartnersData.Instance.UpSbPosMap.GetValueOrDefault(_sbId, -1);
  52. VM.IsUp.selectedIndex = pos < 0 ? 0 : 1;
  53. }
  54. private void ShowAttr(int level)
  55. {
  56. var lvTable = partnerLvUpAttrTableRepo.GetPartnerLvUpAttrTable(_sbId, level);
  57. XGame.Framework.Assert.IsNotNull(lvTable, $"圣兵等级不存在,id:{_sbId},level:{level}");
  58. var partnerTable = PartnerTableRepo.Get(_sbId);
  59. XGame.Framework.Assert.IsNotNull(partnerTable, $"圣兵表不存在,id:{_sbId}");
  60. var map = new Dictionary<int, int>();
  61. for (int i = 0; i < partnerTable.Base_attr.Length; i += 2)
  62. {
  63. map.Add(partnerTable.Base_attr[i], partnerTable.Base_attr[i + 1]);
  64. }
  65. var atkVal = map.GetValueOrDefault((int)EAttributeType.PetDmg, 0);
  66. var atkSpeed = map.GetValueOrDefault((int)EAttributeType.PetSpeed, 0);
  67. for (int i = 0; i < lvTable.Attr.Length; i += 2)
  68. {
  69. var type = lvTable.Attr[i];
  70. if (type == (int)EAttributeType.PetDmg)
  71. {
  72. atkVal += lvTable.Attr[i + 1];
  73. }
  74. else if (type == (int)EAttributeType.PetSpeed)
  75. {
  76. atkSpeed += lvTable.Attr[i + 1];
  77. }
  78. }
  79. //var attributeInfo = AttrDescTableRepo.Get(attrType);
  80. string descAtk = atkVal > 0 ? atkVal.ToRealFloat().ToString("F1") : "0";
  81. VM.AtkValLabel.text = descAtk;
  82. string descSpeed = atkSpeed > 0 ? atkSpeed.ToRealFloat().ToString("F1") : "0";
  83. VM.SpeedValLabel.text = descSpeed;
  84. }
  85. /// <summary>
  86. /// 基础技能描述
  87. /// </summary>
  88. /// <param name="skillId"></param>
  89. private void ShowSkillBaseInfo(int skillId)
  90. {
  91. var skillInfo = SkillTableRepo.Get(skillId);
  92. XGame.Framework.Assert.IsNotNull(skillInfo, $"技能表不存在,id{skillId}");
  93. VM.DescLabel.text = skillInfo.Desc;
  94. }
  95. private void ShowBuff(int starLv)
  96. {
  97. var table = PartnerTableRepo.Get(_sbId);
  98. XGame.Framework.Assert.IsNotNull(table, $"圣兵tableId {_sbId} 不存在");
  99. var starSkillIds = table?.Skill;
  100. var dataList = new List<PartnerSbDetailSkillListItemParam>();
  101. if (starSkillIds?.Length > 0)
  102. {
  103. for (int i = 2; i < starSkillIds.Length; i += 2)
  104. {
  105. var data = new PartnerSbDetailSkillListItemParam()
  106. {
  107. SkillId = starSkillIds[i],
  108. NeedStarLevel = starSkillIds[i + 1],
  109. CurStarLevel = starLv,
  110. };
  111. dataList.Add(data);
  112. }
  113. }
  114. VM.SkillList.BindDatas(dataList);
  115. }
  116. }
  117. }