ShopGachaPanel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. return base.GetFocus();
  30. }
  31. public override CTask LoseFocus()
  32. {
  33. TitlePanel.ClosePanel();
  34. return base.LoseFocus();
  35. }
  36. protected override void AddEvent()
  37. {
  38. }
  39. protected override void DelEvent()
  40. {
  41. }
  42. public override void AddButtonEvent()
  43. {
  44. Btn_ShuangBei.onClick.AddListener(async () =>
  45. {
  46. #if UNITY_ANDROID && !UNITY_EDITOR&& Taptap
  47. if (TakuSDKManager.Instance.IsReady())
  48. {
  49. bool isOK = await TakuSDKManager.Instance.ShowAutoAd();
  50. if (!isOK)
  51. {
  52. return;
  53. }
  54. }
  55. else
  56. {
  57. return;
  58. }
  59. #endif
  60. float beLv =
  61. Utility.UtilTools.GetRandomByWeight(_openBoxConfig.betPara1.ToList(), _openBoxConfig.betPara2);
  62. foreach (var itemInfo in itemInfos)
  63. {
  64. ItemInfo itemInfo1 = new ItemInfo(itemInfo.itemID, (long)(itemInfo.count.Value * (beLv - 1)));
  65. PlayerManager.Instance.BagController.AddItem(itemInfo1);
  66. }
  67. Btn_ShuangBei.gameObject.SetActive(false);
  68. Text_AllCount.text = $"总计:{allConit} x {beLv} = {(int)(allConit * beLv)}";
  69. Text_Bl.text = $"已获得 <color=#FDB34A>{beLv}</color> 倍奖励";
  70. Text_Bl.gameObject.SetActive(true);
  71. // UIManager.Instance.HideUIUIPanel<ShopGachaPanel>();
  72. });
  73. Btn_LingQu.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<ShopGachaPanel>(); });
  74. }
  75. public async override CTask<bool> AsyncInit(object[] uiData)
  76. {
  77. itemInfos = uiData[0] as List<ItemInfo>;
  78. type = (int)uiData[1];
  79. _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
  80. allConit = 0;
  81. foreach (var itemInfo in itemInfos)
  82. {
  83. if (itemInfo.config.associateID == 9)
  84. {
  85. allConit += itemInfo.config.associateVlaue[1];
  86. }
  87. }
  88. Text_AllCount.text = $"总计:{allConit}";
  89. if (itemInfos.Count > 1)
  90. {
  91. for (var i = 0; i < itemInfos.Count; i++)
  92. {
  93. DaiJinJuanWidget widgetItem =
  94. await UIManager.Instance.CreateGComponentForObject<DaiJinJuanWidget>(TenDaiJinJuanWidgetGams[i],
  95. null);
  96. widgetItem.CustomInit(itemInfos[i].itemID);
  97. }
  98. TenRoot.gameObject.SetActive(true);
  99. OneRoot.gameObject.SetActive(false);
  100. }
  101. if (itemInfos.Count == 1)
  102. {
  103. for (var i = 0; i < itemInfos.Count; i++)
  104. {
  105. DaiJinJuanWidget widgetItem =
  106. await UIManager.Instance.CreateGComponentForObject<DaiJinJuanWidget>(DaiJinJuanWidget1Gam,
  107. null);
  108. widgetItem.CustomInit(itemInfos[i].itemID);
  109. }
  110. TenRoot.gameObject.SetActive(false);
  111. OneRoot.gameObject.SetActive(true);
  112. }
  113. return await base.AsyncInit(uiData);
  114. }
  115. public async override CTask Close()
  116. {
  117. OneRoot.gameObject.SetActive(false);
  118. TenRoot.gameObject.SetActive(false);
  119. Text_Bl.gameObject.SetActive(false);
  120. Btn_ShuangBei.gameObject.SetActive(true);
  121. await base.Close();
  122. }
  123. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  124. {
  125. if (UIManager.Instance.GetComponent<ShopGachaPanel>() == null ||
  126. UIManager.Instance.GetComponent<ShopGachaPanel>().IsClose)
  127. {
  128. ShopGachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<ShopGachaPanel>(null,
  129. UILayer.Middle,
  130. uiData: new object[] { itemInfos, type, configId }, isShowBG: true);
  131. }
  132. AudioManager.Instance.PlayAudio("ui_jianglimianban.wav");
  133. }
  134. }
  135. }