DragonEggEquipCtrl.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using FL.Data.Items;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. public class EquipParam
  14. {
  15. public long id; // 装备唯一id
  16. public EEquipType equipType;
  17. }
  18. /// <summary>
  19. /// UI逻辑处理类
  20. /// </summary>
  21. /// <typeparam name=""></typeparam>
  22. public partial class DragonEggEquipCtrl : UIController<DragonEggEquipVM>
  23. {
  24. private EquipItem _newEquip;
  25. private EquipItem _wearEquip;
  26. protected override void OnEnable(object intent)
  27. {
  28. AddUIListenres();
  29. ShowUI(intent as EquipParam);
  30. }
  31. protected override void OnDisable()
  32. {
  33. _newEquip = null;
  34. _wearEquip = null;
  35. RemoveUIListenres();
  36. }
  37. #region UI事件
  38. private void AddUIListenres()
  39. {
  40. VM.SellBtn.onClick.Add(OnClickSellBtn);
  41. VM.WearBtn.onClick.Add(OnClickWearBtn);
  42. VM.DecomposeBtn.onClick.Add(OnClickDecomposeBtn);
  43. }
  44. private void RemoveUIListenres()
  45. {
  46. VM.SellBtn.onClick.Remove(OnClickSellBtn);
  47. VM.WearBtn.onClick.Remove(OnClickWearBtn);
  48. VM.DecomposeBtn.onClick.Remove(OnClickDecomposeBtn);
  49. }
  50. #endregion
  51. /// <summary>
  52. /// 出售按钮事件
  53. /// </summary>
  54. /// <param name="context"></param>
  55. private void OnClickSellBtn(EventContext context)
  56. {
  57. if (_newEquip == null) return;
  58. if (_newEquip.FightingPower > _wearEquip.FightingPower)
  59. {
  60. XGame.Log.Warn($"当前要出售的装备{_newEquip.FightingPower}战力高于身上穿戴的{_wearEquip.FightingPower}");
  61. ConfirmationBoxParam dialogParam = new ConfirmationBoxParam()
  62. {
  63. cnt = StringDefine.sellHightPowerEquip,
  64. tipsKey = EDayTipsKey.SellEquip,
  65. onPromiseCallback = () => { SellEquip(); },
  66. };
  67. Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam);
  68. return;
  69. }
  70. SellEquip();
  71. }
  72. private void SellEquip()
  73. {
  74. DragonEggService.Instance.SellEquip(_newEquip);
  75. ClosePanel();
  76. }
  77. /// <summary>
  78. /// 穿戴|替换按钮事件
  79. /// </summary>
  80. /// <param name="context"></param>
  81. private void OnClickWearBtn(EventContext context)
  82. {
  83. if (_newEquip == null) return;
  84. DragonEggService.Instance.OnChangeEquip(_newEquip.EquipType, _newEquip);
  85. ClosePanel();
  86. }
  87. /// <summary>
  88. /// 分解按钮事件
  89. /// </summary>
  90. /// <param name="context"></param>
  91. private void OnClickDecomposeBtn(EventContext context)
  92. {
  93. ClosePanel();
  94. }
  95. private void ClosePanel()
  96. {
  97. Context.ClosePanel();
  98. }
  99. private void ShowUI(EquipParam param)
  100. {
  101. if (param == null) return;
  102. var id = param.id;
  103. if (param?.equipType != null)
  104. {
  105. var wearPartEquip = ItemData.Instance.GetEquipData(param.equipType);
  106. if (wearPartEquip != null && wearPartEquip.Id == id)
  107. {
  108. ShowEquipInfo(wearPartEquip);
  109. return;
  110. }
  111. }
  112. _newEquip = ItemData.Instance.GetNewEquip(param.id);
  113. if (_newEquip == null) return;
  114. _wearEquip = ItemData.Instance.GetEquipData(_newEquip.EquipType);
  115. bool bShowWear = _wearEquip != null;
  116. if (bShowWear)
  117. {
  118. VM.WearEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip, true);
  119. }
  120. VM.NewEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip);
  121. ShowBtnUI(bShowWear);
  122. }
  123. private void ShowBtnUI(bool bWear)
  124. {
  125. if (bWear)
  126. {
  127. //1_替换和出售 2_【替换】、【出售】、【分解】三个按钮
  128. VM.BtnState.selectedIndex = DragonEggData.Instance.IsUnLockDecompose ? 2 : 1;
  129. }
  130. else
  131. {
  132. // 当前没有同位置的装备,可使用的功能按钮只有【穿戴】
  133. VM.BtnState.selectedIndex = 0;
  134. }
  135. }
  136. private void ShowEquipInfo(EquipItem equip)
  137. {
  138. // 展示装备属性详情
  139. VM.BtnState.selectedIndex = 3;
  140. VM.NewEquipItem.Ctrl.ShowUI(equip, equip, true);
  141. }
  142. }
  143. }