Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging shivam-ui-elements to team-2-ui #209

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Text;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -34,8 +33,9 @@ public class UIElementsDisplay extends UIComponent {
private final Table buttonTable = new Table();
private final Table towerTable = new Table();
Skin skin = new Skin(Gdx.files.internal("images/ui/buttons/glass.json"));
private TextButton remainingMobsButton = new ButtonFactory().createButton("Mobs left:");
private final TextButton timerButton = new ButtonFactory().createButton("Next wave:");
private TextButton remainingMobsButton;
private TextButton timerButton;
private final int timer = 110;

@Override
public void create() {
Expand All @@ -47,6 +47,9 @@ public void create() {
* This method creates the buttons, adds them to the respective tables and draws them on the screen.
*/
private void addActors() {
remainingMobsButton = new ButtonFactory().createButton("Mobs:"
+ ServiceLocator.getWaveService().getEnemyCount());

buttonTable.top().right();
towerTable.top();

Expand Down Expand Up @@ -128,17 +131,6 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
}
});

//Not sure if we need a listened for a label
// // 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");
// }
// });

buttonTable.add(remainingMobsButton).padTop(10f).padRight(10f);
buttonTable.row();
buttonTable.add(timerButton).padRight(10f);
Expand All @@ -151,13 +143,37 @@ public void changed(ChangeEvent changeEvent, Actor actor) {

stage.addActor(buttonTable);
stage.addActor(towerTable);

createTimerButton();
}

/**
* This method updates the mob count button as mobs die in the game
*/
public void updateMobCount() {
remainingMobsButton.getLabel().setText("Mobs:" + ServiceLocator.getWaveService().getEnemyCount());
remainingMobsButton.setText("Mobs:" + ServiceLocator.getWaveService().getEnemyCount());
}

/**
* This method creates the timer button.
*/
public void createTimerButton() {

timerButton = new ButtonFactory().createButton("Next wave in:"
+ (ServiceLocator.getWaveService().getNextWaveTime() / 1000));
buttonTable.row();
buttonTable.add(timerButton).padRight(10f);
}

/**
* This method updates the text for timer button.
*/
public void updateTimerButton() {
int totalSecs = (int) (timer - (ServiceLocator.getTimeSource().getTime() / 1000));
int seconds = totalSecs % 60;
int minutes = (totalSecs % 3600) / 60;
String finalTime = String.format("%02d:%02d", minutes, seconds);
timerButton.setText("Next wave in:" + finalTime);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public void render(float delta) {
ui.getEvents().trigger("lose");
}

ServiceLocator.getWaveService().getDisplay().updateTimerButton();
ServiceLocator.getWaveService().getDisplay().updateMobCount();
renderer.render();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public int getEnemyCount() {
*/
public void updateEnemyCount() {
enemyCount -= 1;
display.updateMobCount();
logger.info("{} enemies remaining in wave", getEnemyCount());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//package com.csse3200.game.components.maingame;
//
//import com.badlogic.gdx.scenes.scene2d.Stage;
//import com.badlogic.gdx.scenes.scene2d.ui.Skin;
//import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
//import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
//import com.csse3200.game.components.maingame.UIElementsDisplay;
//import com.csse3200.game.rendering.RenderService;
//import com.csse3200.game.screens.MainGameScreen;
//import com.csse3200.game.services.ResourceService;
//import com.csse3200.game.services.ServiceLocator;
//import com.csse3200.game.services.WaveService;
//import com.csse3200.game.ui.ButtonFactory;
//import org.junit.Before;
//import org.junit.Test;
//import org.mockito.Mockito;
//
//import java.security.Provider;
//
//import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertNull;
//import static org.mockito.Mockito.*;
//
//public class UIElementsDisplayTest {
//
// private UIElementsDisplay display;
//
// @Before
// public void setUp() {
// RenderService renderService = mock(RenderService.class);
// ResourceService resourceService = mock(ResourceService.class);
// WaveService waveService = mock(WaveService.class);
//
// display = new UIElementsDisplay();
//
// ServiceLocator.registerRenderService(renderService);
// ServiceLocator.registerResourceService(resourceService);
// ServiceLocator.registerWaveService(waveService);
//
// when(ServiceLocator.getWaveService().getEnemyCount()).thenReturn(10);
// when(ServiceLocator.getWaveService().getNextWaveTime()).thenReturn(10000L); // Example time
// when(ServiceLocator.getWaveService().getDisplay()).thenReturn(display);
//
// }
//
// @Test
// public void testUpdateMobCount() {
// TextButton mobButton = display.getRemainingMobsButton();
// assertEquals("Mobs:10", mobButton.getText());
//
// display.updateMobCount();
// assertEquals("Mobs:9", mobButton.getText());
// }
//
// @Test
// public void testCreateTimerButton() {
// assertNull(display.getTimerButton());
// display.createTimerButton();
// assertEquals("Next wave in:10", display.getTimerButton().getText());
// }
//}
Loading