Skip to content

Commit

Permalink
fixed pause menu closing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Oct 16, 2023
1 parent 7b7af9e commit 7bfa5fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7bfa5fb

Please sign in to comment.