package projectzombie.model;

import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;

public class ModelGui extends Model
{
	private int color, flags;
	private int animationSize;
	private int animationSpeed;
	private double width, height;
	private double opacity = 1;
	private TextureRef3D ref;
	private Vec2d size;
	
	public ModelGui(TextureRef3D ref, Vec2d size, int animationSize, int animationSpeed)
	{
		this.ref = ref;
		this.size = size;
		
		this.animationSize = animationSize;
		this.animationSpeed = animationSpeed;
		
		flags = 0b10000;
	}
	
	public ModelGui(TextureRef3D tex, int animationSize, int animationSpeed) {
		this(tex, new Vec2d(1, 1), animationSize, animationSpeed);
	}
	
	public ModelGui(TextureRef3D tex, Vec2d size) {
		this(tex, size, 1, 1);
	}
	
	public ModelGui(TextureRef3D tex) {
		this(tex, new Vec2d(1, 1), 1, 1);
	}
	
	public ModelGui setOpacity(double opacity) {
		this.opacity = opacity;
		return this;
	}
	
	public ModelGui setColor(float r, float g, float b) {
		color = (int)(r * 63) + ((int)(g * 63) << 6) + ((int)(b * 63) << 12);
		flags |= 0b10;
		return this;
	}
	
	@Override
	public int getSize() {
		return 4;
	}
	
	@Override
	public float[] getVerticies()
	{
		float x = (float)size.x;
		float y = (float)size.y;
		float o = (float)opacity;
		
		int asi = animationSize;
		int asp = animationSpeed;
		
		width = x;
		height = y;
		
		return new float[] {
				0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, asi, asp, o, color, flags,
				x, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, asi, asp, o, color, flags,
				x, y, 0, 1, 1, 0, 0, 1, 0, 0, 0, asi, asp, o, color, flags,
				0, y, 0, 0, 1, 0, 0, 1, 0, 0, 0, asi, asp, o, color, flags,
		};
	}
	
	@Override
	public int getIndexSize() {
		return 6;
	}
	
	@Override
	public int[] getIndicies() {
		return new int[] {
				0, 1, 2,
				2, 3, 0,
		};
	}
	
	@Override
	public TextureRef3D[] getTextures()
	{
		return new TextureRef3D[] {
				ref, ref, ref, ref
		};
	}
	
	@Override
	public double getHeight() {
		generate();
		return height;
	}
	
	public double getWidth() {
		generate();
		return width;
	}
}
