ShopPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. private CTask _cTask;
  35. public async override CTask GetFocus()
  36. {
  37. AppBarPanel.OpenPanel(this);
  38. _cTask = CTask.Create();
  39. if (currentSelectedShopBtnWidget == null)
  40. {
  41. foreach (var shopBtnWidget in _shopBtnWidgets)
  42. {
  43. if (shopBtnWidget.ShopGroupConfig.ID == shopId)
  44. {
  45. currentSelectedShopBtnWidget = shopBtnWidget;
  46. break;
  47. }
  48. }
  49. if (currentSelectedShopBtnWidget == null)
  50. {
  51. _shopBtnWidgets[0]?.OnPointerClick();
  52. }
  53. else
  54. {
  55. currentSelectedShopBtnWidget.OnPointerClick();
  56. }
  57. }
  58. else
  59. {
  60. currentSelectedShopBtnWidget.OnPointerClick();
  61. }
  62. await _cTask;
  63. if (PlayerGuideManager.Instance.GuideIsCanDo(7))
  64. {
  65. await PlayerGuideManager.Instance.SetGuid(7);
  66. }
  67. base.GetFocus();
  68. }
  69. public override CTask LoseFocus()
  70. {
  71. // TitlePanel.ClosePanel();
  72. return base.LoseFocus();
  73. }
  74. public int Sort(ShopGroupConfig s, ShopGroupConfig b)
  75. {
  76. return s.pageSortNum.CompareTo(b.pageSortNum);
  77. }
  78. public async override CTask<bool> AsyncInit(object[] uiData)
  79. {
  80. shopId = int.Parse(uiData[0].ToString());
  81. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  82. {
  83. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  84. }
  85. _shopGroupWidgetType1s.Clear();
  86. foreach (var shopBtnWidget in _shopBtnWidgets)
  87. {
  88. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  89. }
  90. _shopBtnWidgets.Clear();
  91. currentSelectedShopBtnWidget = null;
  92. List<ShopGroupConfig> shopGroupConfigs = ConfigComponent.Instance.GetAll<ShopGroupConfig>().ToList();
  93. shopGroupConfigs.Sort(Sort);
  94. foreach (var shopGroupConfig in shopGroupConfigs)
  95. {
  96. if (!shopGroupConfig.isShow)
  97. continue;
  98. #if UNITY_ANDROID && !UNITY_EDITOR
  99. //gm商店不显示
  100. if (shopGroupConfig.ID == 1 || shopGroupConfig.ID == 2 || shopGroupConfig.ID == 3)
  101. {
  102. continue;
  103. }
  104. #endif
  105. ShopBtnWidget shopBtnWidget =
  106. await UIManager.Instance.CreateGComponent<ShopBtnWidget>(null, ShopBtnContent);
  107. shopBtnWidget.CustomInit(shopGroupConfig);
  108. shopBtnWidget.OnClick = OnClick;
  109. _shopBtnWidgets.Add(shopBtnWidget);
  110. // if (shopGroupConfig.ID == shopId)
  111. // {
  112. // currentSelectedShopBtnWidget = shopBtnWidget;
  113. // }
  114. }
  115. ShopBtnContent.GetComponent<UIToggleList>().GetChildObj();
  116. // if (currentSelectedShopBtnWidget == null)
  117. // {
  118. // _shopBtnWidgets[0]?.OnPointerClick();
  119. // }
  120. // else
  121. // {
  122. // currentSelectedShopBtnWidget.OnPointerClick();
  123. // }
  124. return await base.AsyncInit(uiData);
  125. }
  126. public void SelectWidget(int shopId)
  127. {
  128. this.shopId = shopId;
  129. currentSelectedShopBtnWidget = null;
  130. if (currentSelectedShopBtnWidget == null)
  131. {
  132. foreach (var shopBtnWidget in _shopBtnWidgets)
  133. {
  134. if (shopBtnWidget.ShopGroupConfig.ID == shopId)
  135. {
  136. currentSelectedShopBtnWidget = shopBtnWidget;
  137. break;
  138. }
  139. }
  140. if (currentSelectedShopBtnWidget == null)
  141. {
  142. _shopBtnWidgets[0]?.OnPointerClick();
  143. }
  144. else
  145. {
  146. currentSelectedShopBtnWidget.OnPointerClick();
  147. }
  148. }
  149. else
  150. {
  151. currentSelectedShopBtnWidget.OnPointerClick();
  152. }
  153. }
  154. private async void OnClick(ItemWidgetBasic obj)
  155. {
  156. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  157. TitlePanel.OpenPanel(shopBtnWidget.ShopGroupConfig.titleShowItemIds.ToList());
  158. Text_Title.text = LanguageManager.Instance.Text(shopBtnWidget.ShopGroupConfig.shopName);
  159. ShopBtnContent.GetComponent<UIToggleList>()
  160. .ClickWidget(shopBtnWidget.own.GetComponent<UIToggleWidgetBasic>());
  161. currentSelectedShopBtnWidget = shopBtnWidget;
  162. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  163. {
  164. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  165. }
  166. _shopGroupWidgetType1s.Clear();
  167. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  168. foreach (var shopData in _shopDatas)
  169. {
  170. ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopData.id);
  171. if (shopConfig.shopGroup == shopBtnWidget.ShopGroupConfig.ID)
  172. {
  173. if (shopConfig.shopItemGroup == 4)
  174. {
  175. ShopBoxWidget shopBoxWidget =
  176. await UIManager.Instance.CreateGComponent<ShopBoxWidget>(null, Content);
  177. shopBoxWidget.CustomInit();
  178. _shopGroupWidgetType1s.Add(shopBoxWidget);
  179. }
  180. // if (shopData.id == 1 || shopData.id == 5)
  181. // {
  182. // ShopGroupWidgetType1 shopGroupWidgetType1 =
  183. // await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType1,
  184. // null, Content, isInstance: true);
  185. // _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  186. // await shopGroupWidgetType1.CustomInit(shopData);
  187. // }
  188. else
  189. {
  190. #if UNITY_ANDROID && !UNITY_EDITOR && Taptap
  191. //
  192. //付费国内不显示
  193. if (shopConfig.shopItemGroup == 5)
  194. {
  195. continue;
  196. }
  197. #endif
  198. ShopGroupWidgetType1 shopGroupWidgetType1 =
  199. await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(
  200. ShopGroupWidgetType2,
  201. null, Content, isInstance: true);
  202. _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  203. await shopGroupWidgetType1.CustomInit(shopData);
  204. }
  205. }
  206. }
  207. _cTask?.SetResult();
  208. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 1))
  209. {
  210. PlayerGuideManager.Instance.NextGuide();
  211. }
  212. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 3))
  213. {
  214. PlayerGuideManager.Instance.NextGuide();
  215. }
  216. else if (PlayerGuideManager.Instance.GuideIsCanDo(7, 4))
  217. {
  218. PlayerGuideManager.Instance.NextGuide();
  219. }
  220. }
  221. public async override CTask Show()
  222. {
  223. await base.Show();
  224. // foreach (var widget in _energyWidgets)
  225. // {
  226. // UIManager.Instance.DormancyGComponent(widget);
  227. // }
  228. //
  229. // _energyWidgets.Clear();
  230. // EnergyWidget energyWidget =
  231. // await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  232. // energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  233. // _energyWidgets.Add(energyWidget);
  234. // energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  235. // energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  236. // _energyWidgets.Add(energyWidget);
  237. }
  238. private void ShopRefence(IEventData e)
  239. {
  240. currentSelectedShopBtnWidget.OnPointerClick();
  241. }
  242. public override void AddButtonEvent()
  243. {
  244. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  245. }
  246. public async override CTask Close()
  247. {
  248. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  249. {
  250. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  251. }
  252. _shopGroupWidgetType1s.Clear();
  253. foreach (var shopBtnWidget in _shopBtnWidgets)
  254. {
  255. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  256. }
  257. _shopBtnWidgets.Clear();
  258. currentSelectedShopBtnWidget = null;
  259. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  260. // if (mainUIPanel != null)
  261. // {
  262. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  263. // mainUIPanel.FindShop();
  264. // }
  265. await base.Close();
  266. }
  267. public static async CTask<ShopPanel> OpenPanel(int shopId)
  268. {
  269. ShopPanel shopPanel =
  270. await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { shopId },
  271. isFullUI: true);
  272. AudioManager.Instance.PlayAudio("ui_shangdian.wav");
  273. return shopPanel;
  274. }
  275. }
  276. }