import { _decorator, Component, Node } from 'cc';
import GOnHookData, { GOnHookDataEnum } from '../../../data/GOnHookData';
import { app, TD } from '../../../App';
import { Label } from 'cc';
import { TbGEntity } from '../../../config/data/schema';
const { ccclass, property } = _decorator;

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

    @property(Label)
    title:Label;    //标题
    @property(Node)
    progress:Node;  //进度

    onLoad(){
        app.event.on(GOnHookDataEnum.UPDATE,this.onUpdateView,this);
        this.onUpdateView();
    }

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

    onUpdateView(): void {
        
        let info = GOnHookData.getIns().info;
        let sign = null;
        let levelId = info.levelId;
        if(info && levelId){
            sign = TD.TbGOnHookMaps.get(info.onHookMap)?.sign;
            if(!sign) return;
        }else return;
        
        let table:{data:TbGEntity.TOnHookLevel} = TD[sign].get(GOnHookData.getIns().info.levelId);

        //显示难度
        this.title.string = `难度 : ${table.data.level}-${table.data.childLevel}`;
        //显示进度
        this.progress.children.forEach((item,index) => {
            if(index < GOnHookData.getIns().getProgress())
                item.active = true;
            else item.active = false;
        });

    }

}


