package ei.game.hud;

import ei.engine.LWJGLGameWindow;
import ei.engine.effects.BitmapText;
import ei.engine.effects.ProgressBar;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector4f;
import ei.engine.scene.Node;
import ei.engine.scene.Sprite;
import ei.game.player.Player;

/**
 * This clas handles the hud of the game
 * @author Ziver
 *
 */
public class InGameHud {
	private Node hudNode;
	private BitmapText money;
	private Player player;
	private ProgressBar buildBar;
	private InGameBuildHud buildHud;
	private Sprite buildBack;
	
	public InGameHud(Player p){
		player = p;
		
		hudNode = new Node("Hud");
		
		Sprite moneyBack = new Sprite("MoneyBackground","data/hud/money.png");
		moneyBack.setLocation(new Vector2f(
				LWJGLGameWindow.getWidth()-moneyBack.getSize().getX()/2,
				moneyBack.getSize().getY()/2));
		hudNode.add(moneyBack);
		
		money = new BitmapText("MoneyMeter");
		money.setLocation(new Vector2f(LWJGLGameWindow.getWidth()-money.getBound().width,5));
		hudNode.add(money);
		
		buildBack = new Sprite("BuildBackground","data/hud/buildmenu.png");
		buildBack.setLocation(new Vector2f(
				LWJGLGameWindow.getWidth()/2,
				LWJGLGameWindow.getHeight()-buildBack.getSize().getY()/2));
		hudNode.add(buildBack);
		
		buildBar = new ProgressBar("BuildProgressBar",350,5,100);
		buildBar.setBarColor(new Vector4f(0.41f, 0.41f, 0.41f, 1f));
		buildBar.setValueColor(100, new Vector4f(0.21f, 0.7f, 0.44f, 1f));
		buildBar.getNode().setLocation(new Vector2f(
				LWJGLGameWindow.getWidth()/2+50,
				LWJGLGameWindow.getHeight()-55));
		hudNode.add(buildBar.getNode());
		
		buildHud = new InGameBuildHud((int)(buildBack.getLocation().getX()-buildBack.getSize().getX()/4),
				(int)(buildBack.getLocation().getY()+10),player);
		hudNode.add(buildHud.getNode());
	}
	
	public void update(){
		money.setText(""+player.getKredits());
		money.setLocation(new Vector2f(LWJGLGameWindow.getWidth()-money.getBound().width,5));
		
		buildBar.setValue(player.getCC().getBuildProgress());
		
		buildHud.update();
		
		hudNode.setLocation(new Vector2f(
				LWJGLGameWindow.getCamera().getLocation().getX(),
				LWJGLGameWindow.getCamera().getLocation().getY()));
	}
	
	public Node getNode(){
		return hudNode;
	}
	
	public InGameBuildHud getBuildHud(){
		return buildHud;
	}
	
	public Sprite getBuildBar(){
		return buildBack;
	}
}
