import { _decorator, } from 'cc';
import { GameInfo } from '../../GameInfo';
import { UIMgr } from '../../Frames/UIManager';
import { ModulerBase } from '../GameFrameWork/ModulerBase';
import { GameMgr } from '../GameFrameWork/GameMgr';
import { SelectTroops } from './SelectTroops';
import { messageMgr } from '../../Frames/MessageMgr';
import { localDt } from '../../Frames/LocalDt';
const { ccclass, property } = _decorator;

@ccclass('BattleSceneTop')
export class BattleSceneTop extends ModulerBase {

    protected onStart() {
        this.onBtnClick("_btnReturn", this._btnReturn);
        //this._gold(GameInfo.Instance.getGold());
        this._gold(Number(localDt.getData("Gold")));
        this._diamond(GameInfo.Instance.getDiamond());
        this.battleMode("战斗模式");
        messageMgr.addEvent("reduceGold", this._gold, this);
        messageMgr.addEvent("reduceDiamond", this._diamond, this);
        if (GameInfo.Instance.getGameOverReward()?.size != 0) {
            this._gold(GameInfo.Instance.getGameOverReward().get("GameOverRewardGold"));
            this._diamond(GameInfo.Instance.getGameOverReward().get("GameOverRewardDia"));
        }
    }

    //金币数量
    _gold(goldAmound: number) {
        this.getLabel("_gold").string = String(goldAmound);
    }

    //钻石数量
    _diamond(diamondAmound: number) {
        this.getLabel("_diamond").string = String(diamondAmound);
    }

    //返回按钮
    private _btnReturn() {
        if (!GameMgr.Instance.getModuler(SelectTroops).showing()) {
            UIMgr.openUI("Start");
        } else {
            GameMgr.Instance.getModuler(SelectTroops).hide(false);
        }
    }

    battleMode(name: string) {
        this.getLabel("_battleMode").string = name;
    }
}


