ShopPanel.cs 5.2 KB

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