diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java index cb130da50..030d05494 100644 --- a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuButtonComponent.java @@ -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; @@ -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; @@ -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(); @@ -105,7 +106,6 @@ public void changed(ChangeEvent changeEvent, Actor actor) { } }); - window.setResizable(true); window.setModal(true); window.setTouchable(Touchable.enabled); @@ -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 @@ -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); diff --git a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java index e581d47d1..f8f50068e 100644 --- a/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java +++ b/source/core/src/main/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponent.java @@ -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 freezeList; public PauseMenuTimeStopComponent() { } diff --git a/source/core/src/main/com/csse3200/game/components/popupmenu/PopupMenuInputComponent.java b/source/core/src/main/com/csse3200/game/components/popupmenu/PopupMenuInputComponent.java index a12dd12ad..43907be2f 100644 --- a/source/core/src/main/com/csse3200/game/components/popupmenu/PopupMenuInputComponent.java +++ b/source/core/src/main/com/csse3200/game/components/popupmenu/PopupMenuInputComponent.java @@ -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. diff --git a/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java b/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java index e83210b48..4394d6309 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java +++ b/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java @@ -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(); @@ -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(); } } diff --git a/source/core/src/test/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponentTest.java b/source/core/src/test/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponentTest.java index f097b5bb3..3018c6434 100644 --- a/source/core/src/test/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponentTest.java @@ -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 @@ -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(); + } } diff --git a/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java index 1feb7101f..ddcb22223 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java @@ -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(); @@ -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);