import { _decorator, director, EditBox, } from 'cc';
import { GameInfo } from '../../GameInfo';
import { resMgr } from '../../Frames/ResourcesMgr';
import { ModulerBase } from '../GameFrameWork/ModulerBase';
import { GameMgr } from '../GameFrameWork/GameMgr';
import { SelectTroops } from './SelectTroops';
import { BattleSceneTop } from './BattleSceneTop';
import { localDt } from '../../Frames/LocalDt';
const { ccclass, property } = _decorator;

@ccclass('BattleSceneLeft')
export class BattleSceneLeft extends ModulerBase {
    editBox: EditBox | null = null;
    
    protected onStart() {
        this.editBox = this.getComponentInChildren(EditBox);
        this._setEdit();
        
        this._curLv(Number(GameInfo.Instance.getCurlv()));
        this.onBtnClick("_btnLevel", this._btnLevel);
        if(GameInfo.Instance.getOverWin() && GameInfo.Instance.getGameOverReward().size != 0){
            this._curLv(GameInfo.Instance.getGameOverReward().get("CurLv"));
        }
        this.editBox.node.on("editing-did-ended", this._onEdit, this)
    }

    //当前关卡
    private _curLv(lv: number) {
        this.getLabel("_curLv").string = String(lv);
    }

    private _btnLevel() {
        GameMgr.Instance.getModuler(SelectTroops).show();
        GameMgr.Instance.getModuler(BattleSceneTop).battleMode("选择部队")
    }

    //保存名字
    private _onEdit(editbox: EditBox){
        localDt.saveData("PlayerName",editbox.string);
    }

    private _setEdit(){
        if(localDt.getData("PlayerName")){
            this.editBox.string = String(localDt.getData("PlayerName"));
        }
    }
}


