import { BaseView } from "../../../lightMVC/core/base/BaseView"; import SDK from "../../sdk/SDK"; import gameScene from "../../gameScene"; import { App } from "../../Manager/App"; import { SoundManager } from "../../Manager/SoundManager"; import TipPanel from "../tipPanel/TipPanel"; import TipPanelMediator from "../tipPanel/TipPanelMediator"; import AESUtil from "../../AESUtil" import ATSDK from "../../AnyThinkAds/ATJSSDK"; import ATRewardedVideoSDK from "../../AnyThinkAds/ATRewardedVideoJSSDK"; import AAJS2 from "../../ATAndroidJS2"; import GlobalManager from '../../GlobalManager'; import ATInterstitialSDK from "../../AnyThinkAds/ATInterstitialJSSDK"; import ATBannerSDK from "../../AnyThinkAds/ATBannerJSSDK"; import { AdType } from '../../ATAndroidJS2'; const { ccclass, property } = cc._decorator; @ccclass export default class SuccessPanel extends BaseView { passTime = 0; protected onLoad(): void { console.log('zh:SuccessPanel.ts onload '); // this.initAdForPageInter(); 这里的插屏有问题,所以改为激励 SDK.Instance.initAdForPage(); } //add判断插屏 开屏等,需要多次准备 //add判断插屏 开屏等,需要多次准备 initAdForPageInter() { if (cc.sys.os === cc.sys.OS_ANDROID) { console.log('zh:successpanel.ts 开始准备AD .....'); let deviceId = AAJS2.getDeviceUserId(); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; //add判断插屏 开屏等 let pid_inter = AAJS2.getPlacementId2(AdType.Inter); console.log("zh: pid_inter checkstatus:", ATInterstitialSDK.checkAdStatus(pid_inter)); ATInterstitialSDK.loadInterstitial(pid_inter, setting); } } public drawView(): void { SDK.Instance.showInterstitial(); App.DataManager.MissionComplete[3]++; App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_missionComplete, App.DataManager.MissionComplete); this.onLoadAll(); this.NextLevel(); this.BackMain(); this.doubleReward(); } onLoadAll(){ this.ui.getNode("labelCoin").getComponent(cc.Label).string = App.DataManager.UserCoin + ""; this.ui.getNode("labelDiamond").getComponent(cc.Label).string = App.DataManager.UserDiamond + ""; this.ui.getNode("labelAwardCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin +""; App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin; App.DataManager.UserDiamond += 1; App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin); App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_UserDiamond, App.DataManager.UserDiamond); } /** * 点击游戏下一关 */ public NextLevel(): void { let nextBtn = this.ui.getNode("next"); nextBtn.on(cc.Node.EventType.TOUCH_END, () => { if (cc.sys.os == cc.sys.OS_ANDROID) { if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { cc.sys.localStorage.setItem('yxAdMark', 'callBack_gotoNextLevel');//看广告用于 xx 标记 GlobalManager.instance.registerMethod('callBack_gotoNextLevel', this.callBack_gotoNextLevel.bind(this)); ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); } else { console.log('zh:AD 没有OK'); this.callBack_gotoNextLevel(); SDK.Instance.initAdForPage(); } } else { this.callBack_gotoNextLevel(); } //this.showInterAd("callBack_gotoNextLevel",true, () => this.callBack_gotoNextLevel()); // if(App.DataManager.CurrentIntoLevel == 15 && App.DataManager.PassProgress[App.DataManager.CurrentIntoLevel] == 3){ // App.Facade.popView(TipPanelMediator, TipPanel, "恭喜你已通关!", false); // gameScene.instance.ClickBackMain(); // } // else{ // gameScene.instance.JumpNextLevel(); // } }, this); } private callBack_gotoNextLevel(){ console.log('zh:callBack_gotoNextLevel 被触发' ); if(App.DataManager.CurrentIntoLevel == 15 && App.DataManager.PassProgress[App.DataManager.CurrentIntoLevel] == 3){ // App.Facade.popView(TipPanelMediator, TipPanel, "恭喜你已通关!", false); App.Facade.popView(TipPanelMediator, TipPanel, "You're a super chef!", false); gameScene.instance.ClickBackMain(); } else{ gameScene.instance.JumpNextLevel(); } } BackMain(){ let backMainBtn = this.ui.getNode("main"); backMainBtn.on(cc.Node.EventType.TOUCH_END, () => { gameScene.instance.ClickBackMain(); }, this); } /** * 点击看视频 */ public doubleReward(): void { let doubleBtn = this.ui.getNode("btnVideo"); doubleBtn.on(cc.Node.EventType.TOUCH_END, () => { this.ui.getNode("jiantou").getComponent(cc.Animation).stop(); SoundManager.getInstance().VideoStartStop(); if (cc.sys.os == cc.sys.OS_ANDROID) { if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) { cc.sys.localStorage.setItem('yxAdMark', 'callBackFor_successPanel');//看广告用于 xx 标记 GlobalManager.instance.registerMethod('callBackFor_successPanel', this.callBackFor_successPanel.bind(this)); ATRewardedVideoSDK.showAd(AAJS2.getPlacementId()); } else { console.log('zh:AD 没有OK'); this.callBackFor_successPanel(); SDK.Instance.initAdForPage(); } } else { this.callBackFor_successPanel(); } // SDK.Instance.showRewardVideo(() => { // if(this.ui.getNode("jiantou").angle >= 42){ // App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 2; // } // else if(this.ui.getNode("jiantou").angle >= -34 && this.ui.getNode("jiantou").angle < 42){ // App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 3; // } // else if(this.ui.getNode("jiantou").angle >= -69 && this.ui.getNode("jiantou").angle < -34){ // App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 4; // } // else if(this.ui.getNode("jiantou").angle < -69){ // App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 5; // } // App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin); // SoundManager.getInstance().VideoEndOpen(); // gameScene.instance.JumpNextLevel(); // }, () => { // SoundManager.getInstance().VideoEndOpen(); // }, () => { // SoundManager.getInstance().VideoEndOpen(); // }); }, this); } public callBackFor_successPanel(){ console.log('zh:callBackFor_successPanel 被触发' ); if(this.ui.getNode("jiantou").angle >= 42){ App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 2; } else if(this.ui.getNode("jiantou").angle >= -34 && this.ui.getNode("jiantou").angle < 42){ App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 3; } else if(this.ui.getNode("jiantou").angle >= -69 && this.ui.getNode("jiantou").angle < -34){ App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 4; } else if(this.ui.getNode("jiantou").angle < -69){ App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 5; } App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin); SoundManager.getInstance().VideoEndOpen(); gameScene.instance.JumpNextLevel(); } public static path(): string { return "gameScene/prefabs/SuccessPanel"; } update(dt){ this.passTime+=dt; if(this.passTime > 0.1){ this.passTime -= 0.1; if(this.ui.getNode("jiantou").angle >= 42){ this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 2 + ""; } else if(this.ui.getNode("jiantou").angle >= -34 && this.ui.getNode("jiantou").angle < 42){ this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 3 + ""; } else if(this.ui.getNode("jiantou").angle >= -69 && this.ui.getNode("jiantou").angle < -34){ this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 4 + ""; } else if(this.ui.getNode("jiantou").angle < -69){ this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 5 + ""; } } } /** * 显示插屏广告 * * @param adMarkForClose 插屏广告关闭后调用那个方法的具体指示标识 * @param checkClose 是否需要判断关闭事件,有的不需要,如果AD占用游戏时间则为true * @param callback 插屏广告关闭(加载失败\非ANDROID平台)的回调 */ private showInterAd(adMarkForClose: string, checkClose: boolean, callback: () => void) { if (cc.sys.os === cc.sys.OS_ANDROID) { if (checkClose) { cc.sys.localStorage.setItem("adMarkForClose", adMarkForClose);//关闭后,调用哪个方法的标识 } //add判断插屏 开屏等 let pid_inter = AAJS2.getPlacementId2(AdType.Inter); let boo = ATInterstitialSDK.hasAdReady(pid_inter); if (boo) { // 暂停游戏 cc.director.pause(); console.log('zh:showInterAd AD OK'); ATInterstitialSDK.showAd(pid_inter); //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效 if (!checkClose) {//如果不占用游戏时间 this.safeCallback(callback); } } else { console.log('zh:showInterAd AD 没有准备好'); //GlobalManager.getInstance().callMethod('initAdForPageInter'); //this.initAdForPageInter(); this.safeCallback(callback); } } else { this.safeCallback(callback); } } // 辅助方法:安全调用回调函数 private safeCallback(callback?: () => void) { if (callback) { callback(); } } }