Skip to content

Commit

Permalink
Added screen change functionality to pause menu buttons. Noted some c…
Browse files Browse the repository at this point in the history
…rash issues re-entering the level.
  • Loading branch information
AlasdairS4698737 committed Sep 25, 2023
1 parent 29192a8 commit fb25a74
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.GdxGame;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.PauseMenuFactory;
import com.csse3200.game.ui.UIComponent;
Expand All @@ -19,6 +20,12 @@ public class MainGamePauseDisplay extends UIComponent {
private static final float Z_INDEX = 2f;
private Table table;

private GdxGame game;

public MainGamePauseDisplay(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
}

@Override
public void create() {
super.create();
Expand All @@ -38,7 +45,7 @@ private void addActors() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Pause button clicked");
PauseMenuFactory.createPauseMenu();
PauseMenuFactory.createPauseMenu(game);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.csse3200.game.components.pausemenu;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.GdxGame;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,6 +20,11 @@ public class PauseMenuMainMenuButton extends UIComponent {
private static final float Z_INDEX = 2f;
private Table table;

private final GdxGame game;

public PauseMenuMainMenuButton(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
}
@Override
public void create() {
super.create();
Expand All @@ -36,7 +44,7 @@ private void addActors() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Main menu button clicked");
// open settings
game.setScreen(GdxGame.ScreenType.MAIN_MENU);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.csse3200.game.components.pausemenu;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.GdxGame;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,6 +20,11 @@ public class PauseMenuPlanetSelectButton extends UIComponent {
private static final float Z_INDEX = 2f;
private Table table;

private final GdxGame game;

public PauseMenuPlanetSelectButton(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
}
@Override
public void create() {
super.create();
Expand All @@ -36,7 +44,7 @@ private void addActors() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Planet select button clicked");
// open settings
game.setScreen(GdxGame.ScreenType.LEVEL_SELECT);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.csse3200.game.components.pausemenu;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.GdxGame;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,6 +19,12 @@ public class PauseMenuSettingsButton extends UIComponent {
private static final float Z_INDEX = 2f;
private Table table;

private final GdxGame game;

public PauseMenuSettingsButton(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
}

@Override
public void create() {
super.create();
Expand All @@ -36,7 +44,7 @@ private void addActors() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Settings button clicked");
// open settings
game.setScreen(GdxGame.ScreenType.SETTINGS);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.entities.factories;

import com.csse3200.game.GdxGame;
import com.csse3200.game.components.pausemenu.*;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.services.ServiceLocator;
Expand All @@ -13,14 +14,14 @@ public class PauseMenuFactory {
* Creates the pause menu
* @return entity
*/
public static Entity createPauseMenu() {
public static Entity createPauseMenu(GdxGame game) {
Entity pauseMenu = new Entity()
.addComponent(new PauseMenuTimeStopComponent())
.addComponent(new PauseMenuRenderComponent())
.addComponent(new PauseMenuContinueButton())
.addComponent(new PauseMenuSettingsButton())
.addComponent(new PauseMenuPlanetSelectButton())
.addComponent(new PauseMenuMainMenuButton());
.addComponent(new PauseMenuSettingsButton(game))
.addComponent(new PauseMenuPlanetSelectButton(game))
.addComponent(new PauseMenuMainMenuButton(game));
ServiceLocator.getEntityService().register(pauseMenu);
return pauseMenu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void createUI() {
.addComponent(new MainGameActions(this.game))
.addComponent(new MainGameExitDisplay())
.addComponent(new MainGameLoseDisplay())
.addComponent(new MainGamePauseDisplay())
.addComponent(new MainGamePauseDisplay(this.game))
.addComponent(new Terminal())
.addComponent(inputComponent)
.addComponent(new TerminalDisplay());
Expand Down

0 comments on commit fb25a74

Please sign in to comment.