ShopBoxWidget.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System.Collections.Generic;
  2. using Excel2Json;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using GameLogic.Bag;
  6. using GameLogic.Combat.CombatTool;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace Fort23.Mono
  10. {
  11. [UIBinding(prefab = "ShopBoxWidget")]
  12. public partial class ShopBoxWidget : UIComponent
  13. {
  14. private OpenBoxConfig openBoxConfig;
  15. private AccountFileInfo.SummonData summonData;
  16. bool oneBiaoJi = false;
  17. private void Init()
  18. {
  19. }
  20. public override void AddEvent()
  21. {
  22. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  23. }
  24. public override void DelEvent()
  25. {
  26. StaticUpdater.Instance.RemoveRenderUpdateCallBack(Update);
  27. }
  28. private bool isStartAd = false;
  29. public override void AddButtonEvent()
  30. {
  31. oneButton.onClick.AddListener(OnButtonCallBack);
  32. tenButton.onClick.AddListener(TenButtonCallBack);
  33. Btn_AdsFree.onClick.AddListener(async () =>
  34. {
  35. if (AccountFileInfo.Instance.playerData.boxFree)
  36. {
  37. TipMessagePanel.OpenTipMessagePanel(938, Vector2.zero);
  38. return;
  39. }
  40. if (isStartAd)
  41. return;
  42. isStartAd = true;
  43. var dic = new Dictionary<string, string>();
  44. dic.Add("Chouka", "");
  45. // YouLoftSDK.Instance.CustomEvent("OnclickAds", dic);
  46. // bool isOK = await YouLoftSDK.Instance.ShowAd();
  47. bool isOK = true;
  48. isStartAd = false;
  49. if (!isOK)
  50. {
  51. return;
  52. }
  53. dic = new Dictionary<string, string>();
  54. dic.Add("Chouka", "");
  55. // YouLoftSDK.Instance.CustomEvent("AdsPlayOver", dic);
  56. AccountFileInfo.Instance.playerData.boxFree = true;
  57. AccountFileInfo.Instance.SavePlayerData();
  58. // Btn_AdsFree.gameObject.SetActive(false);
  59. List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID, true);
  60. if (allIitem != null)
  61. GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
  62. });
  63. }
  64. private async void OnButtonCallBack()
  65. {
  66. if (summonData.isSummonSocre)
  67. {
  68. TipMessagePanel.OpenTipMessagePanel("已经开启300抽挑战,不能进行单抽了");
  69. return;
  70. }
  71. if (summonData.oneFreeCount >= openBoxConfig.oneConsumeFreePara[1])
  72. {
  73. TipMessagePanel.OpenTipMessagePanel("今日单抽免费次数已用完");
  74. return;
  75. }
  76. if (PlayerManager.Instance.serverTime < summonData.nextOneFreeTime)
  77. {
  78. TipMessagePanel.OpenTipMessagePanel("还未到达免费时间!请稍好再试");
  79. return;
  80. }
  81. //测试代码
  82. List<ItemInfo> allIitem = await BoxHelper.OneBox(openBoxConfig.ID);
  83. if (allIitem != null)
  84. ShopGachaPanel.OpenPanel(allIitem, 1, openBoxConfig.ID);
  85. UpdateUi();
  86. }
  87. private async void TenButtonCallBack()
  88. {
  89. //测试代码
  90. List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID);
  91. if (allIitem != null)
  92. ShopGachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
  93. UpdateUi();
  94. }
  95. public override void Close()
  96. {
  97. CombatController.currActiveCombat.isUpdate = true;
  98. base.Close();
  99. }
  100. public void CustomInit()
  101. {
  102. CombatController.currActiveCombat.isUpdate = false;
  103. openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(1);
  104. ItemConfig config = ConfigComponent.Instance.Get<ItemConfig>(openBoxConfig.CostItemID);
  105. // icon_Oneitem.icon_name = config.icon;
  106. // Icon_TenItem.icon_name = config.icon;
  107. onCion.text = "x" + openBoxConfig.oneConsume;
  108. tenCion.text = "x" + openBoxConfig.tenConsume;
  109. UpdateUi();
  110. }
  111. public void Update()
  112. {
  113. if (summonData == null)
  114. return;
  115. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  116. PlayerManager.Instance.serverTime < summonData.nextTenFreeTime)
  117. {
  118. int time = (int)(summonData.nextTenFreeTime - PlayerManager.Instance.serverTime);
  119. tenCion.text = PlayerManager.TimeToHSM(time / 1000);
  120. if (!Icon_Ads.gameObject.activeSelf)
  121. {
  122. Icon_Ads.gameObject.SetActive(true);
  123. }
  124. }
  125. else
  126. {
  127. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1])
  128. {
  129. if (Icon_Ads.gameObject.activeSelf)
  130. {
  131. tenCion.text = "免费";
  132. Icon_Ads.gameObject.SetActive(false);
  133. }
  134. }
  135. else
  136. {
  137. if (!Icon_Ads.gameObject.activeSelf)
  138. {
  139. tenCion.text = "今日免费次数已经用完";
  140. Icon_Ads.gameObject.SetActive(true);
  141. }
  142. }
  143. }
  144. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  145. PlayerManager.Instance.serverTime < summonData.nextOneFreeTime)
  146. {
  147. int time = (int)(summonData.nextOneFreeTime - PlayerManager.Instance.serverTime);
  148. onCion.text = PlayerManager.TimeToHSM(time / 1000);
  149. if (!oneBiaoJi)
  150. {
  151. oneBiaoJi = true;
  152. oneButton.image.GetComponent<MyImage>().IsGray = true;
  153. }
  154. }
  155. else
  156. {
  157. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1])
  158. {
  159. if (oneBiaoJi)
  160. {
  161. onCion.text = "免费";
  162. oneBiaoJi = false;
  163. oneButton.image.GetComponent<MyImage>().IsGray = false;
  164. }
  165. }
  166. else
  167. {
  168. if (!oneBiaoJi)
  169. {
  170. onCion.text = "今日免费次数已经用完";
  171. oneBiaoJi = true;
  172. oneButton.image.GetComponent<MyImage>().IsGray = false;
  173. }
  174. }
  175. }
  176. }
  177. public void UpdateUi()
  178. {
  179. summonData = PlayerManager.Instance.SummonManager.summonDataMap[1];
  180. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  181. PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime)
  182. {
  183. tenCion.text = "免费";
  184. }
  185. //今日次数已用完
  186. else if (summonData.tenFreeCount >= openBoxConfig.oneConsumeFreePara_1[1])
  187. {
  188. onCion.text = "进入免费次数已经用完";
  189. }
  190. else
  191. {
  192. }
  193. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  194. PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime)
  195. {
  196. onCion.text = "免费";
  197. oneButton.image.GetComponent<MyImage>().IsGray = false;
  198. oneBiaoJi = true;
  199. }
  200. else if (summonData.oneFreeCount >= openBoxConfig.oneConsumeFreePara[1])
  201. {
  202. onCion.text = "进入免费次数已经用完";
  203. oneButton.image.GetComponent<MyImage>().IsGray = true;
  204. oneBiaoJi = false;
  205. }
  206. else
  207. {
  208. oneButton.image.GetComponent<MyImage>().IsGray = true;
  209. oneBiaoJi = false;
  210. }
  211. }
  212. }
  213. }