package de.dbaelz.secludedness.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

import de.dbaelz.secludedness.MainGame;


public class MenuScreen extends AbstractScreen {
	private TextureAtlas mAtlas;
	private Skin mSkin;
	private Table mTable;
	
	public MenuScreen(MainGame game) {
		super(game);
	}

	@Override
	public void show() {
		super.show();
		
		mAtlas = new TextureAtlas(Gdx.files.internal("ui/uiskin.atlas"));
		FileHandle skinFile = Gdx.files.internal( "ui/uiskin.json" );
		mSkin = new Skin(skinFile);

		TextButton playRandomLevel = new TextButton("PLAY RANDOM LEVEL", mSkin);
		playRandomLevel.addListener(new ClickListener() {
			// TODO: Fix touch down -> drag out of button -> touch up issue
			@Override
			public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				
				mGame.setScreen(new LevelScreen(mGame, false));
			}
		});

		TextButton playCampaign = new TextButton("PLAY CAMPAIGN", mSkin);
		playCampaign.addListener(new ClickListener() {
			// TODO: Fix touch down -> drag out of button -> touch up issue
			@Override
			public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				
				mGame.setScreen(new LevelScreen(mGame, true));
			}
		});
		
		mTable = new Table(mSkin);
		mTable.setFillParent(true);
		mStage.addActor(mTable);
		mTable.add(playRandomLevel).size(180, 30).uniform().spaceBottom(10);
		mTable.row();
		mTable.add(playCampaign).size(180, 30).uniform().spaceBottom(10);
		
		
	}
	
	@Override
	public void hide() {
		super.hide();
		mAtlas.dispose();
		mSkin.dispose();
	}
}

@@ -986,75 +986,8 @@
 ) %7B%0A
-%09%09%09// TODO: Fix touch down -%3E drag out of button -%3E touch up issue%0A
 %09%09%09@
@@ -987,32 +987,32 @@
  %7B%0A%09%09%09@Override%0A
+
 %09%09%09public void t
@@ -1320,75 +1320,8 @@
 ) %7B%0A
-%09%09%09// TODO: Fix touch down -%3E drag out of button -%3E touch up issue%0A
 %09%09%09@
@@ -1534,16 +1534,309 @@
 %09%7D);%0A%09%09%0A
+%09%09TextButton endGame = new TextButton(%22END GAME%22, mSkin);%0A%09%09endGame.addListener(new ClickListener() %7B%0A%09%09%09@Override%0A%09%09%09public void touchUp(InputEvent event, float x, float y, int pointer, int button) %7B%0A%09%09%09%09super.touchUp(event, x, y, pointer, button);%09%09%09%09%0A%09%09%09%09Gdx.app.exit();%09%09%09%09 %0A%09%09%09%7D%0A%09%09%7D);%0A%09%09%0A
 %09%09mTable
@@ -2070,18 +2070,105 @@
 (10);%0A%09%09
-%0A%09
+mTable.row();%0A%09%09mTable.add(endGame).size(180, 30).uniform().spaceBottom(10).spaceTop(30);
 %09%0A%09%7D%0A%09%0A%09

Add button to exit game