began integrating mini events into main music selection system

This commit is contained in:
Harrison Deng 2017-05-19 00:53:58 -05:00
parent 14cd210024
commit 59db9c3671
4 changed files with 54 additions and 14 deletions

View File

@ -11,22 +11,21 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import zero1hd.polyjet.Polyjet; import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.audio.AudioAnalyzer; import zero1hd.polyjet.audio.Audio;
import zero1hd.polyjet.audio.WavAudioData; import zero1hd.polyjet.audio.WavAudioData;
import zero1hd.polyjet.controls.RhythmMap;
import zero1hd.polyjet.ui.pages.AnalyzePage; import zero1hd.polyjet.ui.pages.AnalyzePage;
import zero1hd.polyjet.ui.pages.MusicSelectionPage; import zero1hd.polyjet.ui.pages.MusicSelectionPage;
import zero1hd.polyjet.util.MiniEvents;
import zero1hd.polyjet.util.MiniListener;
import zero1hd.polyjet.util.TransitionAdapter; import zero1hd.polyjet.util.TransitionAdapter;
public class PreGameScreen extends ScreenAdapter implements TransitionAdapter { public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, MiniListener {
Polyjet core; Polyjet core;
Stage stage; Stage stage;
Label statusText; Label statusText;
AudioAnalyzer analyzer;
WavAudioData audiofile; WavAudioData audiofile;
RhythmMap rhythmMap;
Vector3 cameraTarget; Vector3 cameraTarget;
Label lastStatement; Label lastStatement;
@ -36,8 +35,6 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
private AnalyzePage analyzePage; private AnalyzePage analyzePage;
public PreGameScreen(final Polyjet core, MainMenu mainMenu) { public PreGameScreen(final Polyjet core, MainMenu mainMenu) {
this.core = core; this.core = core;
analyzer = new AudioAnalyzer();
rhythmMap = new RhythmMap(analyzer);
this.mainMenu = mainMenu; this.mainMenu = mainMenu;
@ -64,7 +61,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
stage.addActor(analyzePage); stage.addActor(analyzePage);
//draw music selector //draw music selector
musicSelection = new MusicSelectionPage(core, mainMenu, analyzePage); musicSelection = new MusicSelectionPage(core, mainMenu);
musicSelection.addListener(this);
stage.addActor(musicSelection); stage.addActor(musicSelection);
musicSelection.beginMusicSearch(); musicSelection.beginMusicSearch();
@ -91,7 +89,6 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
@Override @Override
public void show() { public void show() {
Gdx.input.setInputProcessor(stage); Gdx.input.setInputProcessor(stage);
analyzer.resetVars();
super.show(); super.show();
} }
@ -106,4 +103,13 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
stage.dispose(); stage.dispose();
super.dispose(); super.dispose();
} }
@Override
public void handle(MiniEvents ID) {
switch (ID) {
case MUSIC_SELECTED:
analyzePage.setSong(Audio.getAudioData(musicSelection.getSelectedMusic()), musicSelection.getSelectedMusicInfo());
break;
}
}
} }

View File

@ -91,4 +91,8 @@ public class AnalyzePage extends Page {
public void clearAudioData() { public void clearAudioData() {
music = null; music = null;
} }
public AudioAnalyzer getAudioAnalyzer() {
return audioAnalyzer;
}
} }

View File

@ -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.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array;
import zero1hd.polyjet.Polyjet; import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.audio.Audio; import zero1hd.polyjet.audio.Audio;
import zero1hd.polyjet.audio.AudioInfo;
import zero1hd.polyjet.screens.MainMenu; import zero1hd.polyjet.screens.MainMenu;
import zero1hd.polyjet.ui.builders.MusicSelectable; import zero1hd.polyjet.ui.builders.MusicSelectable;
import zero1hd.polyjet.ui.windows.LoadingWindow; import zero1hd.polyjet.ui.windows.LoadingWindow;
import zero1hd.polyjet.ui.windows.NoticeWindow; import zero1hd.polyjet.ui.windows.NoticeWindow;
import zero1hd.polyjet.util.MiniEvents;
import zero1hd.polyjet.util.MiniListener;
public class MusicSelectionPage extends Page { public class MusicSelectionPage extends Page {
private volatile Table musicChoices; private volatile Table musicChoices;
@ -32,15 +36,15 @@ public class MusicSelectionPage extends Page {
protected volatile boolean cancel; protected volatile boolean cancel;
private TextButton back; private TextButton back;
private AnalyzePage ap; private FileHandle selectedMusic;
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu, AnalyzePage analyzePage) { private AudioInfo selectedMusicInfo;
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) {
super("Select music", core.getDefaultSkin()); super("Select music", core.getDefaultSkin());
this.core = core; this.core = core;
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation"); musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
this.ap = analyzePage;
back = new TextButton("Back", core.getDefaultSkin()); back = new TextButton("Back", core.getDefaultSkin());
back.setPosition(getWidth()-back.getWidth()-15f, getHeightBelowTitle()); back.setPosition(getWidth()-back.getWidth()-15f, getHeightBelowTitle());
back.addListener(new ChangeListener() { back.addListener(new ChangeListener() {
@ -110,7 +114,9 @@ public class MusicSelectionPage extends Page {
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
if (!selectable.isMusicInvalid()) { if (!selectable.isMusicInvalid()) {
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getAudioInfo()); selectedMusic = selectable.getMusicFile();
selectedMusicInfo = selectable.getAudioInfo();
send(MiniEvents.MUSIC_SELECTED);
} else { } else {
//Play "no" sound //Play "no" sound
} }
@ -143,4 +149,12 @@ public class MusicSelectionPage extends Page {
public float panelWidthCalc(float origWidth) { public float panelWidthCalc(float origWidth) {
return (float) (Math.sqrt(getWidth()*35f)+80f); return (float) (Math.sqrt(getWidth()*35f)+80f);
} }
public FileHandle getSelectedMusic() {
return selectedMusic;
}
public AudioInfo getSelectedMusicInfo() {
return selectedMusicInfo;
}
} }

View File

@ -5,10 +5,16 @@ import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; 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 { public class Page extends Group {
private Label pageTitle; private Label pageTitle;
private Array<MiniListener> listeners;
public Page() { public Page() {
setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
setTouchable(Touchable.childrenOnly); setTouchable(Touchable.childrenOnly);
@ -25,4 +31,14 @@ public class Page extends Group {
public float getHeightBelowTitle() { public float getHeightBelowTitle() {
return pageTitle.getY(); 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);
}
} }