ShopPanel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System.Collections.Generic;
  2. using Core.Utility;
  3. using Fort23.Core;
  4. using GameLogic.Combat.CombatTool;
  5. namespace Fort23.Mono
  6. {
  7. [UIBinding(prefab = "ShopPanel")]
  8. public partial class ShopPanel : UIPanel
  9. {
  10. private List<AccountFileInfo.ShopData> _shopDatas;
  11. private List<ShopGroupWidgetType1> _shopGroupWidgetType1s = new List<ShopGroupWidgetType1>();
  12. List<EnergyWidget> _energyWidgets = new List<EnergyWidget>();
  13. // public bool isPauseCombat;
  14. private void Init()
  15. {
  16. isAddStack = true;
  17. }
  18. protected override void AddEvent()
  19. {
  20. EventManager.Instance.AddEventListener(CustomEventType.ShopRefence, ShopRefence);
  21. }
  22. protected override void DelEvent()
  23. {
  24. EventManager.Instance.RemoveEventListener(CustomEventType.ShopRefence, ShopRefence);
  25. }
  26. public override CTask GetFocus()
  27. {
  28. AppBarPanel.OpenPanel(this);
  29. return base.GetFocus();
  30. }
  31. public override CTask<bool> AsyncInit(object[] uiData)
  32. {
  33. // isPauseCombat = uiData[0] as bool? == true;
  34. return base.AsyncInit(uiData);
  35. }
  36. public async override CTask Show()
  37. {
  38. await base.Show();
  39. // if (isPauseCombat)
  40. // {
  41. // if (CombatController.currActiveCombat != null)
  42. // CombatController.currActiveCombat.isUpdate = false;
  43. // }
  44. foreach (var widget in _energyWidgets)
  45. {
  46. UIManager.Instance.DormancyGComponent(widget);
  47. }
  48. _energyWidgets.Clear();
  49. EnergyWidget energyWidget =
  50. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  51. energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  52. _energyWidgets.Add(energyWidget);
  53. energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  54. energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  55. _energyWidgets.Add(energyWidget);
  56. }
  57. private void ShopRefence(IEventData e)
  58. {
  59. CustomInit();
  60. }
  61. public override void AddButtonEvent()
  62. {
  63. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  64. }
  65. public async CTask CustomInit()
  66. {
  67. var dic = new Dictionary<string, string>();
  68. // YouLoftSDK.Instance.CustomEvent("OpenShopPanel", dic);
  69. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  70. {
  71. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  72. }
  73. _shopGroupWidgetType1s.Clear();
  74. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  75. foreach (var shopData in _shopDatas)
  76. {
  77. // if (shopData.id == 1 || shopData.id == 5)
  78. // {
  79. // ShopGroupWidgetType1 shopGroupWidgetType1 =
  80. // await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType1,
  81. // null, Content, isInstance: true);
  82. // _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  83. // await shopGroupWidgetType1.CustomInit(shopData);
  84. // }
  85. // else
  86. {
  87. ShopGroupWidgetType1 shopGroupWidgetType1 =
  88. await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType2,
  89. null, Content, isInstance: true);
  90. _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  91. await shopGroupWidgetType1.CustomInit(shopData);
  92. }
  93. }
  94. }
  95. public override void Close()
  96. {
  97. // if (isPauseCombat)
  98. // {
  99. // if (CombatController.currActiveCombat != null)
  100. // CombatController.currActiveCombat.isUpdate = true;
  101. // }
  102. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  103. {
  104. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  105. }
  106. _shopGroupWidgetType1s.Clear();
  107. foreach (var widget in _energyWidgets)
  108. {
  109. UIManager.Instance.DormancyGComponent(widget);
  110. }
  111. _energyWidgets.Clear();
  112. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  113. // if (mainUIPanel != null)
  114. // {
  115. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  116. // mainUIPanel.FindShop();
  117. // }
  118. base.Close();
  119. }
  120. public static async CTask<ShopPanel> OpenPanel(bool isPauseCombat = false)
  121. {
  122. ShopPanel shopPanel = await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { isPauseCombat });
  123. await shopPanel.CustomInit();
  124. return shopPanel;
  125. }
  126. }
  127. }