Skip to content

Commit

Permalink
Merge pull request #281 from UQcsse3200/team-2-ui-Alasdair
Browse files Browse the repository at this point in the history
Team 2 UI alasdair clean up
  • Loading branch information
The-AhmadAA authored Oct 16, 2023
2 parents 57739fe + cda15de commit a3cabdd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 27 deletions.
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 a3cabdd

Please sign in to comment.