import { Label } from 'cc';
import { Sprite } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { TbGEntity, TbGEnum } from '../../../config/data/schema';
import { TD } from '../../../App';
import TbResource, { IconTypeEnum } from '../../../tools/TbResource';
const { ccclass, property } = _decorator;

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

    //资源品质
    @property(Sprite)
    quality:Sprite;

    //资源图标
    @property(Sprite)
    icon:Sprite;

    //资源数量
    @property(Label)
    num:Label;

    info:TbGEntity.TReward;

    //设置icon
    set(info:TbGEntity.TReward){

        this.info = info;
        if(info.type == TbGEnum.TReward.Resource)
            this.onUpdateResource();

    }

    //刷新资源
    onUpdateResource(){

        let config = TD.TbGResource.get(this.info.id);

        //设置ICON
        TbResource.loadSpriteIcon(IconTypeEnum.资源,config.icon,this.icon,this);
        //设置品质
        TbResource.loadSpriteIcon(IconTypeEnum.品质,config.quality,this.quality,this);

        this.num.string = ``;
        if(this.info.value > 1){
            //显示数量
            this.num.string = `${this.info.value}`;
        }

    }

}
