|
|
|
@@ -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()))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|