Skip to content

Commit

Permalink
Merge branch 'team-2-ui' of github.com:UQcsse3200/2023-studio-3 into …
Browse files Browse the repository at this point in the history
…team-2-ui
  • Loading branch information
The-AhmadAA committed Oct 16, 2023
2 parents 05cf8d0 + a3cabdd commit a4b89dd
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Texture;
Expand Down Expand Up @@ -56,11 +57,18 @@ private void addActors() {
ServiceLocator.getCurrencyService().getCrystal().getAmount());

table.add(scrapsTb).width(scrapsTb.getWidth() * 0.5f).height(scrapsTb.getHeight() * 0.5f);
table.row();
table.add(crystalsTb).width(crystalsTb.getWidth() * 0.5f).height(crystalsTb.getHeight() * 0.5f);
table.setDebug(true);
stage.addActor(table);

scrapsTb.addAction(new SequenceAction(Actions.fadeIn(4f)));
crystalsTb.addAction(new SequenceAction(Actions.fadeIn(8f)));
scrapsTb.setPosition(table.getX() - 200, Gdx.graphics.getHeight() - 205);
scrapsTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20, Gdx.graphics.getHeight() - 205,
1f, Interpolation.fastSlow)));

crystalsTb.setPosition(table.getX() - 200, Gdx.graphics.getHeight() - 268);
crystalsTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20, Gdx.graphics.getHeight() - 268,
1f, Interpolation.fastSlow)));
}

private TextButton createButton(String imageFilePath, int value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
Expand Down Expand Up @@ -34,6 +36,7 @@ private void addActors() {
table.top().left();
table.setFillParent(true);
table.padTop(80f).padLeft(20f);
table.setDebug(true);

Drawable drawable = new TextureRegionDrawable(new TextureRegion(
new Texture("images/engineers/engineerBanner.png")));
Expand All @@ -54,7 +57,10 @@ private void addActors() {
table.add(engineerTb).width(engineerTb.getWidth() * 0.5f).height(engineerTb.getHeight() * 0.5f);
stage.addActor(table);

engineerTb.addAction(new SequenceAction(Actions.fadeIn(4f)));
// Animate the engineer count label
engineerTb.setPosition(table.getX() - 200, Gdx.graphics.getHeight() - 145);
engineerTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20, Gdx.graphics.getHeight() - 145,
1f, Interpolation.fastSlow)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ private void addActors() {
// Create and position the tables that will hold the buttons.

// Contains the tower build menu buttons
towerTable.top().padTop(50f);
towerTable.top().padTop(80f);
towerTable.setFillParent(true);

// Contains other buttons (just pause at this stage)
buttonTable.top().right().padTop(50f).padRight(80f);
buttonTable.top().right().padTop(80f).padRight(80f);
buttonTable.setFillParent(true);

progressTable.top().center().setWidth(500f);
progressTable.setFillParent(true);

levelNameTable.top().left().padLeft(20f).padTop(20f);
levelNameTable.center().top().padLeft(20f).padTop(20f).pad(20f);
levelNameTable.setFillParent(true);

// Stores tower defaults, in case towers haven't been set in the tower select screen
Expand Down Expand Up @@ -305,7 +305,7 @@ public void clicked(InputEvent event, float x, float y) {
progressbar = new LevelProgressBar(500, 10);

levelNameTable.setSkin(getSkin());
levelNameTable.add(this.level, "title");
levelNameTable.add(this.level, "default");

// Scale all the tower build buttons down
// Add all buttons to their respective tables and position them
Expand All @@ -315,7 +315,6 @@ public void clicked(InputEvent event, float x, float y) {
towerTable.add(tower3).padRight(10f);
towerTable.add(tower4).padRight(10f);
towerTable.add(tower5).padRight(10f);
towerTable.stack(new Label(String.format("%s", towers.get(0).getPrice()), getSkin()));
towerTable.row();
towerTable.add("1", "small");
towerTable.add("2", "small");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UIElementsDisplay extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(UIElementsDisplay.class);
private static final float Z_INDEX = 2f;
private final Table buttonTable = new Table();
private final Table timerTable = new Table();
private TextButton remainingMobsButton;
private TextButton timerButton;

Expand All @@ -44,15 +45,14 @@ private void addActors() {
+ ServiceLocator.getWaveService().getEnemyCount());

remainingMobsButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 230);
remainingMobsButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 218,
remainingMobsButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 217,
Gdx.graphics.getHeight() - 230, 1f, Interpolation.fastSlow)));

buttonTable.top().right().padTop(130f).padRight(80f);
buttonTable.top().right().padTop(160f).padRight(80f);
buttonTable.setFillParent(true);

buttonTable.add(remainingMobsButton).right();
buttonTable.row();
buttonTable.add(timerButton);


stage.addActor(buttonTable);

Expand Down Expand Up @@ -82,10 +82,11 @@ public void createTimerButton() {
timerButton = ButtonFactory.createButton("Next wave in:"
+ (ServiceLocator.getWaveService().getNextWaveTime() / 1000));
timerButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 300);
timerButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 445,
timerButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 435,
Gdx.graphics.getHeight() - 300, 1f, Interpolation.fastSlow)));
timerButton.setDisabled(true);
buttonTable.row();
buttonTable.add(timerButton).padRight(10f);
buttonTable.add(timerButton);
}

/**
Expand All @@ -106,10 +107,12 @@ public void updateTimerButton() {
String finalTime = String.format("%02d:%02d", minutes, seconds);
if (ServiceLocator.getTimeSource().getTime() < ServiceLocator.getWaveService().getNextWaveTime()) {
if (!findActor(timerButton)) {
remainingMobsButton.setDisabled(false);
createTimerButton();
}
timerButton.setText("Next wave in: " + finalTime);
} else {
remainingMobsButton.setDisabled(true);
timerButton.addAction(new SequenceAction(Actions.fadeOut(1f), Actions.removeActor()));
stage.act();
stage.draw();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.csse3200.game.components.pausemenu;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
Expand All @@ -16,14 +13,15 @@
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.GdxGame;
import com.csse3200.game.components.maingame.MainGameDisplay;
import com.csse3200.game.entities.factories.PauseMenuFactory;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.ButtonFactory;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Implements the visual aspects of the pause menu, including button interactions.
*/
public class PauseMenuButtonComponent extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(PauseMenuButtonComponent.class);
private static final float Z_INDEX = 2f;
Expand All @@ -42,6 +40,9 @@ public PauseMenuButtonComponent(GdxGame screenSwitchHandle) {
game = screenSwitchHandle;
}

/**
* Sets up the buttons and window of the pause menu when it is first made.
*/
@Override
public void create() {
super.create();
Expand Down Expand Up @@ -105,7 +106,6 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
}
});


window.setResizable(true);
window.setModal(true);
window.setTouchable(Touchable.enabled);
Expand Down Expand Up @@ -136,6 +136,10 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
stage.addActor(window);
}

/**
* Draws the pause menu on the game screen.
* @param batch Batch to render to.
*/
@Override
protected void draw(SpriteBatch batch) {
// handled by stage
Expand All @@ -151,11 +155,18 @@ public void loadSounds() {
closeSound = ServiceLocator.getResourceService().getAsset(sounds[1], Sound.class);
}

/**
* Gets the z-index of the pause menu
* @return The z-index of the pause menu
*/
@Override
public float getZIndex() {
return Z_INDEX;
}

/**
* Removes the pause menu when the entity is disposed.
*/
@Override
public void dispose() {
click.play(0.5f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* Handles the pausing/resuming of time when the pause menu is brought up/put away.
*/
public class PauseMenuTimeStopComponent extends Component {

private Array<Entity> freezeList;
public PauseMenuTimeStopComponent() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
* This input handler only uses keyboard input.
*/
public class PopupMenuInputComponent extends InputComponent{
/** TO DO:
* This component's end goal is to send a deactivation trigger when the
* user clicks on anything other than the menu entity, and reactivate it
* if the user clicks on a tower, with the new tower's stats as per its
* config file.
* Current implementation step: trigger a generic event whenever
* the mouse is clicked, with no checks for the entity clicked on.
/**
* !!!
* NOTE: THIS CLASS IS OBSOLETE
* !!!
*/

public PopupMenuInputComponent() {super(1);}
// Note: will need to change constructor's priority when merging with other
// branches that add other input components.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import com.csse3200.game.components.CombatStatsComponent;
import com.csse3200.game.components.Component;

import static com.csse3200.game.screens.TowerType.INCOME;

/**
* Listens for an event from the popup menu to upgrade
* the turret entity this component is attached to.
*/
public class TowerUpgraderComponent extends Component {
/**
* Enum for specifying what type of upgrade to implement
*/
public enum UPGRADE {
ATTACK, MAXHP, FIRERATE, REPAIR, INCOME
}

/**
* Creates the component and sets it up to respond to upgrade event triggers.
*/
@Override
public void create() {
super.create();
Expand All @@ -29,11 +33,11 @@ public void create() {
*/
public void upgradeTower(UPGRADE upgradeType, int value) {
switch (upgradeType) {
case INCOME -> {getEntity().getEvents().trigger("addIncome", value);}
case ATTACK -> {upgradeTowerAttack(value);}
case MAXHP -> {upgradeTowerMaxHealth( value);}
case FIRERATE -> {getEntity().getEvents().trigger("addFireRate", value);}
case REPAIR -> {repairTower();}
case INCOME -> getEntity().getEvents().trigger("addIncome", value);
case ATTACK -> upgradeTowerAttack(value);
case MAXHP -> upgradeTowerMaxHealth( value);
case FIRERATE -> getEntity().getEvents().trigger("addFireRate", value);
case REPAIR -> repairTower();

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class PauseMenuTimeStopComponentTest {
void beforeEach() {
EntityService entityService = new EntityService();
ServiceLocator.registerEntityService(entityService);
WaveService waveService = new WaveService();
WaveService waveService = mock(WaveService.class);
ServiceLocator.registerWaveService(waveService);
GameTime gameTime = new GameTime();
GameTime gameTime = mock(GameTime.class);
ServiceLocator.registerTimeSource(gameTime);
entity = mock(Entity.class);
when(entity.getId()).thenReturn(-1); //Ensure it does not coincide with the pause menu's ID
Expand Down Expand Up @@ -52,4 +52,17 @@ void doesNotPauseNewEntities() {
ServiceLocator.getEntityService().register(lateEntity);
verify(lateEntity, times(0)).setEnabled(false);
}

@Test
void waveServiceIsPaused() {
ServiceLocator.getEntityService().register(pauseMenu);
verify(ServiceLocator.getWaveService()).toggleGamePause();
}

@Test
void waveServiceIsPausedAndUnpaused() {
ServiceLocator.getEntityService().register(pauseMenu);
pauseMenu.dispose();
verify(ServiceLocator.getWaveService(), times(2)).toggleGamePause();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class PauseMenuFactoryTest {
Entity entity;
GdxGame game;

String[] texture = {
"images/ui/Sprites/UI_Glass_Toggle_Bar_01a.png"
};
@BeforeEach
void beforeEach() {
EntityService entityService = new EntityService();
Expand All @@ -38,7 +35,6 @@ void beforeEach() {
ServiceLocator.registerRenderService(renderService);
ResourceService resourceService = new ResourceService();
ServiceLocator.registerResourceService(resourceService);
resourceService.loadTextures(texture);
resourceService.loadAll();

game = mock(GdxGame.class);
Expand Down

0 comments on commit a4b89dd

Please sign in to comment.