Skip to content

Commit

Permalink
updated PauseMenuFactory and JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Oct 14, 2023
1 parent ce40b81 commit 77c9639
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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 Window window;
private final GdxGame game;
private static final float windowSizeX = 300;
private static final float windowSizeY = 400;
Expand All @@ -46,7 +43,7 @@ public void create() {
*/
private void addActors() {

Window window = new Window("Game Paused", new Skin(Gdx.files.internal("images/ui/buttons/glass.json")));
window = new Window("Game Paused", new Skin(Gdx.files.internal("images/ui/buttons/glass.json")));

TextButton continueBtn = ButtonFactory.createButton("Continue");
continueBtn.pad(20f);
Expand Down Expand Up @@ -124,7 +121,8 @@ public float getZIndex() {

@Override
public void dispose() {
table.clear();
window.clear();
window.remove();
super.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ private void addActors() {
table = new Table();
table.top().right();
table.setFillParent(true);
ButtonFactory buttonFactory = new ButtonFactory();
// TextButton pauseMenuBtn = buttonFactory.createButton("Continue");
TextButton pauseMenuBtn = new TextButton("Continue", skin);
TextButton pauseMenuBtn = ButtonFactory.createButton("Continue");

// Triggers an event when the button is pressed.
pauseMenuBtn.addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ private void addActors() {
table = new Table();
table.top().right();
table.setFillParent(true);
ButtonFactory buttonFactory = new ButtonFactory();
// TextButton pauseMenuBtn = buttonFactory.createButton("Main Menu");
TextButton pauseMenuBtn = new TextButton("Main Menu", skin);
TextButton pauseMenuBtn = ButtonFactory.createButton("Main Menu");

// Triggers an event when the button is pressed.
pauseMenuBtn.addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ private void addActors() {
table = new Table();
table.top().right();
table.setFillParent(true);
ButtonFactory buttonFactory = new ButtonFactory();
// TextButton pauseMenuBtn = buttonFactory.createButton("Planet Select");
TextButton pauseMenuBtn = new TextButton("Planet Select", skin);
TextButton pauseMenuBtn = ButtonFactory.createButton("Planet Select");

// Triggers an event when the button is pressed.
pauseMenuBtn.addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ private void addActors() {
table = new Table();
table.top().right();
table.setFillParent(true);
ButtonFactory buttonFactory = new ButtonFactory();
// TextButton pauseMenuBtn = buttonFactory.createButton("Settings");
TextButton pauseMenuBtn = new TextButton("Settings", skin);
TextButton pauseMenuBtn = ButtonFactory.createButton("Settings");

// Triggers an event when the button is pressed.
pauseMenuBtn.addListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public static Entity createPauseMenu(GdxGame game) {

Entity pauseMenu = new Entity()
.addComponent(new PauseMenuTimeStopComponent())
.addComponent(new PauseMenuContinueButton())
.addComponent(new PauseMenuSettingsButton(game))
.addComponent(new PauseMenuPlanetSelectButton(game))
.addComponent(new PauseMenuMainMenuButton(game))
// .addComponent(new PauseMenuContinueButton())
// .addComponent(new PauseMenuSettingsButton(game))
// .addComponent(new PauseMenuPlanetSelectButton(game))
// .addComponent(new PauseMenuMainMenuButton(game))
.addComponent(new PauseMenuButtonComponent(game));
pauseMenu.setScale(8, 8);
pauseMenu.setPosition(6f, 2f);
Expand Down
39 changes: 20 additions & 19 deletions source/core/src/main/com/csse3200/game/ui/ButtonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

import static com.csse3200.game.ui.UIComponent.skin;

/**
* This class provides static methods for creating various types of TextButtons with different styles.
*/
public class ButtonFactory {
private static Skin defaultSkin;

// Static initializer block to initialize the default skin
static {
defaultSkin = createDefaultSkin();
}

private static Skin createDefaultSkin() {
Skin skin = new Skin(Gdx.files.internal("configs/text.json"));

// Define the button style with the background image
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
style.font = skin.getFont("default");
style.up = new TextureRegionDrawable(new TextureRegion(new Texture("images/ui/Sprites/UI_Glass_Button_Large_Lock_01a1.png"))); // Set the button background to the loaded image

skin.add("default", style);
return skin;
}
// Static initializer block to initialize the default skin -- THIS IS HANDLED BY UICOMPONENT
// static {
// defaultSkin = createDefaultSkin();
// }
//
// private static Skin createDefaultSkin() {
//
// // Define the button style with the background image
// TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
// style.font = skin.getFont("default");
// style.up = new TextureRegionDrawable(new TextureRegion(new Texture("images/ui/Sprites/UI_Glass_Button_Large_Lock_01a1.png"))); // Set the button background to the loaded image
//
// skin.add("default", style);
// return skin;
// }

/**
* Creates a TextButton with the specified text using the default skin.
Expand All @@ -38,9 +39,9 @@ private static Skin createDefaultSkin() {
* @return The created TextButton.
*/
public static TextButton createButton(String text) {
TextButton button = new TextButton(text, defaultSkin);
button.getLabel().setFontScale(0.8f); // Adjust text size
button.pad(10f); // Adjust padding
TextButton button = new TextButton(text, skin);
// button.getLabel().setFontScale(0.8f); // Adjust text size
button.pad(20f); // Adjust padding
return button;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,12 @@ void createsEntity() {
@Test
void entityHasRequiredComponents() {
assertNotNull(entity.getComponent(PauseMenuTimeStopComponent.class));
<<<<<<< Updated upstream
// assertNotNull(entity.getComponent(PauseMenuButtonComponent.class));
// assertNotNull(entity.getComponent(PauseMenuContinueButton.class));
// assertNotNull(entity.getComponent(PauseMenuSettingsButton.class));
// assertNotNull(entity.getComponent(PauseMenuPlanetSelectButton.class));
// assertNotNull(entity.getComponent(PauseMenuMainMenuButton.class));
assertNotNull(entity.getComponent(PauseMenuButtonComponent.class));
assertNotNull(entity.getComponent(TextureRenderComponent.class));
=======
assertNotNull(entity.getComponent(PauseMenuContinueButton.class));
assertNotNull(entity.getComponent(PauseMenuSettingsButton.class));
assertNotNull(entity.getComponent(PauseMenuPlanetSelectButton.class));
assertNotNull(entity.getComponent(PauseMenuMainMenuButton.class));
assertNotNull(entity.getComponent(PauseMenuButtonComponent.class));
>>>>>>> Stashed changes
}

@Test
Expand Down

0 comments on commit 77c9639

Please sign in to comment.