ShopPanel.cs 8.5 KB

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