package MyMain;


import java.awt.*;                          //BorderLayout,GraphicsConfiguration,event

import Cameus.KameusThread;
import MyCanvas.ClearCanvas.*;
import MyCanvas.EndingCanvas.EndingCanvas;
import MyCanvas.GameCanvas.EnemyData;
import MyCanvas.GameCanvas.FiveRoundData;
import MyCanvas.GameCanvas.GameCanvas;
import MyCanvas.KaisetsuCanvas.KaisetsuCanvas;
import MyCanvas.LoadingCanvas.LoadingCanvas;
import MyCanvas.StartCanvas.StartCanvas;

import com.sun.j3d.utils.picking.PickCanvas;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

public class CameraPointingGame implements Runnable{

    public PickCanvas cnvs=null;
    //public Canvas canvasClearGame;
    public LoadingCanvas loadingView;
    
    public ClearCanvas canvasClearGame;
    public StartCanvas canvasStartView;
    public EndingCanvas canvasEndingView;
    public KaisetsuCanvas canvasKaisetsuView;
    public GameCanvas canvasGameView;

    public Cursor cursor;

	public float move1 = 0.0f;
	public float move2 = 0.0f;
	public float move3 = 0.0f;
	public JFrame frame;

    public void init(){
    	
       
        

	}

    public CameraPointingGame(){
    	frame = new JFrame();
    	frame.setBackground(new Color(0.8f, 0.9f, 1.0f));

    	frame.setLayout(new BorderLayout());

    	frame.addWindowListener(new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent e)
            {
            	try{Cameus.KameusThread.capture.release();
                System.out.println("Closed");
                e.getWindow().dispose();
                //System.exit(0);
                }
            	catch (Exception e1) {
                    e.getWindow().dispose();
                    //System.exit(0);
                    }
            	
            }
        });

    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setTitle("CameraPointingGame");
		frame.setBounds(200,200,1024,768);

		frame.getContentPane().setPreferredSize(new Dimension(1000,754));
		frame.pack();

		frame.setVisible(true);
		
		frame.invalidate();
    	frame.validate();        

		frame.setLayout(null);
		frame.setResizable(false);
		
    	loadingView = new LoadingCanvas(this);
        changeLoadingCanvas();

        Thread thread = new Thread(this);
    	thread.start(); 
    }
    public void changeClearCanvas(){

    	ChangeCanvasThread changeCanvasThread = new ChangeCanvasThread(this, "changeClearCanvas");
    	changeCanvasThread.threadStart();

    	FocusCanvas focusCanvas = new FocusCanvas(this);
        focusCanvas.threadStart();
    }
    
    public void changeStartCanvas(){
    	
    	ChangeCanvasThread changeCanvasThread = new ChangeCanvasThread(this, "changeStartCanvas");
    	changeCanvasThread.threadStart();
    	
    	FocusCanvas focusCanvas = new FocusCanvas(this);
        focusCanvas.threadStart();	
    	
    }
    public void changeKaisetsuCanvas(){
    	ChangeCanvasThread changeCanvasThread = new ChangeCanvasThread(this, "chanageKaisetsuCanvas");
    	changeCanvasThread.threadStart();
    	
    	FocusCanvas focusCanvas = new FocusCanvas(this);
        focusCanvas.threadStart();
    }
    public void changeEndingCanvas(){
    	ChangeCanvasThread changeCanvasThread = new ChangeCanvasThread(this, "changeEndingCanvas");
    	changeCanvasThread.threadStart();
    	
    	FocusCanvas focusCanvas = new FocusCanvas(this);
        focusCanvas.threadStart();
    }
    public void changeGameCanvas(){
    	ChangeCanvasThread changeCanvasThread = new ChangeCanvasThread(this, "changeGameCanvas");
    	changeCanvasThread.threadStart();
    	
    	EnemyData.gametimer.timerStart();
    	EnemyData.changeText(EnemyData.enemyCountTFG, TextData.GAME_ENEMY_NUM2  + "10");


		int round = FiveRoundData.nowRound;

		if (round == 1){
			EnemyData.changeText(EnemyData.levelTFG, TextData.GAME_LEVEL_LOW);
		}
		else if (round == 2){
			EnemyData.changeText(EnemyData.levelTFG, TextData.GAME_LEVEL_MIDDLE);
		}
		else if (round == 3){
			EnemyData.changeText(EnemyData.levelTFG, TextData.GAME_LEVEL_HIGH);
		}
			
    	FocusCanvas focusCanvas = new FocusCanvas(this);
        focusCanvas.threadStart();
    }
    
    public void changeLoadingCanvas(){
    	ChangeCanvasThread changeCanvasThread = new ChangeCanvasThread(this, "changeLoadingCanvas");
    	changeCanvasThread.threadStart();
    	
    	FocusCanvas focusCanvas = new FocusCanvas(this);
        focusCanvas.threadStart();
    }
    
    public void destroy(){
    	System.exit(0);
        //simpleU.cleanup();
    }

    public static void main(String[] args){    //Application
        System.loadLibrary("opencv_java300");
        //System.loadLibrary("jnivideoInputLib");
        KameusThread.CameraDeviceNumber = 0;
    	//new GetCameraNumber();
        

    	CameraPointingGame cpg = new CameraPointingGame();
    }
    
	@Override
	public void run() {

		canvasClearGame = new ClearCanvas(this);
		canvasStartView = new StartCanvas(this);
		canvasEndingView = new EndingCanvas(this);
		canvasKaisetsuView = new KaisetsuCanvas(this);
		canvasGameView = new GameCanvas(this);

		changeStartCanvas();
	}
}
