ShopGachaPanel.cs 4.7 KB

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