From 59db9c3671798a55f89365d72ffec56f15673606 Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 19 May 2017 00:53:58 -0500 Subject: [PATCH] began integrating mini events into main music selection system --- .../polyjet/screens/PreGameScreen.java | 24 ++++++++++++------- .../zero1hd/polyjet/ui/pages/AnalyzePage.java | 4 ++++ .../polyjet/ui/pages/MusicSelectionPage.java | 24 +++++++++++++++---- core/src/zero1hd/polyjet/ui/pages/Page.java | 16 +++++++++++++ 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/core/src/zero1hd/polyjet/screens/PreGameScreen.java b/core/src/zero1hd/polyjet/screens/PreGameScreen.java index ca94b35..631274f 100755 --- a/core/src/zero1hd/polyjet/screens/PreGameScreen.java +++ b/core/src/zero1hd/polyjet/screens/PreGameScreen.java @@ -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; + } + } } diff --git a/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java b/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java index b31beb3..a819666 100755 --- a/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java +++ b/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java @@ -91,4 +91,8 @@ public class AnalyzePage extends Page { public void clearAudioData() { music = null; } + + public AudioAnalyzer getAudioAnalyzer() { + return audioAnalyzer; + } } diff --git a/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java b/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java index 6313dfc..97c99c5 100755 --- a/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java +++ b/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java @@ -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; + } } diff --git a/core/src/zero1hd/polyjet/ui/pages/Page.java b/core/src/zero1hd/polyjet/ui/pages/Page.java index 6d87dad..410c238 100755 --- a/core/src/zero1hd/polyjet/ui/pages/Page.java +++ b/core/src/zero1hd/polyjet/ui/pages/Page.java @@ -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 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); + } }