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

/**
 * 对话中的属性选择
 */
const {ccclass, property} = cc._decorator;

/**
 * 对话属性内容
 */
export interface DialogAttrContent{
    name:string,
    about:string,
    icon:string,
    vaule:number,
    type:number,//添加属性类型
}

@ccclass
export default class FDialogAttr extends cc.Component {

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

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

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

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

    public attr:DialogAttrContent;

    private callback:(attr:FDialogAttr)=>void;

    public onclick(){
        if(this.callback){
            this.callback(this);
        }
    }
    public setCallback(callback:(attr:FDialogAttr)=>void){
        this.callback = callback;
    }

    public setVaule(attr:DialogAttrContent){
        this.attr = attr;

        this.mName.string = i18n.t(attr.name)
        this.mAbout.string = i18n.t(attr.about)
        this.mVaule.string = attr.vaule + '%';

        cc.resources.load('icon/attr/'+attr.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
            if(err){
                cc.error(err);
            }else{
               this.mIcon.spriteFrame = spriteFrame;
            }
        } );
        
    }
}
