ShopPanel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. TitlePanel.OpenPanel(new List<int>() { 1001, 1002 });
  34. AppBarPanel.OpenPanel(this);
  35. return base.GetFocus();
  36. }
  37. public override CTask LoseFocus()
  38. {
  39. TitlePanel.ClosePanel();
  40. return base.LoseFocus();
  41. }
  42. public async override CTask<bool> AsyncInit(object[] uiData)
  43. {
  44. ShopGroupConfig[] shopGroupConfigs = ConfigComponent.Instance.GetAll<ShopGroupConfig>();
  45. foreach (var shopGroupConfig in shopGroupConfigs)
  46. {
  47. ShopBtnWidget shopBtnWidget = await UIManager.Instance.CreateGComponent<ShopBtnWidget>(null, ShopBtnContent);
  48. shopBtnWidget.CustomInit(shopGroupConfig);
  49. shopBtnWidget.OnClick = OnClick;
  50. _shopBtnWidgets.Add(shopBtnWidget);
  51. if (currentSelectedShopBtnWidget == null)
  52. {
  53. currentSelectedShopBtnWidget = shopBtnWidget;
  54. }
  55. }
  56. ShopBtnContent.GetComponent<UIToggleList>().GetChildObj();
  57. currentSelectedShopBtnWidget.OnPointerClick();
  58. // isPauseCombat = uiData[0] as bool? == true;
  59. return await base.AsyncInit(uiData);
  60. }
  61. private async void OnClick(ItemWidgetBasic obj)
  62. {
  63. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  64. Text_Title.text = LanguageManager.Instance.Text(shopBtnWidget.ShopGroupConfig.shopName);
  65. ShopBtnContent.GetComponent<UIToggleList>().ClickWidget(shopBtnWidget.own.GetComponent<UIToggleWidgetBasic>());
  66. currentSelectedShopBtnWidget = shopBtnWidget;
  67. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  68. {
  69. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  70. }
  71. _shopGroupWidgetType1s.Clear();
  72. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  73. foreach (var shopData in _shopDatas)
  74. {
  75. ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopData.id);
  76. if (shopConfig.shopGroup == shopBtnWidget.ShopGroupConfig.ID)
  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. }
  97. public async override CTask Show()
  98. {
  99. await base.Show();
  100. // foreach (var widget in _energyWidgets)
  101. // {
  102. // UIManager.Instance.DormancyGComponent(widget);
  103. // }
  104. //
  105. // _energyWidgets.Clear();
  106. // EnergyWidget energyWidget =
  107. // await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  108. // energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  109. // _energyWidgets.Add(energyWidget);
  110. // energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  111. // energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  112. // _energyWidgets.Add(energyWidget);
  113. }
  114. private void ShopRefence(IEventData e)
  115. {
  116. currentSelectedShopBtnWidget.OnPointerClick();
  117. }
  118. public override void AddButtonEvent()
  119. {
  120. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  121. }
  122. public override void Close()
  123. {
  124. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  125. {
  126. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  127. }
  128. _shopGroupWidgetType1s.Clear();
  129. // foreach (var widget in _energyWidgets)
  130. // {
  131. // UIManager.Instance.DormancyGComponent(widget);
  132. // }
  133. //
  134. // _energyWidgets.Clear();
  135. foreach (var shopBtnWidget in _shopBtnWidgets)
  136. {
  137. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  138. }
  139. _shopBtnWidgets.Clear();
  140. currentSelectedShopBtnWidget = null;
  141. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  142. // if (mainUIPanel != null)
  143. // {
  144. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  145. // mainUIPanel.FindShop();
  146. // }
  147. base.Close();
  148. }
  149. public static async CTask<ShopPanel> OpenPanel(bool isPauseCombat = false)
  150. {
  151. ShopPanel shopPanel = await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { isPauseCombat });
  152. return shopPanel;
  153. }
  154. }
  155. }