ShopPanel.cs 8.9 KB

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