Skip to content

Commit

Permalink
Implemented cap to tower selection (you can only select 5 max)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Sep 10, 2023
1 parent 092060c commit eb45138
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion source/core/assets/flat-earth/skin/flat-earth-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: {
font: font
fontColor: black
fontColor: white
}
button: {
font: button
Expand Down
14 changes: 7 additions & 7 deletions source/core/src/main/com/csse3200/game/screens/TowerType.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.csse3200.game.screens;

public enum TowerType {
WEAPON("images/towers/turret01.atlas", "Weapon Tower"),
TNT("images/towers/TNTTower.atlas", "TNT Tower"),
DROID("images/towers/DroidTower.atlas", "Droid Tower"),
WALL("images/towers/wallTower.png", "Wall Tower"),
FIRE("images/towers/fire_tower_atlas.atlas", "Fire Tower"),
STUN("images/towers/stun_tower.atlas", "Stun Tower"),
INCOME("images/economy/econ-tower.atlas", "Income Tower");
WEAPON("images/towers/turret_deployed.png", "Weapon Tower"),
TNT("images/towers/turret_deployed.png", "TNT Tower"),
DROID("images/towers/turret_deployed.png", "Droid Tower"),
WALL("images/towers/turret_deployed.png", "Wall Tower"),
FIRE("images/towers/turret_deployed.png", "Fire Tower"),
STUN("images/towers/turret_deployed.png", "Stun Tower"),
INCOME("images/towers/turret_deployed.png", "Income Tower");

private final String imagePath;
private final String towerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
Expand All @@ -24,19 +25,25 @@

public class TurretSelectionScreen extends ScreenAdapter {

private static final int MAX_SELECTED_TURRETS = 5;
private Stage stage;
private List<TowerType> turretList;
private TextButton confirmButton;

private GdxGame game;

private Label message;
private Label turretsPicked;
private Table table;
private Set<TowerType> selectedTurrets = new HashSet<>();

private static final Logger logger = LoggerFactory.getLogger(MainMenuScreen.class);

public TurretSelectionScreen(GdxGame game) {
this.game = game;
stage = new Stage(new ScreenViewport());
Table table = new Table();
table = new Table();


turretList = new ArrayList<>();
// Add turrets to the list
Expand All @@ -49,7 +56,11 @@ public TurretSelectionScreen(GdxGame game) {
turretList.add(TowerType.INCOME);



Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
message = new Label("Select your turrets", skin);
turretsPicked = new Label("Turrets picked: ", skin);

confirmButton = new TextButton("Continue", skin);
confirmButton.addListener(new ClickListener() {
@Override
Expand All @@ -59,29 +70,48 @@ public void clicked(InputEvent event, float x, float y) {
});



table.add(message).row();
table.add(turretsPicked).row();
for (TowerType turret : turretList) {
TextButton turretButton = new TextButton(turret.getTowerName(), skin);
turretButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
logger.info(String.valueOf(selectedTurrets.size()));
if (selectedTurrets.size() > MAX_SELECTED_TURRETS) {
message.setText("You can only select up to 5 turrets.");
} else {
message.setText("Select your turrets");
}
if (selectedTurrets.contains(turret)) {
// Turret is already selected, unselect it
selectedTurrets.remove(turret);
// You can also change the button appearance to indicate unselection
logger.info(selectedTurrets.toString());
} else {
turretsPicked.setText("Turrets picked: " + selectedTurrets.toString());
} else if (selectedTurrets.size() == MAX_SELECTED_TURRETS) {
// Turret is not selected, but the max number of turrets has been reached
message.setText("You can only select up to 5 turrets.");
} else if (selectedTurrets.size() < MAX_SELECTED_TURRETS) {
// Turret is not selected, select it
selectedTurrets.add(turret);
turretsPicked.setText("Turrets picked: " + selectedTurrets.toString());
logger.info(selectedTurrets.toString());
}
else {
// Turret is not selected, select it
selectedTurrets.add(turret);
turretsPicked.setText("Turrets picked: " + selectedTurrets.toString());
logger.info(selectedTurrets.toString());

// You can change the button appearance to indicate selection
}

}
});
table.add(turretButton).row();
}
table.add(confirmButton).padBottom(-400).row();
table.add(confirmButton).padBottom(20).row();

stage.addActor(table);
table.setFillParent(true);
Expand Down

0 comments on commit eb45138

Please sign in to comment.