Skip to content

Commit

Permalink
Changed Upgrade UI to be balance team friendly
Browse files Browse the repository at this point in the history
Made Upgrades all crystals
repair is scrap

Cost display dynamically changes for required currency.
  • Loading branch information
Hasakev committed Oct 16, 2023
1 parent 1232b9d commit 50fe926
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void addActors() {
table = new Table();
table.top().left();
table.setFillParent(true);
table.padTop(60f).padLeft(5f);
table.padTop(140f).padLeft(20f);

scrapsTb = createButton("images/economy/scrapBanner.png",
ServiceLocator.getCurrencyService().getScrap().getAmount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private void addActors() {
Table table = new Table();
table.top().left();
table.setFillParent(true);
table.padTop(0f).padLeft(5f);
table.padTop(80f).padLeft(20f);

Drawable drawable = new TextureRegionDrawable(new TextureRegion(
new Texture("images/engineers/engineerBanner.png")));
Expand Down
100 changes: 63 additions & 37 deletions source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@
import static java.lang.Math.round;

public class UpgradeUIComponent extends InputComponent {

// CONSTANTS

/**
* The cost for all upgrades are 10 crystals
*/
private static final int UPGRADE_COST = 10; // Crystal

/**
* The cost for repairing a turret is 50 scrap
*/
private static final int REPAIR_COST = 50; // Scrap
private static final float ATTACK_RATE_INCREASE = 0.2f;
private static final int ATTACK_INCREASE = 10; // Damage
private static final int HEALTH_INCREASE = 10; // Health
private static final int TIME_DECREASE = 5; // Scrap
private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class);
private final EntityService entityService;
private final Camera camera;
Expand Down Expand Up @@ -142,7 +158,7 @@ private Table createUpgradeTable(Entity turretEntity) {
upgradeTable.top().left();
upgradeTable.defaults().pad(0).space(0);
upgradeTable.setSize(60, 60);
upgradeTable.padTop(5f).padLeft(5f);
upgradeTable.padTop(30f).padLeft(5f);
upgradeTable.setPosition(0, round((float) Gdx.graphics.getHeight() / 1.3f));

// The inner table contains the upgrade buttons and the stats display
Expand Down Expand Up @@ -172,11 +188,12 @@ private Table createUpgradeTable(Entity turretEntity) {
costDisplay.setWidth(0);
costDisplay.setBackground(drawableBackground);
// Create an Image for the scrap icon
Drawable costDrawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/economy/scrap.png")));
Drawable costDrawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/economy/crystal.png")));
Drawable costDrawableScrap = new TextureRegionDrawable(new TextureRegion(new Texture("images/economy/scrap.png")));
Image costImage = new Image(costDrawable);
costDisplay.add(costImage).center();
costImage.setScaling(Scaling.none);
Label costDisplayLabel = new Label("100", createLabelStyle());
Label costDisplayLabel = new Label("You shouldn't see this", createLabelStyle());
costDisplay.add(costDisplayLabel).padLeft(0);

TextButton closeButton = new TextButton("X", style);
Expand Down Expand Up @@ -209,22 +226,23 @@ public void clicked(InputEvent event, float x, float y) {
upgradeHealth.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
value = ServiceLocator.getCurrencyService().getScrap().getAmount();
value = ServiceLocator.getCurrencyService().getCrystal().getAmount();
logger.info("clicked");
if (value >= 100) {
value -= 100;
ServiceLocator.getCurrencyService().getScrap().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats();
if (value >= UPGRADE_COST) {
value -= UPGRADE_COST;
ServiceLocator.getCurrencyService().getCrystal().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateCrystalsStats();

turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.MAXHP, 10);
turretEntity.getComponent(TowerUpgraderComponent.class)
.upgradeTower(TowerUpgraderComponent.UPGRADE.MAXHP, HEALTH_INCREASE);
int currentHealth = turretEntity.getComponent(CombatStatsComponent.class).getHealth();
int maxHealth = turretEntity.getComponent(CombatStatsComponent.class).getMaxHealth();
healthLabel.setText(String.format("%d/%d", currentHealth, maxHealth));
}
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
costDisplayLabel.setText("10");
costDisplayLabel.setText(String.format("%d", UPGRADE_COST));
costDisplay.setVisible(true);
}
@Override
Expand All @@ -239,20 +257,21 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
upgradeAttack.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
value = ServiceLocator.getCurrencyService().getScrap().getAmount();
if (value >= 10) {
value -= 10;
ServiceLocator.getCurrencyService().getScrap().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats();
turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.ATTACK, 5);
value = ServiceLocator.getCurrencyService().getCrystal().getAmount();
if (value >= UPGRADE_COST) {
value -= UPGRADE_COST;
ServiceLocator.getCurrencyService().getCrystal().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateCrystalsStats();
turretEntity.getComponent(TowerUpgraderComponent.class)
.upgradeTower(TowerUpgraderComponent.UPGRADE.ATTACK, ATTACK_INCREASE);

int attack = turretEntity.getComponent(CombatStatsComponent.class).getBaseAttack();
attackLabel.setText(String.format("%d", attack));
}
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
costDisplayLabel.setText("10");
costDisplayLabel.setText(String.format("%d", UPGRADE_COST));
costDisplay.setVisible(true);
}
@Override
Expand All @@ -268,14 +287,18 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
upgradeFireRate.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
value = ServiceLocator.getCurrencyService().getScrap().getAmount();
if (value >= 10) {
value -= 10;
ServiceLocator.getCurrencyService().getScrap().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats();
float newFireRate = turretEntity.getComponent(UpgradableStatsComponent.class).getAttackRate() + 0.2f;
turretEntity.getComponent(UpgradableStatsComponent.class).setAttackRate(newFireRate);
turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE, (int) newFireRate * 5);
value = ServiceLocator.getCurrencyService().getCrystal().getAmount();
if (value >= UPGRADE_COST) {
value -= UPGRADE_COST;
ServiceLocator.getCurrencyService().getCrystal().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateCrystalsStats();
float newFireRate = turretEntity.getComponent(UpgradableStatsComponent.class)
.getAttackRate() + ATTACK_RATE_INCREASE;
turretEntity.getComponent(UpgradableStatsComponent.class)
.setAttackRate(newFireRate);
turretEntity.getComponent(TowerUpgraderComponent.class)
.upgradeTower(TowerUpgraderComponent.UPGRADE.FIRERATE,
(int) newFireRate * 5);

float fireRate = turretEntity.getComponent(UpgradableStatsComponent.class).getAttackRate();
fireRateLabel.setText(String.format("%.2f", fireRate));
Expand All @@ -285,7 +308,7 @@ public void clicked(InputEvent event, float x, float y) {

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
costDisplayLabel.setText("10");
costDisplayLabel.setText(String.format("%d", UPGRADE_COST));
costDisplay.setVisible(true);
}
@Override
Expand All @@ -301,23 +324,26 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
@Override
public void clicked(InputEvent event, float x, float y) {
value = ServiceLocator.getCurrencyService().getScrap().getAmount();
if (value >= 100) {
value -= 100;
if (value >= REPAIR_COST) {
value -= REPAIR_COST;
ServiceLocator.getCurrencyService().getScrap().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats();
turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.REPAIR, 0);
turretEntity.getComponent(TowerUpgraderComponent.class)
.upgradeTower(TowerUpgraderComponent.UPGRADE.REPAIR, 0);
int currentHealth = turretEntity.getComponent(CombatStatsComponent.class).getHealth();
healthLabel.setText(String.format("%d/%d", currentHealth, maxHealth));
}
}

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
costDisplayLabel.setText("10");
costDisplayLabel.setText(String.format("%d", REPAIR_COST));
costImage.setDrawable(costDrawableScrap);
costDisplay.setVisible(true);
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
costImage.setDrawable(costDrawable);
costDisplay.setVisible(false);
}

Expand Down Expand Up @@ -345,12 +371,12 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
upgradeIncome.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
value = ServiceLocator.getCurrencyService().getScrap().getAmount();
if (value >= 10 && turretEntity.getComponent(IncomeUpgradeComponent.class).getIncomeRate() >= 10) {
value -= 10;
ServiceLocator.getCurrencyService().getScrap().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateScrapsStats();
float newIncome = turretEntity.getComponent(IncomeUpgradeComponent.class).getIncomeRate() - 5;
value = ServiceLocator.getCurrencyService().getCrystal().getAmount();
if (value >= UPGRADE_COST && turretEntity.getComponent(IncomeUpgradeComponent.class).getIncomeRate() >= 10) {
value -= UPGRADE_COST;
ServiceLocator.getCurrencyService().getCrystal().setAmount(value);
ServiceLocator.getCurrencyService().getDisplay().updateCrystalsStats();
float newIncome = turretEntity.getComponent(IncomeUpgradeComponent.class).getIncomeRate() - TIME_DECREASE;
turretEntity.getComponent(IncomeUpgradeComponent.class).setIncomeRate(newIncome);
turretEntity.getComponent(TowerUpgraderComponent.class).upgradeTower(TowerUpgraderComponent.UPGRADE.INCOME, (int) newIncome);
incomeLabel.setText(String.format("%.2f", newIncome));
Expand All @@ -361,7 +387,7 @@ public void clicked(InputEvent event, float x, float y) {

@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
costDisplayLabel.setText("10");
costDisplayLabel.setText(String.format("%d", UPGRADE_COST));
costDisplay.setVisible(true);
}
@Override
Expand Down

0 comments on commit 50fe926

Please sign in to comment.