From 45da676d0df14e225d8f864f2123194508fecafd Mon Sep 17 00:00:00 2001 From: Recrown Date: Thu, 2 Aug 2018 09:21:25 -0500 Subject: [PATCH] progress on untested framework --- .../zero1hd/rhythmbullet/RhythmBullet.java | 20 +- .../zero1hd/rhythmbullet/audio/MusicList.java | 28 ++- .../audio/MusicMetadataController.java | 36 +++- .../audio/analyzer/AudioAnalyzer.java | 22 +-- .../audio/metadata/AudioMetadata.java | 8 +- .../audio/metadata/MP3Metadata.java | 16 +- .../audio/metadata/WAVMetadata.java | 17 +- .../ui/components/MusicSelectable.java | 74 ++++++++ .../graphics/ui/components/ScrollText.java | 3 +- ...enedTextLabel.java => ShortenedLabel.java} | 27 ++- .../desktop/DesktopAssetPack.java | 6 + .../ui/components/GraphicsOptions.java | 10 +- .../ui/components/MusicSelectable.java | 118 ------------ .../ui/components/ResolutionButton.java | 2 +- .../desktop/screens/main/AnalysisPage.java | 62 +++---- ...hicsOptionsPage.java => GraphicsPage.java} | 25 +-- ...ybindOptionsPage.java => KeybindPage.java} | 21 +-- .../desktop/screens/main/MainPage.java | 38 ++-- .../desktop/screens/main/MainScreen.java | 148 ++++++++++----- .../screens/main/MusicSelectionPage.java | 173 ++++-------------- .../desktop/screens/main/OptionsPage.java | 69 +++---- 21 files changed, 428 insertions(+), 495 deletions(-) create mode 100755 core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java rename core/src/zero1hd/rhythmbullet/graphics/ui/components/{ShortenedTextLabel.java => ShortenedLabel.java} (58%) delete mode 100755 desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicSelectable.java rename desktop/src/zero1hd/rhythmbullet/desktop/screens/main/{GraphicsOptionsPage.java => GraphicsPage.java} (56%) rename desktop/src/zero1hd/rhythmbullet/desktop/screens/main/{KeybindOptionsPage.java => KeybindPage.java} (55%) diff --git a/core/src/zero1hd/rhythmbullet/RhythmBullet.java b/core/src/zero1hd/rhythmbullet/RhythmBullet.java index 396c61d..9498482 100755 --- a/core/src/zero1hd/rhythmbullet/RhythmBullet.java +++ b/core/src/zero1hd/rhythmbullet/RhythmBullet.java @@ -36,7 +36,7 @@ public class RhythmBullet extends Game { private AssetManager assetManager = new AssetManager(); private Skin skin; TextureAtlas skinAtlas; - private Preferences prefs; + private Preferences preferences; private RoundingResolutionHandler rRHandler; private Screen initialScreen; private AssetPack assetPack; @@ -58,7 +58,7 @@ public class RhythmBullet extends Game { assetPack.initiateResources(); - prefs = Gdx.app.getPreferences("RhythmBullet Preferences"); + preferences = Gdx.app.getPreferences("RhythmBullet Preferences"); Resolution[] resolution = { new Resolution(1280, 720, "1280x720"), @@ -78,7 +78,7 @@ public class RhythmBullet extends Game { assetManager.setLoader(ParticleEffect.class, new ParticleEffectLoader(genericFileFinder)); assetManager.setLoader(Sound.class, new SoundLoader(genericFileFinder)); - rRHandler.setResolution(getPrefs().getInteger("screen-width"), getPrefs().getInteger("screen-height")); + rRHandler.setResolution(getPreferences().getInteger("screen-width"), getPreferences().getInteger("screen-height")); screenWidth = Gdx.graphics.getWidth(); @@ -86,10 +86,10 @@ public class RhythmBullet extends Game { pixels_per_unit = (int) (Float.valueOf(screenHeight)/Float.valueOf(WORLD_HEIGHT)); - if (getPrefs().getBoolean("fullscreen", true)) { + if (getPreferences().getBoolean("fullscreen", true)) { Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); } else { - Gdx.graphics.setWindowedMode(getPrefs().getInteger("screen-width"), getPrefs().getInteger("screen-height")); + Gdx.graphics.setWindowedMode(getPreferences().getInteger("screen-width"), getPreferences().getInteger("screen-height")); } } @@ -161,9 +161,9 @@ public class RhythmBullet extends Game { } else { throw new IllegalStateException("Cannot perform window resize on a screen that isn't using a resize ready screen."); } - prefs.putInteger("screen-width", width); - prefs.putInteger("screen-height", height); - prefs.flush(); + preferences.putInteger("screen-width", width); + preferences.putInteger("screen-height", height); + preferences.flush(); resizing = true; assetManager.clear(); queueAssets(); @@ -185,8 +185,8 @@ public class RhythmBullet extends Game { return skin; } - public Preferences getPrefs() { - return prefs; + public Preferences getPreferences() { + return preferences; } @Override diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicList.java b/core/src/zero1hd/rhythmbullet/audio/MusicList.java index 7d8b8f7..3f1a788 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicList.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicList.java @@ -31,7 +31,11 @@ public class MusicList extends Observable { * Also notifies listeners that are on the main thread. */ public void asyncSearch() { - searchThread.start(); + if (!searchThread.start()) { + searchThread.stop(); + searchThread = new RecursiveMusicSearchThread("Music Search Thread"); + searchThread.start(); + } } public void setSearchPath(String searchPath) { @@ -96,6 +100,7 @@ public class MusicList extends Observable { private Thread thread; private String threadName; private FileHandle directory; + private volatile boolean work; public RecursiveMusicSearchThread(String name) { this.threadName = name; @@ -107,23 +112,32 @@ public class MusicList extends Observable { @Override public void run() { - musicList = recursiveMusicSearch(directory); - searchComplete(); + Array obtainedAudioFiles = recursiveMusicSearch(directory); + if (work) { + musicList = obtainedAudioFiles; + searchComplete(); + } } - public void start() { - if (thread == null && !thread.isAlive()) { + public boolean start() { + if (thread == null) { + work = true; thread = new Thread(this, threadName); thread.start(); + return true; } else { - throw new IllegalStateException("Two " + threadName + " instances (threads) were created. This is not allowed for optimization as there is no reason to have two running."); + return false; } } + public void stop() { + work = false; + } + private Array recursiveMusicSearch(FileHandle fileHandle) { Array musicFiles = new Array<>(); FileHandle[] files = fileHandle.list(); - for (int i = 0; i < files.length; i++) { + for (int i = 0; i < files.length && work; i++) { if (files[i].isDirectory()) { musicFiles.addAll(recursiveMusicSearch(files[i])); } else { diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicMetadataController.java b/core/src/zero1hd/rhythmbullet/audio/MusicMetadataController.java index c89b654..3d50dac 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicMetadataController.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicMetadataController.java @@ -11,7 +11,7 @@ import zero1hd.rhythmbullet.audio.metadata.AudioMetadata; import zero1hd.rhythmbullet.audio.metadata.MP3Metadata; import zero1hd.rhythmbullet.audio.metadata.WAVMetadata; -public class MusicMetadataController implements Disposable, Observer { +public class MusicMetadataController extends Observable implements Disposable, Observer { private MusicList musicList; private Array metadataArray; private MetadataLoadingThread loadingThread; @@ -20,6 +20,8 @@ public class MusicMetadataController implements Disposable, Observer { public MusicMetadataController(MusicList musicList) { this.musicList = musicList; metadataArray = new Array<>(); + loadingThread = new MetadataLoadingThread(); + musicList.addObserver(this); } public MusicList getMusicList() { @@ -29,8 +31,12 @@ public class MusicMetadataController implements Disposable, Observer { /** * Non-blocking, loads on separate thread. */ - public void loadSongInfo() { - loadingThread.start(); + public void loadAudioMetadata() { + if (!loadingThread.start()) { + loadingThread.stop(); + loadingThread = new MetadataLoadingThread(); + loadingThread.start(); + } } public boolean isDone() { @@ -66,6 +72,7 @@ public class MusicMetadataController implements Disposable, Observer { private class MetadataLoadingThread implements Runnable { private Thread thread; private String name = "Metadata-Load"; + private volatile boolean work; @Override public void run() { @@ -74,7 +81,7 @@ public class MusicMetadataController implements Disposable, Observer { metadataArray.get(i).dispose(); } metadataArray.clear(); - for (int i = 0; i < musicList.getTotal(); i++) { + for (int i = 0; i < musicList.getTotal() && work; i++) { FileHandle musicFile = musicList.getMusicArray().get(i); synchronized (this) { switch (SupportedFormats.valueOf(musicFile.extension().toUpperCase())) { @@ -90,19 +97,32 @@ public class MusicMetadataController implements Disposable, Observer { } } } - searching = false; + if (work) { + searching = false; + notifyObservers(); + } } - public void start() { - if (thread != null && !thread.isAlive()) { + public boolean start() { + if (thread == null) { thread = new Thread(this, name); thread.start(); + return true; + } else { + return false; } } + + public void stop() { + work = false; + } } @Override public void update(Observable o, Object arg) { - // TODO Auto-generated method stub + if (o == musicList) { + loadingThread.stop(); + loadAudioMetadata(); + } } } diff --git a/core/src/zero1hd/rhythmbullet/audio/analyzer/AudioAnalyzer.java b/core/src/zero1hd/rhythmbullet/audio/analyzer/AudioAnalyzer.java index c7a99d8..0c7d826 100755 --- a/core/src/zero1hd/rhythmbullet/audio/analyzer/AudioAnalyzer.java +++ b/core/src/zero1hd/rhythmbullet/audio/analyzer/AudioAnalyzer.java @@ -2,13 +2,12 @@ package zero1hd.rhythmbullet.audio.analyzer; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.MathUtils; -import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.FloatArray; import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D; import zero1hd.rhythmbullet.audio.processor.AudioProcessor; -public class AudioAnalyzer implements Runnable, Disposable { +public class AudioAnalyzer implements Runnable { private Thread thread; private String threadName = "Audio-Analyzer"; @@ -38,15 +37,15 @@ public class AudioAnalyzer implements Runnable, Disposable { private int PUID; private int progress; - public AudioAnalyzer(AudioProcessor audioProcessor) { - this.processor = audioProcessor; - } - - public void start() { - if (thread == null || !thread.isAlive()) { + public boolean start(AudioProcessor processor) { + if (thread == null) { + this.processor = processor; work = true; thread = new Thread(this, threadName); thread.start(); + return true; + } else { + return false; } } @@ -282,13 +281,6 @@ public class AudioAnalyzer implements Runnable, Disposable { public int getProgress() { return progress; } - - @Override - public void dispose() { - if (thread != null) { - work = false; - } - } public void stop() { work = false; diff --git a/core/src/zero1hd/rhythmbullet/audio/metadata/AudioMetadata.java b/core/src/zero1hd/rhythmbullet/audio/metadata/AudioMetadata.java index 7eefc8b..2ac23d8 100755 --- a/core/src/zero1hd/rhythmbullet/audio/metadata/AudioMetadata.java +++ b/core/src/zero1hd/rhythmbullet/audio/metadata/AudioMetadata.java @@ -37,7 +37,13 @@ public interface AudioMetadata extends Disposable { * * @return the length of the song with proper fomatting. */ - public String getLength(); + public String getDuration(); + + /** + * + * @return the length of the song in seconds. + */ + public int getLength(); /** * diff --git a/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java b/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java index 9e0050a..994a93c 100755 --- a/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java +++ b/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java @@ -18,7 +18,8 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; public class MP3Metadata implements AudioMetadata { - private String title, author, length, genre; + private String title, author, duration, genre; + private int length; private Texture albumCover; private FileHandle fileHandle; @@ -38,9 +39,9 @@ public class MP3Metadata implements AudioMetadata { - int lenInSec = mp3file.getAudioHeader().getTrackLength(); - int min = (int) (lenInSec/60); - length = (lenInSec/60) + ":" + (lenInSec - (min*60)); + length = mp3file.getAudioHeader().getTrackLength(); + int min = (int) (length/60); + duration = (length/60) + ":" + (length - (min*60)); author = tag.getFirst(ID3v23FieldKey.ARTIST); genre = tag.getFirst(ID3v23FieldKey.GENRE); @@ -86,7 +87,12 @@ public class MP3Metadata implements AudioMetadata { } @Override - public String getLength() { + public String getDuration() { + return duration; + } + + @Override + public int getLength() { return length; } diff --git a/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java b/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java index bcaa07b..9b9b79b 100755 --- a/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java +++ b/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java @@ -17,7 +17,8 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; public class WAVMetadata implements AudioMetadata { - private String title, author, length, genre; + private String title, author, duration, genre; + private int length; private Texture albumCover; private FileHandle fileHandle; @@ -26,9 +27,9 @@ public class WAVMetadata implements AudioMetadata { try { AudioFile wav = AudioFileIO.read(fileHandle.file()); - int lenInSec = wav.getAudioHeader().getTrackLength(); - int min = (int) (lenInSec/60); - this.length = (lenInSec/60) + ":" + (lenInSec - (min*60)); + length = wav.getAudioHeader().getTrackLength(); + int min = (int) (length/60); + this.duration = (length/60) + ":" + (length - (min*60)); Tag tag = wav.getTag(); title = tag.getFirst(FieldKey.TITLE); @@ -70,9 +71,15 @@ public class WAVMetadata implements AudioMetadata { return title; } @Override - public String getLength() { + public String getDuration() { + return duration; + } + + @Override + public int getLength() { return length; } + @Override public Texture getAlbumCover() { return albumCover; diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java new file mode 100755 index 0000000..ab97ce0 --- /dev/null +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicSelectable.java @@ -0,0 +1,74 @@ +package zero1hd.rhythmbullet.graphics.ui.components; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.scenes.scene2d.ui.Button; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + +import zero1hd.rhythmbullet.audio.metadata.AudioMetadata; + +public class MusicSelectable extends Button { + private Vector2 actualCoords; + private Image album; + private Table informationTable; + private ShortenedLabel name, artist; + private Label time; + private float timeSinceOnScreen; + private AudioMetadata metadata; + private Texture defaultAlbumArt; + + + public MusicSelectable(Skin skin, Texture defaultAlbumArt, AudioMetadata metadata) { + super(skin, "music-selectable"); + this.metadata = metadata; + this.defaultAlbumArt = defaultAlbumArt; + + album = new Image(defaultAlbumArt); + add(album).expand().left(); + + informationTable = new Table(); + name = new ShortenedLabel(metadata.getTitle(), skin, "default-font", skin.getColor("default")); + informationTable.add(name).colspan(2).expandX(); + informationTable.row(); + artist = new ShortenedLabel(metadata.getTitle(), skin, "sub-font", skin.getColor("default")); + informationTable.add(artist).expandX(); + time = new Label(metadata.getDuration(), skin, "sub-font", skin.getColor("default")); + informationTable.add(time).expandX(); + add(informationTable).expand().fill(); + } + + @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()) { + offScreenAct(delta); + } else { + onScreenAct(delta); + } + super.act(delta); + } + + public void onScreenAct(float delta) { + timeSinceOnScreen = 0; + if (metadata.getAlbumCover() == null) { + metadata.loadAlbumCover(); + album.setDrawable(new TextureRegionDrawable(new TextureRegion(metadata.getAlbumCover()))); + } + } + + public void offScreenAct(float delta) { + if (metadata.getAlbumCover() != null) { + timeSinceOnScreen += delta; + if (timeSinceOnScreen >= 2) { + metadata.unloadAlbumCover(); + } + } + } +} diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/ScrollText.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/ScrollText.java index d198f0a..8fc6f20 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/ScrollText.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/ScrollText.java @@ -89,6 +89,8 @@ public class ScrollText extends Widget { @Override public void layout() { + super.layout(); + if (getHeight() < (textHeight+4)) { setHeight(textHeight + 4); } @@ -98,7 +100,6 @@ public class ScrollText extends Widget { if (text1Width < clipBounds.getWidth()) { text1Offset = (clipBounds.getWidth()-text1Width)/2f; } - super.layout(); } @Override diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedTextLabel.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedLabel.java similarity index 58% rename from core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedTextLabel.java rename to core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedLabel.java index f851792..575b7ea 100755 --- a/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedTextLabel.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/ShortenedLabel.java @@ -3,34 +3,37 @@ package zero1hd.rhythmbullet.graphics.ui.components; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.GlyphLayout; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; -public class ShortenedTextLabel extends Label { +public class ShortenedLabel extends Label { private String originalText; private int targetWidth; private GlyphLayout gl; private BitmapFont font; + private Vector2 size; - public ShortenedTextLabel(CharSequence text, Skin skin, String fontName, Color color) { - super(text, skin, fontName, color); + public ShortenedLabel(CharSequence text, Skin skin, String fontName, Color color) { + super(null, skin, fontName, color); originalText = text.toString(); font = skin.getFont(fontName); if (text != null) { gl = new GlyphLayout(skin.getFont(fontName), text); } - } - - public void setTargetWidth(int targetWidth) { - this.targetWidth = targetWidth; + size = new Vector2(); + + setWrap(true); } public void resize() { setToOriginalText(); - while (gl.width > targetWidth && (getText().length - 4) > 0) { - setText(getText().substring(0, getText().length - 4).concat("...")); - gl.setText(font, getText()); + String text = getText().toString(); + while (gl.width > targetWidth && (text.length() - 4) > 0) { + text = text.substring(0, text.length() - 4).concat("..."); + gl.setText(font, text); } + setText(text); } public void setToOriginalText() { @@ -41,6 +44,10 @@ public class ShortenedTextLabel extends Label { @Override public void layout() { super.layout(); + size.x = getWidth(); + size.y = getHeight(); + targetWidth = (int) getStage().stageToScreenCoordinates(size).x; + resize(); } public void setOriginalText(String originalText) { diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java index ac579ad..33086a2 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java @@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle; import com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; @@ -170,6 +171,11 @@ public class DesktopAssetPack implements AssetPack { shuffleButtonStyle.checkboxOff = skin.getDrawable("shuffle"); shuffleButtonStyle.checkboxOn = skin.getDrawable("shuffle-down"); skin.add("shuffle-button", shuffleButtonStyle); + + ButtonStyle musicSelectable = new ButtonStyle(); + musicSelectable.checked = skin.getDrawable("holo-pane-down"); + musicSelectable.up = skin.getDrawable("holo-pane"); + skin.add("music-selectable", musicSelectable); } @Override diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/GraphicsOptions.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/GraphicsOptions.java index 27141d4..2b54b6f 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/GraphicsOptions.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/GraphicsOptions.java @@ -26,7 +26,7 @@ public class GraphicsOptions extends Table { _1366x768; - public GraphicsOptions(Skin skin, final Preferences prefs) { + public GraphicsOptions(Skin skin, final Preferences prefs, ChangeListener bloomLevelSliderListener) { align(Align.center); defaults().space(10f); this.prefs = prefs; @@ -35,8 +35,9 @@ public class GraphicsOptions extends Table { row(); glowShaderLevel = new Slider(0, 4, 1, false, skin); - glowShaderLevel.setValue(prefs.getInteger("glow shader")); add(glowShaderLevel).fillX(); + glowShaderLevel.addListener(bloomLevelSliderListener); + glowShaderLevel.setValue(prefs.getInteger("glow shader")); row(); @@ -95,7 +96,8 @@ public class GraphicsOptions extends Table { prefs.putInteger("glow shader", (int) glowShaderLevel.getValue()); } - public Slider getGlowLevelSlider() { - return glowShaderLevel; + public int getBloomShaderLevel() { + return (int) glowShaderLevel.getValue(); } + } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicSelectable.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicSelectable.java deleted file mode 100755 index 781c17c..0000000 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/MusicSelectable.java +++ /dev/null @@ -1,118 +0,0 @@ -package zero1hd.rhythmbullet.desktop.graphics.ui.components; - -import com.badlogic.gdx.files.FileHandle; -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.ui.Skin; -import com.badlogic.gdx.scenes.scene2d.ui.Table; -import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup; -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; -import com.badlogic.gdx.utils.Disposable; - -import zero1hd.rhythmbullet.audio.MusicInfo; -import zero1hd.rhythmbullet.desktop.screens.main.MusicSelectionPage; -import zero1hd.rhythmbullet.graphics.ui.components.ShortenedTextLabel; - -public class MusicSelectable extends WidgetGroup implements Disposable { - private Table table; - - private ShortenedTextLabel displayName; - - private boolean selected; - - private MusicSelectionPage msp; - private MusicInfo musicInfo; - - private FileHandle musicFile; - - public MusicSelectable(FileHandle musicFile, Skin skin, MusicSelectionPage msp) { - this.musicFile = musicFile; - table = new Table(skin); - table.setBackground("holo-pane"); - table.setFillParent(true); - this.msp = msp; - setName(musicFile.nameWithoutExtension()); - table.defaults().pad(5f).space(15f).expandX(); - - displayName = new ShortenedTextLabel(musicFile.nameWithoutExtension().replace('_', ' '), skin, "sub-font", skin.getColor("default")); - table.add(displayName); - - table.pack(); - addActor(table); - addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - select(); - super.clicked(event, x, y); - } - }); - } - - /** - * updates the UI side of information. - * needs to be called in thread with gl context. - * @param musicInfo the music information for this song. - */ - public void updateInfo(MusicInfo musicInfo) { - this.musicInfo = musicInfo; - displayName.setOriginalText(musicInfo.getMusicName()); - } - - - @Override - public void layout() { - displayName.setTargetWidth((int) (getWidth()*0.8f)); - displayName.resize(); - super.layout(); - } - - @Override - public void draw(Batch batch, float parentAlpha) { - super.draw(batch, parentAlpha); - } - - @Override - public void act(float delta) { - super.act(delta); - } - - public boolean isMusicInvalid() { - return musicInfo.isInvalidMusic(); - } - - /** - * Selects this panel - */ - public void select() { - msp.deselectAll(); - table.setBackground("holo-pane-down"); - selected = true; - msp.setCurrentlySelected(this); - } - - public void deselect() { - table.setBackground("holo-pane"); - selected = false; - } - - public boolean isSelected() { - return selected; - } - - @Override - public float getPrefHeight() { - return table.getMinHeight(); - } - - @Override - public void dispose() { - } - - public FileHandle getMusicFile() { - return musicFile; - } - - public MusicInfo getMusicInfo() { - return musicInfo; - } -} diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ResolutionButton.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ResolutionButton.java index a954574..69e210b 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ResolutionButton.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ResolutionButton.java @@ -12,7 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; public class ResolutionButton extends TextButton { - public ResolutionButton(final int width, final int height, Skin skin, final Preferences prefs) { + public ResolutionButton(int width, int height, Skin skin, Preferences prefs) { super(width + "x" + height, skin); Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/AnalysisPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/AnalysisPage.java index 60afb2c..97df7cb 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/AnalysisPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/AnalysisPage.java @@ -1,6 +1,5 @@ package zero1hd.rhythmbullet.desktop.screens.main; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -12,15 +11,14 @@ 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 zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.audio.analyzer.AudioAnalyzer; +import zero1hd.rhythmbullet.audio.metadata.AudioMetadata; +import zero1hd.rhythmbullet.audio.processor.AudioProcessor; import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page; -import zero1hd.rhythmbullet.desktop.screens.GameScreen; public class AnalysisPage extends Page { - private boolean confirmed; private TextButton backButton; - private AudioAnalyzer aa; + private AudioAnalyzer audioAnalyzer; private Table table; private Table adjustment; private Label difficultyModLabel, healthModLabel, speedModLabel; @@ -29,17 +27,14 @@ public class AnalysisPage extends Page { private Label progressLabel; private TextButton confirmButton; private Image albumArt; - private RhythmBullet core; - public AnalysisPage(MainScreen mainScreen) { + public AnalysisPage(Skin skin, ChangeListener backButtonListener, ChangeListener confirmedButtonListener) { super(2, 0); table = new Table(); table.setFillParent(true); table.defaults().space(10f); addActor(table); - this.core = mainScreen.rhythmBullet; adjustment = new Table(); - Skin skin = core.getSkin(); difficultyModLabel = new Label("Difficulty Modifier: ", skin, "sub-font", skin.getColor("default")); difficultyModifierSlider = new Slider(1, 3, 0.5f, false, skin); @@ -85,7 +80,6 @@ public class AnalysisPage extends Page { confirmButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { - confirmed = true; confirmButton.setDisabled(true); speedModifierSlider.setDisabled(true); healthModifierSlider.setDisabled(true); @@ -94,6 +88,7 @@ public class AnalysisPage extends Page { progressLabel.setText("Loading..."); } }); + confirmButton.addListener(confirmedButtonListener); adjustment.add(confirmButton).colspan(3).fillX(); adjustment.row(); @@ -101,49 +96,40 @@ public class AnalysisPage extends Page { adjustment.add(progressLabel).colspan(2).left().spaceTop(20f); backButton = new TextButton("Cancel", skin); - backButton.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.musicSelectionPage); - aa.dispose(); - } - }); + backButton.addListener(backButtonListener); backButton.setPosition(15, getHeight()-backButton.getHeight()-25); addActor(backButton); + + audioAnalyzer = new AudioAnalyzer(); } - public void processSong(MusicManager mm, Texture albumCover, MusicInfo mi) { + public void processSong(AudioProcessor mm, Texture albumCover, AudioMetadata metadata) { this.albumArt = new Image(albumCover); - confirmButton.setDisabled(false); - speedModifierSlider.setDisabled(false); - healthModifierSlider.setDisabled(false); - difficultyModifierSlider.setDisabled(false); table.clear(); table.add(this.albumArt).size(adjustment.getMinHeight()); table.row(); table.add(adjustment); - if (aa != null) { - aa.dispose(); - } - aa = new AudioAnalyzer(mm); - aa.start(); - } - - @Override - public void act(float delta) { - if (aa != null && aa.isDone()) { - if (confirmed) { - core.setScreen(new GameScreen(core.getAssetManager(), core.getPrefs())); - } - } - super.act(delta); + if (!audioAnalyzer.start(mm)) { + audioAnalyzer.stop(); + audioAnalyzer = new AudioAnalyzer(); + audioAnalyzer.start(mm); + } } @Override public void dispose() { - aa.dispose(); super.dispose(); } + + @Override + public void setCameraPositionToPage(Vector3 cameraPosition) { + confirmButton.setDisabled(false); + speedModifierSlider.setDisabled(false); + healthModifierSlider.setDisabled(false); + difficultyModifierSlider.setDisabled(false); + + super.setCameraPositionToPage(cameraPosition); + } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/GraphicsOptionsPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/GraphicsPage.java similarity index 56% rename from desktop/src/zero1hd/rhythmbullet/desktop/screens/main/GraphicsOptionsPage.java rename to desktop/src/zero1hd/rhythmbullet/desktop/screens/main/GraphicsPage.java index 635529c..614c114 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/GraphicsOptionsPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/GraphicsPage.java @@ -1,37 +1,32 @@ package zero1hd.rhythmbullet.desktop.screens.main; +import com.badlogic.gdx.Preferences; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; -import com.badlogic.gdx.scenes.scene2d.ui.Slider; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import zero1hd.rhythmbullet.desktop.graphics.ui.components.GraphicsOptions; import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page; -public class GraphicsOptionsPage extends Page { +public class GraphicsPage extends Page { private ScrollPane scrollPane; private GraphicsOptions graphicsTable; private TextButton backButton; - public GraphicsOptionsPage(MainScreen mainScreen) { + public GraphicsPage(Skin skin, Preferences preferences, ChangeListener backButtonListener, ChangeListener bloomLevelSliderListener) { super(-1, 1); - graphicsTable = new GraphicsOptions(mainScreen.rhythmBullet.getSkin(), mainScreen.rhythmBullet.getPrefs()); - scrollPane = new ScrollPane(graphicsTable, mainScreen.rhythmBullet.getSkin()); + graphicsTable = new GraphicsOptions(skin, preferences, bloomLevelSliderListener); + scrollPane = new ScrollPane(graphicsTable, skin); scrollPane.setFadeScrollBars(false); scrollPane.setFillParent(true); addActor(scrollPane); - backButton = new TextButton("Back", mainScreen.rhythmBullet.getSkin()); + backButton = new TextButton("Back", skin); backButton.setPosition(10, getHeight() - 10 - backButton.getHeight()); backButton.setWidth(backButton.getWidth() + 20); - backButton.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.optionsPage); - } - }); + backButton.addListener(backButtonListener); addActor(backButton); } @@ -50,7 +45,7 @@ public class GraphicsOptionsPage extends Page { graphicsTable.save(); } - public Slider getGlowLevelSlider() { - return graphicsTable.getGlowLevelSlider(); + public int getBloomLevel() { + return graphicsTable.getBloomShaderLevel(); } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindOptionsPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java similarity index 55% rename from desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindOptionsPage.java rename to desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java index 7a178a6..d03f531 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindOptionsPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java @@ -1,6 +1,7 @@ package zero1hd.rhythmbullet.desktop.screens.main; -import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; @@ -8,27 +9,21 @@ import zero1hd.rhythmbullet.controls.KeyMap; import zero1hd.rhythmbullet.desktop.graphics.ui.components.ControlOptions; import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page; -public class KeybindOptionsPage extends Page { +public class KeybindPage extends Page { private ControlOptions controlTable; private KeyMap keyMap; private TextButton backButton; - public KeybindOptionsPage(MainScreen mainScreen) { + public KeybindPage(AssetManager assetManager, Skin skin, ChangeListener backButtonListener) { super(-1, -1); - keyMap = new KeyMap(mainScreen.rhythmBullet.getAssetManager()); - controlTable = new ControlOptions(mainScreen.rhythmBullet.getSkin(), keyMap); + keyMap = new KeyMap(assetManager); + controlTable = new ControlOptions(skin, keyMap); addActor(controlTable); - backButton = new TextButton("Back", mainScreen.rhythmBullet.getSkin()); + backButton = new TextButton("Back", skin); backButton.setPosition(10, getHeight() - 10 - backButton.getHeight()); backButton.setWidth(backButton.getWidth() + 20); - backButton.addListener(new ChangeListener() { - - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.optionsPage); - } - }); + backButton.addListener(backButtonListener); addActor(backButton); } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java index 4599a7d..e098d81 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainPage.java @@ -4,11 +4,13 @@ import java.util.Observable; import java.util.Observer; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; +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; @@ -37,22 +39,19 @@ public class MainPage extends Page implements Observer { private DoubleHorizontalVisualizer dhv; - private RhythmBullet rhythmBullet; - public MainPage(MainScreen mainScreen) { + public MainPage(MusicController musicController, AssetManager assetManager, Skin skin, ChangeListener playButtonListener, ChangeListener optionsButtonListener) { super(0, 0); - this.mc = mainScreen.musicController; - this.rhythmBullet = mainScreen.rhythmBullet; + this.mc = musicController; dhv = new DoubleHorizontalVisualizer(70, (int) getWidth(), (int) (getHeight()*0.3), 0.3f, mc); dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f)); - title = new Image(rhythmBullet.getAssetManager().get("title.png", Texture.class)); + title = new Image(assetManager.get("title.png", Texture.class)); title.setScale(dhv.getHeight()/title.getHeight()); title.setPosition((getWidth()-title.getWidth())/2f, (getHeight()-title.getHeight())/2f); addActor(title); - versionLabel = new Label("Version: " + RhythmBullet.VERSION, rhythmBullet.getSkin(), "sub-font", - rhythmBullet.getSkin().getColor("default")); + versionLabel = new Label("Version: " + RhythmBullet.VERSION, skin, "sub-font"); versionLabel.setPosition(3, 3); addActor(versionLabel); @@ -61,30 +60,19 @@ public class MainPage extends Page implements Observer { menuTable.align(Align.center); menuTable.defaults().space(10f); addActor(menuTable); - playButton = new TextButton("Start!", rhythmBullet.getSkin()); - playButton.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.musicSelectionPage); - getStage().setKeyboardFocus(mainScreen.musicSelectionPage); - } - }); + playButton = new TextButton("Start!", skin); + playButton.addListener(playButtonListener); menuTable.add(playButton).width(Gdx.graphics.getWidth()*0.2f); menuTable.row(); - optionsButton = new TextButton("Options", rhythmBullet.getSkin(), "sub"); - optionsButton.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.optionsPage); - } - }); + optionsButton = new TextButton("Options", skin, "sub"); + optionsButton.addListener(optionsButtonListener); menuTable.add(optionsButton).fillX(); menuTable.row(); - quitButton = new TextButton("Quit", rhythmBullet.getSkin(), "sub"); + quitButton = new TextButton("Quit", skin, "sub"); quitButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { @@ -93,11 +81,11 @@ public class MainPage extends Page implements Observer { }); menuTable.add(quitButton).fillX(); - musicControls = new MusicControls(rhythmBullet.getSkin(), mc); + musicControls = new MusicControls(skin, mc); musicControls.setPosition((getWidth()-musicControls.getMinWidth() - 20f), getHeight()-musicControls.getMinHeight()-20f); addActor(musicControls); - scrollText = new ScrollText("...", "...", rhythmBullet.getSkin(), false, true); + scrollText = new ScrollText("...", "...", skin, false, true); scrollText.setWidth(0.5f*getWidth()); scrollText.setPosition(15, getHeight() - scrollText.getHeight()-25f); addActor(scrollText); diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java index 6805213..fb6cd0c 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java @@ -28,19 +28,20 @@ import zero1hd.rhythmbullet.util.ResizeReadyScreen; public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { private Stage stage; private Vector3 cameraPosition; + private Listeners listeners; - protected MainPage mainPage; - protected OptionsPage optionsPage; - protected CreditsPage creditsPage; - protected KeybindOptionsPage keybindPage; - protected GraphicsOptionsPage graphicsPage; - protected MusicSelectionPage musicSelectionPage; - protected AnalysisPage analysisPage; + private MainPage mainPage; + private OptionsPage optionsPage; + private KeybindPage keybindPage; + private GraphicsPage graphicsPage; + private CreditsPage creditsPage; + private MusicSelectionPage musicSelectionPage; + private AnalysisPage analysisPage; - protected MusicController musicController; - protected MusicMetadataController musicMetadataController; + private MusicController musicController; + private MusicMetadataController musicMetadataController; - protected RhythmBullet rhythmBullet; + private RhythmBullet rhythmBullet; private BloomShader bloomShader; @@ -56,12 +57,14 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { cameraPosition = new Vector3(stage.getCamera().position); MusicList musicList = new MusicList(new DesktopAudioProcessorFactory()); - musicList.setSearchPath(core.getPrefs().getString("music dir")); - musicController = new MusicController(musicList, core.getPrefs()); + musicList.setSearchPath(core.getPreferences().getString("music dir")); + musicController = new MusicController(musicList, core.getPreferences()); musicController.setAutoPlay(true); musicController.setShuffle(true); musicMetadataController = new MusicMetadataController(musicList); + + listeners = new Listeners(); } @Override @@ -114,47 +117,32 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { background = rhythmBullet.getAssetManager().get("backgrounds/mainBG.png", Texture.class); screenBatch = new SpriteBatch(); - mainPage = new MainPage(this); + + + mainPage = new MainPage(musicController, rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), listeners.musicSelectionPageButtonListener, listeners.optionsPageButtonListener); stage.addActor(mainPage); //End main menu - optionsPage = new OptionsPage(this); + optionsPage = new OptionsPage(musicController, rhythmBullet.getSkin(), rhythmBullet.getPreferences(), listeners.returnToMainPageListener, listeners.graphicsPageButtonListener, listeners.keybindPageButtonListener); stage.addActor(optionsPage); - analysisPage = new AnalysisPage(this); - stage.addActor(analysisPage); - - musicSelectionPage = new MusicSelectionPage(this); - stage.addActor(musicSelectionPage); - - - keybindPage = new KeybindOptionsPage(this); + keybindPage = new KeybindPage(rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), listeners.returnToMainPageListener); stage.addActor(keybindPage); - - graphicsPage = new GraphicsOptionsPage(this); - if (graphicsPage.getGlowLevelSlider().getValue() > 0) { - if (bloomShader == null) bloomShader = new BloomShader(screenBatch); - bloomShader.setBloomLevel((int) graphicsPage.getGlowLevelSlider().getValue()); - } - graphicsPage.getGlowLevelSlider().addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - if (graphicsPage.getGlowLevelSlider().getValue() > 0) { - if (bloomShader == null) bloomShader = new BloomShader(screenBatch); - bloomShader.setBloomLevel((int) graphicsPage.getGlowLevelSlider().getValue()); - } else if (bloomShader != null) { - bloomShader.dispose(); - bloomShader = null; - } - } - }); + + graphicsPage = new GraphicsPage(rhythmBullet.getSkin(), rhythmBullet.getPreferences(), listeners.returnToMainPageListener, listeners.bloomLevelShaderListener); stage.addActor(graphicsPage); - creditsPage = new CreditsPage(rhythmBullet.getSkin()); - creditsPage.setPosition(0, Gdx.graphics.getHeight()); stage.addActor(creditsPage); + musicSelectionPage = new MusicSelectionPage(rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), musicController, musicMetadataController, listeners.returnToMainPageListener, listeners.analysisPageButtonListener); + stage.addActor(musicSelectionPage); + + analysisPage = new AnalysisPage(rhythmBullet.getSkin(), listeners.returnToMainPageListener, listeners.confirmedSongListener); + stage.addActor(analysisPage); + + + stage.addListener(new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { @@ -199,8 +187,8 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { public void saveAll() { if (optionsPage != null) { - optionsPage.saveOptions(rhythmBullet.getPrefs()); - rhythmBullet.getPrefs().flush(); + optionsPage.saveOptions(rhythmBullet.getPreferences()); + rhythmBullet.getPreferences().flush(); } } @@ -233,4 +221,76 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { page.setCameraPositionToPage(cameraPosition); } + private class Listeners { + ChangeListener musicSelectionPageButtonListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + setDisplayedPage(musicSelectionPage); + stage.setKeyboardFocus(musicSelectionPage); + } + }; + + ChangeListener analysisPageButtonListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + musicSelectionPage.getSelectedMusic(); + setDisplayedPage(analysisPage); + } + }; + + ChangeListener returnToMainPageListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + setDisplayedPage(mainPage); + } + }; + + ChangeListener optionsPageButtonListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + setDisplayedPage(optionsPage); + } + }; + + ChangeListener graphicsPageButtonListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + setDisplayedPage(graphicsPage); + } + }; + + ChangeListener keybindPageButtonListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + setDisplayedPage(keybindPage); + } + }; + + ChangeListener creditPageButtonListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + setDisplayedPage(creditsPage); + } + }; + + ChangeListener bloomLevelShaderListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + if (graphicsPage.getBloomLevel() > 0) { + if (bloomShader == null) bloomShader = new BloomShader(screenBatch); + bloomShader.setBloomLevel((int) graphicsPage.getBloomLevel()); + } else if (bloomShader != null) { + bloomShader.dispose(); + bloomShader = null; + } + } + }; + + ChangeListener confirmedSongListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + + } + }; + } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java index 16ebe8c..d6b842f 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java @@ -1,5 +1,6 @@ package zero1hd.rhythmbullet.desktop.screens.main; +import java.util.HashMap; import java.util.Observable; import java.util.Observer; @@ -7,6 +8,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Preferences; import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; @@ -27,8 +29,8 @@ import com.badlogic.gdx.utils.Array; import zero1hd.rhythmbullet.audio.MusicMetadataController; import zero1hd.rhythmbullet.audio.MusicController; -import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicSelectable; import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page; +import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable; import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; public class MusicSelectionPage extends Page implements Observer { @@ -36,10 +38,11 @@ public class MusicSelectionPage extends Page implements Observer { private MusicController mc; private MusicMetadataController mmc; + private Array selectables; + private TextButton back; private Table musicTable; private ScrollPane musicTableScrollPane; - private TextButton back; private Table musicInfoTable; private Table musicSubInfo; @@ -48,29 +51,24 @@ public class MusicSelectionPage extends Page implements Observer { private Label songLength; private Label previousTop; private Label ratedDifficulty; - private Texture albumCoverTexture; private Image albumCover; private AssetManager assets; - private MusicSelectable currentlySelected; - private Skin skin; private boolean down, up; private int musicSelectableIndex; private TextButton beginButton; - private int uiSongCount; - private int uiSongInfoCount; private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer; - public MusicSelectionPage(MainScreen mainScreen) { + public MusicSelectionPage(AssetManager assetManager, Skin skin, MusicController musicController, MusicMetadataController musicMetadataController, ChangeListener backButtonListener, ChangeListener beginButtonListener) { super(1, 0); - this.assets = mainScreen.rhythmBullet.getAssetManager(); - this.skin = mainScreen.rhythmBullet.getSkin(); - this.mc = mainScreen.musicController; - this.mmc = mainScreen.musicMetadataController; + this.assets = assetManager; + this.mc = musicController; + this.mmc = musicMetadataController; musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation"); + musicTable = new Table(); musicTableScrollPane = new ScrollPane(musicTable, skin); musicTable.defaults().spaceTop(5f).spaceBottom(5f); @@ -79,16 +77,10 @@ public class MusicSelectionPage extends Page implements Observer { musicTableScrollPane.setOverscroll(false, false); musicTableScrollPane.setColor(Color.BLUE); addActor(musicTableScrollPane); - selectables = new Array<>(); back = new TextButton("Back", skin); back.setWidth(back.getWidth()+20f); back.setPosition(getWidth()-back.getWidth()-15f, getHeight() - back.getHeight() - 15f); - back.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.mainPage); - } - }); + back.addListener(backButtonListener); addActor(back); back.toFront(); @@ -134,15 +126,7 @@ public class MusicSelectionPage extends Page implements Observer { albumCover = new Image(assets.get("defaultCover.png", Texture.class)); beginButton = new TextButton("Begin", skin); - beginButton.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - if (getSelectedMusic() != null) { - mainScreen.setDisplayedPage(mainScreen.analysisPage); - ap.processSong(mc.getMusicList().newAudioProcessor(getSelectedMusic()), (albumCoverTexture != null ? albumCoverTexture : assets.get("defaultCover.png", Texture.class)), mmc.getInfo(getSelectedMusic())); - } - } - }); + beginButton.addListener(beginButtonListener); } @Override @@ -178,30 +162,23 @@ public class MusicSelectionPage extends Page implements Observer { setCurrentMusic(); } } - - attemptRefreshUpdate(); super.act(delta); } - private void attemptRefreshUpdate() { - if (mc.getMusicList().isSearched() && uiSongInfoCount != mc.getMusicList().getTotal()) { - if (uiSongCount < mc.getMusicList().getTotal()) { - MusicSelectable selectable = new MusicSelectable(mc.getMusicList().getSongFileHandleFromIndex(uiSongCount), skin, this); - selectables.add(selectable); - musicTable.add(selectables.get(uiSongCount)).expandX().fillX(); - uiSongCount++; - musicTable.row(); - if (uiSongCount == mc.getMusicList().getTotal()) { - selectMusicUI(mc.getCurrentMusicManager()); - } - } else if (uiSongInfoCount < selectables.size && mmc.isDone()) { - selectables.get(uiSongInfoCount).updateInfo(mmc.getMetadataArray().get(uiSongInfoCount)); - uiSongInfoCount++; - if (uiSongInfoCount == selectables.size) { - updateInformation(); - } - } + private void scrollDown() { + if ((musicSelectableIndex = (musicTable.getChildren().indexOf(currentlySelected, true) + 1)) == musicTable.getChildren().size) { + musicSelectableIndex = 0; } + ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select(); + musicTableScrollPane.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); + } + + private void scrollUp() { + if ((musicSelectableIndex = (musicTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) { + musicSelectableIndex = musicTable.getChildren().size-1; + } + ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select(); + musicTableScrollPane.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); } public FileHandle getSelectedMusic() { @@ -212,15 +189,11 @@ public class MusicSelectionPage extends Page implements Observer { } } - public MusicInfo getSelectedMusicInfo() { - return currentlySelected.getMusicInfo(); - } - public void refreshUIList() { for (int i = 0; i < selectables.size; i++) { selectables.get(i).dispose(); } - mmc.loadSongInfo(); + mmc.loadAudioMetadata(); musicTable.clear(); selectables.clear(); musicInfoTable.clear(); @@ -253,98 +226,30 @@ public class MusicSelectionPage extends Page implements Observer { super.dispose(); } - public void deselectAll() { - if (currentlySelected != null) { - currentlySelected.deselect(); - } else { - for (int i = 0; i < selectables.size; i++) { - selectables.get(i).deselect(); - } - } - - } - - public void setCurrentlySelected(MusicSelectable currentlySelected) { - this.currentlySelected = currentlySelected; - songSelectionTimer = 1f; - - if (mmc.isDone() && uiSongInfoCount == selectables.size) { - updateInformation(); - } - } - - private void scrollDown() { - if ((musicSelectableIndex = (musicTable.getChildren().indexOf(currentlySelected, true) + 1)) == musicTable.getChildren().size) { - musicSelectableIndex = 0; - } - ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select(); - musicTableScrollPane.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); - } - - private void scrollUp() { - if ((musicSelectableIndex = (musicTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) { - musicSelectableIndex = musicTable.getChildren().size-1; - } - ((MusicSelectable)musicTable.getChildren().get(musicSelectableIndex)).select(); - musicTableScrollPane.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); - } @Override public void update(Observable o, Object arg) { if (o == mc && arg == MusicController.States.Loaded) { - selectMusicUI(mc.getCurrentMusic()); + selectMusicUI(mc.getCurrentMusicFileHandle()); } } - public void selectMusicUI(MusicManager mm) { - if (currentlySelected == null || mm.getMusicFile() != currentlySelected.getMusicFile()) { - for (int i = 0; i < selectables.size; i++) { - if (selectables.get(i).getMusicFile() == mm.getMusicFile()) { - selectables.get(i).select(); - musicSelectableIndex = i; - break; - } - } - } + public void selectMusicUI(FileHandle fileHandle) { + selectables.get(mc.getMusicList().getMusicArray().indexOf(fileHandle, true)).select(); } - private void setCurrentMusic() { - playSelectedMusic(); + @Override + public void setCameraPositionToPage(Vector3 cameraPosition) { + getStage().setKeyboardFocus(this); + super.setCameraPositionToPage(cameraPosition); } - private void playSelectedMusic() { - if (currentlySelected.getMusicFile() != mc.getCurrentMusicManager().getMusicFile()) { - int index = mc.getMusicList().getMusicArray().indexOf(currentlySelected.getMusicFile(), true); - mc.setMusicByIndex(index); - } - } - - /** - * This should only be called when everything is loaded. - */ - private void updateInformation() { - Gdx.app.debug("MusicSelectionPage", "Updating song info panel..."); - if (currentlySelected == null) throw new NullPointerException("Buddy, you need to update this page to have the proper current music selected..."); - if (currentlySelected.getMusicInfo() == null) throw new NullPointerException("K, ur music info is null."); - songTitle.setText(currentlySelected.getMusicInfo().getMusicName(), null); - author.setText("Author: " + currentlySelected.getMusicInfo().getAuthor()); - if (albumCoverTexture != null) { - albumCoverTexture.dispose(); - } - long lengthInSeconds = currentlySelected.getMusicInfo().getDurationInSeconds(); - int min = (int) (lengthInSeconds/60); - int sec = (int) (lengthInSeconds - (min*60)); - songLength.setText("Length: " + min + ":" + (sec > 9 ? sec : "0" + sec)); - - previousTop.setText("Highscore: " + currentlySelected.getMusicInfo().getPreviousTop()); - - String difficulty = (getSelectedMusicInfo().getRatedDifficulty() == -1 ? "N/A" : String.valueOf(getSelectedMusicInfo().getRatedDifficulty())); - ratedDifficulty.setText("Rated Difficulty: " + difficulty); - albumCoverTexture = currentlySelected.getMusicInfo().loadTexture(); - if (albumCoverTexture != null) { - albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(albumCoverTexture)))); - } else { - albumCover.setDrawable((new TextureRegionDrawable(new TextureRegion(assets.get("defaultCover.png", Texture.class))))); + private class musicSelectionLoaderThread implements Runnable { + + @Override + public void run() { + // TODO Auto-generated method stub + } } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/OptionsPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/OptionsPage.java index 2fa8a1d..3db7463 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/OptionsPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/OptionsPage.java @@ -6,12 +6,14 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import zero1hd.rhythmbullet.audio.MusicController; import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page; public class OptionsPage extends Page { @@ -21,17 +23,12 @@ public class OptionsPage extends Page { private TextField directoryField; private float musicSearchTimer; - public OptionsPage(MainScreen mainScreen) { - super(-1, 0, "General", mainScreen.rhythmBullet.getSkin()); + public OptionsPage(MusicController musicController, Skin skin, Preferences preferences, ChangeListener backButtonListener, ChangeListener graphicsButtonListener, ChangeListener controlsButtonListener) { + super(-1, 0, "General", skin); //Back button - TextButton backButton = new TextButton("Back", mainScreen.rhythmBullet.getSkin()); - backButton.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.mainPage); - } - }); + TextButton backButton = new TextButton("Back", skin); + backButton.addListener(backButtonListener); backButton.setWidth(backButton.getWidth() + 20); backButton.setPosition(getWidth() - backButton.getWidth() - 10, getHeightBelowTitle() + 5); addActor(backButton); @@ -41,36 +38,36 @@ public class OptionsPage extends Page { optionsTable.setSize(getWidth(), getHeight()); addActor(optionsTable); - Label musicVolSliderLabel = new Label("Music Volume: ", mainScreen.rhythmBullet.getSkin()); + Label musicVolSliderLabel = new Label("Music Volume: ", skin); optionsTable.add(musicVolSliderLabel); - musicVolSlider = new Slider(0, 100, 0.1f, false, mainScreen.rhythmBullet.getSkin()); - musicVolSlider.setValue(mainScreen.rhythmBullet.getPrefs().getFloat("music vol", 100f)*100f); + musicVolSlider = new Slider(0, 100, 0.1f, false, skin); + musicVolSlider.setValue(preferences.getFloat("music vol", 100f)*100f); optionsTable.add(musicVolSlider).minWidth(0.3f*getWidth()); - final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", mainScreen.rhythmBullet.getSkin()); + final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", skin); musicVolSlider.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); - mainScreen.musicController.getCurrentMusic().setVolume(musicVolSlider.getPercent()); + musicController.getCurrentMusic().setVolume(musicVolSlider.getPercent()); - mainScreen.rhythmBullet.getPrefs().putFloat("music vol", musicVolSlider.getPercent()); + preferences.putFloat("music vol", musicVolSlider.getPercent()); } }); optionsTable.add(musicVolPercentage); optionsTable.row(); - Label fxVolSliderLabel = new Label("FX Volume: ", mainScreen.rhythmBullet.getSkin()); + Label fxVolSliderLabel = new Label("FX Volume: ", skin); optionsTable.add(fxVolSliderLabel); - fxVolSlider = new Slider(0, 100, 0.1f, false, mainScreen.rhythmBullet.getSkin()); - fxVolSlider.setValue(mainScreen.rhythmBullet.getPrefs().getFloat("fx vol", 100f)*100f); + fxVolSlider = new Slider(0, 100, 0.1f, false, skin); + fxVolSlider.setValue(preferences.getFloat("fx vol", 100f)*100f); optionsTable.add(fxVolSlider).fillX(); - final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", mainScreen.rhythmBullet.getSkin()); + final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", skin); fxVolSlider.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%"); - mainScreen.rhythmBullet.getPrefs().putFloat("fx vol", fxVolSlider.getPercent()); + preferences.putFloat("fx vol", fxVolSlider.getPercent()); } }); @@ -78,22 +75,22 @@ public class OptionsPage extends Page { optionsTable.row(); - Label musicDirectoryLabel = new Label("Music Directory: ", mainScreen.rhythmBullet.getSkin()); + Label musicDirectoryLabel = new Label("Music Directory: ", skin); optionsTable.add(musicDirectoryLabel); - directoryField = new TextField(null, mainScreen.rhythmBullet.getSkin() ) { + directoryField = new TextField(null, skin ) { @Override public void act(float delta) { if (musicSearchTimer > 0) { musicSearchTimer -= delta; if (musicSearchTimer <= 0) { - mainScreen.musicController.getMusicList().setSearchPath(directoryField.getText()); - mainScreen.musicController.getMusicList().asyncSearch(); + musicController.getMusicList().setSearchPath(directoryField.getText()); + musicController.getMusicList().asyncSearch(); } } super.act(delta); } }; - directoryField.setText(mainScreen.rhythmBullet.getPrefs().getString("music dir", System.getProperty("user.home")+System.getProperty("file.separator")+"Music")); + directoryField.setText(preferences.getString("music dir", System.getProperty("user.home")+System.getProperty("file.separator")+"Music")); directoryField.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { @@ -104,29 +101,19 @@ public class OptionsPage extends Page { optionsTable.row(); - TextButton keybindSettings = new TextButton("Set Controls", mainScreen.rhythmBullet.getSkin()); - keybindSettings.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.keybindPage); - } - }); + TextButton keybindSettings = new TextButton("Set Controls", skin); + keybindSettings.addListener(controlsButtonListener); optionsTable.add(keybindSettings).colspan(2).fillX(); optionsTable.row(); - TextButton graphicsSettings = new TextButton("Graphics", mainScreen.rhythmBullet.getSkin()); - graphicsSettings.addListener(new ChangeListener() { - @Override - public void changed(ChangeEvent event, Actor actor) { - mainScreen.setDisplayedPage(mainScreen.graphicsPage); - } - }); + TextButton graphicsSettings = new TextButton("Graphics", skin); + graphicsSettings.addListener(graphicsButtonListener); optionsTable.add(graphicsSettings).colspan(2).fillX(); optionsTable.row(); - Label fpsLabel = new Label("", mainScreen.rhythmBullet.getSkin()) { + Label fpsLabel = new Label("", skin) { @Override public void act(float delta) { setText("Current FPS: " + Gdx.graphics.getFramesPerSecond()); @@ -137,7 +124,7 @@ 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()) + "%", mainScreen.rhythmBullet.getSkin()) { + 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; @Override public void act(float delta) {