
cc.Class({
    extends: cc.Component,

    properties: {

        content: cc.Node,
        messageText: cc.RichText,
        confirmNode: cc.Node,
    },

    onLoad() {
        this.confirmNode.on(cc.Node.EventType.TOUCH_END, () => {
            this.close();
        });
    },

    show(parent, text, callback) {
        this.callback = callback;
        this.node.parent = parent;

        this.content.scaleX = 0;
        this.content.scaleY = 0;
        this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));

        this.messageText.string = text;
    },

    close() {
        let cb = this.callback
        let finish = cc.callFunc(() => {
            cb && cb();
            this.node.destroy();
        }, this);
        let sq = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish)
        this.content.runAction(sq);
    },

    outlineString(text, color) {
        return '<outline color=' + color + ' width=2><b>' + text + '</b></outline>';
    },


    onDestory() {
        this.confirmNode.off(cc.Node.EventType.TOUCH_END, this);
    }

});
