From 8a750520ea24bfdb9fcc50b10ac9cfa9324cf972 Mon Sep 17 00:00:00 2001 From: Ahmad Abu-Aysha <111224176+The-AhmadAA@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:15:36 +1000 Subject: [PATCH] modified tower build to deselect after a tower placement --- .../game/components/maingame/UIElementsDisplay.java | 11 ----------- .../com/csse3200/game/input/BuildInputComponent.java | 3 +++ .../com/csse3200/game/services/CurrencyService.java | 5 +++++ .../csse3200/game/input/BuildInputComponentTest.java | 9 ++++++++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java index b84b24fe3..514d2ae20 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/UIElementsDisplay.java @@ -2,28 +2,19 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.utils.Array; -import com.csse3200.game.entities.Entity; -import com.csse3200.game.entities.factories.TowerFactory; import com.csse3200.game.screens.TowerType; 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; -import java.util.HashSet; -import java.util.Set; /** * Displays a button to represent the remaining mobs left in the current wave and a button to skip to the next wave. @@ -40,8 +31,6 @@ public class UIElementsDisplay extends UIComponent { }; private Sound click; private Sound hover; -// 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; diff --git a/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java b/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java index 451c99129..7116d8e31 100644 --- a/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java +++ b/source/core/src/main/com/csse3200/game/input/BuildInputComponent.java @@ -113,6 +113,9 @@ public void buildTower(int x, int y) { long soundId = buildSound.play(); buildSound.setVolume(soundId, 0.4f); + + // deselect the tower after building + ServiceLocator.getCurrencyService().setTowerType(null); } else { // play a sound to indicate an invalid action long soundId = errorSound.play(); diff --git a/source/core/src/main/com/csse3200/game/services/CurrencyService.java b/source/core/src/main/com/csse3200/game/services/CurrencyService.java index d76f7b147..4221d7a9c 100644 --- a/source/core/src/main/com/csse3200/game/services/CurrencyService.java +++ b/source/core/src/main/com/csse3200/game/services/CurrencyService.java @@ -49,6 +49,11 @@ public CurrencyDisplay getDisplay() { return display; } + /** + * Sets the tower type to build - triggered by pressing a tower build button in-game + * newTower can be a towertype or a null value to indicate clearing the value? + * @param newTower The towertype to be set for building, null if deselecting + */ public void setTowerType(TowerType newTower) { if (tower == newTower) { tower = null; diff --git a/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java b/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java index 3cd427659..4d6837a55 100644 --- a/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java +++ b/source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.java @@ -1,8 +1,11 @@ //package com.csse3200.game.input; // +//import com.badlogic.gdx.Gdx; +//import com.badlogic.gdx.Graphics; //import com.badlogic.gdx.graphics.g2d.TextureAtlas; //import com.badlogic.gdx.maps.tiled.TiledMap; //import com.badlogic.gdx.math.Vector2; +//import com.csse3200.game.GdxGame; //import com.csse3200.game.components.CameraComponent; //import com.csse3200.game.currency.Currency; //import com.csse3200.game.entities.Entity; @@ -58,6 +61,9 @@ // // @BeforeEach // void setup() { +// Gdx.graphics = mock(Graphics.class); +// when(Gdx.graphics.getDeltaTime()).thenReturn(10f); +// // GameTime gameTime = mock(GameTime.class); // CameraComponent camera = mock(CameraComponent.class); // when(gameTime.getDeltaTime()).thenReturn(0.02f); @@ -69,7 +75,8 @@ // // CurrencyService currencyService = new CurrencyService(); // ResourceService resourceService = new ResourceService(); -// MapService mapService = new MapService(camera); +// MapService mapService = mock(MapService.class); +// when(mapService.getComponent().tileToWorldPosition(0,0)).thenReturn(new Vector2(0,0)); // EntityService entityService = new EntityService(); // // ServiceLocator.registerResourceService(resourceService);