import i18n from "../../../i18n/i18n";

const {ccclass, property} = cc._decorator;
/**
 * 对话框 - 对话
 */
@ccclass
export default class DialogSay extends cc.Component {

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

    /**
     * 对话框
     */
    @property(cc.Node)
    mDialog: cc.Node = null;


    public index:number = 0;
    /**
     * 对话内容
     */
    private contents:Array<string> = null;

    public setContents(contents:Array<string>){
        this.contents = contents;
        this.mContent.string = i18n.t(this.contents[0]);
        this.index = 0;
    }
    /**
     * 对话结束回调
     */
    public endCallback:()=>void;
    public close(){
        this.node.destroy();
    }

    public setEndCallback(endCallback:()=>void){
        this.endCallback = endCallback;
    }

    public onclick(){
        this.index ++;
        if(this.index >= this.contents.length){
            this.endCallback();
            this.close();
            return;
        }
        this.mContent.string = i18n.t(this.contents[this.index]);
    }

}
