package com.eyeofmidas.cardtrick;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.utils.Scaling;

public class TrainingIntroScreen implements Screen {

	private CardtrickGame game;

	public TrainingIntroScreen() {
		game = (CardtrickGame) Gdx.app.getApplicationListener();
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		game.getStage().act(delta);
		game.getStage().draw();
	}

	@Override
	public void resize(int width, int height) {
		game.getStage().getViewport().update(width, height, true);
	}

	@Override
	public void show() {
		game.getStage().clear();
		game.getStage().addListener(new InputListener() {

			@Override
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
				return true;
			}

			@Override
			public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
				game.goTraining();
			}

			@Override
			public boolean keyDown(InputEvent event, int keyCode) {
				switch (keyCode) {
				case Input.Keys.BACK:
				case Input.Keys.ESCAPE:
					game.goMainMenu();
					break;
				}
				return false;
			}
		});

		Image background = new Image(game.getAssetManager().get("wallpaper.png", Texture.class));
		background.setSize(game.getStage().getWidth(), game.getStage().getHeight());
		background.setScaling(Scaling.fill);
		background.setAlign(Align.center);
		game.getStage().addActor(background);

		String promptText = "The location you press corresponds to a card value. The direction you swipe corresponds to a suit. To perform well, subtly touch the screen in the correct location and swipe in the correct direction.";
		Label promptLabel = new Label(promptText, game.getSkin());
		promptLabel.setWrap(true);
		promptLabel.setAlignment(Align.center);

		Table root = new Table();
		root.row();
		root.add(promptLabel).pad(10).width(game.getStage().getWidth() - 20);
		root.setFillParent(true);

		game.getStage().addActor(root);

		Gdx.input.setInputProcessor(game.getStage());
		Gdx.input.setCatchBackKey(true);

	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
