import { NetInfoManager } from "./NetInfoManager";
import  {AssetPath, AppSetting } from "./AssetManager";
import UserModel, { UserAttr } from "../Net/UserModel";
import { PlayerManager } from "./PlayerManager";
import { GlobalParam } from "../Net/GlobalParam";


import Sprite = Laya.Sprite;
import Stage = Laya.Stage;
import Text = Laya.Text;
import Event = Laya.Event;
import SoundManager = Laya.SoundManager;
import Browser = Laya.Browser;
import Handler = Laya.Handler;
import WebGL = Laya.WebGL;

export class UserInfoManager {
    
    //初始化游戏参数
    public static GameInfo() {
        PlayerManager.Instance.InitPlayer();
    }

    //获取配置信息
    public static SetCfg(cfg) {
        NetInfoManager.Instance._level = cfg[AssetPath.Config.level];
        NetInfoManager.Instance._road = cfg[AssetPath.Config.road];
        NetInfoManager.Instance._block = cfg[AssetPath.Config.block];
        NetInfoManager.Instance._thing = cfg[AssetPath.Config.thing];
        NetInfoManager.Instance._atk = cfg[AssetPath.Config.atk];
        NetInfoManager.Instance._rate = cfg[AssetPath.Config.rate];
       // NetInfoManager.Instance._rate = cfg[AssetPath.tableName.rate];
        NetInfoManager.Instance._theme = cfg[AssetPath.Config.theme];
        NetInfoManager.Instance._globe=cfg[AssetPath.Config.global];
        
        PlayerManager.GlobalMessage();
    }

    
/************************************************************ */
    private setup(): void {
        var gap: number = 10;

        //创建一个Sprite充当音效播放按钮
        var soundButton: Sprite = this.createButton("播放音效");
        soundButton.x = (Laya.stage.width - soundButton.width * 2 + gap) / 2;
        soundButton.y = (Laya.stage.height - soundButton.height) / 2;
        Laya.stage.addChild(soundButton);

        //创建一个Sprite充当音乐播放按钮
        var musicButton: Sprite = this.createButton("播放音乐");
        musicButton.x = soundButton.x + gap + soundButton.width;
        musicButton.y = soundButton.y;
        Laya.stage.addChild(musicButton);

        soundButton.on(Event.CLICK, this, this.onPlaySound);
        musicButton.on(Event.CLICK, this, this.onPlayMusic);
    }
    private createButton(label: string): Sprite {
        var w: number = 110;
        var h: number = 40;

        var button: Sprite = new Sprite();
        button.size(w, h);
        button.graphics.drawRect(0, 0, w, h, "#FF7F50");
        button.graphics.fillText(label, w / 2, 8, "25px SimHei", "#FFFFFF", "center");
        Laya.stage.addChild(button);
        return button;
    }

    private onPlayMusic(e: Event): void {
        console.log("播放音乐");
        SoundManager.playMusic("res/sounds/bgm.mp3", 1, new Handler(this, this.onComplete));
    }

    private onPlaySound(e: Event): void {
        console.log("播放音效");
        SoundManager.playSound("res/sounds/btn.mp3", 1, new Handler(this, this.onComplete));
    }
    private onComplete(): void {
        console.log("播放完成");
    }
    /************************************************************ */



    //设置后台数据
    public static Appseting(data) {


        AppSetting.shareimage = data["shareimage"];
        AppSetting.sharetitle = data["sharetitle"];
        AppSetting.bannerCanMove = Number(data["bannerCanMove"]);
        AppSetting.moveTime = Number(data["moveTime"]);
        AppSetting.OpenSceneValue = Number(data["OpenSceneValue"]);
        AppSetting.freeUpdateVideotime = Number(data["freeUpdateVideotime"]);
        AppSetting.freecoinValue = Number(data["freecoinValue"]);
        AppSetting.freeGetcoinTime = Number(data["freeGetcoinTime"]);
        AppSetting.cheat = data["cheat"];
        AppSetting.cheattime = data["cheattime"];
        AppSetting.checkscene = data["checkscene"];


        GlobalParam.playerspeed = Number(data["playerspeed"]);
        GlobalParam.matespeed = Number(data["friendspeed"]);
        GlobalParam.shootspeed = Number(data["bulletspeed"]);
        GlobalParam.sliderFactor = Number(data["sliderFactor"]);
        GlobalParam.playerMoveMaxX = Number(data["playerMoveMaxX"]);
        GlobalParam.playerRayLengthF = Number(data["playerRayLengthF"]);
        GlobalParam.playerRayLengthLR = Number(data["playerRayLengthLR"]);
        GlobalParam.bulletRayLength = Number(data["bulletRayLength"]);
        GlobalParam.bulletMaxDis = Number(data["bulletMaxDis"]);
        GlobalParam.barrierRoadLength = Number(data["barrierRoadLength"]);
        GlobalParam.barrierRoadAverageNum = Number(data["barrierRoadAverageNum"]);
        GlobalParam.hitmaxcount = Number(data["hitmaxcount"]);
        GlobalParam.boommaxcount = Number(data["boommaxcount"]);
        GlobalParam.blockLRmoveMaxDis = Number(data["blockLRmoveMaxDis"]);
        GlobalParam.arriveStandWidth = Number(data["arriveStandWidth"]);
        GlobalParam.enemySpeed = Number(data["enemySpeed"]);
    }

    //误触
    public static get Cheat():boolean{
        return AppSetting.cheat == "1";
    }
    //误触时间
    public static get CheatTime():number{
        return Number(AppSetting.cheattime); 
    }
    //检测场景值
    public static get CheckScene():boolean{
        return AppSetting.checkscene == "1";
    }


}