const GameModule = require("../utils/GameModule");
const DWTool = require('../utils/DWTool');

cc.Class({
    extends: cc.Component,

    properties: {
        addLabel: cc.Label,

        addRichText: cc.RichText,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // this.node.zIndex = this.zIndex;
        // this.addLabel.active = false;
    },

    start () {

    },

    showAddMoney(showFinish, isAuto = false) {
        let money = DWTool.coinParse(GameModule.userInfo.coinTap);
        this.addRichText.string = `<img src='coin_small'/> +${money}`;

        this.node.opacity = 255;
        this.node.scale = 1.0;
        let upAction = cc.moveBy(0.5, 0, 150);
        let scaleAction = cc.scaleTo(0.2,0.7,0.7);
        let fadeAction = cc.fadeOut(0.5);

        let callback = cc.callFunc(() => {
            this.node.active = false;
            if (showFinish) {
                showFinish();
            }
        });
        let spaw = cc.spawn(upAction,scaleAction,fadeAction);
        let act = spaw.easing(cc.easeIn(1.2));
        this.node.runAction(cc.sequence(act, callback));

        GameModule.userInfo.gold += GameModule.userInfo.coinTap;

        if (!isAuto) {
            GameModule.userInfo.clickCount += 1;
        }
    },

    // update (dt) {},
});
