ShopPanel.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System.Collections.Generic;
  2. using Core.Language;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Combat.CombatTool;
  8. namespace Fort23.Mono
  9. {
  10. [UIBinding(prefab = "ShopPanel")]
  11. public partial class ShopPanel : UIPanel
  12. {
  13. private List<AccountFileInfo.ShopData> _shopDatas;
  14. private List<ShopGroupWidgetType1> _shopGroupWidgetType1s = new List<ShopGroupWidgetType1>();
  15. List<EnergyWidget> _energyWidgets = new List<EnergyWidget>();
  16. ShopBtnWidget currentSelectedShopBtnWidget;
  17. List<ShopBtnWidget> _shopBtnWidgets = new List<ShopBtnWidget>();
  18. private void Init()
  19. {
  20. isAddStack = true;
  21. IsShowAppBar = true;
  22. }
  23. protected override void AddEvent()
  24. {
  25. EventManager.Instance.AddEventListener(CustomEventType.ShopRefence, ShopRefence);
  26. }
  27. protected override void DelEvent()
  28. {
  29. EventManager.Instance.RemoveEventListener(CustomEventType.ShopRefence, ShopRefence);
  30. }
  31. public override CTask GetFocus()
  32. {
  33. AppBarPanel.OpenPanel(this);
  34. return base.GetFocus();
  35. }
  36. public async override CTask<bool> AsyncInit(object[] uiData)
  37. {
  38. ShopGroupConfig[] shopGroupConfigs = ConfigComponent.Instance.GetAll<ShopGroupConfig>();
  39. foreach (var shopGroupConfig in shopGroupConfigs)
  40. {
  41. ShopBtnWidget shopBtnWidget = await UIManager.Instance.CreateGComponent<ShopBtnWidget>(null, ShopBtnContent);
  42. shopBtnWidget.CustomInit(shopGroupConfig);
  43. shopBtnWidget.OnClick = OnClick;
  44. _shopBtnWidgets.Add(shopBtnWidget);
  45. if (currentSelectedShopBtnWidget == null)
  46. {
  47. currentSelectedShopBtnWidget = shopBtnWidget;
  48. }
  49. }
  50. ShopBtnContent.GetComponent<UIToggleList>().GetChildObj();
  51. currentSelectedShopBtnWidget.OnPointerClick();
  52. // isPauseCombat = uiData[0] as bool? == true;
  53. return await base.AsyncInit(uiData);
  54. }
  55. private async void OnClick(ItemWidgetBasic obj)
  56. {
  57. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  58. Text_Title.text = LanguageManager.Instance.Text(shopBtnWidget.ShopGroupConfig.shopName);
  59. ShopBtnContent.GetComponent<UIToggleList>().ClickWidget(shopBtnWidget.own.GetComponent<UIToggleWidgetBasic>());
  60. currentSelectedShopBtnWidget = shopBtnWidget;
  61. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  62. {
  63. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  64. }
  65. _shopGroupWidgetType1s.Clear();
  66. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  67. foreach (var shopData in _shopDatas)
  68. {
  69. ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopData.id);
  70. if (shopConfig.shopGroup == shopBtnWidget.ShopGroupConfig.ID)
  71. {
  72. // if (shopData.id == 1 || shopData.id == 5)
  73. // {
  74. // ShopGroupWidgetType1 shopGroupWidgetType1 =
  75. // await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType1,
  76. // null, Content, isInstance: true);
  77. // _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  78. // await shopGroupWidgetType1.CustomInit(shopData);
  79. // }
  80. // else
  81. {
  82. ShopGroupWidgetType1 shopGroupWidgetType1 =
  83. await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType2,
  84. null, Content, isInstance: true);
  85. _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  86. await shopGroupWidgetType1.CustomInit(shopData);
  87. }
  88. }
  89. }
  90. }
  91. public async override CTask Show()
  92. {
  93. await base.Show();
  94. foreach (var widget in _energyWidgets)
  95. {
  96. UIManager.Instance.DormancyGComponent(widget);
  97. }
  98. _energyWidgets.Clear();
  99. EnergyWidget energyWidget =
  100. await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  101. energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  102. _energyWidgets.Add(energyWidget);
  103. energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  104. energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  105. _energyWidgets.Add(energyWidget);
  106. }
  107. private void ShopRefence(IEventData e)
  108. {
  109. currentSelectedShopBtnWidget.OnPointerClick();
  110. }
  111. public override void AddButtonEvent()
  112. {
  113. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  114. }
  115. public override void Close()
  116. {
  117. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  118. {
  119. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  120. }
  121. _shopGroupWidgetType1s.Clear();
  122. foreach (var widget in _energyWidgets)
  123. {
  124. UIManager.Instance.DormancyGComponent(widget);
  125. }
  126. _energyWidgets.Clear();
  127. foreach (var shopBtnWidget in _shopBtnWidgets)
  128. {
  129. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  130. }
  131. _shopBtnWidgets.Clear();
  132. currentSelectedShopBtnWidget = null;
  133. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  134. // if (mainUIPanel != null)
  135. // {
  136. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  137. // mainUIPanel.FindShop();
  138. // }
  139. base.Close();
  140. }
  141. public static async CTask<ShopPanel> OpenPanel(bool isPauseCombat = false)
  142. {
  143. ShopPanel shopPanel = await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { isPauseCombat });
  144. return shopPanel;
  145. }
  146. }
  147. }