import { _decorator, Component, Node } from 'cc';
import { PetEquip } from '../../../../consts/API';
import { Sprite } from 'cc';
import TbResource, { IconTypeEnum } from '../../../../tools/TbResource';
import { TD } from '../../../../App';
import { Label } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PetEquipIcon')
export class PetEquipIcon extends Component {

    @property(Sprite)
    sprite:Sprite;
    @property(Sprite)
    quality:Sprite;
    @property(Node)
    notEquip:Node;

    @property(Label)
    levelLabel:Label;   //等级

    info:PetEquip;

    onLoad(){
        this.onUpdateView();
    }

    //刷新页面
    onUpdateView(){

        this.levelLabel.node.active = false;
        this.notEquip.active = true;
        if(!this.info) return;

        this.notEquip.active = false;

        let config = TD.TbGRoleEquip.get(this.info.equipCfgId);
        TbResource.loadSpriteIcon(IconTypeEnum.宠物装备,config.icon,this.sprite,this);
        TbResource.loadSpriteIcon(IconTypeEnum.品质,config.quality,this.quality,this);

        this.levelLabel.node.active = true;
        this.levelLabel.string = `Lv ${this.info.equipLevel}`;
        
    }

    //设置icon
    set(info:PetEquip){
        this.info = info;
        this.onUpdateView();
    }

}


