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