ShopPanel.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. ShopBtnWidget shopBtnWidget = await UIManager.Instance.CreateGComponent<ShopBtnWidget>(null, ShopBtnContent);
  55. shopBtnWidget.CustomInit(shopGroupConfig);
  56. shopBtnWidget.OnClick = OnClick;
  57. _shopBtnWidgets.Add(shopBtnWidget);
  58. if (currentSelectedShopBtnWidget == null)
  59. {
  60. currentSelectedShopBtnWidget = shopBtnWidget;
  61. }
  62. }
  63. ShopBtnContent.GetComponent<UIToggleList>().GetChildObj();
  64. currentSelectedShopBtnWidget.OnPointerClick();
  65. // isPauseCombat = uiData[0] as bool? == true;
  66. return await base.AsyncInit(uiData);
  67. }
  68. private async void OnClick(ItemWidgetBasic obj)
  69. {
  70. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  71. Text_Title.text = LanguageManager.Instance.Text(shopBtnWidget.ShopGroupConfig.shopName);
  72. ShopBtnContent.GetComponent<UIToggleList>().ClickWidget(shopBtnWidget.own.GetComponent<UIToggleWidgetBasic>());
  73. currentSelectedShopBtnWidget = shopBtnWidget;
  74. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  75. {
  76. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  77. }
  78. _shopGroupWidgetType1s.Clear();
  79. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  80. foreach (var shopData in _shopDatas)
  81. {
  82. ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopData.id);
  83. if (shopConfig.shopGroup == shopBtnWidget.ShopGroupConfig.ID)
  84. {
  85. if (shopConfig.shopItemGroup == 4)
  86. {
  87. ShopBoxWidget shopBoxWidget = await UIManager.Instance.CreateGComponent<ShopBoxWidget>(null, Content);
  88. shopBoxWidget.CustomInit();
  89. _shopGroupWidgetType1s.Add(shopBoxWidget);
  90. }
  91. // if (shopData.id == 1 || shopData.id == 5)
  92. // {
  93. // ShopGroupWidgetType1 shopGroupWidgetType1 =
  94. // await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType1,
  95. // null, Content, isInstance: true);
  96. // _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  97. // await shopGroupWidgetType1.CustomInit(shopData);
  98. // }
  99. else
  100. {
  101. ShopGroupWidgetType1 shopGroupWidgetType1 =
  102. await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType2,
  103. null, Content, isInstance: true);
  104. _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  105. await shopGroupWidgetType1.CustomInit(shopData);
  106. }
  107. }
  108. }
  109. }
  110. public async override CTask Show()
  111. {
  112. await base.Show();
  113. // foreach (var widget in _energyWidgets)
  114. // {
  115. // UIManager.Instance.DormancyGComponent(widget);
  116. // }
  117. //
  118. // _energyWidgets.Clear();
  119. // EnergyWidget energyWidget =
  120. // await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  121. // energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  122. // _energyWidgets.Add(energyWidget);
  123. // energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  124. // energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  125. // _energyWidgets.Add(energyWidget);
  126. }
  127. private void ShopRefence(IEventData e)
  128. {
  129. currentSelectedShopBtnWidget.OnPointerClick();
  130. }
  131. public override void AddButtonEvent()
  132. {
  133. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  134. }
  135. public override void Close()
  136. {
  137. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  138. {
  139. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  140. }
  141. _shopGroupWidgetType1s.Clear();
  142. // foreach (var widget in _energyWidgets)
  143. // {
  144. // UIManager.Instance.DormancyGComponent(widget);
  145. // }
  146. //
  147. // _energyWidgets.Clear();
  148. foreach (var shopBtnWidget in _shopBtnWidgets)
  149. {
  150. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  151. }
  152. _shopBtnWidgets.Clear();
  153. currentSelectedShopBtnWidget = null;
  154. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  155. // if (mainUIPanel != null)
  156. // {
  157. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  158. // mainUIPanel.FindShop();
  159. // }
  160. base.Close();
  161. }
  162. public static async CTask<ShopPanel> OpenPanel(bool isPauseCombat = false)
  163. {
  164. ShopPanel shopPanel = await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { isPauseCombat },isFullUI:true);
  165. AudioManager.Instance.PlayAudio("ui_shangdian.wav");
  166. return shopPanel;
  167. }
  168. }
  169. }