ShopPanel.cs 9.2 KB

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