import {MouseEvent} from "./MouseEvent";
import {MoundManager} from "../Manager/MoundManager";
import StreetManager from "../Manager/StreetManager";
import {MateManager} from "../Manager/MateManager";
import {MainRoleManager} from "../Manager/MainRoleManager";
import {RoleManager} from "../Manager/RoleManager";
import {ViewManager, ViewType } from "../Net/ViewManager";
import {CameraManager} from "../Manager/CameraManager";
import { CameraState } from "./Camera";
import { Scene3DManager } from "./Scene3DManager";
import { PlayerManager } from "./PlayerManager";
import { DispatcherManager, EventType } from "./DispatcherManager";
import { WXSdk } from "../Net/WXSdk";
import {GuideController} from "../Manager/GuideController";
import {GuangGao} from "../Net/GuangGao";

export  class GameManager {
    private static instance: GameManager;
    public static get Instance(): GameManager {
        return GameManager.instance || (GameManager.instance = new GameManager());
    }

    public Start() {
        this.towerCount = 0;
        this.roleCount = 0;
        this.blockCount = 0;
    }


    public towerCount = 0;
    public roleCount = 0;
    public blockCount = 0;
    public Win() {
        WXSdk.LongVibrate();

        GuangGao.Clear();
        ViewManager.Instance.AddView(ViewType.CompleteView, true);
        MoundManager.Instance.Reset();
        StreetManager.Instance.Reset();
        MateManager.Instance.Reset();
        MainRoleManager.Instance.Reset();
        RoleManager.Instance.Reset();
    }
    Congratulate(isglod = false) {
        GuangGao.CheatBanner(null);
        MainRoleManager.Instance.GoToTiaoWu();
        if (isglod) MateManager.Instance.TiaoWu1();
        else MateManager.Instance.TiaoWu();
        CameraManager.Instance.SetCameraAction(CameraState.jump, 0.03);  //TODO
        Laya.timer.once(4000, this, this.Win);//todo
    }

    //public gameisover=false;
    /**
     * 游戏结束
     */
    public Over() {
        GuideController.Instance.GameOver();
        //this.canshowtoptip = false;
        MouseEvent.Instance.OnClickUp();
        MainRoleManager.Instance.CreateOver();

        MouseEvent.Instance._Switch = false;
        WXSdk.LongVibrate();

        GuangGao.Clear();
        ViewManager.Instance.AddView(ViewType.CompleteView, false);
        MoundManager.Instance.Reset();
        StreetManager.Instance.Reset();
        MateManager.Instance.Reset();
        MainRoleManager.Instance.Reset();
        MainRoleManager.Instance.HidePlayer();
        RoleManager.Instance.Reset();
    }
    
/************************************************************************************** */
    loadUI(){
        Laya.loader.load(["res/threeDimen/ui/button.png"], Laya.Handler.create(this, function() {
				
            this.changeActionButton = Laya.stage.addChild(new Laya.Button("res/threeDimen/ui/button.png", "切换Mesh"));
            this.changeActionButton.size(160, 40);
            this.changeActionButton.labelBold = true;
            this.changeActionButton.labelSize = 30;
            this.changeActionButton.sizeGrid = "4,4,4,4";
            this.changeActionButton.scale(Laya.Browser.pixelRatio, Laya.Browser.pixelRatio);
            this.changeActionButton.pos(Laya.stage.width / 2 - this.changeActionButton.width * Laya.Browser.pixelRatio / 2, Laya.stage.height - 100 * Laya.Browser.pixelRatio);
            
            this.changeActionButton.on(Laya.Event.CLICK, this, function(){
                this.index++;
                if (this.index % 5 === 1 ){
                    //切换mesh
                    this.sphere.meshFilter.sharedMesh = this.box;
                }
                else if (this.index % 5 === 2){
                    //切换mesh
                    this.sphere.meshFilter.sharedMesh = this.capsule;
                }
                else if(this.index % 5 === 3){
                    //切换mesh
                    this.sphere.meshFilter.sharedMesh = this.cylinder;
                }
                else if(this.index % 5 === 3){
                    //切换mesh
                    this.sphere.meshFilter.sharedMesh = this.cone;
                }
                else{
                    //切换mesh
                    this.sphere.meshFilter.sharedMesh = this.sphereMesh;
                }
            });
            
        }));
    }
    /************************************************************************************** */


    //人物到达终点
    public Near() {
        MoundManager.Instance.Reset();
        StreetManager.Instance.Reset();
    }

    public ReStart() {
        MateManager.Instance.Reset();

        Scene3DManager.Instance.InItScene();
        DispatcherManager.event(EventType.Event.ShowMainUi);
        DispatcherManager.event(EventType.Event.SetStagePro, 0);
    }


    public LevelUp() {
        PlayerManager.Instance.stage++;
        Scene3DManager.Instance.InItScene();
        ViewManager.Instance.CloseView(ViewType.CompleteView);
        DispatcherManager.event(EventType.Event.ShowMainUi);
        DispatcherManager.event(EventType.Event.SetStage);
        DispatcherManager.event(EventType.Event.SetStagePro, 0);
    }
  
}