Skip to content

Commit

Permalink
Fixed bug relating to remainingMobsButton that didn't allow updating …
Browse files Browse the repository at this point in the history
…of remaining mob count
  • Loading branch information
shiv-0831 committed Oct 1, 2023
1 parent 7474275 commit aa8727c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.csse3200.game.components.maingame;

import com.badlogic.gdx.Gdx;
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.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
Expand All @@ -21,7 +23,8 @@ public class UIElementsDisplay extends UIComponent {
private static final float Z_INDEX = 2f;
private final Table mobsButtonTable = new Table();
private final Table timerTable = new Table();
private final TextButton remainingMobsButton = new ButtonFactory().createButton("Mobs left:");
Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
private TextButton remainingMobsButton = new ButtonFactory().createButton("Mobs left:");
private final TextButton timerButton = new ButtonFactory().createButton("Next wave:");;

@Override
Expand Down Expand Up @@ -62,7 +65,7 @@ private void addActors() {
* This method updates the mob count button as mobs die in the game
*/
public void updateMobCount() {
remainingMobsButton.setText("Mobs left:" + ServiceLocator.getWaveService().getEnemyCount());
remainingMobsButton.getLabel().setText("Mobs:" + ServiceLocator.getWaveService().getEnemyCount());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void createUI() {
.addComponent(new PerformanceDisplay())
.addComponent(new MainGameActions(this.game))
.addComponent(new MainGameExitDisplay())
.addComponent(new UIElementsDisplay())
.addComponent(ServiceLocator.getWaveService().getDisplay())
.addComponent(new MainGameLoseDisplay())
.addComponent(new Terminal())
.addComponent(inputComponent)
Expand Down
11 changes: 10 additions & 1 deletion source/core/src/main/com/csse3200/game/services/WaveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WaveService {
*/
public WaveService() {
this.enemyCount = 0;
display = new UIElementsDisplay();
this.display = new UIElementsDisplay();
}

/**
Expand Down Expand Up @@ -121,4 +121,13 @@ public long getNextWaveTime() {
public void setNextWaveTime(long nextWaveTime) {
this.nextWaveTime = nextWaveTime;
}

/**
* Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed
* for this instance of the display.
* @return the updating instance of UIElementsDisplay
*/
public UIElementsDisplay getDisplay() {
return this.display;
}
}

0 comments on commit aa8727c

Please sign in to comment.