Skip to content

Commit

Permalink
Added the basic framework for buttons in the main game area
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv-0831 committed Sep 28, 2023
1 parent d76c0db commit a688f05
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a688f05

Please sign in to comment.