EquipEquipItemNestedCtrl.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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(EquipItem newEquip, EquipItem wearEquip, bool bWear = false)
  69. {
  70. VM.State.selectedIndex = bWear ? 0 : 1;
  71. EquipItem equipData = bWear ? wearEquip : newEquip;
  72. ShowEquipItemUI(equipData);
  73. ShowAttrUi(equipData, wearEquip, bWear);
  74. }
  75. private void ShowEquipItemUI(EquipItem equipData)
  76. {
  77. UiParam _uiParam = new UiParam();
  78. _uiParam.bShowLevel = true;
  79. VM.ItemBtn.Ctrl.ShowUI(equipData, _uiParam);
  80. VM.NameLabel.text = equipData.Name;
  81. VM.NameLabel.color = equipData.Quality.ToEquipNameColor();
  82. }
  83. /// <summary>
  84. /// 装备的属性UI
  85. /// </summary>
  86. /// <param name="equipData"></param>
  87. /// <param name="wearEquip"></param>
  88. /// <param name="bWear"></param>
  89. private void ShowAttrUi(EquipItem equipData, EquipItem wearEquip, bool bWear)
  90. {
  91. InitUI();
  92. //装备的属性列表
  93. equipData.Attributes.GetAll(ref _allAttrTypeList, 0);
  94. equipData.Attributes.GetAll(ref _specialAttrTypeList, 2);
  95. if (_specialAttrTypeList.Count > 0)
  96. {
  97. _basicAttrItemMap.Add(_specialAttrTypeList[0], VM.SpecialAttrItem1);
  98. }
  99. if (_specialAttrTypeList.Count > 1)
  100. {
  101. _basicAttrItemMap.Add(_specialAttrTypeList[1], VM.SpecialAttrItem2);
  102. }
  103. foreach (var item in _basicAttrItemMap)
  104. {
  105. bool bShowAttrItem = _allAttrTypeList.FindIndex(attrType => attrType == item.Key) != -1;
  106. if (bShowAttrItem)
  107. {
  108. long attributeVal = equipData.Attributes.GetValue(item.Key);
  109. var compareType = bWear ? eCompareType.None : GetCompareType(item.Key, attributeVal, wearEquip);
  110. item.Value.Ctrl.ShowUI(item.Key, attributeVal, compareType, true);
  111. }
  112. else
  113. {
  114. item.Value.Ctrl.ShowUI(item.Key, 0, eCompareType.None, false);
  115. }
  116. }
  117. }
  118. /// <summary>
  119. /// 新装备属性的比较标识
  120. /// </summary>
  121. /// <param name="attributeType"></param>
  122. /// <param name="atrrVal"></param>
  123. /// <param name="wearEquip"></param>
  124. /// <returns></returns>
  125. private eCompareType GetCompareType(EAttributeType attributeType, long atrrVal, EquipItem wearEquip)
  126. {
  127. if (wearEquip == null) return eCompareType.None;
  128. long val = wearEquip.Attributes.GetValue(attributeType);
  129. return atrrVal == val ? eCompareType.None : (atrrVal > val ? eCompareType.Higth : eCompareType.Low);
  130. }
  131. }
  132. }