EquipEquipItemNestedCtrl.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FL.Data.Items;
  7. using System.Collections.Generic;
  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 EquipEquipItemNestedCtrl : UIController<EquipEquipItemNestedVM>
  17. {
  18. private Dictionary<EAttributeType, EquipAttrItemNestedView> _basicAttrItemMap;
  19. private List<EAttributeType> _allAttrTypeList; // 装备全部属性类型列表
  20. private List<EAttributeType> _specialAttrTypeList;
  21. protected override void OnEnable(object intent)
  22. {
  23. AddUIListenres();
  24. }
  25. protected override void OnDisable()
  26. {
  27. RemoveUIListenres();
  28. _basicAttrItemMap?.Clear();
  29. _basicAttrItemMap = null;
  30. _allAttrTypeList?.Clear();
  31. _allAttrTypeList = null;
  32. _specialAttrTypeList?.Clear();
  33. _specialAttrTypeList = null;
  34. }
  35. #region UI事件
  36. private void AddUIListenres()
  37. {
  38. }
  39. private void RemoveUIListenres()
  40. {
  41. }
  42. #endregion
  43. private void InitUI()
  44. {
  45. if (_basicAttrItemMap == null)
  46. {
  47. _basicAttrItemMap = new Dictionary<EAttributeType, EquipAttrItemNestedView>();
  48. }
  49. else
  50. {
  51. _basicAttrItemMap.Clear();
  52. }
  53. _basicAttrItemMap.Add(EAttributeType.Hp, VM.HpAttrItem);
  54. _basicAttrItemMap.Add(EAttributeType.Atk, VM.AtkAttrItem);
  55. _basicAttrItemMap.Add(EAttributeType.Def, VM.DefAttrItem);
  56. _basicAttrItemMap.Add(EAttributeType.AtkSpeed, VM.SpeedAttrItem);
  57. VM.SpecialAttrItem1.Ctrl.ResetUI();
  58. VM.SpecialAttrItem2.Ctrl.ResetUI();
  59. if (_allAttrTypeList == null)
  60. _allAttrTypeList = new List<EAttributeType>();
  61. else
  62. _allAttrTypeList.Clear();
  63. if (_specialAttrTypeList == null)
  64. _specialAttrTypeList = new List<EAttributeType>();
  65. else
  66. _specialAttrTypeList.Clear();
  67. }
  68. public void ShowUI(EquipAttr newEquip, EquipAttr wearEquip, bool bWear = false)
  69. {
  70. VM.State.selectedIndex = bWear ? 0 : 1;
  71. EquipAttr equipData = bWear ? wearEquip : newEquip;
  72. ShowEquipItemUI(equipData);
  73. ShowAttrUi(equipData, wearEquip, bWear);
  74. }
  75. private void ShowEquipItemUI(EquipAttr equipData)
  76. {
  77. var equipBase = new EquipItemBase();
  78. if (equipData.Id == 0)
  79. {
  80. equipBase.InitByEquipPart(equipData.EquipType);
  81. }
  82. else
  83. {
  84. equipBase.InitById(equipData.Id);
  85. }
  86. VM.ItemBtn.Ctrl.ShowUI(equipBase);
  87. VM.NameLabel.text = equipData.Name;
  88. VM.NameLabel.color = equipData.Quality.ToEquipNameColor();
  89. }
  90. /// <summary>
  91. /// 装备的属性UI
  92. /// </summary>
  93. /// <param name="equipData"></param>
  94. /// <param name="wearEquip"></param>
  95. /// <param name="bWear"></param>
  96. private void ShowAttrUi(EquipAttr equipData, EquipAttr wearEquip, bool bWear)
  97. {
  98. InitUI();
  99. //装备的属性列表
  100. //equipData.Attributes.GetAll(ref _allAttrTypeList, 0);
  101. equipData.Attributes.GetAll(ref _specialAttrTypeList, 2);
  102. if (_specialAttrTypeList.Count > 0)
  103. {
  104. _basicAttrItemMap.Add(_specialAttrTypeList[0], VM.SpecialAttrItem1);
  105. }
  106. if (_specialAttrTypeList.Count > 1)
  107. {
  108. _basicAttrItemMap.Add(_specialAttrTypeList[1], VM.SpecialAttrItem2);
  109. }
  110. foreach (var item in _basicAttrItemMap)
  111. {
  112. long attributeVal = equipData.Attributes.GetValue(item.Key);
  113. if (attributeVal > 0)
  114. {
  115. var compareType = GetCompareType(attributeVal, wearEquip == null ? 0 : wearEquip.Attributes.GetValue(item.Key));
  116. item.Value.Ctrl.ShowUI(item.Key, attributeVal, compareType, true);
  117. }
  118. else
  119. {
  120. item.Value.Ctrl.ShowUI(item.Key, 0, eCompareType.None, false);
  121. }
  122. }
  123. }
  124. /// <summary>
  125. /// 新装备属性的比较标识
  126. /// </summary>
  127. /// <param name="attributeType"></param>
  128. /// <param name="atrrVal"></param>
  129. /// <param name="wearEquip"></param>
  130. /// <returns></returns>
  131. private eCompareType GetCompareType(long atrrVal, long wearAttrVal)
  132. {
  133. return atrrVal == wearAttrVal ? eCompareType.None : (atrrVal > wearAttrVal ? eCompareType.Higth : eCompareType.Low);
  134. }
  135. }
  136. }