import Main from "../../../main/Main";
import { __RoleIcon } from "../../data/sdata/SManage";

/**
 * 称号节点
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class RoleTitleItem extends cc.Component {

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

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

    @property(cc.Node)
    mLock: cc.Node = null;//锁

    public roleIcon:__RoleIcon


    private callback:(frameIcon:RoleTitleItem)=>void

    public setCallback(callback:(frameIcon:RoleTitleItem)=>void){
        this.callback = callback
    }

    public onclick(){
        if(this.callback){
            this.callback(this)
        }
    }

    public init(){
        this.mName.string = this.roleIcon.name
        cc.resources.load('icon/role_head/ch/'+this.roleIcon.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
            if(err){
                cc.error(err);
            }else{
               this.mIcon.spriteFrame = spriteFrame;
            }
        });
    }

    public flushLock(main:Main){
        let roleIcon = main.player.roleIcon
        if(roleIcon.data.indexOf(this.roleIcon.id) < 0){
            this.mLock.active = true
        }else{
            this.mLock.active = false
        }
    }




    
}
