import { ui } from "../ui/layaMaxUI";
import { PlayerManager } from "../Manager/PlayerManager";
import { AssetManager } from "../Resources/AssetManager";
import { GameManager } from "../Manager/GameManager";
import { LevelManager } from "../Manager/LevelManager";
import { AccountManager } from "../NetWork/AccountManager";
import { ServerManager, TeamWave } from "../NetWork/ServerManager";
import GuangGao from "../NetWork/GuangGao";
export class GameResultView extends ui.GameResultViewUI{
    private static ins:GameResultView;
    constructor(){
        super();
        GameResultView.ins = this;
    }
    private _result:boolean;
    public static get Instance():GameResultView{
        if(GameResultView.ins == null){
            return new GameResultView();
        }
        return GameResultView.ins;
    }
    OnShow(data){
        this._result = data;
        if(data){
            this.WinBox.visible = true;
            this.FailBox.visible = false;
        }
        else{
            this.WinBox.visible = false;
            this.FailBox.visible = true;
        }
        LevelManager.Instance.BackMain();
        this.RefreshUI();
        this.RegButton();
        this.height = Laya.stage.height;
        Laya.stage.on(Laya.Event.RESIZE,this,()=>
        {
            this.height = Laya.stage.height;
        })
    }
    RegButton(){
        this.Win_BackBtn.clickHandler = new Laya.Handler(this,this.BackHome);
        this.Win_VideoBtn.clickHandler = new Laya.Handler(this,this.WinVideoGet);
        this.Win_kuangbtn.clickHandler = new Laya.Handler(this,this.ClickWinKuang);
        this.Fail_BackBtn.clickHandler = new Laya.Handler(this,this.BackHome);
        this.Fail_VideoBtn.clickHandler = new Laya.Handler(this,this.LoseVideoGet);
        this.Fail_kuangbtn.clickHandler = new Laya.Handler(this,this.ClickLoseKuang);
    }
    RefreshUI(){
        this.Win_GoldNum.text = (AccountManager.Instance.curplayerData.LevelReward(this._result) + GameManager.GoldNum) + "";
        this.Fail_GoldNum.text = (AccountManager.Instance.curplayerData.LevelReward(this._result) + GameManager.GoldNum) + "";
    }
    ClickWinKuang(){
        this.win_dian.visible = !this.win_dian.visible;
    }
    ClickLoseKuang(){
        this.fail_dian.visible = !this.fail_dian.visible;
    }
    WinVideoGet(){
        GuangGao.ShowVideo((isLoad)=>{
            if(isLoad){

            }
        })
    }
    LoseVideoGet(){
        GuangGao.ShowVideo((isLoad)=>{
            if(isLoad){
                
            }
        })
    }
    BackHome(){
        let stage = AccountManager.Instance.curplayerData.STAGE;
        var iswin = this._result?"1":"0";
        var coinnum = (AccountManager.Instance.curplayerData.LevelReward(this._result) + GameManager.GoldNum) + "";
        var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.play_id},{"win":iswin},{"money":coinnum}];
        ServerManager.Instance.SendHttp(TeamWave.JieShu,args,Laya.Handler.create(this,this.Success),null);
    }
    Success(){
        GameManager.GoldNum = 0;
        GameManager.Instance.GameOver();
    }
    OnHide(){
        
    }
}