package com.kangacult.octogone;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Overlay {
	BitmapFont font;
	SpriteBatch batch;

	public int wave;
	public boolean gameOver;

	public Overlay(int wave) {
		font = new BitmapFont(
				Gdx.files.internal("fonts/FiraSansBold45.fnt")
		);

		batch = new SpriteBatch();
		setWaveNum(wave);
	}

	public void setWaveNum(int wave) {
		this.wave = wave;
	}

	String timeText(float val) {
		int millis = (int) (val * 100f);
		int hours = millis / 360000;
		int minutes = (millis % 360000) / 6000;
		int seconds = ((millis % 360000) % 6000) / 100;
		int milli = ((millis % 360000) % 6000) % 100;

		if (hours > 0) {
			return fixTimer(hours) + ":" + fixTimer(minutes) + ":" + fixTimer(seconds) + ":" + fixTimer(milli);
		} else {
			return fixTimer(minutes) + ":" + fixTimer(seconds) + ":" + fixTimer(milli);
		}
	}

	String fixTimer(int time) {

		if (time == 0) {
			return "00";
		} else if (time < 10) {
			return "0" + time;
		} else {
			return "" + time;
		}
	}

	public void drawMenu() {
		int height = Gdx.graphics.getHeight();
		int width = Gdx.graphics.getWidth();

		batch.begin();
			font.draw(batch, "OCTO-GONE!", width/2 -100, height * 0.90f);
			font.draw(batch, "Press Any Key To Start", width/2 -175, height * 0.32f);
			font.draw(batch, "Michael Stopa, Jonathon Hart, Andrew Dunn, Arlen Drechsler-Savage", 50, height * 0.10f);
		batch.end();
	}

	public void draw(float gameClock) {
		int height = Gdx.graphics.getHeight();
		int width = Gdx.graphics.getWidth();

		batch.begin();

		font.setColor(0.55f, 0.34f, 0.42f, 1f);
		//HighScore
		if (GamePrefs.instance.hScore > 0f) {
			font.draw(batch, "BEST TIME: " + timeText(GamePrefs.instance.hScore), width * 0.05f, height * 0.95f);
		}

		if (GamePrefs.instance.hWave > 0f) {
			font.draw(batch, "BEST WAVE: " + (GamePrefs.instance.hWave), width * 0.05f, height * 0.90f);
		}

		font.setColor(1f, 1f, 1f, 1f);

		//GameClock
		font.draw(batch, "TIME: " + timeText(gameClock), width * 0.70f, height * 0.10f);

		// Wave
		font.draw(batch, "WAVE " + wave, width * 0.10f, height * 0.10f);

		//GameOver
		if (gameOver) {
			font.draw(batch, "GAME OVER: Press [R] or [BACK] to continue", 300, 300);
		}
		batch.end();
	}
}
