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 ca12f8058..195dd578b 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 @@ -21,7 +21,7 @@ * on the screen, handles their behaviour and sound effects. */ public class MainGameDisplay extends UIComponent { - private static final Logger logger = LoggerFactory.getLogger(MainGamePauseDisplay.class); + private static final Logger logger = LoggerFactory.getLogger(MainGameDisplay.class); private static final float Z_INDEX = 2f; private final Table towerTable = new Table(); private final Table buttonTable = new Table(); diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java deleted file mode 100644 index 0e14c6f36..000000000 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.csse3200.game.components.maingame; - -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.ui.ButtonFactory; -import com.csse3200.game.ui.UIComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Displays a button to exit the Main Game screen to the Main Menu screen. - */ -public class MainGameExitDisplay extends UIComponent { - private static final Logger logger = LoggerFactory.getLogger(MainGameExitDisplay.class); - private static final float Z_INDEX = 2f; - private Table table; - - @Override - public void create() { - super.create(); - addActors(); - } - - private void addActors() { - table = new Table(); - table.top().right(); - table.setFillParent(true); - - TextButton mainPauseBtn = ButtonFactory.createButton("Pause"); - TextButton mainMenuBtn = ButtonFactory.createButton("Quit"); - - // Triggers an event when the button is pressed. - mainMenuBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Quit button clicked"); - entity.getEvents().trigger("exit"); - } - }); - - table.add(mainMenuBtn).padTop(125f).padRight(10f); - -// stage.addActor(table); - } - - @Override - public void draw(SpriteBatch batch) { - // draw is handled by the stage - } - - @Override - public float getZIndex() { - return Z_INDEX; - } - - @Override - public void dispose() { - table.clear(); - super.dispose(); - } -} diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java deleted file mode 100644 index f49cab2ef..000000000 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameLoseDisplay.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.csse3200.game.components.maingame; - -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.ui.ButtonFactory; -import com.csse3200.game.ui.UIComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Displays a button to exit the Main Game screen to the Main Menu screen. - */ -public class MainGameLoseDisplay extends UIComponent { - private static final Logger logger = LoggerFactory.getLogger(MainGameExitDisplay.class); - private static final float Z_INDEX = 2f; - private Table table; - - @Override - public void create() { - super.create(); - addActors(); - } - - private void addActors() { - table = new Table(); - table.top().right(); - table.setFillParent(true); - - TextButton mainMenuBtn = ButtonFactory.createButton("Lose"); - - // Triggers an event when the button is pressed. - mainMenuBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Quit button clicked"); - entity.getEvents().trigger("lose"); - } - }); - - table.add(mainMenuBtn).padTop(-100).padBottom(-500); - -// stage.addActor(table); - } - - @Override - public void draw(SpriteBatch batch) { - // draw is handled by the stage - } - - @Override - public float getZIndex() { - return Z_INDEX; - } - - @Override - public void dispose() { - table.clear(); - super.dispose(); - } -} - diff --git a/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java deleted file mode 100644 index 352411082..000000000 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGamePauseDisplay.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.csse3200.game.components.maingame; - -import com.badlogic.gdx.audio.Sound; -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.entities.Entity; -import com.csse3200.game.entities.factories.PauseMenuFactory; -import com.csse3200.game.services.ServiceLocator; -import com.csse3200.game.ui.ButtonFactory; -import com.csse3200.game.ui.UIComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Displays a button to pause the game and bring up a pause menu. - */ -public class MainGamePauseDisplay extends UIComponent { - private static final Logger logger = LoggerFactory.getLogger(MainGamePauseDisplay.class); - private static final float Z_INDEX = 2f; - private Table table; - private GdxGame game; - private final String[] sounds = { - "sounds/ui/open_close/open_01.ogg" - }; - private Sound openSound; - - - public MainGamePauseDisplay(GdxGame screenSwitchHandle) { - game = screenSwitchHandle; - } - - @Override - public void create() { - super.create(); - addActors(); - loadSounds(); - } - - private void addActors() { - table = new Table(); - table.top().right(); - table.setFillParent(true); - - TextButton mainMenuBtn = ButtonFactory.createButton("Pause"); - - // Spawns a pause menu when the button is pressed. - mainMenuBtn.addListener( - new ChangeListener() { - @Override - public void changed(ChangeEvent changeEvent, Actor actor) { - logger.debug("Pause button clicked"); - openSound.play(0.4f); -// PauseMenuFactory.createPauseMenu(game, false); - PauseMenuFactory.createPauseMenu(game); - - } - }); - - table.add(mainMenuBtn).padTop(180f).padRight(30f); - - stage.addActor(table); - } - - @Override - public void draw(SpriteBatch batch) { - // draw is handled by the stage - } - - @Override - public float getZIndex() { - return Z_INDEX; - } - - @Override - public void dispose() { - table.clear(); - super.dispose(); - } - - public void loadSounds() { - ServiceLocator.getResourceService().loadSounds(sounds); - ServiceLocator.getResourceService().loadAll(); - openSound = ServiceLocator.getResourceService().getAsset(sounds[0], Sound.class); - } -} diff --git a/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java index 631707580..afa6b7369 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java @@ -6,6 +6,8 @@ import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; +import com.badlogic.gdx.scenes.scene2d.actions.Actions; +import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; @@ -26,7 +28,7 @@ * Displays a button to represent the remaining mobs left in the current wave and a button to skip to the next wave. */ public class UIElementsDisplay extends UIComponent { - private static final Logger logger = LoggerFactory.getLogger(MainGameExitDisplay.class); + private static final Logger logger = LoggerFactory.getLogger(UIElementsDisplay.class); private static final float Z_INDEX = 2f; private final Table buttonTable = new Table(); private TextButton remainingMobsButton; @@ -101,7 +103,8 @@ public void updateTimerButton() { } timerButton.setText("Next wave in: " + finalTime); } else { - buttonTable.removeActor(timerButton); + timerButton.addAction(new SequenceAction(Actions.fadeOut(1f), Actions.removeActor())); +// buttonTable.removeActor(timerButton); stage.act(); stage.draw(); } diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index b2db2c025..413cf2856 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -16,7 +16,6 @@ import com.csse3200.game.areas.ForestGameArea; import com.csse3200.game.components.gamearea.PerformanceDisplay; import com.csse3200.game.components.maingame.MainGameActions; -import com.csse3200.game.components.maingame.MainGameLoseDisplay; import com.csse3200.game.components.maingame.MainGameDisplay; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; @@ -87,21 +86,19 @@ public class MainGameScreen extends ScreenAdapter { private final PhysicsEngine physicsEngine; private InputComponent upgradedInputHandler; - private final Stage stage; static int screenWidth = Gdx.graphics.getWidth(); static int screenHeight = Gdx.graphics.getHeight(); private Entity ui; - private int random = 0; public static int viewportWidth = screenWidth; public static int viewportHeight= screenHeight; int selectedLevel = GameLevelData.getSelectedLevel(); - private OrthographicCamera camera; - private SpriteBatch batch; + private final OrthographicCamera camera; + private final SpriteBatch batch; private Texture backgroundTexture; private Music music; - private Array ambientSounds = new Array<>(false, 5, String.class); + private final Array ambientSounds = new Array<>(false, 5, String.class); public MainGameScreen(GdxGame game) { this.game = game; @@ -111,7 +108,7 @@ public MainGameScreen(GdxGame game) { batch = new SpriteBatch(); - stage = new Stage(new ScreenViewport()); + Stage stage = new Stage(new ScreenViewport()); logger.debug("Initialising main game screen services"); @@ -169,22 +166,22 @@ public Texture getBackgroundTexture() { Texture background; switch (selectedLevel) { // Desert - case 1: // Ice + case 1 -> { // Ice background = ServiceLocator.getResourceService().getAsset(ICE_BACKDROP, Texture.class); music = ServiceLocator.getResourceService().getAsset(ICE_BGM, Music.class); ambientSounds.addAll(iceSounds); - break; - case 2: // Lava + } + case 2 -> { // Lava background = ServiceLocator.getResourceService().getAsset(LAVA_BACKDROP, Texture.class); music = ServiceLocator.getResourceService().getAsset(LAVA_BGM, Music.class); ambientSounds.addAll(lavaSounds); - break; - default: + } + default -> { // Use a default background for other levels or planets background = ServiceLocator.getResourceService().getAsset(DESERT_BACKDROP, Texture.class); music = ServiceLocator.getResourceService().getAsset(DESERT_BGM, Music.class); ambientSounds.addAll(desertSounds); - break; + } } return background; } @@ -304,7 +301,6 @@ private void createUI() { .addComponent(new PerformanceDisplay()) .addComponent(new MainGameActions(this.game)) .addComponent(ServiceLocator.getWaveService().getDisplay()) - .addComponent(new MainGameLoseDisplay()) //.addComponent(new MainGameWinDisplay()) <- needs to be uncommented when team 3 have implemented the ui .addComponent(new MainGameDisplay(this.game)) .addComponent(new Terminal())