package menus;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;

public class MenuSeleccion2p extends MenuSeleccion{
	int p1;
	public MenuSeleccion2p() {
		super();
		this.local=Menu.SELEC2;
		this.p1=-1;
	}
	
	@Override
	public int draw(SpriteBatch batch, float delta) {
		if(p1!=-1) {
			batch.end();
			shapeDrawer.begin(ShapeType.Filled);
			shapeDrawer.setColor(Color.GRAY);
			if(p1<3) {
				shapeDrawer.rect(10+p1*280, 430, 190, 180);
			}else {
				shapeDrawer.rect(10+(p1-3)*280, 210, 190, 180);
			}
			shapeDrawer.end();
			batch.begin();
		}
		for(int i=0; i<this.caratulas.size();i++) {
			if(i<3) {
				if(i==this.position) {
					batch.end();
					shapeDrawer.begin(ShapeType.Filled);
					if(p1!=-1) {
						shapeDrawer.setColor(Color.BLACK);
					}else {
						shapeDrawer.setColor(Color.GRAY);
					}
					shapeDrawer.rect(10+i*280, 430, 190, 180);
					shapeDrawer.end();
					batch.begin();
				}
				this.caratulas.get(i).draw(batch, 10+i*200, 300);
			}else {
				if(i==this.position) {
					batch.end();
					shapeDrawer.begin(ShapeType.Filled);
					if(p1!=-1) {
						shapeDrawer.setColor(Color.BLACK);
					}else {
						shapeDrawer.setColor(Color.GRAY);
					}
					shapeDrawer.rect(10+(i-3)*280, 210, 190, 180);
					shapeDrawer.end();
					batch.begin();
				}
				this.caratulas.get(i).draw(batch, 10+(i-3)*200, 150);
			}
			
		}
		return this.darSeleccionado();
	}
	
	@Override
	int darSeleccionado() {
		if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
			if(!this.pres) {
				this.position++;
				this.pres=true;
			}
		}else if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
			if(!this.pres) {
				this.position--;
				this.pres=true;
			}
		}else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
			if(!this.pres) {
				this.position=3;
				this.pres=true;
			}
		}else if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
			if(!this.pres) {
				this.position=0;
				this.pres=true;
			}
		}else if (Gdx.input.isKeyPressed(Input.Keys.ENTER)){
			if(!this.pres) {
				this.pres=true;
				if(p1==-1) {
					p1=this.position;
					this.position=0;
				}else {
					Menu.menus.add(new Battle2(this.caratulas.get(this.p1).nombre,
							this.caratulas.get(this.position).nombre));
					this.p1=-1;
					this.position=0;
					return Menu.BATTLE;
				}
			}
		}else if(this.pres) {
			this.pres=false;
		}
		this.position%=this.n_opciones;
		if(this.position<0)this.position=this.n_opciones-1;
		return this.local;
	}
}
