Skip to content

Commit

Permalink
Fixed animation for in-game ui buttons and finished start-up animatio…
Browse files Browse the repository at this point in the history
…ns for in-game ui labels
  • Loading branch information
shiv-0831 committed Oct 16, 2023
1 parent 781a328 commit 8cfe268
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Texture;
Expand Down Expand Up @@ -56,11 +57,18 @@ private void addActors() {
ServiceLocator.getCurrencyService().getCrystal().getAmount());

table.add(scrapsTb).width(scrapsTb.getWidth() * 0.5f).height(scrapsTb.getHeight() * 0.5f);
table.row();
table.add(crystalsTb).width(crystalsTb.getWidth() * 0.5f).height(crystalsTb.getHeight() * 0.5f);
table.setDebug(true);
stage.addActor(table);

scrapsTb.addAction(new SequenceAction(Actions.fadeIn(4f)));
crystalsTb.addAction(new SequenceAction(Actions.fadeIn(8f)));
scrapsTb.setPosition(table.getX() - 200, Gdx.graphics.getHeight() - 205);
scrapsTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20, Gdx.graphics.getHeight() - 205,
1f, Interpolation.fastSlow)));

crystalsTb.setPosition(table.getX() - 200, Gdx.graphics.getHeight() - 268);
crystalsTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20, Gdx.graphics.getHeight() - 268,
1f, Interpolation.fastSlow)));
}

private TextButton createButton(String imageFilePath, int value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.csse3200.game.components.gamearea;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
Expand Down Expand Up @@ -34,6 +36,7 @@ private void addActors() {
table.top().left();
table.setFillParent(true);
table.padTop(80f).padLeft(20f);
table.setDebug(true);

Drawable drawable = new TextureRegionDrawable(new TextureRegion(
new Texture("images/engineers/engineerBanner.png")));
Expand All @@ -54,7 +57,10 @@ private void addActors() {
table.add(engineerTb).width(engineerTb.getWidth() * 0.5f).height(engineerTb.getHeight() * 0.5f);
stage.addActor(table);

engineerTb.addAction(new SequenceAction(Actions.fadeIn(4f)));
// Animate the engineer count label
engineerTb.setPosition(table.getX() - 200, Gdx.graphics.getHeight() - 145);
engineerTb.addAction(new SequenceAction(Actions.moveTo(table.getX() + 20, Gdx.graphics.getHeight() - 145,
1f, Interpolation.fastSlow)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ private void addActors() {
// Create and position the tables that will hold the buttons.

// Contains the tower build menu buttons
towerTable.top().padTop(50f);
towerTable.top().padTop(80f);
towerTable.setFillParent(true);

// Contains other buttons (just pause at this stage)
buttonTable.top().right().padTop(50f).padRight(80f);
buttonTable.top().right().padTop(80f).padRight(80f);
buttonTable.setFillParent(true);

progressTable.top().center().setWidth(500f);
progressTable.setFillParent(true);

levelNameTable.top().left().padLeft(20f).padTop(20f);
levelNameTable.center().top().padLeft(20f).padTop(20f).pad(20f);
levelNameTable.setFillParent(true);

// Stores tower defaults, in case towers haven't been set in the tower select screen
Expand Down Expand Up @@ -306,7 +306,7 @@ public void clicked(InputEvent event, float x, float y) {
progressbar = new LevelProgressBar(500, 10);

levelNameTable.setSkin(getSkin());
levelNameTable.add(this.level, "title");
levelNameTable.add(this.level, "default");

// Scale all the tower build buttons down
// Add all buttons to their respective tables and position them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UIElementsDisplay extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(UIElementsDisplay.class);
private static final float Z_INDEX = 2f;
private final Table buttonTable = new Table();
private final Table timerTable = new Table();
private TextButton remainingMobsButton;
private TextButton timerButton;

Expand All @@ -44,15 +45,14 @@ private void addActors() {
+ ServiceLocator.getWaveService().getEnemyCount());

remainingMobsButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 230);
remainingMobsButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 218,
remainingMobsButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 217,
Gdx.graphics.getHeight() - 230, 1f, Interpolation.fastSlow)));

buttonTable.top().right().padTop(130f).padRight(80f);
buttonTable.top().right().padTop(160f).padRight(80f);
buttonTable.setFillParent(true);

buttonTable.add(remainingMobsButton).right();
buttonTable.row();
buttonTable.add(timerButton);


stage.addActor(buttonTable);

Expand Down Expand Up @@ -82,10 +82,11 @@ public void createTimerButton() {
timerButton = ButtonFactory.createButton("Next wave in:"
+ (ServiceLocator.getWaveService().getNextWaveTime() / 1000));
timerButton.setPosition(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 300);
timerButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 445,
timerButton.addAction(new SequenceAction(Actions.moveTo(Gdx.graphics.getWidth() - 435,
Gdx.graphics.getHeight() - 300, 1f, Interpolation.fastSlow)));
timerButton.setDisabled(true);
buttonTable.row();
buttonTable.add(timerButton).padRight(10f);
buttonTable.add(timerButton);
}

/**
Expand All @@ -106,10 +107,12 @@ public void updateTimerButton() {
String finalTime = String.format("%02d:%02d", minutes, seconds);
if (ServiceLocator.getTimeSource().getTime() < ServiceLocator.getWaveService().getNextWaveTime()) {
if (!findActor(timerButton)) {
remainingMobsButton.setDisabled(false);
createTimerButton();
}
timerButton.setText("Next wave in: " + finalTime);
} else {
remainingMobsButton.setDisabled(true);
timerButton.addAction(new SequenceAction(Actions.fadeOut(1f), Actions.removeActor()));
stage.act();
stage.draw();
Expand Down

0 comments on commit 8cfe268

Please sign in to comment.