diff --git a/android/assets/uiskin.atlas b/android/assets/uiskin.atlas index 6cacd61..f759efa 100755 --- a/android/assets/uiskin.atlas +++ b/android/assets/uiskin.atlas @@ -366,7 +366,7 @@ rect rotate: false xy: 176, 35 size: 14, 14 - split: 4, 4, 4, 4 + split: 3, 3, 3, 3 orig: 14, 14 offset: 0, 0 index: -1 @@ -374,7 +374,7 @@ rect-down rotate: false xy: 191, 35 size: 14, 14 - split: 4, 4, 4, 4 + split: 3, 3, 3, 3 orig: 14, 14 offset: 0, 0 index: -1 @@ -382,7 +382,7 @@ rect-disabled rotate: false xy: 206, 35 size: 14, 14 - split: 4, 4, 4, 4 + split: 3, 3, 3, 3 orig: 14, 14 offset: 0, 0 index: -1 diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicController.java b/core/src/zero1hd/rhythmbullet/audio/MusicController.java index 05dd06d..4f70ba8 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicController.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicController.java @@ -21,6 +21,7 @@ public class MusicController extends Observable implements OnCompletionListener, public final class States { public final Integer LOADED = new Integer(0), PLAYING = new Integer(1); } + public final States states = new States(); private MusicList musicList; private MinimalAudioHeader musicHeader; @@ -191,12 +192,16 @@ public class MusicController extends Observable implements OnCompletionListener, @Override public void update(Observable o, Object arg) { if (o == musicList) { - if (shuffle) { - shuffle(); - } - loadMusic(); - if (autoPlay) { - play(); + if (arg == musicList.states.LOADING) { + pause(); + } else if (arg == musicList.states.COMPLETE) { + if (shuffle) { + shuffle(); + } + loadMusic(); + if (autoPlay) { + play(); + } } } } diff --git a/core/src/zero1hd/rhythmbullet/audio/MusicList.java b/core/src/zero1hd/rhythmbullet/audio/MusicList.java index 4d7f9ab..5251b5a 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MusicList.java +++ b/core/src/zero1hd/rhythmbullet/audio/MusicList.java @@ -17,6 +17,10 @@ import zero1hd.rhythmbullet.audio.processor.WAVAudioProcessor; * @author yunya */ public class MusicList extends Observable { + public final class States { + public final Integer LOADING = new Integer(0), COMPLETE = new Integer(1); + } + public States states = new States(); private Array musicList; private RecursiveMusicSearchThread searchThread; private AudioProcessorFactory audioProcFactory; @@ -45,7 +49,7 @@ public class MusicList extends Observable { */ public void asyncSearch(boolean refresh) { if (refresh) { - + notifyObservers(states.LOADING); if (searchThread != null) { if (!searchThread.start()) { searchThread.stop(); @@ -57,9 +61,7 @@ public class MusicList extends Observable { searchThread.start(); } } else { - if (searched && !hasChanged()) { - notifyObservers(); - } else { + if (!searched || hasChanged()) { asyncSearch(true); } } @@ -154,7 +156,7 @@ public class MusicList extends Observable { searched = true; Gdx.app.debug("MusicList", "recursive async search completed."); setChanged(); - notifyObservers(); + notifyObservers(states.COMPLETE); } } diff --git a/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java b/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java index f7b506e8..5c06f46 100755 --- a/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java +++ b/core/src/zero1hd/rhythmbullet/audio/metadata/MP3Metadata.java @@ -25,7 +25,7 @@ public class MP3Metadata implements AudioMetadata { private int length; private Texture albumCover; private FileHandle fileHandle; - private byte[] imageData; + private Pixmap pixmap; public MP3Metadata(FileHandle fileHandle) { this.fileHandle = fileHandle; @@ -65,8 +65,8 @@ public class MP3Metadata implements AudioMetadata { mp3file = (MP3File) AudioFileIO.read(fileHandle.file()); Artwork art = mp3file.getTag().getFirstArtwork(); if (art != null) { - imageData = art.getBinaryData(); - + byte[] imageData = art.getBinaryData(); + pixmap = new Pixmap(imageData, 0, imageData.length); } } catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) { @@ -109,11 +109,10 @@ public class MP3Metadata implements AudioMetadata { @Override public Texture getAlbumCover() { - if (albumCover == null && imageData != null) { - Pixmap pixmap = new Pixmap(imageData, 0, imageData.length); + if (pixmap != null && albumCover == null) { albumCover = new Texture(pixmap); pixmap.dispose(); - imageData = null; + pixmap = null; } return albumCover; } diff --git a/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java b/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java index 199fe47..ac756cc 100755 --- a/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java +++ b/core/src/zero1hd/rhythmbullet/audio/metadata/WAVMetadata.java @@ -24,7 +24,7 @@ public class WAVMetadata implements AudioMetadata { private int length; private Texture albumCover; private FileHandle fileHandle; - private byte[] imageData; + private Pixmap pixmap; public WAVMetadata(FileHandle fileHandle) { this.fileHandle = fileHandle; @@ -52,10 +52,11 @@ public class WAVMetadata implements AudioMetadata { try { AudioFile wav = AudioFileIO.read(fileHandle.file()); Artwork art = wav.getTag().getFirstArtwork(); - if (art != null) { - imageData = art.getBinaryData(); - } + if (art != null) { + byte[] imageData = art.getBinaryData(); + pixmap = new Pixmap(imageData, 0, imageData.length); + } } catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) { e.printStackTrace(); } @@ -88,11 +89,10 @@ public class WAVMetadata implements AudioMetadata { @Override public Texture getAlbumCover() { - if (albumCover == null && imageData != null) { - Pixmap pixmap = new Pixmap(imageData, 0, imageData.length); + if (pixmap != null && albumCover == null) { albumCover = new Texture(pixmap); pixmap.dispose(); - imageData = null; + pixmap = null; } return albumCover; } diff --git a/core/src/zero1hd/rhythmbullet/controls/KeyMap.java b/core/src/zero1hd/rhythmbullet/controls/KeyMap.java deleted file mode 100755 index d80bda8..0000000 --- a/core/src/zero1hd/rhythmbullet/controls/KeyMap.java +++ /dev/null @@ -1,149 +0,0 @@ -package zero1hd.rhythmbullet.controls; - -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.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -public class KeyMap { - TextureAtlas keyTextures; - private Preferences keyBindPrefs; - - public static final String UP = "up"; - public static final String DOWN = "down"; - public static final String LEFT = "left"; - public static final String RIGHT = "right"; - - public static final String SHOOT = "shoot"; - - public static final String FIRSTTHIRDTELEPORT = "firstThirdTP"; - public static final String SECONDTHIRDTELEPORT = "secondThirdTP"; - public static final String THIRDTHIRDTELEPORT = "thirdThirdTP"; - - public static final String ACCELERATE = "accelerate"; - - /** - * forward binding. - */ - public static int up; - /** - * backward binding. - */ - public static int down; - /** - * left binding. - */ - public static int left; - /** - * right binding. - */ - public static int right; - /** - * shoot binding - */ - public static int shoot; - /** - * teleport first third binding - */ - public static int firstThirdTeleport; - /** - * teleport second third binding - */ - public static int secondThirdTeleport; - /** - * teleport third third binding - */ - public static int thirdThirdTeleport; - - public static int accelerate; - - - public KeyMap(AssetManager assets) { - keyTextures = assets.get("keyboard.atlas", TextureAtlas.class); - - setKeys(Gdx.app.getPreferences("PolyJet_Controls")); - updateKeys(); - } - - public Preferences getKeys() { - return keyBindPrefs; - } - - public void setKeys(Preferences keys) { - this.keyBindPrefs = keys; - } - - public TextureRegion getIcon(int keycode) { -// Gdx.app.debug("Keycode texture name", Keys.toString(keycode)); - - switch (keycode) { - case Keys.ALT_LEFT: - case Keys.ALT_RIGHT: - return keyTextures.findRegion("Keyboard_Black_Alt"); - case Keys.SHIFT_LEFT: - case Keys.SHIFT_RIGHT: - return keyTextures.findRegion("Keyboard_Black_Shift"); - case Keys.LEFT_BRACKET: - return keyTextures.findRegion("Keyboard_Black_Bracket_Left"); - case Keys.RIGHT_BRACKET: - return keyTextures.findRegion("Keyboard_Black_Bracket_Right"); - case Keys.SEMICOLON: - return keyTextures.findRegion("Keyboard_Black_Semicolon"); - case Keys.SLASH: - return keyTextures.findRegion("Keyboard_Black_Slash"); - case Keys.NUM: - return keyTextures.findRegion("Keyboard_Black_Num_Lock"); - default: - return keyTextures.findRegion("Keyboard_Black_" + Keys.toString(keycode).replace(' ', '_')); - } - } - - public void updateKeys() { - up = keyBindPrefs.getInteger(KeyMap.UP, Keys.UP); - down = keyBindPrefs.getInteger(KeyMap.DOWN, Keys.DOWN); - left = keyBindPrefs.getInteger(KeyMap.LEFT, Keys.LEFT); - right = keyBindPrefs.getInteger(KeyMap.RIGHT, Keys.RIGHT); - - shoot = keyBindPrefs.getInteger(KeyMap.SHOOT, Keys.SPACE); - - firstThirdTeleport = keyBindPrefs.getInteger(KeyMap.FIRSTTHIRDTELEPORT, Keys.Q); - secondThirdTeleport = keyBindPrefs.getInteger(KeyMap.SECONDTHIRDTELEPORT, Keys.W); - thirdThirdTeleport = keyBindPrefs.getInteger(KeyMap.THIRDTHIRDTELEPORT, Keys.E); - - accelerate = keyBindPrefs.getInteger(KeyMap.ACCELERATE, Keys.SHIFT_LEFT); - } - - /** - * resets all binding to default; - */ - public void resetAllBinding() { - keyBindPrefs.clear(); - keyBindPrefs.flush(); - } - - public int stringToID(String control) { - if (control == KeyMap.UP) { - return KeyMap.up; - } else if (control == KeyMap.DOWN) { - return KeyMap.down; - } else if (control == KeyMap.LEFT) { - return KeyMap.left; - } else if (control == KeyMap.RIGHT) { - return KeyMap.right; - } else if (control == KeyMap.SHOOT) { - return KeyMap.shoot; - } else if (control == KeyMap.FIRSTTHIRDTELEPORT) { - return KeyMap.firstThirdTeleport; - } else if (control == KeyMap.SECONDTHIRDTELEPORT) { - return KeyMap.secondThirdTeleport; - } else if (control == KeyMap.THIRDTHIRDTELEPORT) { - return KeyMap.thirdThirdTeleport; - } else if (control == KeyMap.ACCELERATE) { - return KeyMap.accelerate; - } else { - return -1; - } - } -} diff --git a/core/src/zero1hd/rhythmbullet/game/GameController.java b/core/src/zero1hd/rhythmbullet/game/GameController.java deleted file mode 100755 index d040fc5..0000000 --- a/core/src/zero1hd/rhythmbullet/game/GameController.java +++ /dev/null @@ -1,148 +0,0 @@ -package zero1hd.rhythmbullet.game; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.InputProcessor; -import com.badlogic.gdx.Preferences; -import com.badlogic.gdx.assets.AssetManager; -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.utils.Disposable; - -import zero1hd.rhythmbullet.controls.KeyMap; -import zero1hd.rhythmbullet.entity.CollisionDetector; -import zero1hd.rhythmbullet.entity.EntityManager; -import zero1hd.rhythmbullet.entity.ally.Laser; -import zero1hd.rhythmbullet.entity.ally.PolyjetEntity; -import zero1hd.rhythmbullet.entity.coordinator.CoordinatorManager; - - -public class GameController implements Disposable, InputProcessor { - public PolyjetEntity polyjet; - - public CoordinatorManager cm; - public EntityManager em; - private CollisionDetector collisionDetector; - - public ScoreManager score = new ScoreManager(); - - public GameController(AssetManager assetManager, Preferences prefs) { - Gdx.app.debug("Game Area", "new area created"); - - polyjet = new PolyjetEntity(assetManager, 25f, 25f, 100, "standard"); - em = new EntityManager(assetManager, prefs); - cm = new CoordinatorManager(em); - - collisionDetector = new CollisionDetector(em.activeEnemies, em.activeAllies, assetManager, prefs); - em.activeAllies.add(polyjet); - } - - public void draw(Batch batch) { - batch.begin(); - for (int i = 0; i < em.activeEnemies.size; i++) { - em.activeEnemies.get(i).draw(batch); - } - for (int i = 0; i < em.activeAllies.size; i++) { - em.activeAllies.get(i).draw(batch); - } - batch.end(); - } - - public void prepare(float delta) { - for (int i = 0; i < em.activeEnemies.size; i++) { - em.activeEnemies.get(i).updatePosition(); - } - for (int i = 0; i < em.activeAllies.size; i++) { - em.activeAllies.get(i).updatePosition(); - } - } - - @Override - public boolean keyDown(int keycode) { - if (keycode == KeyMap.left) { - polyjet.moveLeft = true; - } - if (keycode == KeyMap.right) { - polyjet.moveRight = true; - } - - if (keycode == KeyMap.up) { - polyjet.moveUp = true; - } - - if (keycode == KeyMap.down) { - polyjet.moveDown = true; - } - - if (keycode == KeyMap.accelerate) { - polyjet.accelerate = true; - } - return false; - } - - @Override - public boolean keyUp(int keycode) { - if (keycode == KeyMap.left) { - polyjet.moveLeft = false; - } - if (keycode == KeyMap.right) { - polyjet.moveRight = false; - } - if (keycode == KeyMap.up) { - polyjet.moveUp = false; - } - if (keycode == KeyMap.down) { - polyjet.moveDown = false; - } - - if (keycode == KeyMap.accelerate) { - polyjet.accelerate = false; - } - - if (keycode == KeyMap.shoot) { - Laser laser = em.laser.buildEntity(); - laser.init(polyjet.getX() + polyjet.getWidth()/2f, polyjet.getY() + polyjet.getHeight()+1f, 60f); - } - return false; - } - - public PolyjetEntity getPolyjetEntity() { - return polyjet; - } - - @Override - public void dispose() { - } - - public CollisionDetector getCollisionDetector() { - return collisionDetector; - } - - @Override - public boolean keyTyped(char character) { - return false; - } - - @Override - public boolean touchDown(int screenX, int screenY, int pointer, int button) { - return false; - } - - @Override - public boolean touchUp(int screenX, int screenY, int pointer, int button) { - return false; - } - - @Override - public boolean touchDragged(int screenX, int screenY, int pointer) { - return false; - } - - @Override - public boolean mouseMoved(int screenX, int screenY) { - return false; - } - - @Override - public boolean scrolled(int amount) { - return false; - } -} diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HealthBar.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/HealthBar.java similarity index 91% rename from desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HealthBar.java rename to core/src/zero1hd/rhythmbullet/graphics/ui/components/HealthBar.java index 2239ad2..c7df9ce 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/HealthBar.java +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/HealthBar.java @@ -1,4 +1,4 @@ -package zero1hd.rhythmbullet.desktop.graphics.ui.components; +package zero1hd.rhythmbullet.graphics.ui.components; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.actions.Actions; diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/Controls.java b/desktop/src/zero1hd/rhythmbullet/desktop/Controls.java new file mode 100755 index 0000000..a7dbffa --- /dev/null +++ b/desktop/src/zero1hd/rhythmbullet/desktop/Controls.java @@ -0,0 +1,45 @@ +package zero1hd.rhythmbullet.desktop; + +import com.badlogic.gdx.Preferences; +import com.badlogic.gdx.Input.Keys; + +public enum Controls { + UP("Forward", Keys.UP), DOWN("Backwards", Keys.DOWN), LEFT("Left", Keys.LEFT), RIGHT("Right", Keys.RIGHT), SHOOT("Shoot", Keys.SPACE), ACCELERATE("Boost", Keys.SHIFT_LEFT); + private int keycode; + private final String friendly; + private final int defectKey; + + private Controls(String friendly, int defectKey) { + this.friendly = friendly; + this.defectKey = defectKey; + this.keycode = defectKey; + } + + public Controls setKeycode(int keycode) { + Controls[] controls = Controls.values(); + for (int i = 0; i < controls.length; i++) { + if (controls[i] != this && controls[i].getKeycode() == keycode) { + return controls[i]; + } + } + this.keycode = keycode; + return null; + } + + public int getKeycode() { + return keycode; + } + + public void loadKeyFromPreferences(Preferences preferences) { + setKeycode(preferences.getInteger(name(), defectKey)); + } + + public void saveKeyToPreferences(Preferences preferences) { + preferences.putInteger(name(), keycode); + } + + @Override + public String toString() { + return friendly; + } +} diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java index 1696cd1..e32e05a 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopAssetPack.java @@ -1,6 +1,7 @@ package zero1hd.rhythmbullet.desktop; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Preferences; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Color; @@ -94,13 +95,6 @@ public class DesktopAssetPack implements AssetPack { windowTextButton.font = skin.getFont("window-font"); skin.add("window", windowTextButton); - TextButtonStyle textButtonLeft = new TextButtonStyle(); - textButtonLeft.up = skin.getDrawable("left-button"); - textButtonLeft.down = skin.getDrawable("left-button-down"); - textButtonLeft.font = skin.getFont("default-font"); - textButtonLeft.fontColor = skin.getColor("default"); - skin.add("left", textButtonLeft); - SliderStyle defaultSlider = new SliderStyle(skin.getDrawable("default-slider"), skin.getDrawable("default-slider-knob")); skin.add("default-horizontal", defaultSlider); @@ -172,10 +166,13 @@ public class DesktopAssetPack implements AssetPack { 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); + ButtonStyle selectableButton = new ButtonStyle(); + selectableButton.checked = skin.getDrawable("holo-pane-down"); + selectableButton.up = skin.getDrawable("holo-pane"); + skin.add("selectable-button", selectableButton); + + ButtonStyle selectableCleanButton = new ButtonStyle(); + skin.add("selectable-clean-button", selectableCleanButton); } @Override @@ -220,6 +217,14 @@ public class DesktopAssetPack implements AssetPack { @Override public void complete(AssetManager assetManager) { assetManager.get("standard_thrust.p", ParticleEffect.class).flipY(); + + Preferences controlsPrefs = Gdx.app.getPreferences("RhythmBullet_Controls"); + Controls.UP.loadKeyFromPreferences(controlsPrefs); + Controls.DOWN.loadKeyFromPreferences(controlsPrefs); + Controls.LEFT.loadKeyFromPreferences(controlsPrefs); + Controls.RIGHT.loadKeyFromPreferences(controlsPrefs); + Controls.SHOOT.loadKeyFromPreferences(controlsPrefs); + Controls.ACCELERATE.loadKeyFromPreferences(controlsPrefs); } @Override diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java index a5c737c..4d6304d 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/DesktopLauncher.java @@ -1,16 +1,7 @@ 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; diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ControlOptions.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ControlOptions.java deleted file mode 100755 index 3ab69bf..0000000 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/ControlOptions.java +++ /dev/null @@ -1,123 +0,0 @@ -package zero1hd.rhythmbullet.desktop.graphics.ui.components; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Input.Keys; -import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.InputListener; -import com.badlogic.gdx.scenes.scene2d.actions.Actions; -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.ClickListener; -import com.badlogic.gdx.scenes.scene2d.utils.FocusListener; -import com.badlogic.gdx.utils.Align; - -import zero1hd.rhythmbullet.controls.KeyMap; - -public class ControlOptions extends Table { - private KeyBindButton selected; - - public ControlOptions(Skin skin, KeyMap keyMap) { - super(skin); - align(Align.center); - - ClickListener selectedListener = new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - getStage().setKeyboardFocus(event.getTarget()); - event.getTarget().setColor(Color.ORANGE); - selected = (KeyBindButton) event.getTarget(); - super.clicked(event, x, y); - } - }; - - InputListener keyPressedListener = new InputListener() { - @Override - public boolean keyUp(InputEvent event, int keycode) { - getStage().setKeyboardFocus(null); - Gdx.app.debug("KeySetter", "input keycode received: " + keycode); - if (keycode != Keys.ESCAPE) { - Gdx.app.debug("keySetter", "input has been set to: " + Keys.toString(keycode)); - if (selected.setKey(keycode)) { - keyMap.updateKeys(); - selected.addAction(Actions.sequence(Actions.color(Color.GREEN, 0.2f), Actions.color(Color.WHITE, 0.2f))); - } else { - selected.addAction(Actions.sequence(Actions.color(Color.RED, 0.2f), Actions.delay(0.1f), Actions.color(Color.WHITE, 0.2f))); - } - } - return super.keyUp(event, keycode); - } - }; - - FocusListener deselected = new FocusListener() { - @Override - public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { - if (!focused) { - unselect(); - } - super.keyboardFocusChanged(event, actor, focused); - } - }; - - Label forwardKeyLabel = new Label("Forward: ",skin); - forwardKeyLabel.setName(KeyMap.UP); - add(forwardKeyLabel).left(); - KeyBindButton forwardKeySetter = new KeyBindButton(keyMap, KeyMap.UP, selectedListener, keyPressedListener, deselected); - add(forwardKeySetter).spaceRight(45f); - Label shootKeyLabel = new Label("Shoot: ", skin); - shootKeyLabel.setName(KeyMap.SHOOT); - add(shootKeyLabel).left(); - KeyBindButton shootKeySetter = new KeyBindButton(keyMap, KeyMap.SHOOT, selectedListener, keyPressedListener, deselected); - add(shootKeySetter); - - row(); - - Label backwardKeyLabel = new Label("Backward: ", skin); - backwardKeyLabel.setName(KeyMap.DOWN); - add(backwardKeyLabel).left(); - KeyBindButton backwardKeySetter = new KeyBindButton(keyMap, KeyMap.DOWN, selectedListener, keyPressedListener, deselected); - add(backwardKeySetter).spaceRight(45f); - Label sector1TPKeyLabel = new Label("Left Teleport", skin); - sector1TPKeyLabel.setName(KeyMap.FIRSTTHIRDTELEPORT); - add(sector1TPKeyLabel).left(); - KeyBindButton Sector1TPKeySetter = new KeyBindButton(keyMap, KeyMap.FIRSTTHIRDTELEPORT, selectedListener, keyPressedListener, deselected); - Sector1TPKeySetter.addListener(selectedListener); - add(Sector1TPKeySetter); - - row(); - - Label leftKeyLabel = new Label("Left: ", skin); - leftKeyLabel.setName(KeyMap.LEFT); - add(leftKeyLabel).left(); - KeyBindButton leftKeySetter = new KeyBindButton(keyMap, KeyMap.LEFT, selectedListener, keyPressedListener, deselected); - add(leftKeySetter).spaceRight(45f); - Label sector2TPKeyLabel = new Label("Middle Teleport: ", skin); - sector2TPKeyLabel.setName(KeyMap.SECONDTHIRDTELEPORT); - add(sector2TPKeyLabel).left(); - KeyBindButton sector2TPKeySetter = new KeyBindButton(keyMap, KeyMap.SECONDTHIRDTELEPORT, selectedListener, keyPressedListener, deselected); - sector2TPKeySetter.addListener(selectedListener); - add(sector2TPKeySetter); - - row(); - - Label rightKeyLabel = new Label("Right: ", skin); - rightKeyLabel.setName(KeyMap.RIGHT); - add(rightKeyLabel).left(); - KeyBindButton rightKeySetter = new KeyBindButton(keyMap, KeyMap.RIGHT, selectedListener, keyPressedListener, deselected); - add(rightKeySetter).spaceRight(45f); - Label sector3TPKeyLabel = new Label("Right Teleport: ", skin); - sector3TPKeyLabel.setName(KeyMap.THIRDTHIRDTELEPORT); - add(sector3TPKeyLabel).left(); - KeyBindButton sector3TPKeySetter = new KeyBindButton(keyMap, KeyMap.THIRDTHIRDTELEPORT, selectedListener, keyPressedListener, deselected); - sector3TPKeySetter.addListener(selectedListener); - add(sector3TPKeySetter); - - setFillParent(true); - } - - private void unselect() { - selected.setColor(Color.WHITE); - } -} diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/KeyBindButton.java b/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/KeyBindButton.java deleted file mode 100755 index fb70657..0000000 --- a/desktop/src/zero1hd/rhythmbullet/desktop/graphics/ui/components/KeyBindButton.java +++ /dev/null @@ -1,45 +0,0 @@ -package zero1hd.rhythmbullet.desktop.graphics.ui.components; - -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.InputListener; -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; -import com.badlogic.gdx.scenes.scene2d.utils.FocusListener; - -import zero1hd.rhythmbullet.controls.KeyMap; - -public class KeyBindButton extends Actor { - private TextureRegion keyIcon; - private KeyMap keyMap; - private String controlKey; - - public KeyBindButton(final KeyMap keyMap, final String control, ClickListener selectionListener, InputListener keyPressListener, FocusListener deselectedListener) { - this.keyMap = keyMap; - this.keyIcon = keyMap.getIcon(keyMap.stringToID(control)); - this.controlKey = control; - setSize(keyIcon.getRegionWidth(), keyIcon.getRegionHeight()); - - addListener(selectionListener); - addListener(keyPressListener); - addListener(deselectedListener); - } - - - public boolean setKey(int keycode) { - if (keyMap.getIcon(keycode) != null) { - keyMap.getKeys().putInteger(controlKey, keycode); - keyIcon = keyMap.getIcon(keycode); - return true; - } else { - return false; - } - } - - @Override - public void draw(Batch batch, float parentAlpha) { - batch.setColor(getColor()); - batch.draw(keyIcon, getX(), getY(), getWidth(), getHeight()); - super.draw(batch, parentAlpha); - } -} diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/GameScreen.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/GameScreen.java index 389830a..a1a2792 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/GameScreen.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/GameScreen.java @@ -13,13 +13,11 @@ import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.audio.MusicController; import zero1hd.rhythmbullet.audio.visualizer.CircularVisualizer; import zero1hd.rhythmbullet.desktop.audio.PCMObtainer; -import zero1hd.rhythmbullet.game.GameController; public class GameScreen extends ScreenAdapter { private AssetManager assets; private SpriteBatch batch; private ExtendViewport viewport; - private GameController gc; private CircularVisualizer circleVisualizer; public GameScreen(AssetManager assets, Preferences prefs, MusicController musicController) { diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java index f47fa07..daf3e3e 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/KeybindPage.java @@ -1,30 +1,224 @@ package zero1hd.rhythmbullet.desktop.screens.main; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Preferences; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.InputListener; +import com.badlogic.gdx.scenes.scene2d.Touchable; +import com.badlogic.gdx.scenes.scene2d.actions.Actions; +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.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.TextureRegionDrawable; +import com.badlogic.gdx.utils.Array; -import zero1hd.rhythmbullet.controls.KeyMap; -import zero1hd.rhythmbullet.desktop.graphics.ui.components.ControlOptions; +import zero1hd.rhythmbullet.desktop.Controls; import zero1hd.rhythmbullet.graphics.ui.Page; public class KeybindPage extends Page { - private ControlOptions controlTable; - private KeyMap keyMap; - private TextButton backButton; + private ButtonGroup buttonOptions; + private VerticalGroup group; + private ScrollPane scrollPane; + private Skin skin; + TextureAtlas keyTextures; + private Preferences keyBindPrefs; + private InputListener inputListener; + private ChangeListener checkedListener; + public KeybindPage(AssetManager assetManager, Skin skin, ChangeListener backButtonListener) { super(-1, -1); - keyMap = new KeyMap(assetManager); - controlTable = new ControlOptions(skin, keyMap); - - addActor(controlTable); - - backButton = new TextButton("Back", skin); - backButton.setPosition(10, getHeight() - 10 - backButton.getHeight()); - backButton.setWidth(backButton.getWidth() + 20); + setTouchable(Touchable.enabled); + this.skin = skin; + keyTextures = assetManager.get("keyboard.atlas", TextureAtlas.class); + this.keyBindPrefs = Gdx.app.getPreferences("PolyJet_Controls"); + TextButton backButton = new TextButton("Back", skin); + backButton.setWidth(backButton.getWidth()+20f); + backButton.setPosition(getWidth()-backButton.getWidth()-15f, getHeight() - backButton.getHeight() - 15f); backButton.addListener(backButtonListener); - addActor(backButton); + + inputListener = new InputListener() { + @Override + public boolean keyUp(InputEvent event, int keycode) { + KeyChangeButton button = buttonOptions.getChecked(); + if (button != null) { + if (keycode != Keys.ESCAPE) { + button.attemptSetKeycode(keycode); + } + getStage().setKeyboardFocus(null); + } + return super.keyUp(event, keycode); + } + }; + + checkedListener = new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + KeyChangeButton button = (KeyChangeButton) actor; + if (button.isChecked()) { + button.ready(); + } else { + button.done(); + } + } + }; + + buttonOptions = new ButtonGroup<>(); + buttonOptions.setMinCheckCount(0); + buttonOptions.setMaxCheckCount(1); + group = new VerticalGroup(); + group.setTouchable(Touchable.childrenOnly); + group.space(15f); + Controls[] controls = Controls.values(); + for (int i = 0; i < controls.length; i++) { + KeyChangeButton button = new KeyChangeButton(controls[i]); + buttonOptions.add(button); + group.addActor(button); + } + scrollPane = new ScrollPane(group); + scrollPane.setHeight(Math.min(getHeight(), group.getPrefHeight())); + scrollPane.setWidth(group.getPrefWidth()); + scrollPane.setPosition((getWidth()-scrollPane.getWidth())/2f, (getHeight()-scrollPane.getHeight())/2f); + scrollPane.setTouchable(Touchable.childrenOnly); + addActor(scrollPane); + addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + if (hit(x, y, true) == event.getListenerActor()) { + simpleDebug("unchecking selected key change buttons."); + buttonOptions.uncheckAll(); + } + super.clicked(event, x, y); + } + }); + } + + @Override + public void setCameraPositionToPage(Vector3 cameraPosition) { + getStage().setScrollFocus(scrollPane); + super.setCameraPositionToPage(cameraPosition); + } + + @Override + public void dispose() { + save(); + super.dispose(); + } + public void save() { + keyBindPrefs.flush(); + } + + public class KeyChangeButton extends Button { + private Image keyImage; + private Label nameLabel; + private Controls control; + private boolean error; + + public KeyChangeButton(Controls control) { + super(skin, "selectable-clean-button"); + this.control = control; + nameLabel = new Label(control.toString(), skin); + keyImage = new Image(getIcon(control.getKeycode())); + + add(nameLabel).expandX().left().spaceRight(20f); + add(keyImage).expandX().right(); + + addListener(inputListener); + addListener(checkedListener); + } + + public void attemptSetKeycode(int keycode) { + simpleDebug("Attempting to set keycode to " + keycode); + TextureRegion textureRegion = getIcon(keycode); + if (textureRegion != null) { + setKeycode(keycode, textureRegion); + error = false; + } else { + error = true; + } + setChecked(false); + } + + public void setKeycode(int keycode, TextureRegion texture) { + + Controls conflict = control.setKeycode(keycode); + if (conflict != null) { + Array buttons = buttonOptions.getButtons(); + for (int i = 0; i < buttons.size; i++) { + System.out.println(buttons.get(i).getControl()); + if (buttons.get(i).getControl() == conflict) { + KeyChangeButton b = buttons.get(i); + scrollPane.scrollTo(b.getX(), b.getY(), b.getWidth(), b.getHeight()); + b.done(true); + return; + } + } + } + TextureRegion textureRegion = getIcon(keycode); + if (textureRegion != null) { + keyImage.setDrawable(new TextureRegionDrawable(texture)); + control.saveKeyToPreferences(keyBindPrefs); + } + } + + public void ready() { + getStage().setKeyboardFocus(this); + keyImage.setColor(Color.ORANGE); + } + + public void done() { + done(error); + } + + public void done(boolean error) { + if (error) { + keyImage.addAction(Actions.repeat(3, Actions.sequence(Actions.color(Color.RED, 0.2f), Actions.color(Color.WHITE, 0.1f)))); + } else { + keyImage.addAction(Actions.color(Color.WHITE, 0.2f)); + } + } + + public Controls getControl() { + return control; + } + } + + public TextureRegion getIcon(int keycode) { + switch (keycode) { + case Keys.ALT_LEFT: + case Keys.ALT_RIGHT: + return keyTextures.findRegion("Keyboard_Black_Alt"); + case Keys.SHIFT_LEFT: + case Keys.SHIFT_RIGHT: + return keyTextures.findRegion("Keyboard_Black_Shift"); + case Keys.LEFT_BRACKET: + return keyTextures.findRegion("Keyboard_Black_Bracket_Left"); + case Keys.RIGHT_BRACKET: + return keyTextures.findRegion("Keyboard_Black_Bracket_Right"); + case Keys.SEMICOLON: + return keyTextures.findRegion("Keyboard_Black_Semicolon"); + case Keys.SLASH: + return keyTextures.findRegion("Keyboard_Black_Slash"); + case Keys.NUM: + return keyTextures.findRegion("Keyboard_Black_Num_Lock"); + case Keys.ESCAPE: + return null; + default: + return keyTextures.findRegion("Keyboard_Black_" + Keys.toString(keycode).replace(' ', '_')); + } } } diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java index 48858a5..a84a989 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MainScreen.java @@ -1,7 +1,6 @@ package zero1hd.rhythmbullet.desktop.screens.main; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; @@ -9,11 +8,8 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.InputEvent; -import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.viewport.ScreenViewport; import zero1hd.rhythmbullet.RhythmBullet; @@ -139,28 +135,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { analysisPage = new AnalysisPage(rhythmBullet.getSkin(), listeners.returnToMainPageListener, listeners.confirmedSongListener); stage.addActor(analysisPage); - - - stage.addListener(new InputListener() { - @Override - public boolean keyUp(InputEvent event, int keycode) { - if (keycode == Keys.ESCAPE) { - stage.unfocusAll(); - } - return super.keyUp(event, keycode); - } - }); - - stage.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - if (stage.hit(x, y, true) == null) { - stage.unfocusAll(); - } - super.clicked(event, x, y); - } - }); - musicController.getMusicList().asyncSearch(false); resizing = false; } @@ -221,7 +195,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen { @Override public void changed(ChangeEvent event, Actor actor) { setDisplayedPage(musicSelectionPage); - stage.setKeyboardFocus(musicSelectionPage); } }; diff --git a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java index 66ef7cb..02be40d 100755 --- a/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java +++ b/desktop/src/zero1hd/rhythmbullet/desktop/screens/main/MusicSelectionPage.java @@ -26,8 +26,6 @@ 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; @@ -57,6 +55,8 @@ public class MusicSelectionPage extends Page implements Observer { private boolean down, up; + private boolean frameUsed; + private TextButton beginButton; private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer; @@ -77,6 +77,7 @@ public class MusicSelectionPage extends Page implements Observer { scrollPane.setSize(0.45f*getWidth(), getHeight()); scrollPane.setOverscroll(false, false); scrollPane.setClamp(true); + scrollPane.setSmoothScrolling(false); scrollPane.setColor(Color.BLUE); addActor(scrollPane); back = new TextButton("Back", skin); @@ -121,11 +122,18 @@ public class MusicSelectionPage extends Page implements Observer { mmc.addObserver(this); mc.addObserver(this); + mc.getMusicList().addObserver(this); selectionLoaderThread = new musicSelectionLoaderThread(); } @Override public void act(float delta) { + + if (frameUsed) { + frameUsed = false; + simpleDebug("New frame."); + } + if (down) { if (scrollDelMod > 0.25f) { scrollDelMod -= delta/0.5f; @@ -210,24 +218,31 @@ public class MusicSelectionPage extends Page implements Observer { @Override public void dispose() { + mc.getMusicList().deleteObserver(this); super.dispose(); } @Override public void update(Observable o, Object arg) { if (o == mmc) { - musicInfoTable.setToDefault(); selectionLoaderThread.start(); } else if (o == mc) { if (mc.getMusicList().getTotal() == selectables.size() && mc.getCurrentMusicFileHandle() != selectables.getChecked().getMetadata().getFileHandle()) { selectables.setChecked(mc.getCurrentMusicFileHandle()); } + } else if (o == mc.getMusicList()) { + if (arg == mc.getMusicList().states.LOADING) { + vGroup.clear(); + selectables.clear(); + musicInfoTable.setToDefault(); + } } } @Override public void setCameraPositionToPage(Vector3 cameraPosition) { getStage().setKeyboardFocus(this); + getStage().setScrollFocus(scrollPane); super.setCameraPositionToPage(cameraPosition); } @@ -244,22 +259,14 @@ public class MusicSelectionPage extends Page implements Observer { @Override public void run() { while (work) { - if (selectables.size() != mmc.size()) { - selectables.clear(); - for (int mid = 0; mid < mmc.size(); mid++) { - - } - selectables.uncheckAll(); - } else { + while (queueList.size != 0) { + AudioMetadata metadata; synchronized (this) { - while (queueList.size != 0) { - AudioMetadata metadata = queueList.pop(); - metadata.loadAlbumCover(); - } + metadata = queueList.pop(); + metadata.loadAlbumCover(); + simpleDebug("Loading " + metadata.getTitle()); } - } - synchronized (this) { try { wait(); @@ -283,10 +290,10 @@ public class MusicSelectionPage extends Page implements Observer { return false; } - public synchronized void queue(AudioMetadata metadata) { + public void queue(AudioMetadata metadata) { if (!queueList.contains(metadata, true)) { queueList.add(metadata); - notify(); + start(); } } @@ -298,14 +305,15 @@ public class MusicSelectionPage extends Page implements Observer { private Table informationTable; private Label name, artist; private Label time; - private float timeSinceOnScreen; + private boolean offScreen; + private float timeSinceChanged; private AudioMetadata metadata; private Texture defaultAlbumArt; private TextureRegion albumArtTexture; - private boolean albumArtUsed, albumArtAttempted; + private boolean albumArtDisplayed, albumArtAttempted; public MusicSelectable(AudioMetadata metadata) { - super(skin, "music-selectable"); + super(skin, "selectable-button"); this.metadata = metadata; this.defaultAlbumArt = assets.get("defaultCover.png"); @@ -314,7 +322,6 @@ public class MusicSelectionPage extends Page implements Observer { 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")); @@ -349,19 +356,25 @@ public class MusicSelectionPage extends Page implements Observer { @Override public void draw(Batch batch, float parentAlpha) { - synchronized (albumCoverImage) { - super.draw(batch, parentAlpha); - } + 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; + if (offScreen) { + offScreen = false; + timeSinceChanged = 0; + } else if (timeSinceChanged < 0.75f) { + timeSinceChanged += delta; + } + if (timeSinceChanged >= 0.75f) { + if (!frameUsed && metadata.getAlbumCover() != null && !albumArtDisplayed) { + updateAlbumArtImage(metadata.getAlbumCover()); + albumArtDisplayed = true; + frameUsed = true; + } else if (!albumArtAttempted) { + selectionLoaderThread.queue(metadata); + albumArtAttempted = true; + } } } @@ -372,17 +385,21 @@ public class MusicSelectionPage extends Page implements Observer { } public void offScreenAct(float delta) { + if (!offScreen) { + offScreen = true; + timeSinceChanged = 0; + } if (metadata.getAlbumCover() != null) { - timeSinceOnScreen += delta; - if (timeSinceOnScreen >= 2) { + timeSinceChanged += delta; + if (timeSinceChanged >= 2) { updateAlbumArtImage(defaultAlbumArt); metadata.unloadAlbumCover(); - albumArtUsed = false; + albumArtDisplayed = false; albumArtAttempted = false; } } } - + public AudioMetadata getMetadata() { return metadata; } @@ -446,6 +463,7 @@ public class MusicSelectionPage extends Page implements Observer { protected boolean canCheck(MusicSelectable button, boolean newState) { if (newState) { musicInfoTable.setDisplayedSelectable(button); + musicSelectDelay = 0f; } return super.canCheck(button, newState); } @@ -464,7 +482,6 @@ public class MusicSelectionPage extends Page implements Observer { private Image albumCover; private Table subInformation; - private MusicSelectable displayedSelectable; public InformationTable(float width, float height) { defaults().center(); @@ -481,7 +498,6 @@ public class MusicSelectionPage extends Page implements Observer { } public void setDisplayedSelectable(MusicSelectable displayedSelectable) { - this.displayedSelectable = displayedSelectable; if (displayedSelectable != null) { AudioMetadata metadata = displayedSelectable.getMetadata(); albumCover.setDrawable(new TextureRegionDrawable(displayedSelectable.getAlbumArtTexture())); @@ -502,6 +518,7 @@ public class MusicSelectionPage extends Page implements Observer { } public void setToDefault() { + clear(); subInformation.clear();