diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 6954da1..2d0c5bc 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -137,6 +137,10 @@ public class GameScreen extends BaseScreen implements InputProcessor { gameCam.zoom -= dt; } + // Pause Menu + if (Gdx.input.isKeyPressed( Keys.ESCAPE)) { + SagittariusGame.setActiveScreen( new ResumeScreen(this) ); + } // clamp zoom gameCam.zoom = MathUtils.clamp(gameCam.zoom, 1f, 3f); diff --git a/core/src/sagittarius/view/ResumeScreen.java b/core/src/sagittarius/view/ResumeScreen.java new file mode 100644 index 0000000..8cb0606 --- /dev/null +++ b/core/src/sagittarius/view/ResumeScreen.java @@ -0,0 +1,121 @@ +package sagittarius.view; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener; +import com.badlogic.gdx.utils.Align; +import com.kotcrab.vis.ui.VisUI; +import com.kotcrab.vis.ui.widget.VisCheckBox; +import com.kotcrab.vis.ui.widget.VisTable; +import com.kotcrab.vis.ui.widget.VisTextButton; +import com.kotcrab.vis.ui.widget.spinner.SimpleFloatSpinnerModel; +import com.kotcrab.vis.ui.widget.spinner.Spinner; + +import sagittarius.SagittariusGame; + +public class ResumeScreen extends BaseScreen { + + private GameScreen gameScreen; + + public ResumeScreen (GameScreen gameScreen){ + this.gameScreen = gameScreen; + } + + @Override + public void initialize() { + + SagittariusGame.music.stop(); + SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Metre - Concentric.mp3")); + SagittariusGame.music.setLooping(true); + SagittariusGame.music.play(); + + Gdx.input.setInputProcessor(uiStage); + + // Table creation + VisTable table = new VisTable(true); + table.setFillParent(true); + uiStage.addActor(table); + + // disable music checkbox + VisCheckBox disableMusic = new VisCheckBox("disable music"); + disableMusic.setChecked(SagittariusGame.disableMusic); + + // Change volume of the music + Spinner musicVolume= new Spinner("Music Volume:", new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3)); + + // disable sound checkbox + VisCheckBox disableSounds= new VisCheckBox("disable sounds"); + disableSounds.setChecked(SagittariusGame.disableSounds); + + // Change volume of the sound + Spinner musicSounds= new Spinner("Sounds Volume:", new SimpleFloatSpinnerModel(SagittariusGame.soundsVolume, 0f, 1.0f, 0.01f, 3)); + + // save button + VisTextButton applyButton = new VisTextButton("Apply"); + applyButton.addListener(new ActorGestureListener() { + @Override + public void tap(InputEvent event, float x, float y, int count, int button) { + super.tap(event, x, y, count, button); + + SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText())); + SagittariusGame.soundsVolume = Float.parseFloat(musicVolume.getTextField().getText()); + + // Deactivate music or not + if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()){ + SagittariusGame.music.stop(); + } + + else if (!disableMusic.isChecked() && ! SagittariusGame.music.isPlaying()){ + SagittariusGame.music.play(); + } + + } + }); + + // Resume button + VisTextButton resumeButton = new VisTextButton("Resume"); + resumeButton.addListener(new ActorGestureListener() { + @Override + public void tap(InputEvent event, float x, float y, int count, int button) { + super.tap(event, x, y, count, button); + SagittariusGame.setActiveScreen( gameScreen ); + } + + }); + + // go back to main menu + VisTextButton returnMain = new VisTextButton("Main Menu"); + returnMain.addListener(new ActorGestureListener() { + @Override + public void tap(InputEvent event, float x, float y, int count, int button) { + super.tap(event, x, y, count, button); + SagittariusGame.setActiveScreen( new StartScreen() ); + } + }); + + // Table structure + table.add(resumeButton).width(250); + table.row(); + table.add(disableMusic).width(250); + table.row(); + table.add(musicVolume).width(250); + table.row(); + table.add(disableSounds).width(250); + table.row(); + table.add(musicSounds).width(250); + table.row(); + table.add(applyButton).width(250); + table.row(); + table.add(returnMain).width(250); + } + + @Override + public void update(float dt) {} + + @Override + public void dispose() { + VisUI.dispose(); + super.dispose(); + } + +} \ No newline at end of file