package edu.oswego.tiltandtumble.screens.dialogs;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

import edu.oswego.tiltandtumble.TiltAndTumble;
import edu.oswego.tiltandtumble.screens.GameScreen;


public class PauseDialog extends Dialog {
	private final GameScreen screen;
	private final TiltAndTumble game;
	private final Sound button;
	private static enum Buttons {
		QUIT,
		SETTINGS,
		RETRY,
		CONTINUE
	}

	public PauseDialog(String title, Skin skin, GameScreen screen, final TiltAndTumble game) {
		super(title, skin, "dialog");
		this.screen = screen;
		this.game = game;
		padTop(50);
        setModal(true);
        setMovable(false);

        AssetManager assetManager = new AssetManager();
        String musicFile = "data/soundfx/button-8.wav";
		if (!assetManager.isLoaded(musicFile)) {
			assetManager.load(musicFile, Sound.class);
			assetManager.finishLoading();
		}
		button = assetManager.get(musicFile, Sound.class);

        getButtonTable().row().uniform().fill();
        button("Quit", Buttons.QUIT);
        getButtonTable().row().uniform().fill();
        button("Settings", Buttons.SETTINGS);
        getButtonTable().row().uniform().fill();
        button("Retry", Buttons.RETRY);
        getButtonTable().row().uniform().fill();
		button("Continue", Buttons.CONTINUE);
		this.addListener(new InputListener(){
			public boolean keyDown(InputEvent event, int keycode){
				 if(keycode == Keys.BACK){
				   	 game.showPreviousScreen();
				   	 return true;
				 }
				return false;
			}
		});
		
	}

	@Override
	protected void result(Object object) {
		
		super.result(object);
		Gdx.app.log("dialog result", "" + object);
		if (object != null && object instanceof Buttons) {
			button.play();
			Buttons b = (Buttons)object;
			if (b == Buttons.QUIT) {
				game.playMusic();
				game.showPreviousScreen();
			} else if (b == Buttons.SETTINGS) {
				game.showSettingsScreen();
			} else if (b == Buttons.RETRY) {
				if (screen.getMode() == GameScreen.Mode.ARCADE) {
					screen.loadLevel(0);
				} else {
					screen.loadLevel(screen.getCurrentLevel().getLevelNumber());
				}
			} else if (b == Buttons.CONTINUE) {
				screen.resume();
			}
		} else {
			screen.resume();
		}
		
	}
}

@@ -1595,24 +1595,26 @@
 ONTINUE);%0A%09%09
+//
 this.addList
@@ -1641,16 +1641,18 @@
 er()%7B%0A%09%09
+//
 %09public 
@@ -1701,16 +1701,18 @@
 ode)%7B%0A%09%09
+//
 %09%09 if(ke
@@ -1734,16 +1734,18 @@
 ACK)%7B%0A%09%09
+//
 %09%09   %09 g
@@ -1772,16 +1772,18 @@
 en();%0A%09%09
+//
 %09%09   %09 r
@@ -1800,15 +1800,19 @@
 ;%0A%09%09
+//
 %09%09 %7D%0A%09%09
+//
 %09%09re
@@ -1825,21 +1825,25 @@
 alse;%0A%09%09
+//
 %09%7D%0A%09%09
+//
 %7D);%0A%09%09%0A%09
@@ -2525,14 +2525,234 @@
 ;%0A%09%09%7D%0A%09%09
+this.addListener(new InputListener()%7B%0A%09%09%09public boolean keyDown(InputEvent event, int keycode)%7B%0A%09%09%09%09 if(keycode == Keys.BACK)%7B%0A%09%09%09%09   %09 game.showPreviousScreen();%0A%09%09%09%09   %09 return true;%0A%09%09%09%09 %7D%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D);
 %0A%09%7D%0A%7D%0A

Revert "Finished android back button"