Skip to content

Commit

Permalink
Revert "Moral polish test"
Browse files Browse the repository at this point in the history
  • Loading branch information
AidenRichards03 authored Oct 17, 2024
1 parent 656e49c commit accf8c2
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 111 deletions.
2 changes: 2 additions & 0 deletions source/core/src/main/com/csse3200/game/GdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ private Screen newScreen(ScreenType screenType) {
return new SettingsScreen(this);
case LOAD_GAME:
return new LoadGameScreen(this);
case CUTSCENE:
return new CutsceneScreen(this, CutsceneType.MORAL_2);
case MORAL_SCENE_1:
return new CutsceneScreen(this, CutsceneType.MORAL_1);
case MORAL_SCENE_2:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.csse3200.game.components.maingame;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.csse3200.game.screens.MainGameScreen;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;



//From team 2, this is just a temporary file that serves as the moraldipslay
//when the proper file is implemented, the logic for the eventlisteners will be used in that
//and this file will be deleted

public class MoralDisplayTemp extends UIComponent {
private Table layout; // Layout manager
private boolean isVisible;
private final MainGameScreen game;
private static final Logger logger = LoggerFactory.getLogger(EndDayDisplay.class);


public MoralDisplayTemp(MainGameScreen game) {
super();
this.game = game;
isVisible = false;
}

@Override
public void create() {
super.create();
layout = new Table();
layout.setFillParent(true);
layout.setVisible(isVisible);
stage.addActor(layout);

// Create a white background
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.RED);
pixmap.fill();
Texture pixmapTex = new Texture(pixmap);
pixmap.dispose();
Drawable whiteBackground = new TextureRegionDrawable(new TextureRegion(pixmapTex));
layout.setBackground(whiteBackground);

// Load the image
Texture imgTexture = ServiceLocator.getResourceService()
.getAsset("images/bird.png", Texture.class);
Drawable imgDrawable = new TextureRegionDrawable(imgTexture);
Image dayEndImage = new Image(imgDrawable);
layout.add(dayEndImage).center().padTop(10).row();

initializeUI();

//from team 2, added the listener for when game day ends to toggle visibility
ServiceLocator.getDayNightService().getEvents().addListener("TOMORAL", () -> {
logger.info("it is listened in moral");
toggleVisibility();});

}

private void initializeUI() {
Label titleLabel = new Label("MORAL DILEMMA", new Label.LabelStyle(new BitmapFont(), Color.BLACK));
layout.add(titleLabel).pad(10).row();

// Example event labels
Label eventLabel = new Label("WHAT WILL YOU DO", new Label.LabelStyle(new BitmapFont(), Color.BLACK));
layout.add(eventLabel).pad(10).row();

// Customer lists
List<String> passedCustomers = new List<>(skin);
passedCustomers.setItems("Customer A", "Customer B", "Customer C");
List<String> failedCustomers = new List<>(skin);
failedCustomers.setItems("Customer X", "Customer Y");

Table listTable = new Table();
listTable.add(new Label("Passed Customers", skin)).pad(10);
listTable.add(new Label("Failed Customers", skin)).pad(10).row();
listTable.add(new ScrollPane(passedCustomers, skin)).pad(10);
listTable.add(new ScrollPane(failedCustomers, skin)).pad(10);

layout.add(listTable).expand().fill().row();

TextButton closeBtn = new TextButton("Close", skin);
closeBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
toggleVisibility();
}
});
layout.add(closeBtn).padTop(20).row();
}


public void show() {
isVisible = true;
layout.setVisible(isVisible);
game.pause(); // Pause the game when the display is shown
}

public void hide() {
isVisible = false;
layout.setVisible(isVisible);
game.resume(); // Resume the game when the display is hidden
}

public void toggleVisibility() {
if (isVisible) {
hide();
ServiceLocator.getDayNightService().getEvents().trigger("temp"); //new

} else {
show();
}
}

@Override
public void draw(SpriteBatch batch) {
// draw is handled by the stage

}

@Override
public void setStage(Stage mock) {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class TextDisplay extends UIComponent {
private long lastUpdate = 0L;
private final long delay = 100L;

private InputListener inputListener;

// Displaying variables
private boolean visible;
public Label label;
Expand Down Expand Up @@ -286,9 +284,11 @@ public void update() {
* of the text or clear the textbox from the screen
*/
private void setupInputListener() {
inputListener = new InputListener() {
logger.info(TextDisplay.this.screen);
stage.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {

if (TextDisplay.this.screen.equals("cutscene")) {
if (keycode == com.badlogic.gdx.Input.Keys.ENTER || keycode == com.badlogic.gdx.Input.Keys.SPACE) {
logger.info("we've pressed enter");
Expand All @@ -299,7 +299,7 @@ public boolean keyDown(InputEvent event, int keycode) {
return true;
} else if (TextDisplay.this.screen.equals("moralDecision")) {
Cutscene currentCutscene = ServiceLocator.getCurrentCutscene();
boolean atEnd = currentCutscene.isAtEnd();
Boolean atEnd = currentCutscene.isAtEnd();
if (keycode == com.badlogic.gdx.Input.Keys.ENTER || keycode == com.badlogic.gdx.Input.Keys.SPACE) {
logger.info("at moral in textDisplay");
if (!atEnd) {
Expand All @@ -308,11 +308,13 @@ public boolean keyDown(InputEvent event, int keycode) {
label.setText(currentCutscene.currentText);
}
} else if (keycode == Input.Keys.Y && atEnd) {
logger.info("WE'RE ALMOST THERE");
currentCutscene = ServiceLocator.getCurrentCutscene();
currentCutscene.setTextForScene(currentCutscene.currentScene);

ServiceLocator.getDayNightService().getEvents().trigger("YesAtMoralDecision");
} else if (keycode == Input.Keys.N && atEnd) {
logger.info("WE'RE ALMOST THERE NO");
currentCutscene = ServiceLocator.getCurrentCutscene();
currentCutscene.setTextForScene(currentCutscene.currentScene);

Expand All @@ -322,6 +324,7 @@ public boolean keyDown(InputEvent event, int keycode) {
} else if (TextDisplay.this.screen.equals("backstory")) {
// Handling for backstory cutscenes
Cutscene currentCutscene = ServiceLocator.getCurrentCutscene();
Boolean atEnd = currentCutscene.isAtEnd();

// Check if the current text is "Press Enter to continue"
if (label.getText().toString().equals("Press Enter to continue")) {
Expand All @@ -336,9 +339,11 @@ public boolean keyDown(InputEvent event, int keycode) {
// Continue through the backstory cutscene normally
if (keycode == com.badlogic.gdx.Input.Keys.ENTER || keycode == com.badlogic.gdx.Input.Keys.SPACE) {
logger.info("at backstory in textDisplay");
logger.info("parsing through backstory");
currentCutscene.setTextForScene(currentCutscene.currentScene);
label.setText(currentCutscene.currentText);
if (!atEnd) {
logger.info("parsing through backstory");
currentCutscene.setTextForScene(currentCutscene.currentScene);
label.setText(currentCutscene.currentText);
}
}
}
return true;
Expand All @@ -362,15 +367,10 @@ public boolean keyDown(InputEvent event, int keycode) {
}
return false;
}
};
stage.addListener(inputListener);
});
}






/**
* Overrides the draw method from the Actor class.
* This method is responsible for rendering the component.
Expand Down Expand Up @@ -448,16 +448,5 @@ private void setUpBackstoryLayout() {
// Add stack to the table
table.add(stack).padTop(100).size((int) (Gdx.graphics.getWidth() * 0.6), (int) (Gdx.graphics.getHeight() * 0.15));
}

/**
* Class used in unit tests to simulate keypress
* @param keycode: keycode realting to the key pressed
* @return whether the key was pressed
*/
public boolean simulateKeyPress(int keycode) {
InputEvent event = new InputEvent(); // Create a dummy InputEvent
event.setType(InputEvent.Type.keyDown);
return inputListener.keyDown(event, keycode);
}
}

Loading

0 comments on commit accf8c2

Please sign in to comment.