import { Label } from 'cc';
import { _decorator, Component, Node } from 'cc';
import ResourceData, { ResourceEvent, ResourceType } from '../../../data/ResourceData';
import { Enum } from 'cc';
import { app, TD } from '../../../App';
import NumberTools from '../../../tools/NumberTools';
const { ccclass, property } = _decorator;

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


    //显示的资源
    @property({type:Enum(ResourceType)})
    type:ResourceType = ResourceType.Gold;

    //显示名称
    @property(Label)
    tig:Label;

    //显示文本
    @property(Label)
    show:Label;

    protected onLoad(): void {
        
        //更新
        this.onUpdateView();
        //监听
        app.event.on(ResourceEvent.UPDATE,this.onUpdateView,this);

    }

    protected onDestroy(): void {
        app.event.off(ResourceEvent.UPDATE,this.onUpdateView,this);
    }

    //刷新
    onUpdateView(){

        //更新名称
        this.tig && (this.tig.string = `${TD.TbGResource.get(this.type).name}:`);
        //更新资源数量
        this.show.string = `${NumberTools.NumberStr(ResourceData.getIns().getValue(this.type))}`;

    }

}


