import Scene from "../views/Scene";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";
import VirtualJoystick from "../components/VirtualJoystick"
import GameConst from "../GameConst";

const { TouchEvent } = egret;
export default class PlayScene extends Scene{
    protected get skinKey() { return 'Play' }

    public rulePanel:eui.Panel;
    public fireBtn:eui.Button;
    public photoPanel:eui.Panel;
    public resultPanel:eui.Panel;
    // public VJ:eui.Component;
    

    private vj:VirtualJoystick = new VirtualJoystick(125,GameConst.stage.stageHeight-230);

    public BABYLON:any = window['BABYLON'];
    public nipplejs:any = window['nipplejs'];
    public joystickL:any;
    public joystickR:any;
    public canvasWebgl:any;
    public scene:any;
    public camera:any;
    public light:any;
    public ground:any;
    public fireCollisionArr:any[] = [];
    public tankP:any;
    public tank:any;
    private tankArr:any[] = [];
    private bulletPool:any[] = [];
    private bulletCount:number = 0;
    private isFireEnable:boolean = false;
    private tankSpeed:number = 0.15;
    private gravity:number = -0.98;
    private moveForward:boolean = false;
    private moveBackward:boolean = false;
    private rotateLeft:boolean = false;
    private rotateRight:boolean = false;
    private tankDownHits:any[] = [];
    private pipeline:any;
    private glowLayer:any;
    

    constructor(){
        super()
        this.show();
    }


    show(){

        //开启虚拟摇杆
        this.vj.start();
        this.vj.addEventListener("vj_start",this.onVJStart, this);
        this.vj.addEventListener("vj_end", this.onVJEnd, this);

    }

    private onEnterFrame(){
        this.scene.render();
        
    }
    
    private vecToLocal(vector, mesh){
        var m = mesh.getWorldMatrix();
        var v = BABYLON.Vector3.TransformCoordinates(vector, m);
		return v;		 
    }

    private createGround(){
        
       
    }

    private createFixedMeshes(mesh:any,number:number,shadowGenerator?:any,isCollision?:boolean,isFireCollision?:boolean){
        
    }

    //摇杆启动，人物开始根据摇杆移动
    private onVJStart(){
       
    }
    private onVJMove(e){
       
    }
    //停止摇杆，人物停止移动
    private onVJEnd(){
       
    }


    initEvents() {
        this.fireBtn.addEventListener( egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin_fireBtn, this);
        this.fireBtn.addEventListener( egret.TouchEvent.TOUCH_END, this.onTouchEnd_fireBtn, this);
        this.fireBtn.addEventListener( egret.TouchEvent.TOUCH_TAP, this.onClick_fireBtn, this);
    }

    removeEvents() {
        this.fireBtn.removeEventListener( egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin_fireBtn, this);
        this.fireBtn.removeEventListener( egret.TouchEvent.TOUCH_END, this.onTouchEnd_fireBtn, this);
        this.fireBtn.removeEventListener( egret.TouchEvent.TOUCH_TAP, this.onClick_fireBtn, this);
    }

    private onTouchBegin_fireBtn(e){
        // this.camera.detachControl(document.querySelectorAll("canvas")[0]);
    }

    private onTouchEnd_fireBtn(e){
        // this.camera.attachControl(document.querySelectorAll("canvas")[0],false);
    }

    private onClick_fireBtn(e){
        this.fire();
    }


    /**
     * 开火
     */
    private fire(){
       
    }

    /** 
     * 让物体朝传入方向移动
     * 放在onEnterFrame里或者render里
    */
    public moveByVector(mesh:any, forward:any, speed?:number, isGravity?:boolean){
      
    }

}