TestScene.ts 5.51 KB
import { ui } from "./ui/layaMaxUI";
import AdManager from "./sdk/AdManager";
import RedpacketModel from "./sdk/model/RedpacketModel";
import AppSdk from "./sdk/AppSdk";
import { DotKey } from "./sdk/TeaSdk";
import { EventCenter } from "./event/EventCenter";
import { EventEnum } from "./event/EventEnum";

export default class TestScene extends ui.TestSceneUI {
    constructor() {
        super();
        //关闭多点触控,否则就无敌了
        Laya.MouseManager.multiTouchEnabled = false;
        console.log('---------------TestScene-------')
        this.NativeAD.visible = false;

    }

    onEnable(): void {
        this.btnServer.on(Laya.Event.CLICK, this, this.openServer);
        this.btnDrawal.on(Laya.Event.CLICK, this, this.openPersonal);
        this.btnDraw.on(Laya.Event.CLICK, this, this.onDraw);
        this.btnInvite.on(Laya.Event.CLICK, this, this.invitation);
        this.btnVibrate.on(Laya.Event.CLICK, this, this.onVibrate);
        this.btnPreloadAD.on(Laya.Event.CLICK, this, this.preloadAD);
        this.btnShowBanner.on(Laya.Event.CLICK, this, this.showBanner);
        this.btnShowFullAd.on(Laya.Event.CLICK, this, this.showFullAd);
        this.btnShowNativeAd.on(Laya.Event.CLICK, this, this.showNativeAd);
        this.btnShowInterAd.on(Laya.Event.CLICK, this, this.showInterAd);
        this.btnRewardAd.on(Laya.Event.CLICK, this, this.showRewardAd);
        this.btnRedpacket.on(Laya.Event.CLICK, this, this.openRedpacket);

    }

    /**预加载广告 */
    async preloadAD() {
        console.log('---------------preloadAD-------')
        await AdManager.I.init();
        // MyBridge.testReturn(function (...array) {
        //     console.log("-------web--------onClick----->>cocos JS-------MyBridge.testReturn------" + JSON.stringify(array));

        // });
    }

    /**显示全屏广告 */
    showFullAd() {
        console.log('---------------showFullAd-------')
        AdManager.I.showFullAd();
        // var ret = MyBridge.mapToString({
        //     data: {
        //         "count": 2, "title": [{ "name": "nnn", "value": "nnnvalue", "default_show": 1 }
        //             , { "name": "mmm", "value": "mmmvalue\"aasdasd" }]
        //     }
        // });

        // console.log("-------web--------onClick----->>cocos JS-------MyBridge.mapToString------" + JSON.stringify(ret));
    }
    /**显示banner */
    showBanner() {
        console.log('---------------showBanner-------')
        AdManager.I.showBanner();
    }

    /**信息流广告 */
    showNativeAd() {
        console.log('---------------showNativeAd-------')
        this.NativeAD.visible = true;
    }

    /**插屏广告 */
    showInterAd() {
        console.log('---------------showInterAd-------')

        AdManager.I.showInterAd();
    }
    /**激励视频广告 */
    async showRewardAd() {
        console.log('---------------showRewardAd-------')
        await AdManager.I.showRewardAd('videoType');
        /**成功后执行对应的奖励 */
    }
    /**意见反馈 */
    openServer() {
        console.log('---------------openServer-------')
        AppSdk.I.feedback();
    }


    async openRedpacket() {
        let bol = RedpacketModel.I.checkRedpacket();
        console.log(bol + '红包获取结果:curRedpacket' + RedpacketModel.I.curRedpacket)
        if (bol) {
            //**弹出红包的界面,  暂时处理成 直接看广告获取金币 */
            AdManager.I.showRewardAd(DotKey.reward_ad).then(async (res) => {
                console.log("加金币")
                let coin = await RedpacketModel.I.addCoin(); // 看完广告获取钱(此时已经加到账户了,暂未提供提前知道获取多少钱的方法)
                console.log("获取了钱", coin)
                RedpacketModel.I.getRepacket();//计数
                /**更新基本显示 */
                EventCenter.emit(EventEnum.UPDATE_COIN);
            }).catch(err => {
                console.log("onVideo error")
            })

        }
        // console.log('红包获取结果:' + JSON.stringify(data))
        // ViewManager.I.openPopwin(RedpacketPopwin, 0);
    }

    /**打开个人中心 */
    openPersonal() {
        console.log('---------------openServer-------')
        AppSdk.I.personal();
    }
    /**邀请好友 */
    invitation() {
        AppSdk.I.invitation();
    }
    //震动
    private onVibrate() {
        AppSdk.I.vibrate(0)
    }


    getProps(data) {
        let booster;
        let rewardNum = data.num;
        let type = data.type;
        /**
         * 处理游戏中的道具显示
         */
        // switch (type) {
        //     case 4:
        //         booster = BoosterType.Remove;
        //         break;
        //     case 6:
        //         booster = BoosterType.Change;
        //         break;
        //     case 5:
        //         booster = BoosterType.Refresh;
        //         break;
        //     case 7:
        //         booster = BoosterType.RandRemove;
        //         break;
        //     case 3:
        //         booster = BoosterType.Star;
        //         break;
        // }
        // ViewManager.I.openPopwin(ReceivePropsPopwin, booster, rewardNum);

    }
    /**
     * 看广告获得红包
     */
    async watchADCoin() {
        await AdManager.I.showRewardAd('videoType');
        this.getCoin();
    }
    /**直接获得红包 */
    getCoin() {
        //刷新总金币
        // AppManager.I.redpacket.getRepacket()
        // ViewManager.I.openPopwin(RedPacketReward, 2);
    }

    private onDraw() {
        AppSdk.I.openReward()
    }
}