began deprecating custom events, switching to java observer event system; progress on music selection page
This commit is contained in:
parent
2294b0f9f8
commit
9c2fa0f04b
@ -1,10 +1,12 @@
|
||||
package zero1hd.rhythmbullet.audio;
|
||||
|
||||
import java.util.Observable;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class SongList {
|
||||
public class SongList extends Observable {
|
||||
private Array<FileHandle> songList;
|
||||
private String searchPath;
|
||||
private boolean searched;
|
||||
@ -24,10 +26,15 @@ public class SongList {
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
public void setSearchPath(String searchPath) {
|
||||
this.searchPath = searchPath;
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
public MusicManager getAudioData(FileHandle file) {
|
||||
|
@ -1,17 +1,15 @@
|
||||
package zero1hd.rhythmbullet.audio;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Observable;
|
||||
import java.util.Random;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.audio.Music.OnCompletionListener;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.rhythmbullet.events.OnDifferentSongListener;
|
||||
|
||||
public class SongListController implements OnCompletionListener {
|
||||
public class SongListController extends Observable implements OnCompletionListener {
|
||||
private SongList songList;
|
||||
private MusicManager mdp;
|
||||
private int currentPlaybackID;
|
||||
@ -19,8 +17,6 @@ public class SongListController implements OnCompletionListener {
|
||||
private boolean shuffle;
|
||||
private Random rand;
|
||||
|
||||
private Array<OnDifferentSongListener> listeners;
|
||||
|
||||
private Preferences prefs;
|
||||
public SongListController(SongList songList, Preferences prefs) {
|
||||
if (prefs == null) throw new NullPointerException("preferences can't be null...");
|
||||
@ -28,7 +24,6 @@ public class SongListController implements OnCompletionListener {
|
||||
if (!songList.isSearched()) throw new InvalidParameterException("Song list has to be searched already.");
|
||||
|
||||
this.prefs = prefs;
|
||||
listeners = new Array<>();
|
||||
this.songList = songList;
|
||||
rand = new Random();
|
||||
changeSong();
|
||||
@ -126,26 +121,15 @@ public class SongListController implements OnCompletionListener {
|
||||
mdp = songList.getAudioData(Gdx.files.external("RhythmBullet/Alan Walker - Spectre.mp3"));
|
||||
}
|
||||
mdp.setOnCompletionListener(this);
|
||||
sendEvent();
|
||||
|
||||
setChanged();
|
||||
notifyObservers(mdp);
|
||||
}
|
||||
|
||||
public SongList getSongList() {
|
||||
return songList;
|
||||
}
|
||||
|
||||
private void sendEvent() {
|
||||
for (int i = 0; i < listeners.size; i++) {
|
||||
listeners.get(i).onDifferentSong(mdp);
|
||||
}
|
||||
}
|
||||
|
||||
public void addOnDifferentSongListener(OnDifferentSongListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(OnDifferentSongListener listener) {
|
||||
listeners.removeValue(listener, true);
|
||||
}
|
||||
|
||||
public MusicManager getCurrentSong() {
|
||||
return mdp;
|
||||
|
@ -1,12 +0,0 @@
|
||||
package zero1hd.rhythmbullet.events;
|
||||
|
||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||
|
||||
public interface OnDifferentSongListener {
|
||||
|
||||
/**
|
||||
* Called whenever the Song Controller moves to a different song.
|
||||
* @param mdp contains the next songs basic music system.
|
||||
*/
|
||||
public void onDifferentSong(MusicManager mdp);
|
||||
}
|
@ -46,10 +46,10 @@ public class MusicSelectable extends Widget implements Disposable {
|
||||
|
||||
table.row();
|
||||
|
||||
durationLabel = new Label("Loading...", skin, "sub-font");
|
||||
durationLabel = new Label("Loading...", skin, "sub-font", skin.getColor("default"));
|
||||
table.add(durationLabel);
|
||||
|
||||
authorLabel = new Label("Loading...", skin, "sub-font");
|
||||
authorLabel = new Label("Loading...", skin, "sub-font", skin.getColor("default"));
|
||||
|
||||
table.defaults().pad(10f);
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package zero1hd.rhythmbullet.graphics.ui.pages;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
@ -14,12 +17,11 @@ import com.badlogic.gdx.utils.Align;
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||
import zero1hd.rhythmbullet.audio.SongListController;
|
||||
import zero1hd.rhythmbullet.events.OnDifferentSongListener;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicControls;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.TitleBarVisualizer;
|
||||
|
||||
public class MainPage extends Page implements OnDifferentSongListener {
|
||||
public class MainPage extends Page implements Observer {
|
||||
private Label versionLabel;
|
||||
|
||||
private SongListController sc;
|
||||
@ -38,7 +40,6 @@ public class MainPage extends Page implements OnDifferentSongListener {
|
||||
|
||||
titleBar = new TitleBarVisualizer(core.getAssetManager());
|
||||
addActor(titleBar);
|
||||
sc.addOnDifferentSongListener(this);
|
||||
|
||||
versionLabel = new Label("Version: " + RhythmBullet.VERSION, core.getDefaultSkin(), "sub-font",
|
||||
core.getDefaultSkin().getColor("default"));
|
||||
@ -99,7 +100,6 @@ public class MainPage extends Page implements OnDifferentSongListener {
|
||||
scrollText.invalidate();
|
||||
addActor(scrollText);
|
||||
|
||||
onDifferentSong(sc.getCurrentSong());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,14 +112,21 @@ public class MainPage extends Page implements OnDifferentSongListener {
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDifferentSong(MusicManager mdp) {
|
||||
titleBar.getHvisual().setMM(mdp);
|
||||
scrollText.setText(mdp.getBasicSongName(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o == sc) {
|
||||
MusicManager mm = (MusicManager) arg;
|
||||
updateVisualsForDifferentSong(mm);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateVisualsForDifferentSong(MusicManager mm) {
|
||||
titleBar.getHvisual().setMM(mm);
|
||||
scrollText.setText(mm.getBasicSongName(), null);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
@ -19,7 +20,6 @@ import com.badlogic.gdx.utils.Array;
|
||||
import zero1hd.rhythmbullet.audio.SongInfo;
|
||||
import zero1hd.rhythmbullet.audio.SongList;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
|
||||
import zero1hd.rhythmbullet.util.MiniEvents;
|
||||
|
||||
public class MusicSelectionPage extends Page {
|
||||
Preferences musicFileAnnotation;
|
||||
@ -35,7 +35,7 @@ public class MusicSelectionPage extends Page {
|
||||
|
||||
private Skin skin;
|
||||
private AssetManager assets;
|
||||
public MusicSelectionPage(Skin skin, SongList songList, AssetManager assetManager) {
|
||||
public MusicSelectionPage(Skin skin, SongList songList, AssetManager assetManager, Vector3 cameraTarget) {
|
||||
super("Select music", skin);
|
||||
this.songList = songList;
|
||||
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
||||
@ -51,12 +51,13 @@ public class MusicSelectionPage extends Page {
|
||||
back.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
miniSender.send(MiniEvents.BACK);
|
||||
cameraTarget.x = 0.5f*Gdx.graphics.getWidth();
|
||||
}
|
||||
});
|
||||
addActor(back);
|
||||
|
||||
back.toFront();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,12 +74,14 @@ public class MusicSelectionPage extends Page {
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
Gdx.app.debug("MusicSelectionPage", "Refreshing...");
|
||||
for (int i = 0; i < songList.getAmountOfSongs(); i++) {
|
||||
MusicSelectable selectable = new MusicSelectable(songList.getSongFileHandleFromIndex(i), musicFileAnnotation, skin, assets.get("defaultCover.png", Texture.class));
|
||||
selectables.add(selectable);
|
||||
songTable.add(selectable);
|
||||
songTable.row();
|
||||
}
|
||||
songTable.pack();
|
||||
|
||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||
exec.submit(() -> {
|
||||
@ -90,6 +93,7 @@ public class MusicSelectionPage extends Page {
|
||||
info.updateInfo();
|
||||
});
|
||||
}
|
||||
Gdx.app.debug("MusicSelectionPage", "Refresh complete.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package zero1hd.rhythmbullet.screens;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
@ -29,7 +32,7 @@ import zero1hd.rhythmbullet.graphics.ui.pages.OptionsPage;
|
||||
import zero1hd.rhythmbullet.graphics.ui.pages.VideoOptionsPage;
|
||||
import zero1hd.rhythmbullet.util.TransitionAdapter;
|
||||
|
||||
public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
public class MainMenu extends ScreenAdapter implements TransitionAdapter, Observer {
|
||||
public Stage stage;
|
||||
private Vector3 cameraPosition;
|
||||
|
||||
@ -65,7 +68,6 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
SongList songList = new SongList();
|
||||
songList.setSearchPath(core.getPrefs().getString("music dir"));
|
||||
songList.refresh();
|
||||
|
||||
sc = new SongListController(songList, core.getPrefs());
|
||||
sc.setAutoPlay(true);
|
||||
sc.setShuffle(true);
|
||||
@ -100,8 +102,8 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
creditsPage.setPosition(0, Gdx.graphics.getHeight());
|
||||
stage.addActor(creditsPage);
|
||||
|
||||
musicSelectionPage = new MusicSelectionPage(core.getDefaultSkin(), sc.getSongList(), core.getAssetManager());
|
||||
musicSelectionPage.setPosition(1.5f*Gdx.graphics.getWidth(), 0f);
|
||||
musicSelectionPage = new MusicSelectionPage(core.getDefaultSkin(), sc.getSongList(), core.getAssetManager(), cameraPosition);
|
||||
musicSelectionPage.setPosition(1f*Gdx.graphics.getWidth(), 0f);
|
||||
stage.addActor(musicSelectionPage);
|
||||
|
||||
stage.addListener(new InputListener() {
|
||||
@ -129,6 +131,12 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
sc.deleteObservers();
|
||||
sc.addObserver(mainPage);
|
||||
mainPage.updateVisualsForDifferentSong(sc.getCurrentSong());
|
||||
|
||||
sc.getSongList().addObserver(this);
|
||||
sc.getSongList().refresh();
|
||||
|
||||
Gdx.app.debug("Post Transition", "Beginning screen setup for Main menu.");
|
||||
}
|
||||
@ -355,4 +363,11 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
||||
public Vector3 getCameraPosition() {
|
||||
return cameraPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o == sc.getSongList()) {
|
||||
musicSelectionPage.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
|
||||
|
||||
@Override
|
||||
public void postTransition() {
|
||||
ms = new MusicSelectionPage(core.getDefaultSkin(), songList, core.getAssetManager());
|
||||
ms = new MusicSelectionPage(core.getDefaultSkin(), songList, core.getAssetManager(), cameraPos);
|
||||
ms.miniSender.addListener(this);
|
||||
stage.addActor(ms);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
@Deprecated
|
||||
public enum MiniEvents {
|
||||
SPECTRAL_FLUX_DONE, MUSIC_DATA_CLEANED, MUSIC_SELECTED, BACK, MAP_GENERATED, ANALYZER_ITERATED, MAPGEN_ITERATED;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
@Deprecated
|
||||
public interface MiniListener {
|
||||
public void handle(MiniEvents ID);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package zero1hd.rhythmbullet.util;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
@Deprecated
|
||||
public class MiniSender {
|
||||
private volatile Array<MiniListener> listeners;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user