SelectBreakthroughItemPanel.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using Core.Language;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using GameLogic.Bag;
  7. using UnityEngine;
  8. namespace Fort23.Mono
  9. {
  10. [UIBinding(prefab = "SelectBreakthroughItemPanel")]
  11. public partial class SelectBreakthroughItemPanel : UIPanel
  12. {
  13. ItemConfig itemConfig;
  14. private Action callBack;
  15. private Transform weidgetFater;
  16. BreakthroughItemWidget breakthrough;
  17. private void Init()
  18. {
  19. IsShowAppBar = false;
  20. isAddStack = true;
  21. }
  22. protected override void AddEvent()
  23. {
  24. EventManager.Instance.AddEventListener(CustomEventType.ItemUpdate, ItemUpdateEvent);
  25. }
  26. private void ItemUpdateEvent(IEventData e)
  27. {
  28. CustomInit();
  29. }
  30. protected override void DelEvent()
  31. {
  32. EventManager.Instance.RemoveEventListener(CustomEventType.ItemUpdate, ItemUpdateEvent);
  33. }
  34. public override void AddButtonEvent()
  35. {
  36. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  37. Btn_Affirm.onClick.AddListener(() =>
  38. {
  39. if (!PlayerManager.Instance.BagController.IsEnough(breakthrough.itemId, 1))
  40. {
  41. ItemSourcePanel.OpenPanel(itemConfig.ID, true);
  42. return;
  43. }
  44. this.callBack?.Invoke();
  45. EventManager.Instance.Dispatch(CustomEventType.RefenceBreakthrough, null);
  46. UIManager.Instance.HideUIUIPanel(this);
  47. });
  48. Btn_Cancel.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel(this); });
  49. Btn_Source.onClick.AddListener(() => { ItemSourcePanel.OpenPanel(itemConfig.ID, true); });
  50. }
  51. public override CTask<bool> AsyncInit(object[] uiData)
  52. {
  53. breakthrough = uiData[0] as BreakthroughItemWidget;
  54. this.callBack = uiData[1] as Action;
  55. weidgetFater = breakthrough.transform.parent;
  56. breakthrough.transform.SetParent(this.transform);
  57. breakthrough.Icon_Select.gameObject.SetActive(true);
  58. CustomInit();
  59. return base.AsyncInit(uiData);
  60. }
  61. public void CustomInit()
  62. {
  63. itemConfig = ConfigComponent.Instance.Get<ItemConfig>(breakthrough.itemId);
  64. Text_ItemName.text = LanguageManager.Instance.Text(itemConfig.itemName);
  65. Text_ItemDesc.text = LanguageManager.Instance.Text(itemConfig.itemDesc);
  66. Icon_ItemIcon.icon_name = itemConfig.icon;
  67. if (itemConfig.itemTag == 3)
  68. {
  69. Text_SucceedDesc.text = $"+{itemConfig.associateVlaue[2]}%";
  70. }
  71. else
  72. {
  73. Text_SucceedDesc.text = $"+{itemConfig.associateVlaue[2]}%";
  74. }
  75. if (breakthrough.itemInfo == null)
  76. {
  77. if (PlayerManager.Instance.BagController.IsEnough(breakthrough.itemId, 1))
  78. {
  79. Text_Affirm.text = "使用";
  80. Btn_Affirm.gameObject.SetActive(true);
  81. Btn_Cancel.gameObject.SetActive(true);
  82. Text_NoEnough.gameObject.SetActive(false);
  83. }
  84. else
  85. {
  86. Text_Affirm.text = "使用";
  87. Btn_Affirm.gameObject.SetActive(true);
  88. Btn_Cancel.gameObject.SetActive(true);
  89. Text_NoEnough.gameObject.SetActive(true);
  90. }
  91. }
  92. else
  93. {
  94. Text_Affirm.text = "取消";
  95. Btn_Affirm.gameObject.SetActive(true);
  96. Btn_Cancel.gameObject.SetActive(true);
  97. Text_NoEnough.gameObject.SetActive(false);
  98. }
  99. }
  100. public async override CTask Close()
  101. {
  102. breakthrough.Icon_Select.gameObject.SetActive(false);
  103. breakthrough.transform.SetParent(weidgetFater);
  104. weidgetFater = null;
  105. breakthrough = null;
  106. callBack = null;
  107. await base.Close();
  108. }
  109. public async static CTask<SelectBreakthroughItemPanel> OpenPanel(BreakthroughItemWidget breakthroughItemWidget,
  110. Action callBack)
  111. {
  112. SelectBreakthroughItemPanel selectBreakthroughItemPanel =
  113. await UIManager.Instance.LoadAndOpenPanel<SelectBreakthroughItemPanel>(null, UILayer.Middle,
  114. uiData: new object[] { breakthroughItemWidget, callBack },
  115. isFocus: false);
  116. return selectBreakthroughItemPanel;
  117. }
  118. }
  119. }