began integrating mini events into main music selection system
This commit is contained in:
parent
14cd210024
commit
59db9c3671
@ -11,22 +11,21 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
import zero1hd.polyjet.audio.Audio;
|
||||
import zero1hd.polyjet.audio.WavAudioData;
|
||||
import zero1hd.polyjet.controls.RhythmMap;
|
||||
import zero1hd.polyjet.ui.pages.AnalyzePage;
|
||||
import zero1hd.polyjet.ui.pages.MusicSelectionPage;
|
||||
import zero1hd.polyjet.util.MiniEvents;
|
||||
import zero1hd.polyjet.util.MiniListener;
|
||||
import zero1hd.polyjet.util.TransitionAdapter;
|
||||
|
||||
|
||||
public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, MiniListener {
|
||||
Polyjet core;
|
||||
Stage stage;
|
||||
Label statusText;
|
||||
|
||||
AudioAnalyzer analyzer;
|
||||
WavAudioData audiofile;
|
||||
RhythmMap rhythmMap;
|
||||
Vector3 cameraTarget;
|
||||
|
||||
Label lastStatement;
|
||||
@ -36,8 +35,6 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
private AnalyzePage analyzePage;
|
||||
public PreGameScreen(final Polyjet core, MainMenu mainMenu) {
|
||||
this.core = core;
|
||||
analyzer = new AudioAnalyzer();
|
||||
rhythmMap = new RhythmMap(analyzer);
|
||||
|
||||
this.mainMenu = mainMenu;
|
||||
|
||||
@ -64,7 +61,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
stage.addActor(analyzePage);
|
||||
|
||||
//draw music selector
|
||||
musicSelection = new MusicSelectionPage(core, mainMenu, analyzePage);
|
||||
musicSelection = new MusicSelectionPage(core, mainMenu);
|
||||
musicSelection.addListener(this);
|
||||
stage.addActor(musicSelection);
|
||||
musicSelection.beginMusicSearch();
|
||||
|
||||
@ -91,7 +89,6 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
analyzer.resetVars();
|
||||
super.show();
|
||||
}
|
||||
|
||||
@ -106,4 +103,13 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
stage.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MiniEvents ID) {
|
||||
switch (ID) {
|
||||
case MUSIC_SELECTED:
|
||||
analyzePage.setSong(Audio.getAudioData(musicSelection.getSelectedMusic()), musicSelection.getSelectedMusicInfo());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,4 +91,8 @@ public class AnalyzePage extends Page {
|
||||
public void clearAudioData() {
|
||||
music = null;
|
||||
}
|
||||
|
||||
public AudioAnalyzer getAudioAnalyzer() {
|
||||
return audioAnalyzer;
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,17 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
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 com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.Audio;
|
||||
import zero1hd.polyjet.audio.AudioInfo;
|
||||
import zero1hd.polyjet.screens.MainMenu;
|
||||
import zero1hd.polyjet.ui.builders.MusicSelectable;
|
||||
import zero1hd.polyjet.ui.windows.LoadingWindow;
|
||||
import zero1hd.polyjet.ui.windows.NoticeWindow;
|
||||
import zero1hd.polyjet.util.MiniEvents;
|
||||
import zero1hd.polyjet.util.MiniListener;
|
||||
|
||||
public class MusicSelectionPage extends Page {
|
||||
private volatile Table musicChoices;
|
||||
@ -32,15 +36,15 @@ public class MusicSelectionPage extends Page {
|
||||
protected volatile boolean cancel;
|
||||
private TextButton back;
|
||||
|
||||
private AnalyzePage ap;
|
||||
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu, AnalyzePage analyzePage) {
|
||||
private FileHandle selectedMusic;
|
||||
private AudioInfo selectedMusicInfo;
|
||||
|
||||
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) {
|
||||
super("Select music", core.getDefaultSkin());
|
||||
this.core = core;
|
||||
|
||||
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
||||
|
||||
this.ap = analyzePage;
|
||||
|
||||
back = new TextButton("Back", core.getDefaultSkin());
|
||||
back.setPosition(getWidth()-back.getWidth()-15f, getHeightBelowTitle());
|
||||
back.addListener(new ChangeListener() {
|
||||
@ -110,7 +114,9 @@ public class MusicSelectionPage extends Page {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
|
||||
if (!selectable.isMusicInvalid()) {
|
||||
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getAudioInfo());
|
||||
selectedMusic = selectable.getMusicFile();
|
||||
selectedMusicInfo = selectable.getAudioInfo();
|
||||
send(MiniEvents.MUSIC_SELECTED);
|
||||
} else {
|
||||
//Play "no" sound
|
||||
}
|
||||
@ -143,4 +149,12 @@ public class MusicSelectionPage extends Page {
|
||||
public float panelWidthCalc(float origWidth) {
|
||||
return (float) (Math.sqrt(getWidth()*35f)+80f);
|
||||
}
|
||||
|
||||
public FileHandle getSelectedMusic() {
|
||||
return selectedMusic;
|
||||
}
|
||||
|
||||
public AudioInfo getSelectedMusicInfo() {
|
||||
return selectedMusicInfo;
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,16 @@ import com.badlogic.gdx.scenes.scene2d.Group;
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.polyjet.util.MiniEvents;
|
||||
import zero1hd.polyjet.util.MiniListener;
|
||||
|
||||
public class Page extends Group {
|
||||
private Label pageTitle;
|
||||
|
||||
private Array<MiniListener> listeners;
|
||||
|
||||
public Page() {
|
||||
setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
setTouchable(Touchable.childrenOnly);
|
||||
@ -25,4 +31,14 @@ public class Page extends Group {
|
||||
public float getHeightBelowTitle() {
|
||||
return pageTitle.getY();
|
||||
}
|
||||
|
||||
public void send(MiniEvents ID) {
|
||||
while (listeners.iterator().hasNext()) {
|
||||
listeners.iterator().next().handle(ID);
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(MiniListener handler) {
|
||||
listeners.add(handler);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user