ShopGachaPanel.cs 4.6 KB

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