From d91ea8ca38a0bd50a080ba64b3d25504643b8608 Mon Sep 17 00:00:00 2001 From: Kevin <104761532+Hasakev@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:58:39 +1000 Subject: [PATCH] Added pop-up when a turret is clicked --- .../game/input/UpgradeUIComponent.java | 46 ++++++++++++++++++- .../csse3200/game/screens/MainGameScreen.java | 2 +- 2 files changed, 46 insertions(+), 2 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 52a06442c..cb004554d 100644 --- a/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java +++ b/source/core/src/main/com/csse3200/game/input/UpgradeUIComponent.java @@ -1,9 +1,21 @@ package com.csse3200.game.input; import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.Drawable; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; +import com.badlogic.gdx.utils.Align; import com.csse3200.game.areas.ForestGameArea; +import com.csse3200.game.components.gamearea.TowerUpgradeDisplay; import com.csse3200.game.components.tower.TowerUpgraderComponent; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.EntityService; @@ -15,16 +27,20 @@ public class UpgradeUIComponent extends InputComponent { private static final Logger logger = LoggerFactory.getLogger(ForestGameArea.class); private final EntityService entityService; private final Camera camera; + private final Stage stage; + + private Table upgradeTable; int value; /** * Constructor for the UpgradeUIComponent * @param camera the camera to be used, this is the camera that the game is rendered with */ - public UpgradeUIComponent(Camera camera) { + public UpgradeUIComponent(Camera camera, Stage stage) { this.value = ServiceLocator.getCurrencyService().getScrap().getAmount(); this.entityService = ServiceLocator.getEntityService(); this.camera = camera; + this.stage = stage; } /** @@ -35,6 +51,10 @@ public Camera getCamera() { return camera; } + public Stage getStage() { + return stage; + } + /** * When the mouse is clicked, this method is called. * @@ -53,10 +73,34 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) { if (clickedEntity != null && clickedEntity.getComponent(TowerUpgraderComponent.class) != null) { logger.info("clicked a turret that is upgradable!"); + createUpgradeTable(clickedEntity, screenX, screenY); + stage.addActor(upgradeTable); return true; } return false; } + private void createUpgradeTable(Entity turretEntity, int screenX, int screenY) { + upgradeTable = new Table(); + upgradeTable.align(Align.top); + upgradeTable.setPosition(screenX, screenY); + + // Create a BitmapFont for the LabelStyle + BitmapFont font = new BitmapFont(); // You can customize this font as needed + + Drawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture("images/ui/Sprites/UI_Glass_Button_Small_Lock_01a2.png"))); + TextButton.TextButtonStyle style = new TextButton.TextButtonStyle( + drawable, drawable, drawable, new BitmapFont()); + + // create button + TextButton tb = new TextButton("Hello World", style); + tb.setDisabled(true); + + upgradeTable.add(tb); + + upgradeTable.setVisible(true); + } + + } diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index 42afa287f..3dc66d55a 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -97,7 +97,7 @@ public MainGameScreen(GdxGame game) { /* Input components */ InputComponent dropInputHandler = new DropInputComponent(renderer.getCamera().getCamera()); - InputComponent upgradeInputHandler = new UpgradeUIComponent(renderer.getCamera().getCamera()); + InputComponent upgradeInputHandler = new UpgradeUIComponent(renderer.getCamera().getCamera(), renderer.getStage()); ServiceLocator.getInputService().register(dropInputHandler); ServiceLocator.getInputService().register(upgradeInputHandler);