123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import { Widget, _decorator, Node, tween, v3, Label, Vec2, v2, math, Tween,sys } from 'cc';
- import { GameMgr } from '../manager/GameMgr';
- import { AudioMgr } from '../manager/AudioMgr';
- import { CoinMgr } from '../manager/CoinMgr';
- import { ArrayUtil } from '../util/ArrayUtil';
- import { InputBlock } from '../misc/InputBlock';
- import { TimeMgr } from '../manager/TimeMgr';
- import { UI } from '../enum/UI';
- import { UIBase } from '../scriptBase/UIBase';
- import { CoinItem } from '../uiItem/CoinItem';
- import { Global } from '../Global';
- import { TransMgr } from '../manager/TransMgr';
- import { BYTEDANCE } from 'cc/env';
- import { ModeName } from '../enum/Mode';
- import { AdMgr } from '../manager/AdMgr';
- import { EventMgr } from '../manager/EventMgr';
- import { Debug } from "../util/Debug";
- const Tag: string = 'zh:UIWin';
- import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoTSSDK"
- import AAJS2 from "../utils/ATAndroidJS2";
- import ATJSSDK from "../AnyThinkAds/ATJSSDK";
- const { ccclass, property, requireComponent } = _decorator;
- @ccclass('UI/UIWin')
- @requireComponent(Widget)
- export class UIWin extends UIBase {
- private pointer: Node = null
- private lbCoin: Label = null
- private coinItem: CoinItem = null
- private coin: number = 0
- public set Coin(v: number) {
- this.coin = Math.max(v, 0)
- this.lbCoin.string = `x${this.coin}`
- }
- private multi: number = 1
- private readonly posArr: Vec2[] = [
- v2(-120, -74),
- v2(-72, 80),
- v2(-17, 29),
- v2(32, 86),
- v2(90, 120),
- ]
- private readonly multiArr: number[] = [2, 3, 5, 3, 4]
- private tw: Tween<Node> = null
- protected onLoad(): void {
- this.pointer = this.findNode('Pointer')
- this.lbCoin = this.findComp('LbCoin', Label)
- this.coinItem = this.findComp('CoinItem', CoinItem)
- this.initAdForPage();
- console.log('zh:UIWin onload 注册事件 Ad_play_end s')
- EventMgr.on('Ad_play_end', this.defCode, this)
- console.log('zh:UIWin onload 注册事件 Ad_play_end e')
- }
-
- /**
- * 初始化广告
- */
- initAdForPage() {
- Debug.Log(Tag, 'initAdForPage foir UIGetSkill.ts')
- if (sys.os === sys.OS.ANDROID) {
- let deviceId = AAJS2.getDeviceUserId();
- Debug.Log(Tag, 'checkAdStatus ='+ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
- var setting = {};
- setting[ATRewardedVideoSDK.userIdKey] = deviceId;
- ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
- }
- }
- public onOpen(data?: unknown): void {
- AudioMgr.stopBgm()
- AudioMgr.playSfx('通关成功')
- GameMgr.passGame()
- this.coinItem.init(CoinMgr.CurCoin)
- GameMgr.Pause = true
- const duration: number = 0.75
- this.tw = tween(this.pointer).sequence(
- tween(this.pointer).to(duration, { position: v3(120, -25) }),
- tween(this.pointer).to(duration, { position: v3(-120, -25) })
- ).repeatForever().start()
- this.Coin = Global.Normal_Level_Coin_Default_Cnt + (GameMgr.CurLevel - 1) * Global.Normal_Level_Coin_Add_Cnt
- CoinMgr.CurCoin += this.coin
- }
- public onClose(data?: unknown): void {
- GameMgr.Pause = false
- InputBlock.Active = false
- }
- protected async onBtnMultiClick() {
- console.log('zh:点击了多倍奖励s')
- const onSucc = async () => {
- Debug.Log(Tag, 'onSucc 111')
- this.tw.stop()
- const idx: number = ArrayUtil.pickItem([0, 0, 0, 0, 0, 1, 2, 3])
- this.multi = this.multiArr[idx]
- const posRange: Vec2 = this.posArr[idx]
- const posX: number = math.randomRangeInt(posRange.x, posRange.y)
- this.pointer.setPosition(posX, this.pointer.position.y)
- const extraCoin: number = (this.multi - 1) * this.coin
- this.Coin = this.multi * this.coin
- CoinMgr.CurCoin += extraCoin
- this.coinItem.updateCoin(CoinMgr.CurCoin)
- Debug.Log(Tag, 'onSucc 222')
- InputBlock.Active = true
- await TimeMgr.delay(2)
- await TransMgr.Inst.fadeIn()
- GameMgr.startGame()
- this.close()
- TransMgr.Inst.fadeOut()
- Debug.Log(Tag, 'onSucc 333')
- }
- console.log('zh:点击了多倍奖励e');
- if (sys.os == sys.OS.ANDROID) {
- if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
- Debug.Log(Tag, 'onBtnGetClick ad ok')
- sys.localStorage.setItem('yxAdMark', 'duoBeiGetXingXing');//看广告用于 多倍星星
- ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
- // onSucc();
- // AdMgr.showRewardedVideo(onSucc) 仔细测试有BUG
- } else {
- Debug.Log(Tag, 'onBtnGetClick ad no ok')
- AdMgr.showRewardedVideo(onSucc)
- }
- }
- //下面是原有的逻辑
- // AdMgr.showRewardedVideo(onSucc)
- // console.log('zh:点击了多倍奖励e2');
- }
-
- /**
- * 默认代码,原有的逻辑
- */
- public defCode(): void {
- console.log('zh:uiwin Ad_play_end go .....')
- const onSucc = async () => {
- Debug.Log(Tag, 'onSucc 111')
- this.tw.stop()
- const idx: number = ArrayUtil.pickItem([0, 0, 0, 0, 0, 1, 2, 3])
- this.multi = this.multiArr[idx]
- const posRange: Vec2 = this.posArr[idx]
- const posX: number = math.randomRangeInt(posRange.x, posRange.y)
- this.pointer.setPosition(posX, this.pointer.position.y)
-
- const extraCoin: number = (this.multi - 1) * this.coin
- this.Coin = this.multi * this.coin
-
- CoinMgr.CurCoin += extraCoin
- this.coinItem.updateCoin(CoinMgr.CurCoin)
- Debug.Log(Tag, 'onSucc 222')
- InputBlock.Active = true
- await TimeMgr.delay(2)
- await TransMgr.Inst.fadeIn()
- GameMgr.startGame()
- this.close()
- TransMgr.Inst.fadeOut()
- Debug.Log(Tag, 'onSucc 333')
- }
- AdMgr.showRewardedVideo(onSucc)
- }
- protected async onBtnNextClick() {
- this.coinItem.updateCoin(CoinMgr.CurCoin)
- InputBlock.Active = true
- await TimeMgr.delay(2)
- await TransMgr.Inst.fadeIn()
- GameMgr.startGame()
- this.close()
- TransMgr.Inst.fadeOut()
- }
- protected async onBtnCloseClick() {
- await TransMgr.Inst.fadeIn()
- this.close()
- GameMgr.quitGame()
- this.open(UI.Main)
- TransMgr.Inst.fadeOut()
- }
- }
|