From 50fe926a30e45facdaa4a1690acef3b449ac3aca Mon Sep 17 00:00:00 2001 From: Kevin <104761532+Hasakev@users.noreply.github.com> Date: Tue, 17 Oct 2023 01:13:44 +1000 Subject: [PATCH] Changed Upgrade UI to be balance team friendly Made Upgrades all crystals repair is scrap Cost display dynamically changes for required currency. --- .../components/gamearea/CurrencyDisplay.java | 2 +- .../gamearea/EngineerCountDisplay.java | 2 +- .../game/input/UpgradeUIComponent.java | 100 +++++++++++------- 3 files changed, 65 insertions(+), 39 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java b/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java index 7219ee9a6..858563858 100644 --- a/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/gamearea/CurrencyDisplay.java @@ -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()); diff --git a/source/core/src/main/com/csse3200/game/components/gamearea/EngineerCountDisplay.java b/source/core/src/main/com/csse3200/game/components/gamearea/EngineerCountDisplay.java index 151c4882e..6334e1b4a 100644 --- a/source/core/src/main/com/csse3200/game/components/gamearea/EngineerCountDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/gamearea/EngineerCountDisplay.java @@ -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"))); diff --git a/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java b/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java index 059995335..b68cc1205 100644 --- a/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java +++ b/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java @@ -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; @@ -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 @@ -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); @@ -209,14 +226,15 @@ 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)); @@ -224,7 +242,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 @@ -239,12 +257,13 @@ 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)); @@ -252,7 +271,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 @@ -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)); @@ -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 @@ -301,11 +324,12 @@ 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)); } @@ -313,11 +337,13 @@ 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", 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); } @@ -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)); @@ -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