ShopPanel.cs 7.2 KB

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