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 {
try {
AudioFile audioFile = AudioFileIO.read(musicFile.file());
WavTag wavTag = (WavTag) AudioFileIO.read(musicFile.file()).getTag();
@ -88,6 +87,8 @@ public class SongInfo implements Disposable {
if (author == null || author.isEmpty()) {
author = "N/A";
}
containsInfo = true;
}
public void setupTexture(Texture defaultAlbumCover) {
@ -104,7 +105,7 @@ public class SongInfo implements Disposable {
return durationInSeconds;
}
public String getSongName() {
public String getMusicName() {
return songName.replace('_', ' ');
}
@ -117,7 +118,7 @@ public class SongInfo implements Disposable {
}
public int getPreviousTop() {
return previousTop;
return previousTop == -1 ? 0 : previousTop;
}
public int getRatedDifficulty() {
@ -133,13 +134,6 @@ public class SongInfo implements Disposable {
albumCover.dispose();
}
/**
* tells this song info that it does contain information
*/
public void doesContainsInformation() {
containsInfo = true;
}
/**
* Asks if this contains information.
* @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.
*/
public void updateInfo() {
displayName.setOriginalText(songInfo.getSongName());
displayName.setOriginalText(songInfo.getMusicName());
displayName.setToOriginalText();
durationLabel.setText("Runtime: "
+ ((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);
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++) {
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.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
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.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicManager;
@ -33,18 +35,19 @@ import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
public class MusicSelectionPage extends Page implements Observer {
Preferences musicFileAnnotation;
private boolean extraInfoDone;
private MusicListController mc;
private Array<MusicSelectable> selectables;
private Table musicTable;
private ScrollPane scrollbar;
private ScrollPane musicTableScrollPane;
private TextButton back;
private ScrollText songTitle;
private Label author;
private Label songLength;
private Label previousTop;
private Table songInfoTable;
private Table musicInfoTable;
private Image albumCover;
private MusicSelectable currentlySelected;
@ -60,24 +63,17 @@ public class MusicSelectionPage extends Page implements Observer {
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
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"));
this.skin = skin;
this.mc = musicList;
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
this.assets = assetManager;
musicTable = new Table();
scrollbar = new ScrollPane(musicTable, skin);
scrollbar.setSize(0.45f*getWidth(), getHeight());
scrollbar.setFadeScrollBars(false);
scrollbar.setOverscroll(false, false);
addActor(scrollbar);
musicTableScrollPane = new ScrollPane(musicTable, skin);
musicTableScrollPane.setSize(0.45f*getWidth(), getHeight());
musicTableScrollPane.setFadeScrollBars(false);
musicTableScrollPane.setOverscroll(false, false);
addActor(musicTableScrollPane);
selectables = new Array<>();
back = new TextButton("Back", skin);
back.setWidth(back.getWidth()+20f);
@ -89,9 +85,7 @@ public class MusicSelectionPage extends Page implements Observer {
}
});
addActor(back);
back.toFront();
refresh();
addListener(new InputListener() {
@Override
@ -119,6 +113,21 @@ public class MusicSelectionPage extends Page implements Observer {
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
@ -151,7 +160,7 @@ public class MusicSelectionPage extends Page implements Observer {
if (songSelectionTimer > 0f) {
songSelectionTimer -= delta;
if (songSelectionTimer <= 0f) {
playCurrentMusic();
setCurrentMusic();
}
}
super.act(delta);
@ -168,6 +177,8 @@ public class MusicSelectionPage extends Page implements Observer {
public void refresh() {
musicTable.clear();
selectables.clear();
musicInfoTable.clear();
for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose();
}
@ -187,11 +198,24 @@ public class MusicSelectionPage extends Page implements Observer {
for (int i = 0; i < selectables.size; i++) {
MusicSelectable info = selectables.get(i);
info.getAudioInfo().loadInfo();
info.getAudioInfo().doesContainsInformation();
Gdx.app.postRunnable(() -> {
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.");
});
}
@ -222,7 +246,7 @@ public class MusicSelectionPage extends Page implements Observer {
musicSelectableIndex = 0;
}
((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() {
@ -231,7 +255,7 @@ public class MusicSelectionPage extends Page implements Observer {
}
deselectAll();
((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
@ -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()) {
int index = mc.getMusicList().getSongList().indexOf(currentlySelected.getMusicFile(), true);
mc.setMusicByIndex(index);
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());
mc.getMusicList().addObserver(this);
Gdx.app.debug("Post Transition", "Beginning screen setup for Main menu.");
musicSelectionPage.selectSong(mc.getCurrentMusicManager());
}
public void attemptLoadShaders() {
if (core.getPrefs().getBoolean("glow shader", true)) {