Skip to content

Commit

Permalink
Modified TurretSelectionScreen Class to improve UI
Browse files Browse the repository at this point in the history
Next objective is to make the buttons individual for
  • Loading branch information
SonjaMcNeilly committed Sep 30, 2023
1 parent cb36f90 commit c4710d7
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 58 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import org.w3c.dom.Text;

/**
* A UI component for displaying the currency owned
Expand All @@ -28,6 +29,7 @@ public class CurrencyDisplay extends UIComponent {
private TextButton scrapsTb;
private TextButton crystalsTb;
private Sound clickSound;
private TextButton test;

/**
* Adds actors to stage
Expand All @@ -53,9 +55,11 @@ private void addActors() {
ServiceLocator.getCurrencyService().getScrap().getAmount());
crystalsTb = createButton("images/economy/crystalBanner.png",
ServiceLocator.getCurrencyService().getCrystal().getAmount());
test = createButton("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", 100);

table.add(scrapsTb).width(scrapsTb.getWidth() * 0.5f).height(scrapsTb.getHeight() * 0.5f);
table.add(crystalsTb).width(crystalsTb.getWidth() * 0.5f).height(crystalsTb.getHeight() * 0.5f);
table.add(test).width(test.getWidth() * 0.5f).height(test.getHeight() * 0.5f);
stage.addActor(table);
}

Expand All @@ -69,7 +73,7 @@ private TextButton createButton(String imageFilePath, int value) {
tb.setDisabled(true);
tb.getLabel().setAlignment(Align.right);

tb.pad(0, 0, 0, 50);
tb.pad(0, 0, 0, 0);
tb.setTransform(true);

return tb;
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,19 +1,19 @@
package com.csse3200.game.screens;

public enum TowerType {
WEAPON("images/towers/turret_deployed.png", "Weapon Tower",
WEAPON("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "Weapon Tower",
"The Weapon Tower is a simple and basic turret that fires rapid shots at enemies dealing damage over time."),
TNT("images/towers/turret_deployed.png", "TNT Tower",
TNT("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "TNT Tower",
"The TNT Tower launches explosive projectiles, dealing area damage to groups of enemies."),
DROID("images/towers/turret_deployed.png", "Droid Tower",
DROID("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "Droid Tower",
"Droid Towers deploy robotic helpers that assist in combat and provide support to nearby turrets."),
WALL("images/towers/turret_deployed.png", "Wall Tower",
WALL("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "Wall Tower",
"The Wall Tower creates barriers to block enemy paths, slowing down their progress."),
FIRE("images/towers/turret_deployed.png", "Fire Tower",
FIRE("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "Fire Tower",
"The Fire Tower emits flames, causing damage over time to enemies caught in its fiery radius."),
STUN("images/towers/turret_deployed.png", "Stun Tower",
STUN("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "Stun Tower",
"The Stun Tower releases electric shocks that temporarily immobilize and damage enemies."),
INCOME("images/towers/turret_deployed.png", "Income Tower",
INCOME("images/ui/Sprites/UI_Glass_Frame_Standard_01a.png", "Income Tower",
"The Income Tower generates additional in-game currency over time.");

private final String imagePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
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;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Text;


import java.util.*;
Expand Down Expand Up @@ -92,59 +99,21 @@ public void clicked(InputEvent event, float x, float y) {
Table turretTable = new Table();
turretTable.center(); // Center the contents of the nested table

Pixmap pixmap200 = new Pixmap(Gdx.files.internal(String.valueOf(Gdx.files.internal(turret.getImagePath()))));
Pixmap pixmap100 = new Pixmap(150, 150, pixmap200.getFormat());
pixmap100.drawPixmap(pixmap200,
0, 0, pixmap200.getWidth(), pixmap200.getHeight(),
0, 0, pixmap100.getWidth(), pixmap100.getHeight()
);

// Load the turret image
Texture turretTexture = new Texture(Gdx.files.internal(turret.getImagePath()));
Texture turretTexture = new Texture(pixmap100);
Image turretImage = new Image(turretTexture);

TextButton button = createButton("images/turret-select/imageedit_2_8132799771.png",
"images/ui/Sprites/UI_Glass_Frame_Lite_01a.png", 100);
// Add the image to the nested table
turretTable.add(turretImage).pad(10).row();

// Create a label for the turret description
Label turretDescriptionLabel = new Label(turret.getDescription(), skin);
turretDescriptionLabel.setWrap(true); // Wrap text if it's too long

// Add the description label to the nested table
turretTable.add(turretDescriptionLabel).center().width(200).pad(10).row(); // Adjust width if needed

// Create a TextButton for the turret name
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());
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
}
}
});

// Add the turret name button to the nested table
turretTable.add(turretButton).center();
//turretTable.add(turretImage).pad(10).row();
turretTable.add(button).pad(10).row();

// Add the nested table to the main table
table.add(turretTable).pad(10).center();
Expand All @@ -161,6 +130,7 @@ public void clicked(InputEvent event, float x, float y) {
// Centered the "continue" button
table.add(confirmButton).center().colspan(4).padBottom(20).row();


// Center the table within the stage
table.center();
stage.addActor(table);
Expand All @@ -178,6 +148,44 @@ public void render(float delta) {
stage.draw();
}

private TextButton createButton(String defaultImageFilePath, String alternateImageFilePath, int cost) {
Drawable defaultDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(defaultImageFilePath)));
Drawable alternateDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(alternateImageFilePath)));

TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
buttonStyle.font = new BitmapFont(); // Set your desired font
buttonStyle.up = defaultDrawable; // Default state

// Create button
TextButton tb = new TextButton(String.format("%d", cost), buttonStyle);

// Add click listener to toggle the image
final boolean[] isDefaultImage = {true}; // Keep track of the image state

tb.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);

// Toggle the image
if (isDefaultImage[0]) {
tb.getStyle().up = alternateDrawable;
} else {
tb.getStyle().up = defaultDrawable;
}

// Update the image state
isDefaultImage[0] = !isDefaultImage[0];
}
});

tb.setDisabled(true);

return tb;
}



public List<TowerType> getTurretList() {
return turretList;
}
Expand Down
8 changes: 8 additions & 0 deletions source/core/src/main/com/csse3200/game/screens/Turrets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.csse3200.game.screens;

import com.badlogic.gdx.Gdx;

public class Turrets {
public final static int[] BASIC = {
};
}

0 comments on commit c4710d7

Please sign in to comment.