package projectzombie.menu;

import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.init.Models;
import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.GUIAlignment;
import projectzombie.menu.gui.GUILabel;
import projectzombie.util.gl.GlHelpers;
import projectzombie.world.chunk.ChunkEventHandler;

public class MenuLoadingWorld extends Menu
{
	private GUI gui;
	
	public MenuLoadingWorld()
	{
		doGameloop = true;
		doGameRender = true;
		keepMouse = false;
		showIngameGUI = false;
		
		GUILabel label = new GUILabel();
		label.setText("Loading world...");
		label.setAlign(GUIAlignment.CENTRE);
		
		gui = new GUI();
		input = new InputGUI(gui);
		
		gui.add(label);
	}
	
	@Override
	public void render()
	{
		double a = GlHelpers.getAspectRatio();
		
		for(int x = 0; x < 16; x ++) {
			for(int y = 0; y < 16; y ++)
			{
				Models.UI_STONE_BG.setModel(Matrix4.multiply(
						Matrix4.scale(new Vec3d(1.25 * a, 1.25 * a, 1)),
						Matrix4.translate(new Vec3d(-10 * a + 1.25 * a * x, -10 * a + 1.25 * a * y, 0))));
				Models.UI_STONE_BG.render();
			}
		}
		
		gui.render();
	}
	
	@Override
	public void update()
	{
		super.update();
		
		if(ChunkEventHandler.loaded) {
			Main.menu = new MenuGame();
		}
	}
}
