From a688f0573e686839c87d365858a87943aebec60f Mon Sep 17 00:00:00 2001 From: Shivam Date: Thu, 28 Sep 2023 22:23:21 +1000 Subject: [PATCH] Added the basic framework for buttons in the main game area --- .../maingame/MainGameExitDisplay.java | 2 +- .../maingame/UIElementsDisplay.java | 68 ++++++++++++++++++- .../csse3200/game/screens/MainGameScreen.java | 2 + 3 files changed, 70 insertions(+), 2 deletions(-) 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 index 105b30874..408cb8b21 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/MainGameExitDisplay.java @@ -40,7 +40,7 @@ public void changed(ChangeEvent changeEvent, Actor actor) { } }); - table.add(mainMenuBtn).padTop(10f).padRight(10f); + table.add(mainMenuBtn).padTop(125f).padRight(10f); stage.addActor(table); } 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 30c8c9c6a..39b132139 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 @@ -1,2 +1,68 @@ -package com.csse3200.game.components.maingame;public class UIElementsDisplay { +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.Button; +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; +import org.w3c.dom.Text; + +/** + * Displays a button to exit the Main Game screen to the Main Menu screen. + */ +public class UIElementsDisplay 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 remainingMobsButton = new ButtonFactory().createButton("Remaining mobs:"); + TextButton testSlider = new ButtonFactory().createButton("Test slider"); + + // Triggers an event when the button is pressed. + remainingMobsButton.addListener( + new ChangeListener() { + @Override + public void changed(ChangeEvent changeEvent, Actor actor) { + logger.debug("Wave counter button clicked"); + entity.getEvents().trigger("wave counter"); + } + }); + + table.add(remainingMobsButton).padTop(0f).padRight(10f); + table.add(testSlider).padTop(90).padRight(10f); + + stage.addActor(table); + } + + @Override + public void draw(SpriteBatch batch) { + // drawing 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/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index ab475797f..49e1510a5 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -22,6 +22,7 @@ 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.UIElementsDisplay; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; import com.csse3200.game.entities.factories.PlayerFactory; @@ -200,6 +201,7 @@ private void createUI() { .addComponent(new PerformanceDisplay()) .addComponent(new MainGameActions(this.game)) .addComponent(new MainGameExitDisplay()) + .addComponent(new UIElementsDisplay()) .addComponent(new MainGameLoseDisplay()) .addComponent(new Terminal()) .addComponent(inputComponent)