ShopPanel.cs 7.5 KB

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