EquipEquipItemNestedCtrl.cs 5.1 KB

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