-
Notifications
You must be signed in to change notification settings - Fork 4
Turret Selection Screen
The turret selection screen allows the user to pick 5 turrets from a list of all turrets. (The 5 turret maximum is highly subject to change)
The user is given a description on what each turret does. This is shown when the user hovers over a turret, it will appear in the top right of the screen.
The story screen uses a basic screen model that includes:
- show()
- render()
- resize()
- dispose()
A createButton()
function was made to make all of the buttons on the screen, including the description label and description text box.
private TextButton createButton(String defaultImageFilePath, String alternateImageFilePath, String cost,
String towerName, String turretDesc) {
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(cost, buttonStyle);
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];
}
});
// Add a hover listener to update turretName when hovered over
tb.addListener(new InputListener() {
@Override
public void enter(InputEvent event, float x, float y, int pointer, com.badlogic.gdx.scenes.scene2d.Actor fromActor) {
super.enter(event, x, y, pointer, fromActor);
turretDescription = towerName; // Update turretDescription when hovering over the button
turretDescriptionText = turretDesc;
updateDescriptionLabel();
updateDescriptionText();
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, com.badlogic.gdx.scenes.scene2d.Actor toActor) {
super.exit(event, x, y, pointer, toActor);
turretDescription = ""; // Reset turretDescription when exiting the button
turretDescriptionText = "";
updateDescriptionLabel();
updateDescriptionText();
}
});
tb.setDisabled(true);
return tb;
}
This handles the creation of buttons, button clicking, changing image when clicked, and updating the description label and description text on hover.
The updateDescriptionLabel()
function sets the description label to display the current turret name which is stored under turretDescripion
private void updateDescriptionLabel() {
descriptionLabel.setText("Description: " + turretDescription);
}
The updateDescriptionText()
function sets the description text to display the current turret description which is stored under turretDescripionText
private void updateDescriptionText() {
descText.setText(turretDescriptionText);
}
Due to the state of UI, it cannot be directly JUNIT/mockito tested. Here is a test plan for the screen:
- Background appears.
- Image and price display for each turret.
- Clicking a turret correctly adds it to the list of turrets picked.
- Clicking a turret in the list of turrets picked correctly removes turret from list.
- Clicking a turret in the list when it exceeds the maximum correctly displays message.
- Hovering over a turret button displays it's correct tower name
- Hovering over a turret button displays it's correct description text
- Clicking a button makes a clicking sound
- Back button appears
- Clicking a turret in the list when it exceeds the maximum correctly stops turrets from being added to the list.
- Clicking continue takes you to the main game screen
The test was manually conducted 3 times, all tests passed.
See Link
Logic functions the same for this turret selection screen