updated sound fx, added notice window

This commit is contained in:
Harrison Deng 2017-05-09 21:02:29 -05:00
parent f390f4f6dd
commit 819fb35680
10 changed files with 81 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -117,8 +117,8 @@ public class Polyjet extends Game {
assetManager.load("cybercircle1.png", Texture.class); assetManager.load("cybercircle1.png", Texture.class);
assetManager.load("defaultCover.png", Texture.class); assetManager.load("defaultCover.png", Texture.class);
assetManager.load("teleport-cloak.p", ParticleEffect.class); assetManager.load("teleport-cloak.p", ParticleEffect.class);
assetManager.load("sounds/SFX_open.ogg", Sound.class); assetManager.load("sounds/pop_open.ogg", Sound.class);
assetManager.load("sounds/SFX_close.ogg", Sound.class); assetManager.load("sounds/pop_close.ogg", Sound.class);
} }
public void generateFonts() { public void generateFonts() {
initComplete = true; initComplete = true;

View File

@ -56,6 +56,7 @@ public class MusicSelectable extends Button implements Disposable {
if (musicFile.extension().toLowerCase().equals("mp3")) { if (musicFile.extension().toLowerCase().equals("mp3")) {
MP3File mp3File; MP3File mp3File;
try { try {
mp3File = new MP3File(musicFile.file()); mp3File = new MP3File(musicFile.file());
durationInSeconds = mp3File.getAudioHeader().getTrackLength(); durationInSeconds = mp3File.getAudioHeader().getTrackLength();
@ -70,7 +71,6 @@ public class MusicSelectable extends Button implements Disposable {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
wavinfo = new WavInfo(musicFile.file()); wavinfo = new WavInfo(musicFile.file());

View File

@ -41,6 +41,7 @@ public class ScrollText extends Widget {
fontHeight = gLayout.height; fontHeight = gLayout.height;
fontWidth = gLayout.width; fontWidth = gLayout.width;
addListener(new ClickListener() { addListener(new ClickListener() {
@Override @Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
@ -57,8 +58,6 @@ public class ScrollText extends Widget {
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
} }
}); });
} }
@ -74,12 +73,15 @@ public class ScrollText extends Widget {
@Override @Override
public void layout() { public void layout() {
setHeight(fontHeight+4); setHeight(fontHeight+4);
clipBounds.set(getParent().getX()+getX()-scrollCoords.getVisualScrollX(), getParent().getY()+getY(), getWidth(), getHeight()); clipBounds.set(getParent().getX()+getX()-scrollCoords.getVisualScrollX(), getParent().getY()+getY() - getHeight()*0.5f, getWidth(), getHeight()*1.5f);
super.layout(); super.layout();
} }
@Override @Override
public void act(float delta) { public void act(float delta) {
clipBounds.setX(getParent().getX()+getX()+scrollCoords.getWidget().getX());
clipBounds.setY(getParent().getY()+getY()+scrollCoords.getWidget().getY());
if (fontWidth > clipBounds.getWidth()) { if (fontWidth > clipBounds.getWidth()) {
if (scrollOnHover) { if (scrollOnHover) {
if ((int) textOffset != 0 || currentlyHovering) { if ((int) textOffset != 0 || currentlyHovering) {
@ -102,7 +104,6 @@ public class ScrollText extends Widget {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
validate(); validate();
clipBounds.setX(getParent().getX()+getX()+scrollCoords.getWidget().getX());
getStage().calculateScissors(clipBounds, scissors); getStage().calculateScissors(clipBounds, scissors);
batch.flush(); batch.flush();

View File

@ -2,6 +2,8 @@ package zero1hd.polyjet.ui.pages;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
@ -17,6 +19,7 @@ import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.screens.MainMenu; import zero1hd.polyjet.screens.MainMenu;
import zero1hd.polyjet.ui.builders.MusicSelectable; import zero1hd.polyjet.ui.builders.MusicSelectable;
import zero1hd.polyjet.ui.windows.LoadingWindow; import zero1hd.polyjet.ui.windows.LoadingWindow;
import zero1hd.polyjet.ui.windows.NoticeWindow;
public class MusicSelectionPage extends Page { public class MusicSelectionPage extends Page {
private volatile Table musicChoices; private volatile Table musicChoices;
@ -25,6 +28,8 @@ public class MusicSelectionPage extends Page {
private volatile ScrollPane musicChoiceScroller; private volatile ScrollPane musicChoiceScroller;
private volatile LoadingWindow loadingWindow; private volatile LoadingWindow loadingWindow;
protected volatile boolean cancel;
private TextButton back;
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) { public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) {
super("Select music", core.defaultSkin); super("Select music", core.defaultSkin);
@ -33,12 +38,13 @@ public class MusicSelectionPage extends Page {
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation"); musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
TextButton back = new TextButton("Back", core.defaultSkin); back = new TextButton("Back", core.defaultSkin);
back.setPosition(getWidth()-back.getWidth()-15f, getHeight()-back.getHeight()-15f); back.setPosition(getWidth()-back.getWidth()-15f, getHeight()-back.getHeight()-15f);
back.addListener(new ChangeListener() { back.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
core.setScreen(mainMenu); core.setScreen(mainMenu);
cancel = true;
} }
}); });
addActor(back); addActor(back);
@ -54,12 +60,13 @@ public class MusicSelectionPage extends Page {
musicChoices.defaults().pad(10f); musicChoices.defaults().pad(10f);
musicChoiceScroller = new ScrollPane(musicChoices); musicChoiceScroller = new ScrollPane(musicChoices);
musicChoiceScroller.setScrollingDisabled(false, true); musicChoiceScroller.setScrollingDisabled(false, true);
musicChoiceScroller.setSize(getWidth(), getHeight()*0.85f); musicChoiceScroller.setSize(getWidth(), getHeight()-(getHeight()-back.getY()));
musicChoiceScroller.debug(); musicChoiceScroller.debug();
addActor(musicChoiceScroller); addActor(musicChoiceScroller);
loadingWindow.toFront(); loadingWindow.toFront();
back.toFront();
} }
@Override @Override
@ -70,9 +77,11 @@ public class MusicSelectionPage extends Page {
public void beginMusicSearch() { public void beginMusicSearch() {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
Logger.getLogger("org.jaudiotagger").setLevel(Level.SEVERE);
FileHandle[] musicFiles = new FileHandle(core.prefs.getString("music dir")).list(new FilenameFilter() { FileHandle[] musicFiles = new FileHandle(core.prefs.getString("music dir")).list(new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
@ -83,18 +92,19 @@ public class MusicSelectionPage extends Page {
} }
}); });
if (musicFiles.length != 0) { if (musicFiles.length > 0) {
for (int music = 0; music < musicFiles.length; music++) { for (int music = 0; music < musicFiles.length && !cancel; music++) {
final MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, core.defaultSkin, core.assetManager.get("defaultCover.png", Texture.class)); final MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, core.defaultSkin, core.assetManager.get("defaultCover.png", Texture.class));
Gdx.app.postRunnable(new Runnable() { Gdx.app.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
Gdx.app.debug("Music Search Thread", "Finished loading: " + selectable.getName()); Gdx.app.debug("Music Search Thread", "Finished loading: " + selectable.getName());
musicChoices.add(selectable).prefSize(0.3f*getWidth(), 0.8f*getHeight()); musicChoices.add(selectable).prefSize(panelWidthCalc(getWidth()), musicChoiceScroller.getHeight());
selectable.addInfoToPanel(musicChoiceScroller, 0.28f*getWidth()); selectable.addInfoToPanel(musicChoiceScroller, panelWidthCalc(getWidth()) - 20f);
} }
}); });
System.out.println(music);
Gdx.app.debug("Music Search Thread", "Completed: " + music);
int prog = (int) (100f*music/(musicFiles.length-1f)); int prog = (int) (100f*music/(musicFiles.length-1f));
loadingWindow.setProgress(prog); loadingWindow.setProgress(prog);
} }
@ -102,10 +112,20 @@ public class MusicSelectionPage extends Page {
loadingWindow.remove(); loadingWindow.remove();
} else { } else {
NoticeWindow notice = new NoticeWindow(core.defaultSkin, "default", "No song's found in:\n\"" + core.prefs.getString("music dir") + "\"\nTo change the search directory, go to game options.");
notice.setSize(0.6f*getWidth(), 0.6f*getHeight());
notice.setPosition((getWidth()-notice.getWidth())/2f, (getHeight()-notice.getHeight())/2f);
notice.setModal(true);
notice.setMovable(false);
loadingWindow.remove();
addActor(notice);
back.toFront();
} }
} }
}).start(); }).start();
}
public float panelWidthCalc(float origWidth) {
return (float) (Math.sqrt(getWidth()*35f)+80f);
} }
} }

View File

@ -7,8 +7,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Window; import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.utils.Disposable;
public class LoadingWindow extends Window { public class LoadingWindow extends Window implements Disposable {
private Label status; private Label status;
private Sound closeSound; private Sound closeSound;
@ -17,8 +18,8 @@ public class LoadingWindow extends Window {
public LoadingWindow(Skin skin, boolean progress, AssetManager assets, float vol) { public LoadingWindow(Skin skin, boolean progress, AssetManager assets, float vol) {
super("loading...", skin); super("loading...", skin);
this.openSound = assets.get("sounds/SFX_open.ogg", Sound.class); this.openSound = assets.get("sounds/pop_open.ogg", Sound.class);
this.closeSound = assets.get("sounds/SFX_close.ogg", Sound.class); this.closeSound = assets.get("sounds/pop_close.ogg", Sound.class);
this.vol = vol; this.vol = vol;
Image loading = new Image(skin, "loading"); Image loading = new Image(skin, "loading");
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f))); loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
@ -42,8 +43,8 @@ public class LoadingWindow extends Window {
public LoadingWindow(Skin skin, String styleName, boolean progress, AssetManager assets, float vol) { public LoadingWindow(Skin skin, String styleName, boolean progress, AssetManager assets, float vol) {
super("loading...", skin, styleName); super("loading...", skin, styleName);
this.openSound = assets.get("sounds/SFX_open.ogg", Sound.class); this.openSound = assets.get("sounds/pop_open.ogg", Sound.class);
this.closeSound = assets.get("sounds/SFX_close.ogg", Sound.class); this.closeSound = assets.get("sounds/pop_close.ogg", Sound.class);
this.vol = vol; this.vol = vol;
Image loading = new Image(skin, "loading"); Image loading = new Image(skin, "loading");
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f))); loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
@ -78,4 +79,10 @@ public class LoadingWindow extends Window {
public void setProgress(float progress) { public void setProgress(float progress) {
status.setText(String.valueOf((int) progress) + '%'); status.setText(String.valueOf((int) progress) + '%');
} }
@Override
public void dispose() {
openSound.dispose();
closeSound.dispose();
}
} }

View File

@ -0,0 +1,31 @@
package zero1hd.polyjet.ui.windows;
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 TextButton finalButton;
private Skin skin;
public NoticeWindow(Skin skin, String styleName, String text) {
super("Notice", skin);
this.skin = skin;
debug();
noticeText = new Label(text, skin);
noticeText.setWrap(true);
noticeText.setAlignment(Align.center);
add(noticeText).expandX().fill().center().padLeft(20f).padRight(20f);
}
public void setupButton(String text, ChangeListener changeListener) {
finalButton = new TextButton(text, skin, "sub-font");
finalButton.addListener(changeListener);
add(finalButton);
}
}