diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameDisplay.java index e4849623e..71887854d 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGameDisplay.java @@ -12,6 +12,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Array; import com.csse3200.game.GdxGame; +import com.csse3200.game.components.pausemenu.PauseMenuButtonComponent; +import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.PauseMenuFactory; import com.csse3200.game.screens.TowerType; import com.csse3200.game.services.ServiceLocator; @@ -52,6 +54,7 @@ public class MainGameDisplay extends UIComponent { private ImageButton tower4; private ImageButton tower5; private LevelProgressBar progressbar; + private Entity pauseMenu; /** * The constructor for the display @@ -150,17 +153,20 @@ public void changed(ChangeEvent changeEvent, Actor actor) { } }); + // Pause menu escape key opening listener stage.addListener( new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { if ((keycode == Input.Keys.ESCAPE) && !ServiceLocator.getTimeSource().getPaused()) { - game.getScreen().pause(); openSound.play(0.4f); - PauseMenuFactory.createPauseMenu(game); + pauseMenu = PauseMenuFactory.createPauseMenu(game); ServiceLocator.getTimeSource().setPaused(true); return true; + } else if ((keycode == Input.Keys.ESCAPE) && ServiceLocator.getTimeSource().getPaused()) { + pauseMenu.dispose(); + return false; } return false; } diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java index 15c0f839d..5f37a68ed 100644 --- a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java @@ -105,23 +105,23 @@ public void changed(ChangeEvent changeEvent, Actor actor) { } }); - window.addListener( - new InputListener() { - - @Override - public boolean keyUp (InputEvent event, int keycode) { - if (keycode == Input.Keys.ESCAPE && ServiceLocator.getTimeSource().getPaused()) { - logger.debug("Closing pause menu with escape key"); - click.play(0.5f); - closeSound.play(0.5f); - ServiceLocator.getTimeSource().setPaused(false); - entity.dispose(); - return true; - } - return false; - } - } - ); +// window.addListener( +// new InputListener() { +// +// @Override +// public boolean keyUp (InputEvent event, int keycode) { +// if (keycode == Input.Keys.ESCAPE && ServiceLocator.getTimeSource().getPaused()) { +// logger.debug("Closing pause menu with escape key"); +// click.play(0.5f); +// closeSound.play(0.5f); +// ServiceLocator.getTimeSource().setPaused(false); +// entity.dispose(); +// return true; +// } +// return false; +// } +// } +// ); // window.setKeepWithinStage(true); window.setResizable(true); @@ -168,6 +168,9 @@ public float getZIndex() { @Override public void dispose() { + click.play(0.5f); + closeSound.play(0.5f); + ServiceLocator.getTimeSource().setPaused(false); window.clear(); window.remove(); super.dispose();