Skip to content

Commit

Permalink
Merge pull request #641 from UQcsse3200/team2_upgrades2
Browse files Browse the repository at this point in the history
Team2 upgrades2
  • Loading branch information
willembor authored Oct 16, 2024
2 parents c458735 + bebb58d commit 8402f8a
Show file tree
Hide file tree
Showing 15 changed files with 535 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void clicked(InputEvent event, float x, float y) {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
logger.debug("Restart button clicked");
game.resetScreen();
entity.getEvents().trigger("restart");
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.csse3200.game.components.ordersystem;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
Expand Down Expand Up @@ -144,8 +145,19 @@ public void create() {
ServiceLocator.getDocketService().getEvents().addListener("removeBigTicket", this::removeBigTicket);

//From Team 2, these listeners are for our dance party upgrade to pause and unpause docket times
ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->setPaused(true));
ServiceLocator.getDocketService().getEvents().addListener("UnDancing", ()->setPaused(false));
// ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{
// addTimeToDockets(600000);
// });
ServiceLocator.getRandomComboService().getEvents().addListener("Dancing", ()->{
addTimeToDockets(600000);
});

ServiceLocator.getDocketService().getEvents().addListener("paused", ()->{
setPaused(true);
});
ServiceLocator.getDocketService().getEvents().addListener("unpaused", ()->{
setPaused(false);
});

//From team 2, I used your dispose method here when listening for a new day, so current dockets get removed
//when the end of day occurs
Expand All @@ -165,7 +177,7 @@ public boolean keyDown(InputEvent event, int keycode) {
* @return true if the ESCAPE key was pressed and the event was handled, false otherwise.
*/
public boolean handleKeyDown(int keycode) {
if (keycode == com.badlogic.gdx.Input.Keys.ESCAPE) {
if (keycode == com.badlogic.gdx.Input.Keys.ESCAPE || keycode == Input.Keys.NUM_0) {
setPaused(!isPaused);
return true;
}
Expand Down Expand Up @@ -197,6 +209,14 @@ public void addActors() {
table.setPosition(xVal, yVal);
table.padTop(25f);
Docket background = new Docket(getTimer());

// Check if Dancing is active, and add 60 seconds to the timer for new tickets
long ticketTimer = getTimer();
if (ServiceLocator.getRandomComboService().dancing()) {
ticketTimer += 600000; // Add 60 seconds
}
recipeTimeArrayList.add(ticketTimer); // Add adjusted time to the list

backgroundArrayList.add(background);
table.setBackground(background.getImage().getDrawable());

Expand Down Expand Up @@ -722,5 +742,10 @@ public long getTotalPausedDuration() {
return totalPausedDuration;

}
private void addTimeToDockets(long additionalTime) {
for (int i = 0; i < recipeTimeArrayList.size(); i++) {
recipeTimeArrayList.set(i, recipeTimeArrayList.get(i) + additionalTime);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ public class DancePartyUpgrade extends UIComponent implements Upgrade {
private static final String[] greenTexture = {"images/green_fill.png"};
private static final String[] whiteBgTexture = {"images/white_background.png"};
public Table layout;
public Label text; // the "Upgrade" text above the speedMeter
public Label text; // the "Upgrade" text above the meter
public ProgressBar meter; // the meter that show the remaining time
private Sound bgEffect;
private boolean playSound = false;


/**
* Constructor for DancePartyUpgrade that initializes the upgrade and sets up event listeners.
* It listens for "playerCreated" and "Dance party" events.
*/
public DancePartyUpgrade() {
ServiceLocator.getPlayerService().getEvents().addListener("playerCreated", (Entity player) -> this.combatStatsComponent = player.getComponent(CombatStatsComponent.class));
gameTime = ServiceLocator.getTimeSource();
Expand All @@ -52,6 +56,12 @@ public DancePartyUpgrade() {
ServiceLocator.getRandomComboService().getEvents().addListener("Dance partyoff", this::deactivate);
}

/**
* Constructor for DancePartyUpgrade with an explicit CombatStatsComponent.
* This initializes the upgrade and registers the same event listeners as the default constructor.
*
* @param combatStatsComponent the CombatStatsComponent for the player
*/
public DancePartyUpgrade(CombatStatsComponent combatStatsComponent) {
this.combatStatsComponent = combatStatsComponent;
this.orderManager = orderManager;
Expand All @@ -62,6 +72,11 @@ public DancePartyUpgrade(CombatStatsComponent combatStatsComponent) {
ServiceLocator.getRandomComboService().getEvents().addListener("Dance partyoff", this::deactivate);
}

/**
* Initializes the Dance Party upgrade by loading necessary assets,
* such as textures and sound effects, and setting up the UI components
* (progress meter and label). This method is called when the component is created.
*/
@Override
public void create() {
super.create();
Expand All @@ -74,7 +89,7 @@ public void create() {
layout = new Table();
layout.setFillParent(true);
layout.setVisible(false);
setupMeter();
// setupMeter();
}


Expand All @@ -84,31 +99,37 @@ public void create() {
* Also initializes the accompanying label.
*/
private void setupMeter() {
if (meter == null) {
Texture whiteBgTexture = ServiceLocator.getResourceService().getAsset("images/white_background.png", Texture.class);
Texture fillTexture = ServiceLocator.getResourceService().getAsset("images/green_fill.png", Texture.class);
Texture whiteBgTexture = ServiceLocator
.getResourceService().getAsset("images/white_background.png", Texture.class);
Texture fillTexture = ServiceLocator
.getResourceService().getAsset("images/green_fill.png", Texture.class);

ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle();
style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture));
style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture));
ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle();

style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture));
style.background.setMinHeight(15);
style.background.setMinWidth(10);
// Setting white background
style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture));
style.background.setMinHeight(15);
style.background.setMinWidth(10);

// Setting green fill color
style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture));
style.knobBefore.setMinHeight(15);
style.background.setMinWidth(10);
// Setting green fill color
style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture));
style.knobBefore.setMinHeight(15);
style.background.setMinWidth(10);


// Only show the speed meter if it is activated
if (isActive) {
meter = new ProgressBar(0f, 1f, 0.01f, false, style);
meter.setValue(1f);
meter.setPosition(8, 500);
meter.setValue(1f); // Initially, the meter is full
meter.setPosition(30, 250);

text = new Label("Upgrade", skin);
text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8);
layout.add(text).row();
layout.add(meter);
// Set up text
text = new Label("Upgrade", skin);
text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); // Placed above meter
}
else {
meter = null;
text = null;
}
}

Expand All @@ -123,8 +144,13 @@ public void activate() {
dancePartyCost();
isActive = true;
layout.setVisible(true);
setupMeter();
System.out.println("Dance party meter value on activate: " + meter.getValue());

ServiceLocator.getDocketService().getEvents().trigger("Dancing");
ServiceLocator.getRandomComboService().getEvents().trigger("Dancing");
}
else{
ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney");
}
}

Expand All @@ -142,11 +168,17 @@ public void deactivate() {
ServiceLocator.getDocketService().getEvents().trigger("UnDancing");
}


/**
* Handles the cost of the Dance Party upgrade, deducting gold from the player's CombatStatsComponent.
*/
public void dancePartyCost() {
combatStatsComponent.addGold(-20);
}

/**
* Checks and updates the remaining time for the Dance Party upgrade, updating the progress bar meter.
* It also checks if the upgrade's time has run out and deactivates it accordingly.
*/
@Override
public void update() {
if (isActive) {
Expand All @@ -168,27 +200,79 @@ public void update() {
}
}

if (Gdx.input.isKeyJustPressed(Input.Keys.V)) {
if (isActive) {
deactivate();
} else {
activate();
}
}
// if (Gdx.input.isKeyJustPressed(Input.Keys.V)) {
// if (isActive) {
// deactivate();
// } else {
// activate();
// }
// }
}

/**
* Disposes of assets and cleans up when the upgrade is no longer needed.
* Unloads the textures used by the upgrade.
*/
@Override
public void dispose() {
super.dispose();
ServiceLocator.getResourceService().unloadAssets(whiteBgTexture);
ServiceLocator.getResourceService().unloadAssets(greenTexture);
}

/**
* Draw method required by the UIComponent class, but not used in this upgrade.
*
* @param batch the SpriteBatch used to draw
*/
@Override
protected void draw(SpriteBatch batch) {

}

/**
* Sets the stage for the UI components, such as the layout, meter, and text.
*
* @param mock the Stage to which the UI components belong
*/
@Override
public void setStage(Stage mock) {
this.stage = mock;
}

/**
* Gets the current active state of the Dance Party upgrade.
*
* @return true if the upgrade is currently active, false otherwise
*/
public boolean isActive() {
return isActive;
}

/**
* Retrieves the remaining time for which the upgrade will stay active.
*
* @return the remaining active time in milliseconds
*/
public float getActiveTimeRemaining() {
return activeTimeRemaining;
}

/**
* Retrieves the total upgrade duration.
*
* @return the total duration of the upgrade in milliseconds
*/
public long getUpgradeDuration() {
return UPGRADE_DURATION;
}

/**
* Retrieves the current state of the playSound flag, which indicates whether the upgrade's sound has been played.
*
* @return true if the sound has been played, false otherwise
*/
public boolean getPlaySound() {
return playSound;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class ExtortionUpgrade extends UIComponent implements Upgrade {

private static final String[] greenTexture = {"images/green_fill.png"};
private static final String[] whiteBgTexture = {"images/white_background.png"};
private Table layout;
private Label text; // the "Upgrade" text above the speedMeter
private ProgressBar meter; // the meter that show the remaining time
public Table layout;
public Label text; // the "Upgrade" text above the meter
public ProgressBar meter; // the meter that show the remaining time
private boolean isVisible;
private Sound bgEffect;
private boolean playSound = false;
Expand All @@ -49,6 +49,14 @@ public ExtortionUpgrade() {
ServiceLocator.getRandomComboService().getEvents().addListener("Extortionoff", this::deactivate);
}

public ExtortionUpgrade(CombatStatsComponent combatStatsComponent) {
this.isActive = false;
this.gameTime = ServiceLocator.getTimeSource();
this.combatStatsComponent = combatStatsComponent;
ServiceLocator.getRandomComboService().getEvents().addListener("Extortion", this::activate);
ServiceLocator.getRandomComboService().getEvents().addListener("Extortionoff", this::deactivate);
}

@Override
public void create() {
super.create();
Expand All @@ -61,6 +69,7 @@ public void create() {
layout = new Table();
layout.setFillParent(true);
layout.setVisible(isVisible);
// setupMeter();
}

/**
Expand Down Expand Up @@ -90,10 +99,10 @@ private void setupMeter() {
if (isActive) {
meter = new ProgressBar(0f, 1f, 0.01f, false, style);
meter.setValue(1f); // Initially, the meter is full
meter.setPosition(8, 500);
meter.setPosition(30, 250);

// Set up text
text = new Label("Upgrade", skin);
text = new Label("Upgrade", skin);
text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); // Placed above meter
}
else {
Expand Down Expand Up @@ -134,15 +143,9 @@ public void deactivate() {
layout.setVisible(false);
ServiceLocator.getRandomComboService().getEvents().trigger("extortion unactive");

// Ensure the text and meter are removed from the stage after time finish
if (meter != null && meter.hasParent()) {
meter.remove();
text.remove();
}
}

public boolean isActive() {
return isActive;
meter.remove();
text.remove();
}

/**
Expand Down Expand Up @@ -189,6 +192,26 @@ protected void draw(SpriteBatch batch) {

@Override
public void setStage(Stage mock) {
this.stage = mock;
}

public boolean isActive() {
return isActive;
}

public boolean isVisible() {
return isVisible;
}

public long getUpgradeDuration() {
return upgradeDuration;
}

public float getActivateTimeRemaining() {
return activateTimeRemaining;
}

public boolean getPlaySound() {
return playSound;
}
}
Loading

0 comments on commit 8402f8a

Please sign in to comment.