package zero1hd.rhythmbullet.ui.pages;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.controls.KeyMap;
import zero1hd.rhythmbullet.ui.components.GraphicsTable;
import zero1hd.rhythmbullet.ui.components.SetControls;

public class MoreOptionsPage extends Page {
	private KeyMap keymap;
	private ScrollPane controlsScroller;
	private SetControls controlSetter;
	
	private ScrollPane graphicsScroller;
	private GraphicsTable graphicsSettings;
	
	
	public MoreOptionsPage(RhythmBullet core, final Vector3 targetLocation) {
		keymap = new KeyMap(core);
		
		TextButton backArrow = new TextButton("Back", core.getDefaultSkin());
		backArrow.setPosition(15, getHeight()-backArrow.getHeight()-10);
		backArrow.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				targetLocation.y = 0.5f*Gdx.graphics.getHeight();
			}
		});
		addActor(backArrow);
		
		controlSetter = new SetControls(core.getDefaultSkin(), keymap);
		controlsScroller = new ScrollPane(controlSetter, core.getDefaultSkin());
		controlsScroller.setFadeScrollBars(false);
		controlsScroller.setSize(getWidth()-backArrow.getWidth()-backArrow.getX()-10, getHeight());
		controlsScroller.setX(backArrow.getWidth()+10+backArrow.getX());
		addActor(controlsScroller);
		controlsScroller.setVisible(false);
		
		graphicsSettings = new GraphicsTable(core.getDefaultSkin(), core.getPrefs());
		graphicsScroller = new ScrollPane(graphicsSettings, core.getDefaultSkin());
		graphicsScroller.setFadeScrollBars(false);
		graphicsScroller.setSize(getWidth()-backArrow.getWidth()-backArrow.getX()-10, getHeight());
		graphicsScroller.setX(backArrow.getWidth()+10+backArrow.getX());
		addActor(graphicsScroller);
		graphicsScroller.setVisible(false);
	}
	
	public void controlUnselect() {
		controlSetter.unselect();
	}
	
	public void setControlType(byte type) {
		switch (type) {
		case 0:
			controlsScroller.setVisible(true);
			graphicsScroller.setVisible(false);
			break;
		case 1:
			controlsScroller.setVisible(false);
			graphicsScroller.setVisible(true);
			break;
		}
	}
	
	public GraphicsTable getGraphicsSettings() {
		return graphicsSettings;
	}
}
