From 2ec2a93a9dd1685392b25a927e0946374b97bbbd Mon Sep 17 00:00:00 2001 From: MajorDzaster Date: Sat, 14 Oct 2023 13:09:15 +1000 Subject: [PATCH 1/2] Changed the tables PauseMenuButtonComponent uses into a window, to aid in fixing the pause menu screen sizing bug. --- .../core/assets/images/ui/buttons/glass.json | 1 - .../pausemenu/PauseMenuButtonComponent.java | 46 +++++++++---------- .../entities/factories/PauseMenuFactory.java | 4 +- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/source/core/assets/images/ui/buttons/glass.json b/source/core/assets/images/ui/buttons/glass.json index f76bad834..648881aac 100644 --- a/source/core/assets/images/ui/buttons/glass.json +++ b/source/core/assets/images/ui/buttons/glass.json @@ -192,7 +192,6 @@ com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: { background: UI_Glass_Frame_Standard_01a titleFont: font_small titleFontColor: White - stageBackground: UI_Glass_Frame_Standard_01a } } } \ No newline at end of file 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 7c2f1fd4d..9a17034d6 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 @@ -1,11 +1,18 @@ package com.csse3200.game.components.pausemenu; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.Touchable; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.Window; +import com.badlogic.gdx.scenes.scene2d.ui.Dialog; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.csse3200.game.GdxGame; import com.csse3200.game.ui.ButtonFactory; import com.csse3200.game.ui.UIComponent; @@ -15,10 +22,7 @@ public class PauseMenuButtonComponent extends UIComponent { private static final Logger logger = LoggerFactory.getLogger(PauseMenuButtonComponent.class); private static final float Z_INDEX = 2f; - private Table table; - private Table table2; - private Table table3; - private Table table4; + private Dialog window; private final GdxGame game; public PauseMenuButtonComponent(GdxGame screenSwitchHandle) { @@ -33,18 +37,9 @@ public void create() { /** * Initialises the pause menu buttons - * Positions them on the stage using a table + * Positions them on the stage using a window */ private void addActors() { - //window = new Window("",); - table = new Table(); - table.setFillParent(true); - table2 = new Table(); - table2.setFillParent(true); - table3 = new Table(); - table3.setFillParent(true); - table4 = new Table(); - table4.setFillParent(true); TextButton continueBtn = ButtonFactory.createButton("Continue"); TextButton settingsBtn = ButtonFactory.createButton("Settings"); TextButton planetSelectBtn = ButtonFactory.createButton("Planet Select"); @@ -81,15 +76,17 @@ public void changed(ChangeEvent changeEvent, Actor actor) { game.setScreen(GdxGame.ScreenType.MAIN_MENU); } }); - table.add(continueBtn).padBottom(50f).padRight(200f); - table2.add(settingsBtn).padBottom(50f).padLeft(200f); - table3.add(planetSelectBtn).padTop(50f).padRight(200f); - table4.add(mainMenuBtn).padTop(50f).padLeft(200f); - - stage.addActor(table); - stage.addActor(table2); - stage.addActor(table3); - stage.addActor(table4); + window = new Dialog("Game Paused", new Skin(Gdx.files.internal("images/ui/buttons/glass.json"))); + window.setFillParent(false); + window.setModal(true); + window.add(continueBtn); + window.row(); + window.add(settingsBtn); + window.row(); + window.add(planetSelectBtn); + window.row(); + window.add(mainMenuBtn); + stage.addActor(window); } @Override @@ -104,7 +101,8 @@ public float getZIndex() { @Override public void dispose() { - table.clear(); + window.remove(); + window.clear(); super.dispose(); } } diff --git a/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java index 1a48b3c85..3248f3c30 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/PauseMenuFactory.java @@ -23,8 +23,8 @@ public static Entity createPauseMenu(GdxGame game) { Entity pauseMenu = new Entity() .addComponent(new PauseMenuTimeStopComponent()) - .addComponent(new PauseMenuButtonComponent(game)) - .addComponent(new TextureRenderComponent("images/ui/Sprites/UI_Glass_Toggle_Bar_01a.png")); + .addComponent(new PauseMenuButtonComponent(game)); + //.addComponent(new TextureRenderComponent("images/ui/Sprites/UI_Glass_Toggle_Bar_01a.png")); pauseMenu.setScale(8, 8); pauseMenu.setPosition(6f, 2f); ServiceLocator.getEntityService().register(pauseMenu); From e731e35c91c611557fac25ea49cb118bc9e5d193 Mon Sep 17 00:00:00 2001 From: MajorDzaster Date: Sat, 14 Oct 2023 13:16:10 +1000 Subject: [PATCH 2/2] Updated PauseMenuFactoryTest junit test to match changed implementation --- .../csse3200/game/entities/factories/PauseMenuFactoryTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java index 5ad5603f5..984a0fdc2 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java @@ -49,7 +49,6 @@ void createsEntity() { void entityHasRequiredComponents() { assertNotNull(entity.getComponent(PauseMenuTimeStopComponent.class)); assertNotNull(entity.getComponent(PauseMenuButtonComponent.class)); - assertNotNull(entity.getComponent(TextureRenderComponent.class)); } @Test