package tv.rocketbeans.supermafiosi.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;

import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import de.bitbrain.braingdx.assets.SharedAssetManager;
import de.bitbrain.braingdx.audio.AudioManager;
import de.bitbrain.braingdx.screens.AbstractScreen;
import de.bitbrain.braingdx.tweens.SharedTweenManager;
import tv.rocketbeans.supermafiosi.Colors;
import tv.rocketbeans.supermafiosi.SuperMafiosiGame;
import tv.rocketbeans.supermafiosi.assets.Asset;

public class InitialCreditsScreen extends AbstractScreen<SuperMafiosiGame>{
	
	private boolean isFadingOut = false;

	public InitialCreditsScreen(SuperMafiosiGame game) {
		super(game);
	}

	@Override
	protected void onCreateStage(Stage stage, int width, int height) {
		super.onCreateStage(stage, width, height);
		setBackgroundColor(Colors.BACKGROUND);
		getScreenTransitions().in(0.5f);
		
		getInput().addProcessor(new InputAdapter() {			
			public boolean keyDown(int keycode) {
				isFadingOut = true;
				AudioManager.getInstance().fadeOutMusic(Asset.Music.GAME_WIN_MAIN);
				AudioManager.getInstance().fadeInMusic(Asset.Music.MENU_CHAR_SELECT_INTRO);
				getScreenTransitions().out(new IntroScreen(getGame()), 2f);
				return true;
			};
		});
		
		Tween.call(new TweenCallback() {
			@Override
			public void onEvent(int arg0, BaseTween<?> arg1) {
				getScreenTransitions().out(new IntroScreen(getGame()), 2f);
			}
		}).delay(3f).start(SharedTweenManager.getInstance());
		
		Table table = new Table();
		table.setFillParent(true);
		Image logoA = new Image(new SpriteDrawable(new Sprite(SharedAssetManager.getInstance().get(Asset.Textures.LOGO_BEANSJAM, Texture.class))));
		Image logoB = new Image(new SpriteDrawable(new Sprite(SharedAssetManager.getInstance().get(Asset.Textures.LOGO_WEESEKS, Texture.class))));
		
		table.add(logoA).width(120f * 2f).height(200 * 2f).padRight(250f);
		table.add(logoB).width(200f * 2f).height(200f * 2f);
		
		stage.addActor(table);
	}
	
	@Override
	protected void onUpdate(float delta) {
		if (Gdx.input.isTouched() && !isFadingOut) {
			isFadingOut = true;
			getScreenTransitions().out(new IntroScreen(getGame()), 2f);
		}
	}
}

@@ -1375,16 +1375,21 @@
 ) %7B%0A%09%09%09%09
+if (!
 isFading
@@ -1395,169 +1395,38 @@
 gOut
- = true;%0A%09%09%09%09AudioManager.getInstance().fadeOutMusic(Asset.Music.GAME_WIN_MAIN);%0A%09%09%09%09AudioManager.getInstance().fadeInMusic(Asset.Music.MENU_CHAR_SELECT_INTRO)
+) %7B%0A%09%09%09%09%09isFadingOut = true
 ;%0A
+%09
 %09%09%09%09
@@ -1480,21 +1480,24 @@
 ame()), 
-2
+0.5
 f);%0A
+%09
 %09%09%09%09retu
@@ -1505,16 +1505,54 @@
 n true;%0A
+%09%09%09%09%7D else %7B%0A%09%09%09%09%09return false;%0A%09%09%09%09%7D%0A
 %09%09%09%7D;%0A%09%09
@@ -1656,24 +1656,49 @@
 %3C?%3E arg1) %7B%0A
+%09%09%09%09if (!isFadingOut) %7B%0A%09
 %09%09%09%09getScree
@@ -1749,16 +1749,22 @@
 ), 2f);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D
@@ -2495,25 +2495,27 @@
 getGame()), 
-2
+0.5
 f);%0A%09%09%7D%0A%09%7D%0A%7D

Fix sound