ShopGachaPanel.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Core.Audio;
  4. using Core.Language;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Bag;
  9. namespace Fort23.Mono
  10. {
  11. [UIBinding(prefab = "ShopGachaPanel")]
  12. public partial class ShopGachaPanel : UIPanel
  13. {
  14. List<WidgetItem> widgetItems = new List<WidgetItem>();
  15. private List<ItemInfo> itemInfos;
  16. private int type;
  17. private OpenBoxConfig _openBoxConfig;
  18. private AccountFileInfo.SummonData SummonData;
  19. private int allConit;
  20. private void Init()
  21. {
  22. isAddStack = true;
  23. IsShowAppBar = false;
  24. }
  25. public override CTask GetFocus()
  26. {
  27. AppBarPanel.ClosePanel();
  28. TitlePanel.ClosePanel();
  29. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 2))
  30. {
  31. PlayerGuideManager.Instance.NextGuide();
  32. }
  33. return base.GetFocus();
  34. }
  35. public override CTask LoseFocus()
  36. {
  37. TitlePanel.ClosePanel();
  38. return base.LoseFocus();
  39. }
  40. protected override void AddEvent()
  41. {
  42. }
  43. protected override void DelEvent()
  44. {
  45. }
  46. public override void AddButtonEvent()
  47. {
  48. Btn_ShuangBei.onClick.AddListener(async () =>
  49. {
  50. #if UNITY_ANDROID && !UNITY_EDITOR&& Ads
  51. if (!PlayerManager.Instance.BagController.IsEnough(23001, 1) && !PlayerManager.Instance.BagController.IsEnough(23002, 1))
  52. {
  53. bool relust = await TipsPanle.OpenPnael(10800);
  54. if (!relust)
  55. {
  56. return;
  57. }
  58. if (TakuSDKManager.Instance.IsReady())
  59. {
  60. bool isOK = await TakuSDKManager.Instance.ShowAutoAd();
  61. if (!isOK)
  62. {
  63. return;
  64. }
  65. }
  66. else
  67. {
  68. return;
  69. }
  70. }
  71. #endif
  72. float beLv =
  73. Utility.UtilTools.GetRandomByWeight(_openBoxConfig.betPara1.ToList(), _openBoxConfig.betPara2);
  74. foreach (var itemInfo in itemInfos)
  75. {
  76. ItemInfo itemInfo1 = new ItemInfo(itemInfo.itemID,
  77. (long)(itemInfo.config.associateVlaue[1] * (beLv - 1)));
  78. //TODO 代金卷双倍
  79. PlayerManager.Instance.BagController.AddItem(itemInfo1);
  80. }
  81. Btn_ShuangBei.gameObject.SetActive(false);
  82. Text_AllCount.text = $"总计:{allConit} x {beLv} = {(int)(allConit * beLv)}";
  83. Text_Bl.text = $"已获得 <color=#FDB34A>{beLv}</color> 倍奖励";
  84. Text_Bl.gameObject.SetActive(true);
  85. // UIManager.Instance.HideUIUIPanel<ShopGachaPanel>();
  86. });
  87. Btn_LingQu.onClick.AddListener(async () => { UIManager.Instance.HideUIUIPanel<ShopGachaPanel>(); });
  88. }
  89. public async override CTask<bool> AsyncInit(object[] uiData)
  90. {
  91. itemInfos = uiData[0] as List<ItemInfo>;
  92. type = (int)uiData[1];
  93. _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
  94. allConit = 0;
  95. foreach (var itemInfo in itemInfos)
  96. {
  97. if (itemInfo.config.associateID == 9)
  98. {
  99. allConit += itemInfo.config.associateVlaue[1];
  100. }
  101. }
  102. Text_AllCount.text = $"总计:{allConit}";
  103. if (itemInfos.Count > 1)
  104. {
  105. for (var i = 0; i < itemInfos.Count; i++)
  106. {
  107. DaiJinJuanWidget widgetItem =
  108. await UIManager.Instance.CreateGComponentForObject<DaiJinJuanWidget>(TenDaiJinJuanWidgetGams[i],
  109. null);
  110. widgetItem.CustomInit(itemInfos[i].itemID);
  111. }
  112. TenRoot.gameObject.SetActive(true);
  113. OneRoot.gameObject.SetActive(false);
  114. }
  115. if (itemInfos.Count == 1)
  116. {
  117. for (var i = 0; i < itemInfos.Count; i++)
  118. {
  119. DaiJinJuanWidget widgetItem =
  120. await UIManager.Instance.CreateGComponentForObject<DaiJinJuanWidget>(DaiJinJuanWidget1Gam,
  121. null);
  122. widgetItem.CustomInit(itemInfos[i].itemID);
  123. }
  124. TenRoot.gameObject.SetActive(false);
  125. OneRoot.gameObject.SetActive(true);
  126. }
  127. return await base.AsyncInit(uiData);
  128. }
  129. public async override CTask Close()
  130. {
  131. OneRoot.gameObject.SetActive(false);
  132. TenRoot.gameObject.SetActive(false);
  133. Text_Bl.gameObject.SetActive(false);
  134. Btn_ShuangBei.gameObject.SetActive(true);
  135. await base.Close();
  136. }
  137. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  138. {
  139. if (UIManager.Instance.GetComponent<ShopGachaPanel>() == null ||
  140. UIManager.Instance.GetComponent<ShopGachaPanel>().IsClose)
  141. {
  142. ShopGachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<ShopGachaPanel>(null,
  143. UILayer.Middle,
  144. uiData: new object[] { itemInfos, type, configId }, isShowBG: true);
  145. }
  146. AudioManager.Instance.PlayAudio("ui_jianglimianban.wav");
  147. }
  148. }
  149. }