ShopPanel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. AppBarPanel.OpenPanel(this);
  36. if (currentSelectedShopBtnWidget != null)
  37. {
  38. currentSelectedShopBtnWidget.OnPointerClick();
  39. }
  40. return base.GetFocus();
  41. }
  42. public override CTask LoseFocus()
  43. {
  44. // TitlePanel.ClosePanel();
  45. return base.LoseFocus();
  46. }
  47. public int Sort(ShopGroupConfig s, ShopGroupConfig b)
  48. {
  49. return s.pageSortNum.CompareTo(b.pageSortNum);
  50. }
  51. public async override CTask<bool> AsyncInit(object[] uiData)
  52. {
  53. int shopId = int.Parse(uiData[0].ToString());
  54. List<ShopGroupConfig> shopGroupConfigs = ConfigComponent.Instance.GetAll<ShopGroupConfig>().ToList();
  55. shopGroupConfigs.Sort(Sort);
  56. foreach (var shopGroupConfig in shopGroupConfigs)
  57. {
  58. if (!shopGroupConfig.isShow)
  59. continue;
  60. ShopBtnWidget shopBtnWidget =
  61. await UIManager.Instance.CreateGComponent<ShopBtnWidget>(null, ShopBtnContent);
  62. shopBtnWidget.CustomInit(shopGroupConfig);
  63. shopBtnWidget.OnClick = OnClick;
  64. _shopBtnWidgets.Add(shopBtnWidget);
  65. if (shopGroupConfig.ID == shopId)
  66. {
  67. currentSelectedShopBtnWidget = shopBtnWidget;
  68. }
  69. }
  70. ShopBtnContent.GetComponent<UIToggleList>().GetChildObj();
  71. if (currentSelectedShopBtnWidget == null)
  72. {
  73. _shopBtnWidgets[0]?.OnPointerClick();
  74. }
  75. else
  76. {
  77. currentSelectedShopBtnWidget.OnPointerClick();
  78. }
  79. // isPauseCombat = uiData[0] as bool? == true;
  80. return await base.AsyncInit(uiData);
  81. }
  82. private async void OnClick(ItemWidgetBasic obj)
  83. {
  84. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  85. TitlePanel.OpenPanel(shopBtnWidget.ShopGroupConfig.titleShowItemIds.ToList());
  86. Text_Title.text = LanguageManager.Instance.Text(shopBtnWidget.ShopGroupConfig.shopName);
  87. ShopBtnContent.GetComponent<UIToggleList>()
  88. .ClickWidget(shopBtnWidget.own.GetComponent<UIToggleWidgetBasic>());
  89. currentSelectedShopBtnWidget = shopBtnWidget;
  90. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  91. {
  92. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  93. }
  94. _shopGroupWidgetType1s.Clear();
  95. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  96. foreach (var shopData in _shopDatas)
  97. {
  98. ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopData.id);
  99. if (shopConfig.shopGroup == shopBtnWidget.ShopGroupConfig.ID)
  100. {
  101. if (shopConfig.shopItemGroup == 4)
  102. {
  103. ShopBoxWidget shopBoxWidget =
  104. await UIManager.Instance.CreateGComponent<ShopBoxWidget>(null, Content);
  105. shopBoxWidget.CustomInit();
  106. _shopGroupWidgetType1s.Add(shopBoxWidget);
  107. }
  108. // if (shopData.id == 1 || shopData.id == 5)
  109. // {
  110. // ShopGroupWidgetType1 shopGroupWidgetType1 =
  111. // await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType1,
  112. // null, Content, isInstance: true);
  113. // _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  114. // await shopGroupWidgetType1.CustomInit(shopData);
  115. // }
  116. else
  117. {
  118. ShopGroupWidgetType1 shopGroupWidgetType1 =
  119. await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(
  120. ShopGroupWidgetType2,
  121. null, Content, isInstance: true);
  122. _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  123. await shopGroupWidgetType1.CustomInit(shopData);
  124. }
  125. }
  126. }
  127. }
  128. public async override CTask Show()
  129. {
  130. await base.Show();
  131. // foreach (var widget in _energyWidgets)
  132. // {
  133. // UIManager.Instance.DormancyGComponent(widget);
  134. // }
  135. //
  136. // _energyWidgets.Clear();
  137. // EnergyWidget energyWidget =
  138. // await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  139. // energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  140. // _energyWidgets.Add(energyWidget);
  141. // energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  142. // energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  143. // _energyWidgets.Add(energyWidget);
  144. }
  145. private void ShopRefence(IEventData e)
  146. {
  147. currentSelectedShopBtnWidget.OnPointerClick();
  148. }
  149. public override void AddButtonEvent()
  150. {
  151. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  152. }
  153. public async override CTask Close()
  154. {
  155. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  156. {
  157. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  158. }
  159. _shopGroupWidgetType1s.Clear();
  160. // foreach (var widget in _energyWidgets)
  161. // {
  162. // UIManager.Instance.DormancyGComponent(widget);
  163. // }
  164. //
  165. // _energyWidgets.Clear();
  166. foreach (var shopBtnWidget in _shopBtnWidgets)
  167. {
  168. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  169. }
  170. _shopBtnWidgets.Clear();
  171. currentSelectedShopBtnWidget = null;
  172. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  173. // if (mainUIPanel != null)
  174. // {
  175. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  176. // mainUIPanel.FindShop();
  177. // }
  178. await base.Close();
  179. }
  180. public static async CTask<ShopPanel> OpenPanel(int shopId)
  181. {
  182. ShopPanel shopPanel =
  183. await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { shopId },
  184. isFullUI: true);
  185. AudioManager.Instance.PlayAudio("ui_shangdian.wav");
  186. return shopPanel;
  187. }
  188. }
  189. }