From a49a4fab52f1e38a6ae0e28dca71d7d7f0f6e272 Mon Sep 17 00:00:00 2001 From: Kevin <104761532+Hasakev@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:03:14 +1000 Subject: [PATCH] Added some important comments to files --- .../game/input/UpgradeUIComponent.java | 59 ++++++++++++++++--- .../game/screens/TurretSelectionScreen.java | 26 ++++++++ 2 files changed, 76 insertions(+), 9 deletions(-) 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 1d2052c14..8e0c3f4a1 100644 --- a/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java +++ b/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java @@ -66,10 +66,21 @@ public Camera getCamera() { return camera; } + /** + * Getter for the stage + * @return the stage + */ public Stage getStage() { return stage; } + /** + * Method to handle the touch down event + * @param screenX the x coordinate of the touch + * @param screenY the y coordinate of the touch + * @param pointer the pointer + * @param button the button + */ @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { Vector3 worldCoordinates = new Vector3((float) screenX, (float) screenY, 0); @@ -77,8 +88,11 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) { Vector2 cursorPosition = new Vector2(worldCoordinates.x, worldCoordinates.y); Entity clickedEntity = entityService.getEntityAtPosition(cursorPosition.x, cursorPosition.y); - if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null && clickedEntity.getComponent(TNTDamageComponent.class) == null) { -// // Clear all existing upgrade tables + // If the clicked position contains a turret, and the turret is upgradable and not a TNT tower + if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null + && clickedEntity.getComponent(TNTDamageComponent.class) == null) { + // TNT TowerUpgraderComponent can be removed later, but possibly useful for future sprint. + // Clear all existing upgrade tables logger.info("clickedEntity: " + clickedEntity); clearUpgradeTables(); // Check if there is an existing upgrade table for this turret entity @@ -112,28 +126,43 @@ private void clearUpgradeTables() { upgradeTables.clear(); } + /** + * Creates the upgrade table for the associated turret entity + *

+ * Each button has a listener that will upgrade the turret entity when clicked + * if the player has enough scrap. Additionally when the player hovers over a button + * the cost of the upgrade will be displayed in the cost display + *

+ * + * Currently, the cost of each upgrade is hardcoded to 10 scrap, this can be changed to global + * variables to make balancing easier (contact @Hasakev (Kevin) if confused) + * + * @param turretEntity the turret entity to create the upgrade table for (the entity that was clicked) + * @return the upgrade table for the turret entity + */ private Table createUpgradeTable(Entity turretEntity) { + // This is the overarching table that contains the close button, the inner table, and the cost display Table upgradeTable = new Table(); upgradeTable.top(); upgradeTable.defaults().pad(0).space(0); upgradeTable.setSize(60, 60); + + // The inner table contains the upgrade buttons and the stats display Table innerUpgradeTable = new Table(); innerUpgradeTable.top(); innerUpgradeTable.defaults().pad(10).space(0).padBottom(1); innerUpgradeTable.setSize(60, 60); // set table background String imageFilePath = "images/ui/Sprites/UI_Glass_Frame_Standard_01a.png"; - String upgradeButtonFilePath = "images/economy/scrapBanner.png"; Drawable drawableBackground = new TextureRegionDrawable(new TextureRegion(new Texture(imageFilePath))); innerUpgradeTable.setBackground(drawableBackground); + // Stying for all the buttons Drawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/ui/Sprites/UI_Glass_Button_Small_Lock_01a2.png"))); - Drawable econDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(upgradeButtonFilePath))); TextButton.TextButtonStyle style = new TextButton.TextButtonStyle( drawable, drawable, drawable, new BitmapFont()); - TextButton.TextButtonStyle econStyle = new TextButton.TextButtonStyle( - econDrawable, econDrawable, econDrawable, new BitmapFont()); - // create button + + // Default values for the stats int maxHealth = turretEntity.getComponent(CombatStatsComponent.class).getMaxHealth(); int currentHealth = turretEntity.getComponent(CombatStatsComponent.class).getHealth(); turretEntity.getComponent(CombatStatsComponent.class).setHealth(5); // for testing @@ -173,9 +202,12 @@ public void clicked(InputEvent event, float x, float y) { Drawable fireRateDrawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/hourglass.png"))); Image fireRateImage = new Image(fireRateDrawable); - Drawable healthStyle = new TextureRegionDrawable(new TextureRegion(new Texture("images/heart_upgrade.png"))); ImageButton upgradeHealth = new ImageButton(healthStyle); + + //// UPGRADE BUTTONS //// + + // Health upgrade button upgradeHealth.setScale(0.8f); upgradeHealth.addListener(new ClickListener() { @Override @@ -204,6 +236,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) } }); + // Attack upgrade button Drawable attackStyle = new TextureRegionDrawable(new TextureRegion(new Texture("images/damage_upgrade.png"))); ImageButton upgradeAttack = new ImageButton(attackStyle); upgradeAttack.addListener(new ClickListener() { @@ -232,7 +265,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) }); - + // Fire rate upgrade button Drawable asStyle = new TextureRegionDrawable(new TextureRegion(new Texture("images/hourglass_upgrade.png"))); ImageButton upgradeFireRate = new ImageButton(asStyle); upgradeFireRate.addListener(new ClickListener() { @@ -265,6 +298,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) } }); + // Repair button Drawable repair = new TextureRegionDrawable(new TextureRegion(new Texture("images/hammer.png"))); ImageButton repairButton = new ImageButton(repair); repairButton.addListener(new ClickListener() { @@ -299,7 +333,10 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) innerUpgradeTable.add(healthLabel).expandX().left(); innerUpgradeTable.row(); TextButton upgradeIncome = null; + // if the turret has an income upgrade component, add the income upgrade button if (turretEntity.getComponent(IncomeUpgradeComponent.class) != null) { + + // Income label and upgrade button Drawable incomeDrawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/economy/scrap.png"))); Image incomeImage = new Image(incomeDrawable); Label incomeLabel = new Label(String.format("%.2f", turretEntity.getComponent(IncomeUpgradeComponent.class).getIncomeRate()), createLabelStyle()); @@ -365,6 +402,10 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) return upgradeTable; } + /** + * Creates a label style for the upgrade table + * @return the label style + */ private LabelStyle createLabelStyle() { LabelStyle style = new LabelStyle(); style.font = new BitmapFont(); diff --git a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java index a679dd30c..7bfe77121 100644 --- a/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/TurretSelectionScreen.java @@ -59,6 +59,10 @@ public class TurretSelectionScreen extends ScreenAdapter { private static final Logger logger = LoggerFactory.getLogger(MainMenuScreen.class); + /** + * Constructor for the TurretSelectionScreen + * @param game The game object + */ public TurretSelectionScreen(GdxGame game) { this.game = game; stage = new Stage(new ScreenViewport()); @@ -219,10 +223,23 @@ public void render(float delta) { stage.draw(); // Draw the stage } + /** + * Returns the list of selected turrets + * @return The list of selected turrets + */ public List getTurretList() { return turretList; } + /** + * Creates a button with the specified images and text + * @param defaultImageFilePath The file path to the default image + * @param alternateImageFilePath The file path to the alternate image + * @param cost The cost of the turret + * @param towerName The name of the turret + * @param turretDesc The description of the turret + * @return The created button + */ private TextButton createButton(String defaultImageFilePath, String alternateImageFilePath, String cost, String towerName, String turretDesc) { Drawable defaultDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(defaultImageFilePath))); @@ -280,14 +297,23 @@ public void exit(InputEvent event, float x, float y, int pointer, com.badlogic.g return tb; } + /** + * Updates the description label + */ private void updateDescriptionLabel() { descriptionLabel.setText("Description: " + turretDescription); } + /** + * Updates the description text + */ private void updateDescriptionText() { descText.setText(turretDescriptionText); } + /** + * Disposes of the stage + */ @Override public void dispose() { stage.dispose();