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

public class StatusMenuCamera extends GenericCamera {
	private StatusMenuPanel panel;
	
	public StatusMenuCamera(StatusMenuPanel 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_STATUS_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("Back", 40, 64);
		
		
		//Draw Cursor Position
		cursorPos = panel.getCursorPosition();
		
		if(cursorPos == StatusMenuPanel.CURSOR_QUIT) {
			g.fillRect(16, 44, 16, 16);
		}		
		
		drawCharacterStatsAt(g,20,136,0);
		drawCharacterStatsAt(g,212,136,1);
		drawCharacterStatsAt(g,404,136,2);
		drawCharacterStatsAt(g,596,136,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, 184, 446);
		
		g.setColor(Color.WHITE);
		//g.setFont(new Font("Sans Serif",Font.BOLD,20));
		g.setFont(FontPool.getInstance().getPoolItem(FontPool.FONT_MINECRAFT).deriveFont(Font.BOLD,20));
		
		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+8,y+70);
		g.drawString("HP: " + player.getHP() + " / " + player.getMaxHP(),x+8,y+110);
		g.drawString("MP: " + player.getMP() + " / " + player.getMaxMP(),x+8,y+140);
		
		g.drawString("Atk: " + player.getAttack(),x+8,y+180);
		g.drawString("Def: " + player.getDefense(),x+8,y+210);
		g.drawString("Skl: " + player.getSkill(),x+8,y+240);
		g.drawString("Bar: " + player.getBarrier(),x+8,y+270);
		
		g.drawString("Exp: " + player.getExperience(),x+8,y+310);
		g.drawString("Next: " + player.getExperienceToNextLevel(),x+8,y+340);
	}
}
