package rpgEngine.UI;

import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import rpgEngine.Logic.Camera.GenericCamera;
import rpgEngine.Logic.Camera.TitleCamera;
import rpgEngine.Logic.Game.GameFactory;

public class TitlePanel extends GenericPanel {

	private static final long serialVersionUID = 6538729434640140830L;
	private GenericCamera camera;
	private Integer cursorPosition;
	
	public static final Integer CURSOR_NEWGAME = 0;
	public static final Integer CURSOR_LOADGAME = 1;
	public static final Integer CURSOR_QUIT = 2;
	
	
	public TitlePanel(Integer id, MainFrame p) {
		super(id, p);
		
		camera = new TitleCamera(this);
		cursorPosition = CURSOR_NEWGAME;
	}
	
	@Override
	public void ProcessKeyEvent(KeyEvent e) {
		if(e.getKeyCode() == KeyEvent.VK_DOWN) {
			if(cursorPosition < 2) {
				cursorPosition++;
			}
			else {
				cursorPosition = 0;
			}
		}
		else if(e.getKeyCode() == KeyEvent.VK_UP) {
			if(cursorPosition > 0) {
				cursorPosition--;
			}
			else {
				cursorPosition = 2;
			}			
		}
		else if(e.getKeyCode() == KeyEvent.VK_ENTER) {
			if(cursorPosition == TitlePanel.CURSOR_NEWGAME) {
				this.getParentMainFrame().setGame(GameFactory.CreateNewGame());
				this.getParentMainFrame().showScreen(MainFrame.PANEL_GAME);
			}
			else if(cursorPosition == TitlePanel.CURSOR_LOADGAME) {
				this.getParentMainFrame().showScreen(MainFrame.PANEL_LOAD_GAME);
			}
			else if(cursorPosition == TitlePanel.CURSOR_QUIT) {
				System.exit(0);
			}
		}
	}
	
	@Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
     
        BufferedImage img = camera.getImage();
        
        g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
    }

	public Integer getCursorPosition() {
		return cursorPosition;
	}

	public void setCursorPosition(Integer cursorPosition) {
		this.cursorPosition = cursorPosition;
	}

}
