123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- 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 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 FailPanel extends BaseView {
- passTime = 0;
- protected onLoad(): void {
- console.log('zh:fp.ts onload ');
- SDK.Instance.initAdForPage();
- }
- public drawView(): void {
- SDK.Instance.showInterstitial();
- this.onLoadAll();
- this.btnReplay()
- this.BackMain();
- this.btnVideo();
- }
- 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 + "";
- this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 3 + "";
- App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin;
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin);
- }
- /**
- * 点击回到主页
- */
- public BackMain(): void {
- let backMainBtn = this.ui.getNode("main");
- backMainBtn.on(cc.Node.EventType.TOUCH_END, () => {
- gameScene.instance.ClickBackMain();
- }, this);
- }
- btnReplay() {
- console.log('zh:btnReplay')
- let backMainBtn = this.ui.getNode("restart");
- backMainBtn.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_btnReplay');//看广告用于 xx 标记
- GlobalManager.instance.registerMethod('callBack_btnReplay', this.callBack_btnReplay.bind(this));
- ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
- } else {
- console.log('zh:AD 没有OK');
- this.callBack_btnReplay();
- SDK.Instance.initAdForPage();
- }
- } else {
- this.callBack_btnReplay();
- }
- // this.showInterAd("callBack_btnReplay", true, () => this.callBack_btnReplay());
- // gameScene.instance.LoadLevel();
- // this.closeView();
- }, this);
- }
- public callBack_btnReplay() {
- console.log('zh:callBack_btnReplay 被触发')
- gameScene.instance.LoadLevel();
- this.closeView();
- }
- /**
- * 点击游戏重新开始
- */
- public btnVideo(): void {
- console.log('zh:抽奖-观看视频~11');
- let btnVideo = this.ui.getNode("btnVideo");
- btnVideo.active = true;
- btnVideo.on(cc.Node.EventType.TOUCH_END, () => {
- console.log('zh:抽奖-观看视频~22');
- SoundManager.getInstance().VideoStartStop();
- if (cc.sys.os == cc.sys.OS_ANDROID) {
- if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
- cc.sys.localStorage.setItem('yxAdMark', 'callBack_for_chouJiang');//看广告用于 xx 标记
- GlobalManager.instance.registerMethod('callBack_for_chouJiang', this.callBack_for_chouJiang.bind(this));
- ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
- } else {
- console.log('zh:AD 没有OK');
- this.callBack_for_chouJiang();
- SDK.Instance.initAdForPage();
- }
- } else {
- this.callBack_for_chouJiang();
- }
- //zh:diy 下面是原始的代码
- // SDK.Instance.showRewardVideo(() => {
- // console.log('抽奖-观看视频~3');
- // this.callBack_for_chouJiang();
- // }, () => {
- // console.log('抽奖-观看视频~4');
- // SoundManager.getInstance().VideoEndOpen();
- // }, () => {
- // console.log('抽奖-观看视频~5');
- // SoundManager.getInstance().VideoEndOpen();
- // });
- }, this);
- }
- public callBack_for_chouJiang() {
- console.log('zh:抽奖被触发')
- if (this.ui.getNode("jiantou").angle >= 42) {
- App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 2;
- console.log('zh:userCoin1=' + App.DataManager.UserCoin);
- }
- else if (this.ui.getNode("jiantou").angle >= -34 && this.ui.getNode("jiantou").angle < 42) {
- App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 3;
- console.log('zh:userCoin2=' + App.DataManager.UserCoin);
- }
- else if (this.ui.getNode("jiantou").angle >= -69 && this.ui.getNode("jiantou").angle < -34) {
- App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 4;
- console.log('zh:userCoin3=' + App.DataManager.UserCoin);
- }
- else if (this.ui.getNode("jiantou").angle < -69) {
- App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 5;
- console.log('zh:userCoin4=' + App.DataManager.UserCoin);
- }
- console.log('zh:userCoin5=' + App.DataManager.UserCoin);
- App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin);
- let cout2 = App.DataManager.UserCoin;
- // App.Facade.popView(TipPanelMediator, TipPanel, "金币:"+cout2, false);
-
- SoundManager.getInstance().VideoEndOpen();
- gameScene.instance.replay();
- }
- public static path(): string {
- return "gameScene/prefabs/FailPanel";
- }
- 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();
- }
- }
- }
|