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.StatusMenuCamera;

public class StatusMenuPanel extends GenericPanel{
	private static final long serialVersionUID = 6538729434652140830L;
	private GenericCamera camera;
	private Integer cursorPosition;
	
	public static final Integer CURSOR_QUIT = 0;
	
	
	public StatusMenuPanel(Integer id, MainFrame p) {
		super(id, p);
		
		camera = new StatusMenuCamera(this);
		cursorPosition = CURSOR_QUIT;
	}
	
	@Override
	public void ProcessKeyEvent(KeyEvent e) {
		if(e.getKeyCode() == KeyEvent.VK_DOWN) {
			if(cursorPosition < 0) {
				cursorPosition++;
			}
			else {
				cursorPosition = 0;
			}
		}
		else if(e.getKeyCode() == KeyEvent.VK_UP) {
			if(cursorPosition > 0) {
				cursorPosition--;
			}
			else {
				cursorPosition = 0;
			}
		}
		else if(e.getKeyCode() == KeyEvent.VK_ENTER) {
			processActionKey();
		}
		else if(e.getKeyCode() == KeyEvent.VK_SPACE) {
			processActionKey();
		}
		else if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
			processEscapeKey();
		}		
	}
	
	
	private void processActionKey() {
		
		if(cursorPosition == CURSOR_QUIT) {
			this.getParentMainFrame().showScreen(MainFrame.PANEL_MENU_MAIN);
		}
		
	}
	
	
	private void processEscapeKey() {
		this.getParentMainFrame().showScreen(MainFrame.PANEL_MENU_MAIN);
	}
	
	@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;
	}
}
