GachaPanel.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Audio;
  5. using Core.Language;
  6. using Core.Utility;
  7. using Excel2Json;
  8. using Fort23.Core;
  9. using Fort23.UTool;
  10. using GameLogic.Bag;
  11. using UnityEngine;
  12. using Random = UnityEngine.Random;
  13. namespace Fort23.Mono
  14. {
  15. [UIBinding(prefab = "GachaPanel")]
  16. public partial class GachaPanel : UIPanel
  17. {
  18. List<WidgetItem> widgetItems = new List<WidgetItem>();
  19. private List<ItemInfo> itemInfos;
  20. private int type;
  21. private OpenBoxConfig _openBoxConfig;
  22. List<GameObjectPool> _gameObjectPools = new List<GameObjectPool>();
  23. List<EnergyWidget> _energyWidgets = new List<EnergyWidget>();
  24. private AccountFileInfo.SummonData SummonData;
  25. private void Init()
  26. {
  27. isAddStack = true;
  28. IsShowAppBar = false;
  29. }
  30. public override CTask GetFocus()
  31. {
  32. AppBarPanel.ClosePanel();
  33. TitlePanel.OpenPanel(new List<int>() { GlobalParam.Item_Coin_ID, GlobalParam.Item_Diamond_ID });
  34. return base.GetFocus();
  35. }
  36. public override CTask LoseFocus()
  37. {
  38. TitlePanel.ClosePanel();
  39. return base.LoseFocus();
  40. }
  41. protected override void AddEvent()
  42. {
  43. }
  44. protected override void DelEvent()
  45. {
  46. }
  47. public override void AddButtonEvent()
  48. {
  49. tenButton.onClick.AddListener(() =>
  50. {
  51. float beLv = Utility.UtilTools.GetRandomByWeight(_openBoxConfig.betPara1.ToList(), _openBoxConfig.betPara2);
  52. foreach (var itemInfo in itemInfos)
  53. {
  54. ItemInfo itemInfo1 = new ItemInfo(itemInfo.itemID, (long)(itemInfo.count.Value * (beLv - 1)));
  55. PlayerManager.Instance.BagController.AddItem(itemInfo1);
  56. }
  57. UIManager.Instance.HideUIUIPanel<GachaPanel>();
  58. });
  59. oneButton.onClick.AddListener(async () =>
  60. {
  61. /*if (type == 1)
  62. {
  63. itemInfos = await BoxHelper.OneBox(_openBoxConfig.ID);
  64. }
  65. else if (type == 2)
  66. {
  67. itemInfos = await BoxHelper.TenBox(_openBoxConfig.ID);
  68. }
  69. if (itemInfos == null)
  70. return;
  71. for (var i = 0; i < _imageMoveContainers.Count; i++)
  72. {
  73. _imageMoveContainers[i].Dispose();
  74. }
  75. _imageMoveContainers.Clear();
  76. tenButton.gameObject.SetActive(false);
  77. oneButton.gameObject.SetActive(false);
  78. for (var i = 0; i < widgetItems.Count; i++)
  79. {
  80. widgetItems[i].SetActive(false);
  81. widgetItems[i].InitWidget(itemInfos[i]);
  82. }
  83. CusstomInit();*/
  84. UIManager.Instance.HideUIUIPanel<GachaPanel>();
  85. });
  86. }
  87. public async override CTask<bool> AsyncInit(object[] uiData)
  88. {
  89. itemInfos = uiData[0] as List<ItemInfo>;
  90. type = (int)uiData[1];
  91. _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
  92. SummonData = PlayerManager.Instance.SummonManager.summonDataMap[_openBoxConfig.ID];
  93. foreach (var widget in _energyWidgets)
  94. {
  95. UIManager.Instance.DormancyGComponent(widget);
  96. }
  97. // _energyWidgets.Clear();
  98. // EnergyWidget energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  99. // energyWidget.CustomInit(GlobalParam.Item_Coin_ID);
  100. // _energyWidgets.Add(energyWidget);
  101. // energyWidget = await UIManager.Instance.CreateGComponent<EnergyWidget>(null, Group_ResourceBar);
  102. // energyWidget.CustomInit(GlobalParam.Item_Diamond_ID);
  103. // _energyWidgets.Add(energyWidget);
  104. /*
  105. if (type == 1)
  106. {
  107. text_btnText.text = "开启一次";
  108. Trxt_Cion.text = "x" + _openBoxConfig.oneConsume;
  109. }
  110. else if (type == 2)
  111. {
  112. text_btnText.text = "开启十次";
  113. Trxt_Cion.text = "x" + _openBoxConfig.tenConsume;
  114. }*/
  115. foreach (var itemInfo in itemInfos)
  116. {
  117. WidgetItem widgetItem = await UIManager.Instance.CreateGComponent<WidgetItem>(null, GridItem, isActive: false);
  118. widgetItem.InitWidget(itemInfo);
  119. widgetItems.Add(widgetItem);
  120. }
  121. return await base.AsyncInit(uiData);
  122. }
  123. private float timer = 0;
  124. private List<ImageMoveContainer> _imageMoveContainers = new List<ImageMoveContainer>();
  125. [CustomMethod(CustomMethodType.Update)]
  126. public void Update()
  127. {
  128. foreach (var imageMoveContainer in _imageMoveContainers)
  129. {
  130. imageMoveContainer.RenderUpdateCallBack();
  131. }
  132. }
  133. public async CTask CusstomInit()
  134. {
  135. foreach (var gameObjectPool in _gameObjectPools)
  136. {
  137. gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = transform.worldToLocalMatrix * fxpos.position;
  138. UIManager.Instance.DormancyGComponent(gameObjectPool);
  139. }
  140. _gameObjectPools.Clear();
  141. for (var i = 0; i < widgetItems.Count; i++)
  142. {
  143. //animTween.Play("click", false);
  144. fx_ui_box_click.gameObject.SetActive(true);
  145. fx_ui_box_click.Play();
  146. ImageMoveContainer imageMoveContainer = new ImageMoveContainer();
  147. GameObjectPool gameObjectPool = null;
  148. if (widgetItems[i].itemInfo.config.quality >= 1 && widgetItems[i].itemInfo.config.quality <= 3)
  149. {
  150. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_1");
  151. }
  152. else if (widgetItems[i].itemInfo.config.quality > 3 && widgetItems[i].itemInfo.config.quality <= 5)
  153. {
  154. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_2");
  155. }
  156. else
  157. {
  158. gameObjectPool = await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_ui_box_click_3");
  159. }
  160. _gameObjectPools.Add(gameObjectPool);
  161. gameObjectPool.own.transform.GetComponent<RectTransform>().anchoredPosition = transform.worldToLocalMatrix * fxpos.position;
  162. gameObjectPool.own.transform.SetParent(this.transform);
  163. Vector2 pos = transform.worldToLocalMatrix * fxpos.position;
  164. Vector2 pos1 = transform.worldToLocalMatrix * (PosRoot[i] as RectTransform).position;
  165. gameObjectPool.own.GetComponent<RectTransform>().anchoredPosition = pos;
  166. // gameObjectPool.own.SetActive(true);
  167. imageMoveContainer.AddACurve(pos, pos1, 0, 3f, gameObjectPool);
  168. _imageMoveContainers.Add(imageMoveContainer);
  169. int index = i;
  170. TimerComponent.Instance.AddTimer(300, () =>
  171. {
  172. fx_ui_box_click.gameObject.SetActive(false);
  173. widgetItems[index].SetActive(true);
  174. // widgetItems[index].PlayerAnim();
  175. });
  176. await TimerComponent.Instance.WaitAsync(180 + Random.Range(0, 100));
  177. // await TimerComponent.Instance.WaitAsync(200);
  178. }
  179. tenButton.gameObject.SetActive(true);
  180. oneButton.gameObject.SetActive(true);
  181. }
  182. public override void Close()
  183. {
  184. foreach (var widgetItem in widgetItems)
  185. {
  186. UIManager.Instance.DormancyGComponent(widgetItem);
  187. }
  188. widgetItems.Clear();
  189. for (var i = 0; i < _imageMoveContainers.Count; i++)
  190. {
  191. _imageMoveContainers[i].Dispose();
  192. }
  193. _imageMoveContainers.Clear();
  194. _gameObjectPools.Clear();
  195. tenButton.gameObject.SetActive(false);
  196. oneButton.gameObject.SetActive(false);
  197. foreach (var widget in _energyWidgets)
  198. {
  199. UIManager.Instance.DormancyGComponent(widget);
  200. }
  201. _energyWidgets.Clear();
  202. //完成挑战过后自动打开挑战界面
  203. if (_openBoxConfig.ProgressRewardChoukaCount != -1 &&
  204. SummonData.drawHistory.Count >= _openBoxConfig.ProgressRewardChoukaCount)
  205. {
  206. OpenBoxScorePanel.OpenPanel();
  207. }
  208. base.Close();
  209. }
  210. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  211. {
  212. if (UIManager.Instance.GetComponent<GachaPanel>() == null || UIManager.Instance.GetComponent<GachaPanel>().IsClose)
  213. {
  214. GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Middle, uiData: new object[] { itemInfos, type, configId });
  215. await TimerComponent.Instance.WaitAsync(300);
  216. gachaPanel.CusstomInit();
  217. }
  218. }
  219. }
  220. }