ShopPanel.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. private async void OnClick(ItemWidgetBasic obj)
  127. {
  128. ShopBtnWidget shopBtnWidget = obj as ShopBtnWidget;
  129. TitlePanel.OpenPanel(shopBtnWidget.ShopGroupConfig.titleShowItemIds.ToList());
  130. Text_Title.text = LanguageManager.Instance.Text(shopBtnWidget.ShopGroupConfig.shopName);
  131. ShopBtnContent.GetComponent<UIToggleList>()
  132. .ClickWidget(shopBtnWidget.own.GetComponent<UIToggleWidgetBasic>());
  133. currentSelectedShopBtnWidget = shopBtnWidget;
  134. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  135. {
  136. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  137. }
  138. _shopGroupWidgetType1s.Clear();
  139. _shopDatas = ShopManger.Instance.GetAllShopConfig();
  140. foreach (var shopData in _shopDatas)
  141. {
  142. ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopData.id);
  143. if (shopConfig.shopGroup == shopBtnWidget.ShopGroupConfig.ID)
  144. {
  145. if (shopConfig.shopItemGroup == 4)
  146. {
  147. ShopBoxWidget shopBoxWidget =
  148. await UIManager.Instance.CreateGComponent<ShopBoxWidget>(null, Content);
  149. shopBoxWidget.CustomInit();
  150. _shopGroupWidgetType1s.Add(shopBoxWidget);
  151. }
  152. // if (shopData.id == 1 || shopData.id == 5)
  153. // {
  154. // ShopGroupWidgetType1 shopGroupWidgetType1 =
  155. // await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(ShopGroupWidgetType1,
  156. // null, Content, isInstance: true);
  157. // _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  158. // await shopGroupWidgetType1.CustomInit(shopData);
  159. // }
  160. else
  161. {
  162. #if UNITY_ANDROID && !UNITY_EDITOR && Taptap
  163. //
  164. //付费国内不显示
  165. if (shopConfig.shopItemGroup == 5)
  166. {
  167. continue;
  168. }
  169. #endif
  170. ShopGroupWidgetType1 shopGroupWidgetType1 =
  171. await UIManager.Instance.CreateGComponentForObject<ShopGroupWidgetType1>(
  172. ShopGroupWidgetType2,
  173. null, Content, isInstance: true);
  174. _shopGroupWidgetType1s.Add(shopGroupWidgetType1);
  175. await shopGroupWidgetType1.CustomInit(shopData);
  176. }
  177. }
  178. }
  179. _cTask?.SetResult();
  180. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 1))
  181. {
  182. PlayerGuideManager.Instance.NextGuide();
  183. }
  184. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 3))
  185. {
  186. PlayerGuideManager.Instance.NextGuide();
  187. }
  188. else if (PlayerGuideManager.Instance.GuideIsCanDo(7, 4))
  189. {
  190. PlayerGuideManager.Instance.NextGuide();
  191. }
  192. }
  193. public async override CTask Show()
  194. {
  195. await base.Show();
  196. // foreach (var widget in _energyWidgets)
  197. // {
  198. // UIManager.Instance.DormancyGComponent(widget);
  199. // }
  200. //
  201. // _energyWidgets.Clear();
  202. // EnergyWidget energyWidget =
  203. // await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  204. // energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  205. // _energyWidgets.Add(energyWidget);
  206. // energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  207. // energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  208. // _energyWidgets.Add(energyWidget);
  209. }
  210. private void ShopRefence(IEventData e)
  211. {
  212. currentSelectedShopBtnWidget.OnPointerClick();
  213. }
  214. public override void AddButtonEvent()
  215. {
  216. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopPanel>(); });
  217. }
  218. public async override CTask Close()
  219. {
  220. foreach (var shopGroupWidgetType1 in _shopGroupWidgetType1s)
  221. {
  222. UIManager.Instance.DormancyGComponent(shopGroupWidgetType1);
  223. }
  224. _shopGroupWidgetType1s.Clear();
  225. foreach (var shopBtnWidget in _shopBtnWidgets)
  226. {
  227. UIManager.Instance.DormancyGComponent(shopBtnWidget);
  228. }
  229. _shopBtnWidgets.Clear();
  230. currentSelectedShopBtnWidget = null;
  231. // MainUIPanel mainUIPanel = UIManager.Instance.GetComponent<MainUIPanel>();
  232. // if (mainUIPanel != null)
  233. // {
  234. // mainUIPanel.shopDatas = AccountFileInfo.Instance.playerData.shopDatas;
  235. // mainUIPanel.FindShop();
  236. // }
  237. await base.Close();
  238. }
  239. public static async CTask<ShopPanel> OpenPanel(int shopId)
  240. {
  241. ShopPanel shopPanel =
  242. await UIManager.Instance.LoadAndOpenPanel<ShopPanel>(null, uiData: new object[] { shopId },
  243. isFullUI: true);
  244. AudioManager.Instance.PlayAudio("ui_shangdian.wav");
  245. return shopPanel;
  246. }
  247. }
  248. }