song info displayed on the right side of the music selection page

This commit is contained in:
Harrison Deng 2017-11-24 16:50:33 -06:00
parent 27606f3c8f
commit 9829748a03
6 changed files with 75 additions and 37 deletions

View File

@ -61,7 +61,6 @@ public class SongInfo implements Disposable {
} }
} else { } else {
try { try {
AudioFile audioFile = AudioFileIO.read(musicFile.file()); AudioFile audioFile = AudioFileIO.read(musicFile.file());
WavTag wavTag = (WavTag) AudioFileIO.read(musicFile.file()).getTag(); WavTag wavTag = (WavTag) AudioFileIO.read(musicFile.file()).getTag();
@ -88,6 +87,8 @@ public class SongInfo implements Disposable {
if (author == null || author.isEmpty()) { if (author == null || author.isEmpty()) {
author = "N/A"; author = "N/A";
} }
containsInfo = true;
} }
public void setupTexture(Texture defaultAlbumCover) { public void setupTexture(Texture defaultAlbumCover) {
@ -104,7 +105,7 @@ public class SongInfo implements Disposable {
return durationInSeconds; return durationInSeconds;
} }
public String getSongName() { public String getMusicName() {
return songName.replace('_', ' '); return songName.replace('_', ' ');
} }
@ -117,7 +118,7 @@ public class SongInfo implements Disposable {
} }
public int getPreviousTop() { public int getPreviousTop() {
return previousTop; return previousTop == -1 ? 0 : previousTop;
} }
public int getRatedDifficulty() { public int getRatedDifficulty() {
@ -133,13 +134,6 @@ public class SongInfo implements Disposable {
albumCover.dispose(); albumCover.dispose();
} }
/**
* tells this song info that it does contain information
*/
public void doesContainsInformation() {
containsInfo = true;
}
/** /**
* Asks if this contains information. * Asks if this contains information.
* @return whether this contains data * @return whether this contains data

View File

@ -79,7 +79,7 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
* needs to be called in thread with gl context. * needs to be called in thread with gl context.
*/ */
public void updateInfo() { public void updateInfo() {
displayName.setOriginalText(songInfo.getSongName()); displayName.setOriginalText(songInfo.getMusicName());
displayName.setToOriginalText(); displayName.setToOriginalText();
durationLabel.setText("Runtime: " durationLabel.setText("Runtime: "
+ ((songInfo.getDurationInSeconds() / 60 < 1) ? "00" : songInfo.getDurationInSeconds() / 60) + ":" + ((songInfo.getDurationInSeconds() / 60 < 1) ? "00" : songInfo.getDurationInSeconds() / 60) + ":"

View File

@ -201,7 +201,7 @@ public class AnalyzePage extends Page implements MiniListener, Disposable {
audioAnalyzer.sender.addListener(this); audioAnalyzer.sender.addListener(this);
songInfo.add(new ScrollText(audioInfo.getSongName(), null, skin, true, false)).expandX().fillX().spaceBottom(20f); songInfo.add(new ScrollText(audioInfo.getMusicName(), null, skin, true, false)).expandX().fillX().spaceBottom(20f);
for (int i = 0; i < info.length; i++) { for (int i = 0; i < info.length; i++) {
info[i].setColor(1f, 1f, 1f, 0f); info[i].setColor(1f, 1f, 1f, 0f);

View File

@ -12,6 +12,7 @@ import com.badlogic.gdx.assets.AssetManager;
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.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
@ -23,6 +24,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
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;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.MusicManager;
@ -33,18 +35,19 @@ import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
public class MusicSelectionPage extends Page implements Observer { public class MusicSelectionPage extends Page implements Observer {
Preferences musicFileAnnotation; Preferences musicFileAnnotation;
private boolean extraInfoDone;
private MusicListController mc; private MusicListController mc;
private Array<MusicSelectable> selectables; private Array<MusicSelectable> selectables;
private Table musicTable; private Table musicTable;
private ScrollPane scrollbar; private ScrollPane musicTableScrollPane;
private TextButton back; private TextButton back;
private ScrollText songTitle; private ScrollText songTitle;
private Label author; private Label author;
private Label songLength; private Label songLength;
private Label previousTop; private Label previousTop;
private Table songInfoTable; private Table musicInfoTable;
private Image albumCover; private Image albumCover;
private MusicSelectable currentlySelected; private MusicSelectable currentlySelected;
@ -60,24 +63,17 @@ public class MusicSelectionPage extends Page implements Observer {
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer; private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
public MusicSelectionPage(Skin skin, MusicListController musicList, AssetManager assetManager, Vector3 cameraTarget) { public MusicSelectionPage(Skin skin, MusicListController musicList, AssetManager assetManager, Vector3 cameraTarget) {
songInfoTable = new Table();
songTitle = new ScrollText("", null, skin, true, false);
author = new Label(null, skin, "sub-font", skin.getColor("default"));
songLength = new Label(null, skin, "sub-font", skin.getColor("default"));
previousTop = new Label(null, skin, "sub-font", skin.getColor("default"));
albumCover = new Image(assetManager.get("defaultCover.png", Texture.class));
setTextureBackground(assetManager.get("gradients.atlas", TextureAtlas.class).findRegion("red-round")); setTextureBackground(assetManager.get("gradients.atlas", TextureAtlas.class).findRegion("red-round"));
this.skin = skin; this.skin = skin;
this.mc = musicList; this.mc = musicList;
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation"); musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
this.assets = assetManager; this.assets = assetManager;
musicTable = new Table(); musicTable = new Table();
scrollbar = new ScrollPane(musicTable, skin); musicTableScrollPane = new ScrollPane(musicTable, skin);
scrollbar.setSize(0.45f*getWidth(), getHeight()); musicTableScrollPane.setSize(0.45f*getWidth(), getHeight());
scrollbar.setFadeScrollBars(false); musicTableScrollPane.setFadeScrollBars(false);
scrollbar.setOverscroll(false, false); musicTableScrollPane.setOverscroll(false, false);
addActor(scrollbar); addActor(musicTableScrollPane);
selectables = new Array<>(); selectables = new Array<>();
back = new TextButton("Back", skin); back = new TextButton("Back", skin);
back.setWidth(back.getWidth()+20f); back.setWidth(back.getWidth()+20f);
@ -89,9 +85,7 @@ public class MusicSelectionPage extends Page implements Observer {
} }
}); });
addActor(back); addActor(back);
back.toFront(); back.toFront();
refresh();
addListener(new InputListener() { addListener(new InputListener() {
@Override @Override
@ -119,6 +113,21 @@ public class MusicSelectionPage extends Page implements Observer {
return super.keyUp(event, keycode); return super.keyUp(event, keycode);
} }
}); });
musicInfoTable = new Table();
musicInfoTable.defaults().center();
musicInfoTable.setPosition(musicTableScrollPane.getWidth() + musicTableScrollPane.getX(), 0);
musicInfoTable.setSize(getWidth()-musicTableScrollPane.getWidth(), getHeight());
addActor(musicInfoTable);
songTitle = new ScrollText("", null, skin, true, false);
author = new Label(null, skin, "sub-font", skin.getColor("default"));
songLength = new Label(null, skin, "sub-font", skin.getColor("default"));
previousTop = new Label(null, skin, "sub-font", skin.getColor("default"));
albumCover = new Image(assetManager.get("defaultCover.png", Texture.class));
refresh();
} }
@Override @Override
@ -151,7 +160,7 @@ public class MusicSelectionPage extends Page implements Observer {
if (songSelectionTimer > 0f) { if (songSelectionTimer > 0f) {
songSelectionTimer -= delta; songSelectionTimer -= delta;
if (songSelectionTimer <= 0f) { if (songSelectionTimer <= 0f) {
playCurrentMusic(); setCurrentMusic();
} }
} }
super.act(delta); super.act(delta);
@ -168,6 +177,8 @@ public class MusicSelectionPage extends Page implements Observer {
public void refresh() { public void refresh() {
musicTable.clear(); musicTable.clear();
selectables.clear(); selectables.clear();
musicInfoTable.clear();
for (int i = 0; i < selectables.size; i++) { for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose(); selectables.get(i).dispose();
} }
@ -187,11 +198,24 @@ public class MusicSelectionPage extends Page implements Observer {
for (int i = 0; i < selectables.size; i++) { for (int i = 0; i < selectables.size; i++) {
MusicSelectable info = selectables.get(i); MusicSelectable info = selectables.get(i);
info.getAudioInfo().loadInfo(); info.getAudioInfo().loadInfo();
info.getAudioInfo().doesContainsInformation();
Gdx.app.postRunnable(() -> { Gdx.app.postRunnable(() -> {
info.updateInfo(); info.updateInfo();
}); });
} }
extraInfoDone = true;
musicInfoTable.add(songTitle).width(musicInfoTable.getWidth()*0.7f);
musicInfoTable.row();
musicInfoTable.add(author);
musicInfoTable.row();
musicInfoTable.add(songLength);
musicInfoTable.row();
musicInfoTable.add(previousTop);
musicInfoTable.row();
musicInfoTable.add(albumCover).size(musicInfoTable.getWidth()/2f);
if (currentlySelected != null) {
updateInformation();
}
Gdx.app.debug("MusicSelectionPage", "Refresh complete. " + selectables.size + " songs loaded."); Gdx.app.debug("MusicSelectionPage", "Refresh complete. " + selectables.size + " songs loaded.");
}); });
} }
@ -222,7 +246,7 @@ public class MusicSelectionPage extends Page implements Observer {
musicSelectableIndex = 0; musicSelectableIndex = 0;
} }
((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select(); ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select();
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); musicTableScrollPane.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
} }
private void scrollUp() { private void scrollUp() {
@ -231,7 +255,7 @@ public class MusicSelectionPage extends Page implements Observer {
} }
deselectAll(); deselectAll();
((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select(); ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select();
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); musicTableScrollPane.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
} }
@Override @Override
@ -254,11 +278,31 @@ public class MusicSelectionPage extends Page implements Observer {
} }
} }
public void playCurrentMusic() { private void setCurrentMusic() {
playSelectedMusic();
if (extraInfoDone) {
updateInformation();
}
}
private void playSelectedMusic() {
if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) { if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) {
int index = mc.getMusicList().getSongList().indexOf(currentlySelected.getMusicFile(), true); int index = mc.getMusicList().getSongList().indexOf(currentlySelected.getMusicFile(), true);
mc.setMusicByIndex(index); mc.setMusicByIndex(index);
mc.play(); mc.play();
} }
} }
private void updateInformation() {
songTitle.setText(currentlySelected.getAudioInfo().getMusicName(), null);
author.setText("Author: " + currentlySelected.getAudioInfo().getAuthor());
long lengthInSeconds = currentlySelected.getAudioInfo().getDurationInSeconds();
int min = (int) (lengthInSeconds/60);
int sec = (int) (lengthInSeconds - (min*60));
songLength.setText("Length: " + min + ":" + sec);
previousTop.setText("Highscore: " + currentlySelected.getAudioInfo().getPreviousTop());
albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(currentlySelected.getAudioInfo().getAlbumCover()))));
}
} }

View File

@ -137,7 +137,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observ
mainPage.updateVisualsForDifferentSong(mc.getCurrentMusicManager()); mainPage.updateVisualsForDifferentSong(mc.getCurrentMusicManager());
mc.getMusicList().addObserver(this); mc.getMusicList().addObserver(this);
Gdx.app.debug("Post Transition", "Beginning screen setup for Main menu."); musicSelectionPage.selectSong(mc.getCurrentMusicManager());
} }
public void attemptLoadShaders() { public void attemptLoadShaders() {
if (core.getPrefs().getBoolean("glow shader", true)) { if (core.getPrefs().getBoolean("glow shader", true)) {