package rpgEngine.Logic.Camera;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import rpgEngine.Data.Abstract.Party.HumanPlayer;
import rpgEngine.Resources.FontPool;
import rpgEngine.Resources.ImagePool;
import rpgEngine.UI.MainMenuPanel;


public class MainMenuCamera extends GenericCamera {
	private MainMenuPanel panel;
	
	public MainMenuCamera(MainMenuPanel p) {
		super();
		
		panel = p;
	}

	@Override
	public BufferedImage getImage() {
		BufferedImage img = null;
		Graphics2D g = null;
		Integer width = 800;
		Integer height = 600;
		Integer cursorPos = 0;
		
		img = new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB);
		
		g = img.createGraphics();
		
		//Draw Background
		g.setColor(Color.BLACK);
		g.fillRect(0, 0, width, height);		
		g.drawImage(ImagePool.getInstance().getPoolItem(ImagePool.ID_MENU_MAIN_BACKGROUND),0,0,width,height,null);
				
		//Draw Menu Choices
		g.setColor(Color.WHITE);
		//g.setFont(new Font("Sans Serif",Font.BOLD,32));
		g.setFont(FontPool.getInstance().getPoolItem(FontPool.FONT_MINECRAFT).deriveFont(Font.BOLD,32));
		g.drawString("Items", 40, 64);
		g.drawString("Skills", 40, 128);
		g.drawString("Equipment", 40, 192);
		g.drawString("Status", 40, 256);
		g.drawString("Save", 40, 320);
		g.drawString("Quit Game", 40, 384);
		
		//Draw Gold
		g.setColor(Color.WHITE);
		//g.setFont(new Font("Sans Serif",Font.BOLD,24));
		g.setFont(FontPool.getInstance().getPoolItem(FontPool.FONT_MINECRAFT).deriveFont(Font.BOLD,24));
		g.drawString("Gold: " + panel.getParentMainFrame().getGame().getGold(), 25, 550);
		
		//Draw Cursor Position
		cursorPos = panel.getCursorPosition();
		
		if(cursorPos == MainMenuPanel.CURSOR_ITEMS) {
			g.fillRect(16, 44, 16, 16);
		}
		else if(cursorPos == MainMenuPanel.CURSOR_SKILLS) {
			g.fillRect(16, 110, 16, 16);
		}
		else if(cursorPos == MainMenuPanel.CURSOR_EQUIPMENT) {
			g.fillRect(16, 174, 16, 16);
		}
		else if(cursorPos == MainMenuPanel.CURSOR_STATUS) {
			g.fillRect(16, 236, 16, 16);
		}
		else if(cursorPos == MainMenuPanel.CURSOR_SAVE) {
			g.fillRect(16, 300, 16, 16);
		}
		else if(cursorPos == MainMenuPanel.CURSOR_QUIT) {
			g.fillRect(16, 362, 16, 16);
		}		
		
		drawCharacterStatsAt(g, 280, 20, 0);
		drawCharacterStatsAt(g, 280, 150, 1);
		drawCharacterStatsAt(g, 280, 280, 2);
		drawCharacterStatsAt(g, 280, 410, 3);
		
		return img;
	}
	
	
	private void drawCharacterStatsAt(Graphics2D g, int x, int y, int c) {
		
		g.setColor(new Color(0,0,41));
		g.fillRect(x, y, 500, 120);
		
		g.setColor(Color.WHITE);
		//g.setFont(new Font("Sans Serif",Font.BOLD,24));
		g.setFont(FontPool.getInstance().getPoolItem(FontPool.FONT_MINECRAFT).deriveFont(Font.BOLD,24));
		
		HumanPlayer player = null;
		
		try {
			player = panel.getParentMainFrame().getGame().getParty().get(c);
		}
		catch(Exception e) {
			player = null;
		}
		
		if(player == null) {
			return;
		}
		
		g.drawString(player.getName(), x+8, y+30);
		g.drawString("Level " + player.getLevel(),x+360,y+30);
		g.drawString("HP: " + player.getHP() + " / " + player.getMaxHP(),x+8,y+70);
		g.drawString("MP: " + player.getMP() + " / " + player.getMaxMP(),x+8,y+100);
		
	}
	

}
