Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/UQcsse3200/2024-studio-3 in…
Browse files Browse the repository at this point in the history
…to backstory-p2
  • Loading branch information
shravya132 committed Oct 17, 2024
2 parents f103517 + 9647251 commit c048856
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ public Confirmationpopup(String title, Skin skin, Stage stage, GdxGame game) {
@Override
protected void result(Object object) {
int isTrue = (int) object;
if (isTrue == 1) {
game.setScreen(new TutorialScreen(game));
} else if (isTrue == 2) {
// game.setScreen(GdxGame.ScreenType.MAIN_GAME);
// User chose "No", transition to BackstoryCutscene
BackstoryCutscene backstoryCutscene = new BackstoryCutscene();
game.setCurrentCutscene(backstoryCutscene); // Set the backstory cutscene as current
game.setScreen(new CutsceneScreen(game, GdxGame.CutsceneType.BACK_STORY)); // Start the cutscene screen the backstory
} else {
game.setScreen(GdxGame.ScreenType.MAIN_GAME);
switch (isTrue) {
case 1 -> {
game.setScreen(new TutorialScreen(game));
}
case 2 -> {
BackstoryCutscene backstoryCutscene = new BackstoryCutscene();
game.setCurrentCutscene(backstoryCutscene);
game.setScreen(new CutsceneScreen(game, GdxGame.CutsceneType.BACK_STORY));
}
default -> game.setScreen(GdxGame.ScreenType.MAIN_GAME);
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public Table createKeybindsMenu() {
* @param isPressed keybinds button is pressed
*/
public void showKeybinds(boolean isPressed) {
System.out.println("showKeybinds called with isPressed: " + isPressed);
keybindsMenu.setVisible(isPressed);
keybindsText.setVisible(isPressed);
}
Expand All @@ -84,9 +83,9 @@ public void showKeybinds(boolean isPressed) {
*/
public Table createButtonTable() {
keybindButton = new Table();
keybindButton.bottom().right();
keybindButton.left();
keybindButton.setFillParent(true);
keybindButton.padRight(20f);
keybindButton.padTop(270f).padLeft(20f);

TextButton button = new TextButton("Keybindings", skin);
button.addListener(new ChangeListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.csse3200.game.components.tutorial;

import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Array;
import com.csse3200.game.GdxGame;
import com.csse3200.game.components.ordersystem.MainGameOrderBtnDisplay;
import com.csse3200.game.components.player.PlayerActions;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.screens.MainGameScreen;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import com.csse3200.game.components.ordersystem.MainGameOrderTicketDisplay;
Expand All @@ -25,26 +20,16 @@
*/
public class TutorialScreenDisplay extends UIComponent {
private static final Logger logger = LoggerFactory.getLogger(TutorialScreenDisplay.class);
private GdxGame game;
private final GdxGame game;
private int tutorialStep = 0;
private MainGameOrderBtnDisplay orderBtnDisplay;
private boolean createOrderPressed = false;
private boolean docketsShifted = false;
private Table table;
private TextDisplay textDisplay;
private PlayerActions playerActions;
private boolean wPressedLastFrame = false;
private boolean aPressedLastFrame = false;
private boolean sPressedLastFrame = false;
private boolean dPressedLastFrame = false;
private static final int MAX_TUTORIAL_STEP = 8; // Increased for combining step
int i = 0;

public TutorialScreenDisplay(GdxGame game) {

this.game = game;
// this.orderTicketDisplay = new MainGameOrderTicketDisplay(ServiceLocator.getRenderService(), ServiceLocator.getPlayerService());
// this.orderBtnDisplay = new MainGameOrderBtnDisplay();

if (this.game == null) {
logger.error("Game null");
Expand All @@ -59,12 +44,7 @@ public void create() {
MainGameOrderTicketDisplay.resetOrderNumb();

if (entity != null) {
//playerActions = ServiceLocator.getPlayerService().getPlayer().getComponent(PlayerActions.class);
if (playerActions == null) {
logger.info("PlayerActions component not found.");
}else{
logger.info("PlayerActions component attatched");
}
logger.info("PlayerActions component attatched");

} else {
logger.error("Entity null");
Expand All @@ -86,12 +66,6 @@ public void create() {

advanceTutorialStep();

// Add event listeners for create order
//entity.getEvents().addListener("createOrder", this::onCreateOrderPressed);
//ServiceLocator.getInputService().getEvents().addListener("createOrder", this::onCreateOrderPressed);
// ServiceLocator.getInputService().getEvents().addListener("walked", this::onPlayerMoved);
// ServiceLocator.getInputService().getEvents().addListener("interact", this::onInteraction);// start the tutorial from the first step

stage.addActor(table);
}

Expand Down Expand Up @@ -253,109 +227,100 @@ private void completeTutorial() {
* Advances the tutorial to the next tut
*/
private void onTextComplete(int currentPart) {
if (currentPart >= 0 && currentPart <= textDisplay.getText().size()) {
switch (tutorialStep) {
case 1:
if (Gdx.input.isKeyJustPressed(Input.Keys.W) || Gdx.input.isKeyJustPressed(Input.Keys.A) ||
Gdx.input.isKeyJustPressed(Input.Keys.S) || Gdx.input.isKeyJustPressed(Input.Keys.D) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
advanceTutorialStep();
}
break;
case 2:
if (Gdx.input.isKeyJustPressed(Input.Keys.E) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
advanceTutorialStep();
}
break;
case 3:
if (Gdx.input.isKeyJustPressed(Input.Keys.LEFT_BRACKET) || Gdx.input.isKeyJustPressed(Input.Keys.RIGHT_BRACKET) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
docketsShifted = true;
logger.debug("Dockets shifted!");
advanceTutorialStep();
}
break;
case 4:
if (Gdx.input.isKeyJustPressed(Input.Keys.R) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
advanceTutorialStep();
}
break;
case 5:
if (Gdx.input.isKeyJustPressed(Input.Keys.Q) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
advanceTutorialStep();
}
break;
case 6:
if (Gdx.input.isKeyJustPressed(Input.Keys.K) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
advanceTutorialStep();
}
break;
case 7:
if (Gdx.input.isKeyJustPressed(Input.Keys.J) || Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
advanceTutorialStep();
}
break;
case 8:
if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
startGame();
}
break;
default:
logger.error("Unexpected tutorial step: " + tutorialStep);
break;
}
if (currentPart < 0 || currentPart > textDisplay.getText().size()) {
return;
}

handleTutorialStep();
}

/**
* breaks out tutorial handling
*/
private void handleTutorialStep() {
switch (tutorialStep) {
case 1 -> handleMovementKeys();
case 2 -> handleInteractionKey();
case 3 -> handleDocketSwitch();
case 4 -> handleReloadKey();
case 5 -> handleWeaponChangeKey();
case 6 -> handleSpecialActionKey();
case 7 -> handleSecondaryActionKey();
case 8 -> handleStartGame();
default -> logger.error("Unexpected tutorial step: " + tutorialStep);
}
}

@Override
public void update() {
switch (tutorialStep) {
case 1:
if (Gdx.input.isKeyJustPressed(Input.Keys.W) || Gdx.input.isKeyJustPressed(Input.Keys.A) ||
Gdx.input.isKeyJustPressed(Input.Keys.S) || Gdx.input.isKeyJustPressed(Input.Keys.D)) {
advanceTutorialStep();
}
break;
case 2:
if (Gdx.input.isKeyJustPressed(Input.Keys.E)) {
advanceTutorialStep();
}
break;
case 3:
textDisplay.setText("Now use [ and ] keys to switch dockets.");

if (Gdx.input.isKeyJustPressed(Input.Keys.LEFT_BRACKET) || Gdx.input.isKeyJustPressed(Input.Keys.RIGHT_BRACKET)) {
docketsShifted = true;
logger.debug("Dockets shifted");
}

if (docketsShifted) {
advanceTutorialStep();
}
break;
case 4:
if (Gdx.input.isKeyJustPressed(Input.Keys.R)) {
advanceTutorialStep();
}
break;
case 5:
if (Gdx.input.isKeyJustPressed(Input.Keys.Q)) {
advanceTutorialStep();
}
break;
case 6:
if (Gdx.input.isKeyJustPressed(Input.Keys.K)) {
advanceTutorialStep();
}
break;
case 7:
if (Gdx.input.isKeyJustPressed(Input.Keys.J)) {
advanceTutorialStep();
}
break;
case 8:
if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
startGame();
}
break;
case 1 -> handleMovementKeys();
case 2 -> handleInteractionKey();
case 3 -> handleDocketSwitch();
case 4 -> handleReloadKey();
case 5 -> handleWeaponChangeKey();
case 6 -> handleSpecialActionKey();
case 7 -> handleSecondaryActionKey();
case 8 -> handleStartGame();
default -> {
// Invalid case or no operation
}
}
}

private void handleMovementKeys() {
if (Gdx.input.isKeyJustPressed(Input.Keys.W) || Gdx.input.isKeyJustPressed(Input.Keys.A) ||
Gdx.input.isKeyJustPressed(Input.Keys.S) || Gdx.input.isKeyJustPressed(Input.Keys.D)) {
advanceTutorialStep();
}
}

private void handleInteractionKey() {
if (Gdx.input.isKeyJustPressed(Input.Keys.E)) {
advanceTutorialStep();
}
}

private void handleDocketSwitch() {
textDisplay.setText("Now use [ and ] keys to switch dockets.");

if (Gdx.input.isKeyJustPressed(Input.Keys.LEFT_BRACKET) || Gdx.input.isKeyJustPressed(Input.Keys.RIGHT_BRACKET)) {
docketsShifted = true;
logger.debug("Dockets shifted");
}

if (docketsShifted) {
advanceTutorialStep();
}
}

private void handleReloadKey() {
if (Gdx.input.isKeyJustPressed(Input.Keys.R)) {
advanceTutorialStep();
}
}

private void handleWeaponChangeKey() {
if (Gdx.input.isKeyJustPressed(Input.Keys.Q)) {
advanceTutorialStep();
}
}

private void handleSpecialActionKey() {
if (Gdx.input.isKeyJustPressed(Input.Keys.K)) {
advanceTutorialStep();
}
}

private void handleSecondaryActionKey() {
if (Gdx.input.isKeyJustPressed(Input.Keys.J)) {
advanceTutorialStep();
}
}

private void handleStartGame() {
if (Gdx.input.isKeyJustPressed(Input.Keys.ENTER)) {
startGame();
}
}

Expand Down Expand Up @@ -406,10 +371,6 @@ public void dispose() {
table.clear();
}

if (orderBtnDisplay != null) {
orderBtnDisplay.dispose();
}

if (textDisplay != null) {
textDisplay.setVisible(false);
textDisplay.getTable().clear();
Expand All @@ -429,15 +390,4 @@ public void setStage(Stage stage) {
this.stage = stage;
}

public int getTutorialStep() {
return tutorialStep;
}

public void setTutorialStep(int i) {
this.tutorialStep = i;
}

public boolean isCreateOrderPressed() {
return createOrderPressed;
}
}

0 comments on commit c048856

Please sign in to comment.