package rpgEngine.Logic.Camera;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import rpgEngine.Logic.Game.GameFactory;
import rpgEngine.Resources.FontPool;
import rpgEngine.Resources.ImagePool;
import rpgEngine.UI.SaveGamePanel;


public class SaveGameCamera extends GenericCamera {
	private SaveGamePanel panel;
	
	public SaveGameCamera(SaveGamePanel 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_SAVE_LOAD_GAME_BACKGROUND),0,0,width,height,null);
		
		g.setColor(Color.WHITE);
		g.setFont(FontPool.getInstance().getPoolItem(FontPool.FONT_MINECRAFT).deriveFont(Font.BOLD,32));
		g.drawString("Back", 40, 64);
		
		//Draw Game Slots
		drawGameSlotAt(g,20,136,0);
		drawGameSlotAt(g,212,136,1);
		drawGameSlotAt(g,404,136,2);
		drawGameSlotAt(g,596,136,3);
		
		//Draw Cursor Position
		g.setColor(Color.WHITE);
		cursorPos = panel.getCursorPosition();
		
		if(cursorPos == SaveGamePanel.CURSOR_CANCEL) {
			g.fillRect(16, 44, 16, 16);
		}	
		else if(cursorPos == SaveGamePanel.CURSOR_GAME1) {
			g.fillRect(30,146,164,16);
		}
		else if(cursorPos == SaveGamePanel.CURSOR_GAME2) {
			g.fillRect(222,146,164,16);
		}
		else if(cursorPos == SaveGamePanel.CURSOR_GAME3) {
			g.fillRect(414,146,164,16);
		}
		else if(cursorPos == SaveGamePanel.CURSOR_GAME4) {
			g.fillRect(606,146,164,16);
		}
		
		return img;
	}
	
	
	private void drawGameSlotAt(Graphics2D g, int x, int y, int c) {
		g.setColor(new Color(0,0,41));
		g.fillRect(x, y, 184, 446);
		
		if(GameFactory.doesSaveGameExist(c)) {	
			g.setColor(Color.WHITE);
			g.setFont(FontPool.getInstance().getPoolItem(FontPool.FONT_MINECRAFT).deriveFont(Font.BOLD,20));
			
			g.drawString("Save " + (c+1), x+8, y+60);
		}
	}
	
}
