package uk.co.beercave.gunboat;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;

import uk.co.beercave.gunboat.renderers.GuiRenderer;

public class LevelOutro {

	public static float time = 0;
	private static boolean setup = false;
	private static Color spudColor1;
	private static Color spudColor2;
	public static boolean update(float delta) {
		float scale = Math.min(time*2,1);
		GuiRenderer.Sprite(ResourceManager.blankTx, 400, 240, 400/16, 400/16*scale);
		time += delta;
		if (time > .5f){
			GuiRenderer.Text("LEVEL CLEAR", 220, 430, .5f, Color.BLACK);
			
		}
		if (time > .6f){
			if (!setup) doSetup();

			GuiRenderer.Text("EPIC SPUD BONUS!!!", 240, 360, .25f, Color.BLACK);
			GuiRenderer.Sprite(ResourceManager.blankTx, 400, 240, 100/16f, 150/16f, spudColor2);
			GuiRenderer.Sprite(ResourceManager.blankTx, 380, 200, 100/16f, 150/16f, spudColor2);

			GuiRenderer.Sprite(ResourceManager.blankTx, 380, 290, 2, 2, spudColor1);
			GuiRenderer.Sprite(ResourceManager.blankTx, 425, 185, 2, 2, spudColor1);
			GuiRenderer.Sprite(ResourceManager.blankTx, 360, 160, 2, 2, spudColor1);
			GuiRenderer.Sprite(ResourceManager.blankTx, 370, 240, 2, 2, spudColor1);
			
			if (GuiRenderer.Button("CONTINUE", 300, 100, .5f, Color.BLACK)){
				Gdx.app.log("GUI", "Button clicked");
				return true;
			}
		}
		
		return false;
	}

	private static void doSetup() {
		setup = true;
		spudColor1 = colourFromHex("b36f04");
		spudColor2 = colourFromHex("dcd172");
		
	}

	public static void reset() {
		time = 0;
	}

	private static Color colourFromHex(String hex){
		Gdx.app.log("", "colour from hex : " + hex);
		String xr = hex.substring(0, 2);
		String xg = hex.substring(2, 4);
		String xb = hex.substring(4, 6);
		
		Gdx.app.log("", "R=" + xr + " G=" + xg + " B=" + xb);
		
		float r = (float)Integer.valueOf(xr, 16) * 1/255f;
		float g = Integer.valueOf(xg, 16) * 1/255f;
		float b = Integer.valueOf(xb, 16) * 1/255f;
		
		Gdx.app.log("", "R=" + new Float(r).toString() + " G=" + new Float(g).toString() + " B=" + new Float(b).toString());

		return new Color(r,g,b,1);
	}
}
