112 lines
2.8 KiB
Java
Executable File
112 lines
2.8 KiB
Java
Executable File
package zero1hd.rhythmbullet.screens;
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.ScreenAdapter;
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
import com.badlogic.gdx.math.Vector3;
|
|
import com.badlogic.gdx.scenes.scene2d.Stage;
|
|
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
|
|
|
import zero1hd.rhythmbullet.RhythmBullet;
|
|
import zero1hd.rhythmbullet.audio.Audio;
|
|
import zero1hd.rhythmbullet.ui.pages.AnalyzePage;
|
|
import zero1hd.rhythmbullet.ui.pages.MusicSelectionPage;
|
|
import zero1hd.rhythmbullet.util.MiniEvents;
|
|
import zero1hd.rhythmbullet.util.MiniListener;
|
|
import zero1hd.rhythmbullet.util.TransitionAdapter;
|
|
|
|
|
|
public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, MiniListener {
|
|
Stage stage;
|
|
|
|
MusicSelectionPage ms;
|
|
public AnalyzePage ap;
|
|
private Vector3 cameraPos;
|
|
private RhythmBullet core;
|
|
|
|
public PreGameScreen(RhythmBullet core) {
|
|
stage = new Stage(new ScreenViewport());
|
|
cameraPos = new Vector3(stage.getCamera().position);
|
|
this.core = core;
|
|
postTransition();
|
|
}
|
|
|
|
@Override
|
|
public void render(float delta) {
|
|
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
|
|
stage.getViewport().apply();
|
|
try {
|
|
stage.act();
|
|
stage.draw();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (stage.getCamera().position.x != cameraPos.x) {
|
|
stage.getCamera().position.lerp(cameraPos, 0.25f);
|
|
}
|
|
super.render(delta);
|
|
}
|
|
|
|
@Override
|
|
public void resize(int width, int height) {
|
|
stage.getViewport().update(width, height);
|
|
super.resize(width, height);
|
|
}
|
|
|
|
@Override
|
|
public void handle(MiniEvents ID) {
|
|
switch (ID) {
|
|
case MUSIC_SELECTED:
|
|
cameraPos.x = 1.5f*Gdx.graphics.getWidth();
|
|
ap.setSong(Audio.getAudioData(ms.getSelectedMusic()), ms.getSelectedMusicInfo(), this);
|
|
break;
|
|
case BACK:
|
|
if (cameraPos.x == 1.5f*Gdx.graphics.getWidth()) {
|
|
cameraPos.x = 0.5f*Gdx.graphics.getWidth();
|
|
} else {
|
|
core.setScreen(new MainMenu(core));
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void preTransition() {
|
|
stage.clear();
|
|
}
|
|
|
|
@Override
|
|
public void postTransition() {
|
|
ms = new MusicSelectionPage(core);
|
|
ms.miniSender.addListener(this);
|
|
ms.beginMusicSearch();
|
|
stage.addActor(ms);
|
|
|
|
ap = new AnalyzePage(core);
|
|
ap.miniSender.addListener(this);
|
|
ap.setPosition(Gdx.graphics.getWidth(), ap.getY());
|
|
stage.addActor(ap);
|
|
}
|
|
|
|
public void setPhase(int phase) {
|
|
cameraPos.x = Gdx.graphics.getWidth()*(phase + 0.5f);
|
|
}
|
|
|
|
@Override
|
|
public void show() {
|
|
Gdx.input.setInputProcessor(stage);
|
|
super.show();
|
|
}
|
|
|
|
@Override
|
|
public void dispose() {
|
|
stage.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|