Skip to content

Commit

Permalink
Added pop-up when a turret is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Oct 1, 2023
1 parent 6b93621 commit d91ea8c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -35,6 +51,10 @@ public Camera getCamera() {
return camera;
}

public Stage getStage() {
return stage;
}

/**
* When the mouse is clicked, this method is called.
*
Expand All @@ -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);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d91ea8c

Please sign in to comment.