package zero1hd.rhythmbullet.ui.windows;

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;

public class NoticeWindow extends Window {
	private Label noticeText;
	private Skin skin;
	
	private Sound closeSound;
	private Sound openSound;
	private float vol;
	public NoticeWindow(Skin skin, String styleName, String text, float vol, AssetManager assets) {
		super("Notice", skin, "tinted");
		this.skin = skin;
		
		this.openSound = assets.get("pop_open.ogg", Sound.class);
		this.closeSound = assets.get("pop_close.ogg", Sound.class);
		this.vol = vol;
		
		noticeText = new Label(text, skin, "sub-font", skin.getColor("default"));
		noticeText.setWrap(true);
		noticeText.setAlignment(Align.center);
		add(noticeText).expandX().fill().center().padLeft(20f).padRight(20f);
	}
	
	public NoticeWindow(Skin skin, String styleName, String title, String text, float vol, AssetManager assets) {
		super(title, skin, styleName);
		this.skin = skin;
		
		this.openSound = assets.get("pop_open.ogg", Sound.class);
		this.closeSound = assets.get("pop_close.ogg", Sound.class);
		this.vol = vol;
		
		noticeText = new Label(text, skin, "sub-font", skin.getColor("default"));
		noticeText.setWrap(true);
		noticeText.setAlignment(Align.center);
		add(noticeText).expandX().fill().center().padLeft(20f).padRight(20f);
	}
	
	public void setupButton(String text, ChangeListener changeListener, int alignment) {
		TextButton button = new TextButton(text, skin, "sub");
		button.addListener(changeListener);
		add(button).align(alignment);
	}
	
	public void playOpenSound() {
		openSound.play(vol/100f);
	}
	
	@Override
	public boolean remove() {
		closeSound.play(vol/100f);
		return super.remove();
	}
	
}
