main difference: music selection screen now completely functional; other

refactoring and changes to make better use of the framework were made;
some cleanup happened;
This commit is contained in:
2018-08-18 22:19:08 -05:00
parent fa8dd9622f
commit d7008796f4
21 changed files with 521 additions and 470 deletions

View File

@@ -1,24 +1,37 @@
package zero1hd.rhythmbullet.desktop;
import java.awt.Canvas;
import java.awt.Color;
import javax.swing.JFrame;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl.LwjglGraphics;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.screens.SplashScreen;
public class DesktopLauncher {
public class DesktopLauncher {
public static void main (String[] arg) {
RhythmBullet core;
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
DesktopScreenConfiguration screenConfig = new DesktopScreenConfiguration(config);
config.title = "Rhythm Bullet";
config.resizable = false;
config.useHDPI = true;
config.samples = 2;
config.width = 512;
config.height = 512;
config.allowSoftwareMode = true;
core = new RhythmBullet();
core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig);
new LwjglApplication(core, config);
while (screenConfig.shouldStart()) {
LwjglApplication app = new LwjglApplication(core, config);
}
}
}

View File

@@ -2,13 +2,14 @@ package zero1hd.rhythmbullet.desktop;
import org.lwjgl.opengl.Display;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import zero1hd.rhythmbullet.util.ScreenConfiguration;
public class DesktopScreenConfiguration implements ScreenConfiguration {
private LwjglApplicationConfiguration configuration;
private boolean start = true;
public DesktopScreenConfiguration(LwjglApplicationConfiguration configuration) {
this.configuration = configuration;
}
@@ -18,16 +19,20 @@ public class DesktopScreenConfiguration implements ScreenConfiguration {
configuration.foregroundFPS = fps;
}
@Override
public int getTargetFramesPerSecond() {
return configuration.foregroundFPS;
}
/**
* Requires restart. Can be done by calling {@link #restart()}
*/
@Override
public void setVsync(boolean useVsync) {
configuration.vSyncEnabled = useVsync;
}
@Override
public int getFramesPerSecond() {
return configuration.foregroundFPS;
}
@Override
public boolean getVsync() {
return configuration.vSyncEnabled;
@@ -67,4 +72,16 @@ public class DesktopScreenConfiguration implements ScreenConfiguration {
public void setWindowLocation(int x, int y) {
Display.setLocation(x, y);
}
@Override
public void restart() {
Gdx.app.exit();
start = true;
}
public boolean shouldStart() {
boolean should = start;
start = false;
return should;
}
}

View File

@@ -34,7 +34,7 @@ public class PCMObtainer implements Observer, PCMSystem {
private ShortBuffer playingBuffer;
private ShortBuffer intermediateBuffer;
private ShortBuffer buffer;
private int sourceID;
private volatile int sourceID;
private int channelCount;
private MusicController mc;
private BufferStreamReadThread streamReadThread;
@@ -177,13 +177,7 @@ public class PCMObtainer implements Observer, PCMSystem {
windowsRead++;
//contemplate synchronization
try {
currentPlaybackWindow = MathUtils.round((mc.getCurrentPosition() * sampleRate) / windowSize);
} catch (UnsatisfiedLinkError ule) {
if (run) {
ule.printStackTrace();
}
}
currentPlaybackWindow = MathUtils.round((mc.getCurrentPosition() * sampleRate) / windowSize);
if (windowsRead != currentPlaybackWindow) {
synchronizeBufferWithPlayback();
}

View File

@@ -1,89 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.components;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import zero1hd.rhythmbullet.audio.MusicController;
public class MusicControls extends HorizontalGroup {
private ImageButton reverse, forward;
private CheckBox shuffle, play;
public MusicControls(Skin skin, final MusicController sc) {
reverse = new ImageButton(skin, "rewind-button");
reverse.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
boolean wasPlaying = sc.isPlaying();
sc.previous();
if (wasPlaying) {
sc.play();
}
}
});
addActor(reverse);
play = new CheckBox(null, skin, "play-button") {
@Override
public void act(float delta) {
if (sc.hasSongLoaded()) {
play.setChecked(sc.isPlaying());
} else {
play.setChecked(false);
}
super.act(delta);
}
};
play.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (play.isChecked()) {
sc.play();
} else {
sc.pause();
}
super.clicked(event, x, y);
}
});
addActor(play);
forward = new ImageButton(skin, "fast-forward-button");
forward.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
boolean wasPlaying = sc.isPlaying();
sc.skip();
if (wasPlaying) {
sc.play();
}
}
});
addActor(forward);
shuffle = new CheckBox(null, skin, "shuffle-button") {
@Override
public void act(float delta) {
shuffle.setChecked(sc.isShuffle());
super.act(delta);
}
};
shuffle.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shuffle.isChecked()) {
sc.setShuffle(true);
} else {
sc.setShuffle(false);
}
}
});
addActor(shuffle);
space(15);
setSize(getMinWidth(), getMinHeight());
}
}

View File

@@ -22,6 +22,7 @@ public class SplashScreen extends ScreenAdapter implements InitialScreen {
@Override
public void init() {
stage = new Stage(new ScreenViewport());
splash = new Texture(Gdx.files.internal("splashlogo.png"));
zero1HD = new Image(splash);
}
@@ -47,14 +48,19 @@ public class SplashScreen extends ScreenAdapter implements InitialScreen {
@Override
public void postAssetLoad() {
stage = new Stage(new ScreenViewport());
stage.addActor(zero1HD);
zero1HD.setScale((Gdx.graphics.getHeight()*0.5f)/zero1HD.getHeight()*zero1HD.getScaleY());
zero1HD.setScale((stage.getHeight()*0.8f)/(zero1HD.getHeight()));
zero1HD.setColor(0f,1f,1f,0f);
zero1HD.setPosition((stage.getWidth() - zero1HD.getWidth()*zero1HD.getScaleX())/2f, (stage.getHeight() - zero1HD.getHeight()*zero1HD.getScaleY())/2f);
zero1HD.setPosition((stage.getWidth() - (zero1HD.getWidth()*zero1HD.getScaleX()))/2f, (stage.getHeight() - (zero1HD.getHeight()*zero1HD.getScaleY()))/2f);
stage.addActor(zero1HD);
zero1HD.addAction(Actions.sequence(Actions.color(Color.WHITE, 1f), Actions.fadeOut(0.5f)));
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height);
super.resize(width, height);
}
@Override
public Screen createMainScreen(RhythmBullet game) {
return new MainScreen(game);

View File

@@ -20,8 +20,8 @@ import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.audio.visualizer.DoubleHorizontalVisualizer;
import zero1hd.rhythmbullet.desktop.audio.PCMObtainer;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls;
import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.graphics.ui.components.MusicControls;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
import zero1hd.rhythmbullet.util.ScreenConfiguration;
@@ -46,7 +46,7 @@ public class MainPage extends Page implements Observer {
this.mc = musicController;
this.mc.addObserver(this);
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) 0, 2.5f, 0, screenConfiguration.getFramesPerSecond(), mc, new PCMObtainer(mc));
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) 0, getHeight(), 0, screenConfiguration.getTargetFramesPerSecond(), mc, new PCMObtainer(mc));
dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
title = new Image(assetManager.get("title.png", Texture.class));
@@ -95,7 +95,6 @@ public class MainPage extends Page implements Observer {
scrollText.setWidth(0.5f*getWidth());
scrollText.setPosition(15, getHeight() - scrollText.getHeight()-30f);
addActor(scrollText);
}
@Override

View File

@@ -62,7 +62,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
musicController = new MusicController(musicList, core.getPreferences());
musicController.setAutoPlay(true);
musicController.setShuffle(true);
musicMetadataController = new MusicMetadataController(musicList);
listeners = new Listeners();
@@ -110,6 +109,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
}
background = null;
musicController.deleteObservers();
musicMetadataController.deleteObservers();
}
@Override
@@ -161,8 +161,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
}
});
musicController.addObserver(musicSelectionPage);
musicController.addObserver(mainPage);
musicController.getMusicList().asyncSearch(false);
resizing = false;
}

View File

@@ -10,27 +10,32 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
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.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicMetadataController;
import zero1hd.rhythmbullet.audio.metadata.AudioMetadata;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectableButtonGroup;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
public class MusicSelectionPage extends Page implements Observer {
@@ -39,21 +44,13 @@ public class MusicSelectionPage extends Page implements Observer {
private MusicController mc;
private MusicMetadataController mmc;
private MusicSelectableButtonGroup selectables;
private Stack stackSelectables;
private VerticalGroup vGroup;
private TextButton back;
private ScrollPane musicTableScrollPane;
private ScrollPane scrollPane;
private ClickListener selectionListener;
private musicSelectionLoaderThread thread;
private musicSelectionLoaderThread selectionLoaderThread;
private Table musicInfoTable;
private Table musicSubInfo;
private ScrollText songTitle;
private Label author;
private Label songLength;
private Label previousTop;
private Label ratedDifficulty;
private Image albumCover;
private InformationTable musicInfoTable;
private AssetManager assets;
private Skin skin;
@@ -63,23 +60,25 @@ public class MusicSelectionPage extends Page implements Observer {
private TextButton beginButton;
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
private float musicSelectDelay;
public MusicSelectionPage(AssetManager assetManager, Skin skin, MusicController musicController, MusicMetadataController musicMetadataController, ChangeListener backButtonListener, ChangeListener beginButtonListener) {
super(1, 0);
this.assets = assetManager;
this.mc = musicController;
this.mmc = musicMetadataController;
this.skin = skin;
stackSelectables = new Stack();
vGroup = new VerticalGroup();
vGroup.space(10f);
selectables = new MusicSelectableButtonGroup();
selectables.setMinCheckCount(0);
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
musicTableScrollPane = new ScrollPane(stackSelectables, skin);
musicTableScrollPane.setSize(0.45f*getWidth(), getHeight());
musicTableScrollPane.setFadeScrollBars(false);
musicTableScrollPane.setOverscroll(false, false);
musicTableScrollPane.setColor(Color.BLUE);
addActor(musicTableScrollPane);
scrollPane = new ScrollPane(vGroup, skin);
scrollPane.setSize(0.45f*getWidth(), getHeight());
scrollPane.setOverscroll(false, false);
scrollPane.setClamp(true);
scrollPane.setColor(Color.BLUE);
addActor(scrollPane);
back = new TextButton("Back", skin);
back.setWidth(back.getWidth()+20f);
back.setPosition(getWidth()-back.getWidth()-15f, getHeight() - back.getHeight() - 15f);
@@ -114,51 +113,15 @@ public class MusicSelectionPage extends Page implements Observer {
}
});
musicInfoTable = new Table();
musicInfoTable.defaults().center();
musicInfoTable.setPosition(musicTableScrollPane.getWidth() + musicTableScrollPane.getX(), 0);
musicInfoTable.setSize(getWidth()-musicTableScrollPane.getWidth(), getHeight());
musicInfoTable = new InformationTable(getWidth()-scrollPane.getWidth(), getHeight());
addActor(musicInfoTable);
musicSubInfo = new Table(skin);
musicSubInfo.setBackground("corner-panel");
songTitle = new ScrollText("", null, skin, true, true);
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"));
ratedDifficulty = new Label(null, skin, "sub-font", skin.getColor("default"));
albumCover = new Image(assets.get("defaultCover.png", Texture.class));
beginButton = new TextButton("Begin", skin);
beginButton.addListener(beginButtonListener);
mmc.addObserver(this);
thread = new musicSelectionLoaderThread();
selectionListener = new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
MusicSelectable selectable = (MusicSelectable) event.getListenerActor();
if (selectable.getMetadata().getTitle() != null) {
songTitle.setText(selectable.getMetadata().getTitle(), null);
} else {
songTitle.setText(selectable.getFileHandle().nameWithoutExtension(), null);
}
author.setText(selectable.getMetadata().getAuthor());
songLength.setText(selectable.getMetadata().getDuration());
previousTop.setText("...");
ratedDifficulty.setText("...");
if (selectable.getMetadata().getAlbumCover() != null) {
albumCover.setDrawable(new TextureRegionDrawable(new TextureRegion(selectable.getMetadata().getAlbumCover())));
} else {
albumCover.setDrawable(new TextureRegionDrawable(new TextureRegion(assets.get("defaultCover.png", Texture.class))));
}
}
};
mc.addObserver(this);
selectionLoaderThread = new musicSelectionLoaderThread();
}
@Override
@@ -193,74 +156,58 @@ public class MusicSelectionPage extends Page implements Observer {
if (songSelectionTimer <= 0f) {
}
}
if (mc.getMusicList().isSearched() && selectables.getButtons().size == mc.getMusicList().getTotal()) {
if (selectables.getButtons().size != stackSelectables.getChildren().size) {
int index = selectables.getButtons().size - stackSelectables.getChildren().size - 1;
stackSelectables.add(selectables.getButtons().get(index));
} else {
if (selectables.getChecked() == null) {
selectables.setChecked(mc.getCurrentMusicFileHandle());
} else if (selectables.getChecked().getFileHandle() != mc.getCurrentMusicFileHandle()) {
songSelectionTimer += delta;
if (songSelectionTimer > 2f) {
mc.setMusicByFileHandle(selectables.getChecked().getFileHandle());
}
} else {
songSelectionTimer = 0;
}
if (mc.getMusicList().isSearched()) {
if (mc.getMusicList().getTotal() != 0) {
}
}
updateList(delta);
super.act(delta);
}
private void updateList(float delta) {
if (mc.getMusicList().isSearched()) {
if (mc.getMusicList().getTotal() != 0) {
if (selectables.size() != mmc.size()) {
MusicSelectable selectable = new MusicSelectable(mmc.getMetadata(selectables.size()));
selectables.add(selectable);
} else if (selectables.size() != vGroup.getChildren().size) {
vGroup.addActor(selectables.getButtons().get(vGroup.getChildren().size));
} else {
if (selectables.getChecked() == null) {
selectables.setMinCheckCount(1);
selectables.setChecked(mc.getCurrentMusicFileHandle());
scrollPane.scrollTo(selectables.getChecked().getX(), selectables.getChecked().getY(), selectables.getChecked().getWidth(), selectables.getChecked().getHeight());
} else if (selectables.getChecked().getMetadata().getFileHandle() != mc.getCurrentMusicFileHandle()) {
musicSelectDelay += delta;
if (musicSelectDelay >= 1f) {
mc.setMusicByFileHandle(selectables.getChecked().getMetadata().getFileHandle());
musicSelectDelay = 0;
}
}
}
} else {
//TODO: Error message reporting empty music list or something
}
}
}
private void scrollDown() {
selectables.selectNext();
musicTableScrollPane.scrollTo(selectables.getChecked().getX(), selectables.getChecked().getY(), selectables.getChecked().getWidth(), selectables.getChecked().getHeight());
scrollPane.scrollTo(selectables.getChecked().getX(), selectables.getChecked().getY(), selectables.getChecked().getWidth(), selectables.getChecked().getHeight());
}
private void scrollUp() {
selectables.selectPrevious();
musicTableScrollPane.scrollTo(selectables.getChecked().getX(), selectables.getChecked().getY(), selectables.getChecked().getWidth(), selectables.getChecked().getHeight());
scrollPane.scrollTo(selectables.getChecked().getX(), selectables.getChecked().getY(), selectables.getChecked().getWidth(), selectables.getChecked().getHeight());
}
public FileHandle getSelectedMusic() {
return selectables.getChecked().getMetadata().getFileHandle();
}
public void refreshUIList() {
selectables.clear();
mmc.loadAudioMetadata();
selectables.clear();
musicInfoTable.clear();
musicSubInfo.clear();
Gdx.app.debug("MusicSelectionPage", "Refreshing...");
songTitle.setText("loading...", null);
musicInfoTable.add(songTitle).width(musicInfoTable.getWidth()*0.6f).spaceBottom(30f);
musicInfoTable.row();
author.setText("...");
musicSubInfo.add(author);
musicSubInfo.row();
songLength.setText("...");
musicSubInfo.add(songLength);
musicSubInfo.row();
previousTop.setText("...");
musicSubInfo.add(previousTop);
musicSubInfo.row();
ratedDifficulty.setText("...");
musicSubInfo.add(ratedDifficulty);
musicSubInfo.pack();
musicInfoTable.add(musicSubInfo).spaceBottom(20f);
musicInfoTable.row();
albumCover.setDrawable(new TextureRegionDrawable(new TextureRegion(assets.get("defaultCover.png", Texture.class))));
musicInfoTable.add(albumCover).size(musicInfoTable.getWidth()/2f);
musicInfoTable.row();
musicInfoTable.add(beginButton).spaceTop(20f).fillX();
}
@Override
public void dispose() {
super.dispose();
@@ -269,7 +216,12 @@ public class MusicSelectionPage extends Page implements Observer {
@Override
public void update(Observable o, Object arg) {
if (o == mmc) {
thread.start();
musicInfoTable.setToDefault();
selectionLoaderThread.start();
} else if (o == mc) {
if (mc.getMusicList().getTotal() == selectables.size() && mc.getCurrentMusicFileHandle() != selectables.getChecked().getMetadata().getFileHandle()) {
selectables.setChecked(mc.getCurrentMusicFileHandle());
}
}
}
@@ -281,9 +233,9 @@ public class MusicSelectionPage extends Page implements Observer {
private class musicSelectionLoaderThread implements Runnable {
private Thread thread;
private Array<MusicSelectable> queueList;
private Array<AudioMetadata> queueList;
private String name = "Music-Selection-Loader-Thread";
private volatile boolean work;
private volatile boolean work = true;
public musicSelectionLoaderThread() {
queueList = new Array<>();
@@ -292,18 +244,23 @@ public class MusicSelectionPage extends Page implements Observer {
@Override
public void run() {
while (work) {
while (selectables.getButtons().size != mc.getMusicList().getTotal()) {
MusicSelectable selectable = new MusicSelectable(skin, assets.get("defaultCover.png"), mmc.getMetadata(selectables.getButtons().size), queueList);
selectable.addListener(selectionListener);
selectables.add(selectable);
if (selectables.size() != mmc.size()) {
selectables.clear();
for (int mid = 0; mid < mmc.size(); mid++) {
}
selectables.uncheckAll();
} else {
synchronized (this) {
while (queueList.size != 0) {
AudioMetadata metadata = queueList.pop();
metadata.loadAlbumCover();
}
}
}
for (int i = 0; i < queueList.size; i++) {
queueList.get(i).loadAlbumCover();
queueList.removeIndex(i);
}
synchronized (queueList) {
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
@@ -318,12 +275,259 @@ public class MusicSelectionPage extends Page implements Observer {
thread = new Thread(this, name);
thread.start();
return true;
}
synchronized (queueList) {
notify();
} else {
synchronized (this) {
notify();
}
}
return false;
}
public synchronized void queue(AudioMetadata metadata) {
if (!queueList.contains(metadata, true)) {
queueList.add(metadata);
notify();
}
}
}
private class MusicSelectable extends Button {
private Vector2 actualCoords;
private Image albumCoverImage;
private Table informationTable;
private Label name, artist;
private Label time;
private float timeSinceOnScreen;
private AudioMetadata metadata;
private Texture defaultAlbumArt;
private TextureRegion albumArtTexture;
private boolean albumArtUsed, albumArtAttempted;
public MusicSelectable(AudioMetadata metadata) {
super(skin, "music-selectable");
this.metadata = metadata;
this.defaultAlbumArt = assets.get("defaultCover.png");
albumArtTexture = new TextureRegion(defaultAlbumArt);
albumCoverImage = new Image();
updateAlbumArtImage(defaultAlbumArt);
setSize(getPrefWidth(), getPrefHeight());
informationTable = new Table();
informationTable.row().width(0.75f*getWidth());
name = new Label(metadata.getTitle(), skin, "default-font", skin.getColor("default"));
name.setEllipsis(true);
informationTable.add(name).colspan(2).left().expand();
informationTable.row();
artist = new Label(metadata.getAuthor(), skin, "sub-font", skin.getColor("default"));
artist.setEllipsis(true);
informationTable.add(artist).left().width(getWidth()*0.375f);
time = new Label(metadata.getDuration(), skin, "sub-font", skin.getColor("default"));
informationTable.add(time).right();
add(informationTable).spaceRight(15f).padLeft(15f);
add(albumCoverImage).right().expandX().size(informationTable.getMinHeight());
albumCoverImage.setSize(100, 100);
actualCoords = new Vector2();
}
@Override
public void act(float delta) {
actualCoords.x = getX() + getParent().getX();
actualCoords.y = getY() + getParent().getY();
if ((actualCoords.y < 0 - getHeight() || actualCoords.y > getStage().getHeight() || actualCoords.x < 0 - getWidth() || actualCoords.x > getStage().getWidth()) && selectables.getChecked() != this) {
offScreenAct(delta);
} else {
onScreenAct(delta);
}
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
synchronized (albumCoverImage) {
super.draw(batch, parentAlpha);
}
}
public void onScreenAct(float delta) {
timeSinceOnScreen = 0;
if (metadata.getAlbumCover() != null && !albumArtUsed) {
updateAlbumArtImage(metadata.getAlbumCover());
albumArtUsed = true;
} else if (!albumArtAttempted) {
selectionLoaderThread.queue(metadata);
albumArtAttempted = true;
}
}
private void updateAlbumArtImage(Texture texture) {
if (texture == null) throw new IllegalArgumentException("Texture can't be null!");
albumArtTexture.setRegion(texture);
albumCoverImage.setDrawable(new TextureRegionDrawable(albumArtTexture));
}
public void offScreenAct(float delta) {
if (metadata.getAlbumCover() != null) {
timeSinceOnScreen += delta;
if (timeSinceOnScreen >= 2) {
updateAlbumArtImage(defaultAlbumArt);
metadata.unloadAlbumCover();
albumArtUsed = false;
albumArtAttempted = false;
}
}
}
public AudioMetadata getMetadata() {
return metadata;
}
public FileHandle getFileHandle() {
return metadata.getFileHandle();
}
@Override
public float getPrefWidth() {
return scrollPane.getScrollWidth();
}
@Override
public float getPrefHeight() {
return super.getPrefHeight();
}
public TextureRegion getAlbumArtTexture() {
return albumArtTexture;
}
}
private class MusicSelectableButtonGroup extends ButtonGroup<MusicSelectable> {
private Array<MusicSelectable> buttons;
public MusicSelectableButtonGroup() {
buttons = getButtons();
}
public void setChecked(FileHandle fileHandle) {
if (fileHandle == null) throw new IllegalArgumentException("fileHandle can't be null.");
MusicSelectable button;
for (int i = 0; i < buttons.size; i++) {
button = buttons.get(i);
if (button.getFileHandle() == fileHandle) {
button.setChecked(true);
return;
}
}
}
public void selectNext() {
int index = getCheckedIndex() + 1;
if (index == buttons.size) {
index = 0;
}
buttons.get(index).setChecked(true);
}
public void selectPrevious() {
int index = getCheckedIndex() - 1;
if (index == -1) {
index = buttons.size -1;
}
buttons.get(index).setChecked(true);
}
@Override
protected boolean canCheck(MusicSelectable button, boolean newState) {
if (newState) {
musicInfoTable.setDisplayedSelectable(button);
}
return super.canCheck(button, newState);
}
public int size() {
return buttons.size;
}
}
private class InformationTable extends Table {
private ScrollText songTitle;
private Label author;
private Label musicDuration;
private Label previousTop;
private Label ratedDifficulty;
private Image albumCover;
private Table subInformation;
private MusicSelectable displayedSelectable;
public InformationTable(float width, float height) {
defaults().center();
setPosition(scrollPane.getWidth() + scrollPane.getX(), 0);
setSize(width, height);
subInformation = new Table(skin);
subInformation.setBackground("corner-panel");
albumCover = new Image(assets.get("defaultCover.png", Texture.class));
songTitle = new ScrollText("", null, skin, true, true);
author = new Label(null, skin, "sub-font", skin.getColor("default"));
musicDuration = new Label(null, skin, "sub-font", skin.getColor("default"));
previousTop = new Label(null, skin, "sub-font", skin.getColor("default"));
ratedDifficulty = new Label(null, skin, "sub-font", skin.getColor("default"));
}
public void setDisplayedSelectable(MusicSelectable displayedSelectable) {
this.displayedSelectable = displayedSelectable;
if (displayedSelectable != null) {
AudioMetadata metadata = displayedSelectable.getMetadata();
albumCover.setDrawable(new TextureRegionDrawable(displayedSelectable.getAlbumArtTexture()));
songTitle.setText(metadata.getTitle(), null);
author.setText(metadata.getAuthor());
musicDuration.setText(metadata.getDuration());
//TODO previous top
//TODO rated difficulty
beginButton.setDisabled(false);
} else {
albumCover.setDrawable(new TextureRegionDrawable(new TextureRegion(assets.get("defaultCover.png", Texture.class))));
songTitle.setText("loading...", null);
author.setText("...");
musicDuration.setText("...");
previousTop.setText("...");
ratedDifficulty.setText("...");
}
}
public void setToDefault() {
clear();
subInformation.clear();
albumCover.setDrawable(new TextureRegionDrawable(new TextureRegion(assets.get("defaultCover.png", Texture.class))));
add(albumCover).size(getWidth()/2f).spaceBottom(25f);
row();
songTitle.setText("...", null);
add(songTitle).width(getWidth()*0.6f).spaceBottom(30f);
row();
author.setText("...");
author.setEllipsis(true);
author.setAlignment(Align.center);
subInformation.add(author).expand();
subInformation.row();
musicDuration.setText("...");
subInformation.add(musicDuration);
subInformation.row();
previousTop.setText("...");
subInformation.add(previousTop);
subInformation.row();
ratedDifficulty.setText("...");
subInformation.add(ratedDifficulty);
add(subInformation).width(0.4f*getWidth());
row();
add(beginButton).spaceTop(20f).fillX();
beginButton.setDisabled(true);
}
}
}

View File

@@ -127,12 +127,12 @@ public class OptionsPage extends Page {
optionsTable.row();
Label usageLabel = new Label("Current usage (lower the better): " + 100f*((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory()) + "%", skin) {
float refreshTime = 60;
float refreshTime = 20;
@Override
public void act(float delta) {
refreshTime -= delta;
if (refreshTime <= 0) {
refreshTime = 60;
refreshTime = 20;
setText("Current usage (lower the better): " + 100f*((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory()) + "%");
}
super.act(delta);