package sg.states;


import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jmex.font2d.Font2D;
import com.jmex.font2d.Text2D;
import com.jmex.game.state.BasicGameState;

public class HudState extends BasicGameState{
	private Node hudNode;


	public HudState(String name) {
		super(name);

		hudNode = new Node("hud");
		hudNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
		hudNode.setCullHint(Spatial.CullHint.Never);
		hudNode.setLocalTranslation(new Vector3f(
				DisplaySystem.getDisplaySystem().getWidth()/2,
				DisplaySystem.getDisplaySystem().getHeight()/2,0));

		//Add the alpha values for the transparent node
		BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
		alphaState.setBlendEnabled(true);
		alphaState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
		alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
		alphaState.setTestEnabled(true);
		alphaState.setTestFunction(BlendState.TestFunction.GreaterThan);
		alphaState.setEnabled(true);
		
		ZBufferState zbs = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
		zbs.setFunction(ZBufferState.TestFunction.Always);
		
		Font2D font = new Font2D();
		Text2D text = font.createText("Loading...", 10.0f, 0);
		text.setRenderQueueMode(Renderer.QUEUE_ORTHO);
		text.setRenderState(zbs);
		text.updateRenderState();
		hudNode.attachChild(text);
		
		hudNode = new Node("hud_node");
		hudNode.setLightCombineMode(LightCombineMode.Off);
		hudNode.setRenderState(alphaState);
		hudNode.setRenderState(zbs);
		hudNode.updateRenderState();
		rootNode.attachChild(hudNode);
	}

	public void update(float tpf) {

		// last thing
		super.update(tpf);
	}
}
