import FunBtns from "./FunBtns";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Game extends cc.Component {
    @property({ type: cc.Node, displayName: "游戏核心" })
    node_game: cc.Node = null;
    @property({ type: cc.Node, displayName: "功能按钮" })
    node_btn: cc.Node = null;
    @property({ type: cc.Sprite, displayName: "头像" })
    img_head: cc.Sprite = null;
    @property({ type: cc.Label, displayName: "红包币" })
    lbl_redMoney: cc.Label = null;
    @property({ type: cc.Label, displayName: "金猪币" })
    lbl_rmb: cc.Label = null;
    @property({ type: cc.Sprite, displayName: "红包提现" })
    btn_cashOutNormal: cc.Sprite = null;
    @property({ type: cc.Sprite, displayName: "金猪提现" })
    btn_cashOutGold: cc.Sprite = null;
    @property({ type: cc.Node, displayName: "气泡红包1" })
    btn_getRed1: cc.Node = null;
    @property({ type: cc.Node, displayName: "气泡红包2" })
    btn_getRed2: cc.Node = null;
    @property({ type: cc.Node, displayName: "气泡红包3" })
    btn_getRed3: cc.Node = null;
    @property({ type: cc.Button, displayName: "开始游戏" })
    btn_start: cc.Button = null;
    @property({ type: cc.Node, displayName: "红包币图标" })
    icon_hb: cc.Node = null;
    @property({ type: cc.Node, displayName: "金猪币图标" })
    icon_zb: cc.Node = null;
    
    onLoad() {
        gData.gameData.gameStyle = this;
        mk.ui.closePanel("login");
    }

    start() {
        this.initMusic();
        this.initBtns();
        this.initQiPaos();
        this.initInfo();
    }

    private initMusic() {
        mk.audio.playMusic("bgm");
    }

    /**
     * 根据配置，添加开启的功能按钮
     */
    private initBtns() {
        let sc = this.node_btn.getComponent(FunBtns) as FunBtns;
        sc.init();
    }

    private initQiPaos() {
        cc.tween(this.btn_getRed1).to(2, { y: 100 }).to(2, { y: 0 }).union().repeatForever().start();
        cc.tween(this.btn_getRed2).delay(0.3).to(2, { y: 100 }).to(2, { y: 0 }).union().repeatForever().start();
        cc.tween(this.btn_getRed3).delay(0.6).to(2, { y: -50 }).to(2, { y: -150 }).union().repeatForever().start();
    }

    private initInfo() {
        this.lbl_redMoney.string = gData.gameData.gameData.redMoney + "";
        this.lbl_rmb.string = gData.gameData.gameData.piggyBank + "";
    }

    //测试道具获取效果
    private testFly() {
        mk.fly.PlayCoinAnim(1, 20, cc.v2(0, -300), cc.v2(0, 0));
        // mk.fly.PlayCoinAnim(2, 20, cc.v2(0, -300), 'Canvas/界面层/game/功能按钮/右侧按钮/btn2');
    }
}

