Skip to content

Commit

Permalink
Merge pull request #257 from UQcsse3200/shivam-ui-elements
Browse files Browse the repository at this point in the history
merging shivam-ui-elements to team-2-ui
  • Loading branch information
The-AhmadAA authored Oct 14, 2023
2 parents e0b39e3 + 8e4bc89 commit 9952abc
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Null;
import com.csse3200.game.screens.TowerType;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.ButtonFactory;
Expand Down Expand Up @@ -187,7 +188,8 @@ public void createTimerButton() {
* This method updates the text for timer button.
*/
public void updateTimerButton() {
int totalSecs = (int) (timer - (ServiceLocator.getTimeSource().getTime() / 1000));
int totalSecs = (int) ((ServiceLocator.getWaveService().getNextWaveTime()
- ServiceLocator.getTimeSource().getTime()) / 1000);

// TODO : THESE SHOULD BE REMOVED AND PLACED WHEREVER THE BOSS MOB GETS SPAWNED
if (totalSecs % 20 == 0) {
Expand All @@ -197,7 +199,30 @@ public void updateTimerButton() {
int seconds = totalSecs % 60;
int minutes = (totalSecs % 3600) / 60;
String finalTime = String.format("%02d:%02d", minutes, seconds);
timerButton.setText("Next wave in:" + finalTime);
if (ServiceLocator.getTimeSource().getTime() < ServiceLocator.getWaveService().getNextWaveTime()) {
if (!findActor(timerButton)) {
createTimerButton();
}
timerButton.setText("Next wave in: " + finalTime);
} else {
buttonTable.removeActor(timerButton);
stage.act();
stage.draw();
}
}

/**
* This function checks if a certain actor is present in buttonTable.
* @param actor the actor to find in buttonTable.
* @return true if the actor is present and false otherwise.
*/
public boolean findActor(Actor actor) {
for (Actor actors: buttonTable.getChildren()) {
if (actors == actor) {
return true;
}
}
return false;
}

@Override
Expand Down

0 comments on commit 9952abc

Please sign in to comment.