/**
 * @description 互推弹出红包界面
 * @author kaka
 */

import JsbSystem from "../../../mk/system/JsbSystem";


const { ccclass, property } = cc._decorator;

@ccclass
export default class MoreGamePopNode extends cc.Component {

    @property(cc.Sprite)
    icon: cc.Sprite = null;

    @property(cc.Label)
    labName: cc.Label = null;

    data = null

    start() {
        gData.moreGame.init_moreGameList = true;
    }

    update() {
        if (gData.moreGame.init_moreGameList) {
            this.init();
        }
    }

    lateUpdate() {
        gData.moreGame.init_moreGameList = false;
    }

    init() {
        this.data = gData.moreGame.getRandomNormal();
        if (this.data) {
            //pc不加载，加载会报错
            if (cc.sys.os != cc.sys.OS_WINDOWS) {
                cc.loader.load(this.data.icon, (err, res) => {
                    if (err) {
                        console.log('err:', err);
                        return;
                    }
                    let tex: cc.Texture2D = res as cc.Texture2D;
                    this.icon.spriteFrame = new cc.SpriteFrame(tex);
                })
            }

            this.labName.string = this.data.title
        }
    }

    cool = false
    creatorDownLoadTask() {
        mk.audio.playEffect('button');

        if (this.cool) {
            return
        }

        this.cool = true

        if (!JsbSystem.ifCanStartGame(this.data.packageName, true)) {
            gData.moreGame.createNewTask(this.data)
        }
    }

    onClosePanel() {
        // mk.audio.playEffect('getGold');
        mk.tip.pop('红包币+300');
        //     GameM.commonData.updateRedMoney(300, RecordTYPE.online)
        mk.fly.PlayCoinAnim(1, 20, cc.v2(0, -300), cc.v2(0, 0));
    }
}
