UIWin.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { Widget, _decorator, Node, tween, v3, Label, Vec2, v2, math, Tween,sys } from 'cc';
  2. import { GameMgr } from '../manager/GameMgr';
  3. import { AudioMgr } from '../manager/AudioMgr';
  4. import { CoinMgr } from '../manager/CoinMgr';
  5. import { ArrayUtil } from '../util/ArrayUtil';
  6. import { InputBlock } from '../misc/InputBlock';
  7. import { TimeMgr } from '../manager/TimeMgr';
  8. import { UI } from '../enum/UI';
  9. import { UIBase } from '../scriptBase/UIBase';
  10. import { CoinItem } from '../uiItem/CoinItem';
  11. import { Global } from '../Global';
  12. import { TransMgr } from '../manager/TransMgr';
  13. import { BYTEDANCE } from 'cc/env';
  14. import { ModeName } from '../enum/Mode';
  15. import { AdMgr } from '../manager/AdMgr';
  16. import { Debug } from "../util/Debug";
  17. const Tag: string = 'zh:UIWin';
  18. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoTSSDK"
  19. import AAJS2 from "../utils/ATAndroidJS2";
  20. import ATJSSDK from "../AnyThinkAds/ATJSSDK";
  21. const { ccclass, property, requireComponent } = _decorator;
  22. @ccclass('UI/UIWin')
  23. @requireComponent(Widget)
  24. export class UIWin extends UIBase {
  25. private pointer: Node = null
  26. private lbCoin: Label = null
  27. private coinItem: CoinItem = null
  28. private coin: number = 0
  29. public set Coin(v: number) {
  30. this.coin = Math.max(v, 0)
  31. this.lbCoin.string = `x${this.coin}`
  32. }
  33. private multi: number = 1
  34. private readonly posArr: Vec2[] = [
  35. v2(-120, -74),
  36. v2(-72, 80),
  37. v2(-17, 29),
  38. v2(32, 86),
  39. v2(90, 120),
  40. ]
  41. private readonly multiArr: number[] = [2, 3, 5, 3, 4]
  42. private tw: Tween<Node> = null
  43. protected onLoad(): void {
  44. this.pointer = this.findNode('Pointer')
  45. this.lbCoin = this.findComp('LbCoin', Label)
  46. this.coinItem = this.findComp('CoinItem', CoinItem)
  47. this.initAdForPage();
  48. }
  49. /**
  50. * 初始化广告
  51. */
  52. initAdForPage() {
  53. Debug.Log(Tag, 'initAdForPage foir UIGetSkill.ts')
  54. if (sys.os === sys.OS.ANDROID) {
  55. let deviceId = AAJS2.getDeviceUserId();
  56. Debug.Log(Tag, 'checkAdStatus ='+ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  57. var setting = {};
  58. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  59. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  60. }
  61. }
  62. public onOpen(data?: unknown): void {
  63. AudioMgr.stopBgm()
  64. AudioMgr.playSfx('通关成功')
  65. GameMgr.passGame()
  66. this.coinItem.init(CoinMgr.CurCoin)
  67. GameMgr.Pause = true
  68. const duration: number = 0.75
  69. this.tw = tween(this.pointer).sequence(
  70. tween(this.pointer).to(duration, { position: v3(120, -25) }),
  71. tween(this.pointer).to(duration, { position: v3(-120, -25) })
  72. ).repeatForever().start()
  73. this.Coin = Global.Normal_Level_Coin_Default_Cnt + (GameMgr.CurLevel - 1) * Global.Normal_Level_Coin_Add_Cnt
  74. CoinMgr.CurCoin += this.coin
  75. }
  76. public onClose(data?: unknown): void {
  77. GameMgr.Pause = false
  78. InputBlock.Active = false
  79. }
  80. protected async onBtnMultiClick() {
  81. console.log('zh:点击了多倍奖励s')
  82. const onSucc = async () => {
  83. Debug.Log(Tag, 'onSucc 111')
  84. this.tw.stop()
  85. const idx: number = ArrayUtil.pickItem([0, 0, 0, 0, 0, 1, 2, 3])
  86. this.multi = this.multiArr[idx]
  87. const posRange: Vec2 = this.posArr[idx]
  88. const posX: number = math.randomRangeInt(posRange.x, posRange.y)
  89. this.pointer.setPosition(posX, this.pointer.position.y)
  90. const extraCoin: number = (this.multi - 1) * this.coin
  91. this.Coin = this.multi * this.coin
  92. CoinMgr.CurCoin += extraCoin
  93. this.coinItem.updateCoin(CoinMgr.CurCoin)
  94. Debug.Log(Tag, 'onSucc 222')
  95. InputBlock.Active = true
  96. await TimeMgr.delay(2)
  97. await TransMgr.Inst.fadeIn()
  98. GameMgr.startGame()
  99. this.close()
  100. TransMgr.Inst.fadeOut()
  101. Debug.Log(Tag, 'onSucc 333')
  102. }
  103. console.log('zh:点击了多倍奖励e');
  104. if (sys.os == sys.OS.ANDROID) {
  105. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  106. Debug.Log(Tag, 'onBtnGetClick ad ok')
  107. sys.localStorage.setItem('yxAdMark', 'duoBeiGetXingXing');//看广告用于 多倍星星
  108. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  109. // onSucc();
  110. AdMgr.showRewardedVideo(onSucc)
  111. } else {
  112. Debug.Log(Tag, 'onBtnGetClick ad no ok')
  113. AdMgr.showRewardedVideo(onSucc)
  114. }
  115. }
  116. //下面是原有的逻辑
  117. // AdMgr.showRewardedVideo(onSucc)
  118. // console.log('zh:点击了多倍奖励e2');
  119. }
  120. protected async onBtnNextClick() {
  121. this.coinItem.updateCoin(CoinMgr.CurCoin)
  122. InputBlock.Active = true
  123. await TimeMgr.delay(2)
  124. await TransMgr.Inst.fadeIn()
  125. GameMgr.startGame()
  126. this.close()
  127. TransMgr.Inst.fadeOut()
  128. }
  129. protected async onBtnCloseClick() {
  130. await TransMgr.Inst.fadeIn()
  131. this.close()
  132. GameMgr.quitGame()
  133. this.open(UI.Main)
  134. TransMgr.Inst.fadeOut()
  135. }
  136. }