package hud.constructionmenu;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import _texture.loader.Textures;
import engine.Game;
import engine.MouseInput;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public final class ConstructionMenu {

	public static final int WIDTH = 80, HEIGHT = 450, BOXWIDTH = 46, BOXHEIGHT = 45, MENUWIDTH = 140, MENUHEIGHT = 400;
	public static int x, y;
	public static boolean hidden;
	public static Rectangle bounds = new Rectangle(0, 0, WIDTH, HEIGHT);
	public static Rectangle hideBounds = new Rectangle(0, 0, MENUWIDTH + WIDTH, Game.game.getHeight());

	public static final synchronized void init() {ConstructionMenuCategory.init();}

	public static final void tick() {
		for (final ConstructionMenuCategory i : ConstructionMenuCategory.categories) i.tick();

		if (hideBounds.contains(MouseInput.mouseXY)) { reveal(); if (x == 0) hidden = false;
		} else { hide(); if (x == -WIDTH + 15) hidden = true; }
	}

	public static final void render(Graphics2D g2d) {
		g2d.drawImage(Textures.baseConstructionSheet[0], x, Game.game.getHeight() / 2 - HEIGHT / 2, null);

		for (final ConstructionMenuCategory cmg : ConstructionMenuCategory.categories) cmg.render(g2d);

		if (Game.drawInventoryBounds) {
			g2d.setColor(Color.green); g2d.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
			g2d.setColor(Color.orange); g2d.drawRect(hideBounds.x, hideBounds.y, hideBounds.width, hideBounds.height);
		}
	}

	private static final void hide() {
		if (x > -WIDTH + 15) x -= 3; if(x < -WIDTH + 15) x = -WIDTH + 15;
		changeSettings();
	}

	private static final void reveal() {
		if (x < 0) x += 5; if(x > 0) x = 0;
		changeSettings();
	}

	public static final void changeSettings() {
		y = Game.game.getHeight() / 2 - HEIGHT / 2;
		ConstructionMenuCategory.changeSettings();
		bounds.x = x; bounds.y = y;

		hideBounds.height = Game.game.getHeight();
		hideBounds.width = MENUWIDTH + WIDTH;
		hideBounds.x = hideBounds.y = 0;
	}
}
