ShopPanel.cs 7.7 KB

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