From f345e1de8c8af64fb3947e8a93eb6f6085ee12da Mon Sep 17 00:00:00 2001 From: Recrown Date: Sat, 14 Oct 2017 16:56:07 -0500 Subject: [PATCH] forgot to add this important file... --- .../graphics/ui/components/MusicControls.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicControls.java diff --git a/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicControls.java b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicControls.java new file mode 100755 index 0000000..8b6a512 --- /dev/null +++ b/core/src/zero1hd/rhythmbullet/graphics/ui/components/MusicControls.java @@ -0,0 +1,105 @@ +package zero1hd.rhythmbullet.graphics.ui.components; + +import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.ui.CheckBox; +import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; +import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; + +import sun.security.provider.DSAPublicKeyImpl; +import zero1hd.rhythmbullet.audio.SongListController; + +public class MusicControls extends HorizontalGroup { + private SongListController sc; + private ImageButton reverse, forward; + private CheckBox shuffle, play; + private float disableTimer; + public MusicControls(Skin skin, SongListController sc) { + this.sc = sc; + + reverse = new ImageButton(skin, "rewind-button"); + reverse.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + boolean wasPlaying = sc.getCurrentSong().isPlaying(); + sc.previous(); + if (wasPlaying) { + sc.play(); + } + + forward.setDisabled(true); + reverse.setDisabled(true); + disableTimer = 0.75f; + } + }); + addActor(reverse); + + play = new CheckBox(null, skin, "play-button") { + @Override + public void act(float delta) { + play.setChecked(sc.getCurrentSong().isPlaying()); + super.act(delta); + } + }; + play.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + if (play.isChecked()) { + sc.getCurrentSong().play(); + } else { + sc.getCurrentSong().pause(); + } + } + }); + addActor(play); + + forward = new ImageButton(skin, "fast-forward-button"); + forward.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + boolean wasPlaying = sc.getCurrentSong().isPlaying(); + sc.skip(); + if (wasPlaying) { + sc.play(); + } + + forward.setDisabled(true); + reverse.setDisabled(true); + disableTimer = 0.75f; + } + }); + addActor(forward); + shuffle = new CheckBox(null, skin, "shuffle-button") { + @Override + public void act(float delta) { + shuffle.setChecked(sc.isShuffle()); + super.act(delta); + } + }; + shuffle.addListener(new ChangeListener() { + @Override + public void changed(ChangeEvent event, Actor actor) { + if (shuffle.isChecked()) { + sc.setShuffle(true); + } else { + sc.setShuffle(false); + } + } + }); + addActor(shuffle); + space(15); + } + + @Override + public void act(float delta) { + if (disableTimer > 0) { + disableTimer -= delta; + if (disableTimer <= 0) { + forward.setDisabled(false); + reverse.setDisabled(false); + } + } + super.act(delta); + } +}