Worked on code architecture, edited music selection ui, worked on clipping text

This commit is contained in:
Harrison Deng 2017-05-03 22:33:13 -05:00
parent f57602788e
commit c6a80e9e57
7 changed files with 67 additions and 37 deletions

View File

@ -67,7 +67,6 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
targetPosition.y = 0.5f*Gdx.graphics.getHeight(); targetPosition.y = 0.5f*Gdx.graphics.getHeight();
} }
moreOptionsPage.controlUnselect(); moreOptionsPage.controlUnselect();
optionsPage.saveOptions(core.prefs);
} }
return super.keyUp(event, keycode); return super.keyUp(event, keycode);
} }
@ -93,6 +92,14 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
super.show(); super.show();
} }
@Override
public void hide() {
if (optionsPage != null) {
optionsPage.saveOptions(core.prefs);
}
super.hide();
}
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f); Gdx.gl.glClearColor(1f, 1f, 1f, 1f);

View File

@ -32,12 +32,12 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
private MainMenu mainMenu; private MainMenu mainMenu;
public PreGameScreen(final Polyjet core) { public PreGameScreen(final Polyjet core, MainMenu mainMenu) {
this.core = core; this.core = core;
analyzer = new AudioAnalyzer(); analyzer = new AudioAnalyzer();
rhythmMap = new RhythmMap(analyzer); rhythmMap = new RhythmMap(analyzer);
mainMenu = (MainMenu) core.getScreen(); this.mainMenu = mainMenu;
stage = new Stage(); stage = new Stage();

View File

@ -49,6 +49,8 @@ public class MusicSelectable extends Button implements Disposable {
super(skin, "info-button"); super(skin, "info-button");
this.skin = skin; this.skin = skin;
setName(musicFile.name());
this.albumCover = defaultAlbumC; this.albumCover = defaultAlbumC;
if (musicFile.extension().toLowerCase().equals("mp3")) { if (musicFile.extension().toLowerCase().equals("mp3")) {
@ -57,7 +59,7 @@ public class MusicSelectable extends Button implements Disposable {
mp3File = new MP3File(musicFile.file()); mp3File = new MP3File(musicFile.file());
durationInSeconds = mp3File.getAudioHeader().getTrackLength(); durationInSeconds = mp3File.getAudioHeader().getTrackLength();
if (mp3File.getTag() != null) { if (mp3File.getTag() != null && mp3File.getTag().getFirstArtwork() != null) {
albumWorkBytes = mp3File.getTag().getFirstArtwork().getBinaryData(); albumWorkBytes = mp3File.getTag().getFirstArtwork().getBinaryData();
} }
@ -91,8 +93,8 @@ public class MusicSelectable extends Button implements Disposable {
songName = musicFile.nameWithoutExtension(); songName = musicFile.nameWithoutExtension();
} }
previousTop = musicData.getInteger(songName + ":previous top"); previousTop = musicData.getInteger(songName + ":previous top", -1);
ratedDifficulty = musicData.getInteger(songName + ":difficulty"); ratedDifficulty = musicData.getInteger(songName + ":difficulty", -1);
if (author == null || author.isEmpty()) { if (author == null || author.isEmpty()) {
author = "N/A"; author = "N/A";
@ -105,7 +107,7 @@ public class MusicSelectable extends Button implements Disposable {
defaults().align(Align.top); defaults().align(Align.top);
add(displayName).fillX().padTop(15f).top(); add(displayName).expandX().fillX().padTop(15f).top();
row(); row();
String formattedTime = "Run time: "+ String.valueOf(durationInSeconds/60) + ":"; String formattedTime = "Run time: "+ String.valueOf(durationInSeconds/60) + ":";
@ -124,11 +126,11 @@ public class MusicSelectable extends Button implements Disposable {
songInfoTable.add(authorLabel).expandY(); songInfoTable.add(authorLabel).expandY();
songInfoTable.row(); songInfoTable.row();
previousTopLabel = new Label("Previous Top: " + previousTop, skin, "sub-font", skin.getColor("default")); previousTopLabel = new Label("High Score: " + (previousTop != -1 ? previousTop : "N/A"), skin, "sub-font", skin.getColor("default"));
songInfoTable.add(previousTopLabel).center(); songInfoTable.add(previousTopLabel).center();
songInfoTable.row(); songInfoTable.row();
ratedDifficultyLabel = new Label("Difficulty: " + ratedDifficulty, skin, "sub-font", skin.getColor("default")); ratedDifficultyLabel = new Label("Difficulty: " + (ratedDifficulty != -1 ? ratedDifficulty : "N/A"), skin, "sub-font", skin.getColor("default"));
songInfoTable.add(ratedDifficultyLabel).expandY(); songInfoTable.add(ratedDifficultyLabel).expandY();
songInfoTable.row(); songInfoTable.row();
@ -148,7 +150,7 @@ public class MusicSelectable extends Button implements Disposable {
} }
Gdx.app.debug("UI", "album cover invalid or null for image: " + songName); Gdx.app.debug("UI", "album cover invalid or null for image: " + songName);
} }
add(imageIcon).size(246f); add(imageIcon).prefSize(256f).expandY().center();
} }
public int getPreviousTop() { public int getPreviousTop() {

View File

@ -77,18 +77,21 @@ public class ScrollText extends Widget {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (scrollOnHover) { clipBounds.setPosition(getParent().getX()+getX(), getParent().getY()+getY());
if ((int) textOffset != 0 || currentlyHovering) { if (fontWidth > clipBounds.getWidth()) {
if (scrollOnHover) {
if ((int) textOffset != 0 || currentlyHovering) {
if (textOffset < -fontWidth) {
textOffset = clipBounds.getWidth();
}
textOffset -= 60*delta;
}
} else {
if (textOffset < -fontWidth) { if (textOffset < -fontWidth) {
textOffset = clipBounds.getWidth(); textOffset = clipBounds.getWidth();
} }
textOffset -= 60*delta; textOffset -= 60*delta;
} }
} else {
if (textOffset < -fontWidth) {
textOffset = clipBounds.getWidth();
}
textOffset -= 60*delta;
} }
super.act(delta); super.act(delta);
} }

View File

@ -14,6 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import zero1hd.polyjet.Polyjet; import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.screens.MainMenu;
import zero1hd.polyjet.screens.PreGameScreen; import zero1hd.polyjet.screens.PreGameScreen;
public class MainPage extends Page { public class MainPage extends Page {
@ -99,7 +100,7 @@ public class MainPage extends Page {
Actions.run(new Runnable() { Actions.run(new Runnable() {
@Override @Override
public void run() { public void run() {
core.setScreen(new PreGameScreen(core)); core.setScreen(new PreGameScreen(core, (MainMenu) core.getScreen()));
} }
}), Actions.parallel(Actions.scaleTo(1, 1), Actions.alpha(0.6f)))); }), Actions.parallel(Actions.scaleTo(1, 1), Actions.alpha(0.6f))));
} }

View File

@ -7,9 +7,11 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
@ -20,10 +22,11 @@ import zero1hd.polyjet.screens.MainMenu;
import zero1hd.polyjet.ui.builders.MusicSelectable; import zero1hd.polyjet.ui.builders.MusicSelectable;
public class MusicSelectionPage extends Page { public class MusicSelectionPage extends Page {
Image loading; private volatile Image loading;
private volatile Table musicChoices; private volatile Table musicChoices;
Preferences musicFileAnnotation; Preferences musicFileAnnotation;
private Polyjet core; private Polyjet core;
private volatile Label status;
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);
@ -43,11 +46,16 @@ public class MusicSelectionPage extends Page {
addActor(back); addActor(back);
loading = new Image(core.defaultSkin, "loading"); loading = new Image(core.defaultSkin, "loading");
loading.setPosition((getWidth()-loading.getWidth())/2, (getHeight()-loading.getHeight())/2); loading.setPosition((getWidth()-loading.getWidth())/2, getHeight()-loading.getHeight() - 32f);
loading.setOrigin(loading.getWidth()/2, loading.getHeight()/2); loading.setOrigin(loading.getWidth()/2, loading.getHeight()/2);
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f))); loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
addActor(loading); addActor(loading);
status = new Label("Loading: ", core.defaultSkin, "sub-font", core.defaultSkin.getColor("default"));
status.setPosition(loading.getX()+loading.getWidth()+12f, loading.getY()-15f);
addActor(status);
musicChoices = new Table(); musicChoices = new Table();
musicChoices.defaults().pad(10f); musicChoices.defaults().pad(10f);
ScrollPane musicChoiceScroller = new ScrollPane(musicChoices); ScrollPane musicChoiceScroller = new ScrollPane(musicChoices);
@ -57,9 +65,7 @@ public class MusicSelectionPage extends Page {
@Override @Override
public void act(float delta) { public void act(float delta) {
if (musicChoices.hasChildren()) {
loading.remove();
}
super.act(delta); super.act(delta);
} }
@ -68,7 +74,6 @@ public class MusicSelectionPage extends Page {
@Override @Override
public void run() { public void run() {
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) {
@ -78,17 +83,32 @@ public class MusicSelectionPage extends Page {
return false; return false;
} }
}); });
for (int music = 0; music < musicFiles.length; music++) {
final MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, core.defaultSkin, core.assetManager.get("defaultCover.png", Texture.class)); if (musicFiles.length != 0) {
Gdx.app.postRunnable(new Runnable() { for (int music = 0; music < musicFiles.length; music++) {
@Override final MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, core.defaultSkin, core.assetManager.get("defaultCover.png", Texture.class));
public void run() { Gdx.app.postRunnable(new Runnable() {
musicChoices.add(selectable).size(256f, 0.8f*getHeight()); @Override
selectable.addInfoToPanel(); public void run() {
} Gdx.app.debug("Music Search Thread", "Finished loading: " + selectable.getName());
}); musicChoices.add(selectable).prefSize(256, 0.8f*getHeight());
selectable.addInfoToPanel();
}
});
System.out.println(music);
int prog = (int) (100f*music/(musicFiles.length-1f));
status.setText("Loading: " + prog + "%");
}
loading.clearActions();
status.setText("Done!");
} else {
loading.clearActions();
status.setText("No music found.");
} }
} }
}).start(); }).start();
} }
} }

View File

@ -45,7 +45,6 @@ public class OptionsPage extends Page {
musicVolSlider.addListener(new ChangeListener() { musicVolSlider.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
saveOptions(core.prefs);
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%");
} }
}); });
@ -62,7 +61,6 @@ public class OptionsPage extends Page {
fxVolSlider.addListener(new ChangeListener() { fxVolSlider.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
saveOptions(core.prefs);
fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%"); fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%");
} }
}); });
@ -88,7 +86,6 @@ public class OptionsPage extends Page {
if (keycode == Keys.ENTER) { if (keycode == Keys.ENTER) {
Gdx.app.debug("Debug Field", debugCodeField.getText()); Gdx.app.debug("Debug Field", debugCodeField.getText());
if (debugCodeField.getText().equals("creative")) { if (debugCodeField.getText().equals("creative")) {
saveOptions(core.prefs);
Gdx.app.debug("Debug Field", "going to creative test room..."); Gdx.app.debug("Debug Field", "going to creative test room...");
goToScreen = 1; goToScreen = 1;
} }
@ -140,10 +137,10 @@ public class OptionsPage extends Page {
}); });
optionsTable.add(graphicsSettings).colspan(2).fill(); optionsTable.add(graphicsSettings).colspan(2).fill();
saveOptions(core.prefs);
} }
public void saveOptions(Preferences prefs) { public void saveOptions(Preferences prefs) {
Gdx.app.debug("Preferences", "Saved all basic options page values.");
prefs.putFloat("music vol", musicVolSlider.getValue()); prefs.putFloat("music vol", musicVolSlider.getValue());
prefs.putFloat("fx vol", fxVolSlider.getValue()); prefs.putFloat("fx vol", fxVolSlider.getValue());
prefs.putString("music dir", directoryField.getText()); prefs.putString("music dir", directoryField.getText());