Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed pause menu closing issue #275

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading