moar optimizations! (hopefully...)

This commit is contained in:
Harrison Deng 2017-12-07 19:13:43 -06:00
parent a858fa9159
commit 6f59e2f236
3 changed files with 23 additions and 11 deletions

View File

@ -31,6 +31,9 @@ public class MusicInfoController implements Disposable {
*/
public void loadSongInfo() {
doneLoading = false;
for (int i = 0; i < songInfoArray.size; i++) {
songInfoArray.get(i).dispose();
}
songInfoArray.clear();
exec.submit(() -> {
for (int i = 0; i < musicList.getAmountOfMusic(); i++) {
@ -54,4 +57,8 @@ public class MusicInfoController implements Disposable {
public synchronized boolean isDoneLoading() {
return doneLoading;
}
public Array<MusicInfo> getSongInfoArray() {
return songInfoArray;
}
}

View File

@ -34,7 +34,7 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
table.setFillParent(true);
this.msp = msp;
setName(musicFile.nameWithoutExtension());
table.defaults().pad(5f).space(15f);
table.defaults().pad(5f).space(15f).expandX();
displayName = new ShortenedTextLabel(musicFile.nameWithoutExtension().replace('_', ' '), skin, "sub-font", skin.getColor("default"));
table.add(displayName);

View File

@ -63,6 +63,7 @@ public class MusicSelectionPage extends Page implements Observer {
private TextButton beginButton;
private int uiSongCount;
private int uiSongInfoCount;
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
public MusicSelectionPage(Skin skin, MusicListController musicListController, AssetManager assetManager, Vector3 cameraTarget, AnalysisPage ap) {
@ -74,6 +75,7 @@ public class MusicSelectionPage extends Page implements Observer {
this.assets = assetManager;
musicTable = new Table();
musicTableScrollPane = new ScrollPane(musicTable, skin);
musicTable.defaults().spaceTop(5f).spaceBottom(5f);
musicTableScrollPane.setSize(0.45f*getWidth(), getHeight());
musicTableScrollPane.setFadeScrollBars(false);
musicTableScrollPane.setOverscroll(false, false);
@ -174,13 +176,20 @@ public class MusicSelectionPage extends Page implements Observer {
setCurrentMusic();
}
}
super.act(delta);
if (uiSongCount < selectables.size) {
if (uiSongCount < mc.getMusicList().getAmountOfMusic()) {
MusicSelectable selectable = new MusicSelectable(mc.getMusicList().getSongFileHandleFromIndex(uiSongCount), skin, this);
selectables.add(selectable);
musicTable.add(selectables.get(uiSongCount)).expandX().fillX();
uiSongCount++;
musicTable.row();
}
if (mic.isDoneLoading() && uiSongInfoCount < selectables.size) {
selectables.get(uiSongInfoCount).updateInfo(mic.getSongInfoArray().get(uiSongInfoCount));
uiSongInfoCount++;
}
}
public FileHandle getSelectedMusic() {
@ -192,6 +201,9 @@ public class MusicSelectionPage extends Page implements Observer {
}
public void refreshUIList() {
for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose();
}
musicTable.clear();
selectables.clear();
musicInfoTable.clear();
@ -199,17 +211,10 @@ public class MusicSelectionPage extends Page implements Observer {
extraInfoDone = false;
uiSongCount = 0;
mic.loadSongInfo();
for (int i = 0; i < selectables.size; i++) {
selectables.get(i).dispose();
}
uiSongInfoCount = 0;
Gdx.app.debug("MusicSelectionPage", "Refreshing...");
for (int i = 0; i < mc.getMusicList().getAmountOfMusic(); i++) {
MusicSelectable selectable = new MusicSelectable(mc.getMusicList().getSongFileHandleFromIndex(i), skin, this);
selectables.add(selectable);
}
musicInfoTable.add(songTitle).width(musicInfoTable.getWidth()*0.6f).spaceBottom(30f);
musicInfoTable.row();
musicSubInfo.add(author);