UIWin.ts 6.7 KB

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