diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameEngineView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameEngineView.java new file mode 100644 index 0000000..e18b372 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameEngineView.java @@ -0,0 +1,79 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames; + +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; + +import java.util.function.IntConsumer; + +public final class GameEngineView extends ViewElement { + private Button quitButton; + private Label scoreLabel; + private Label timerLabel; + private Label rankLabel; + private HBox topDashboardBar; + private int curScore; + + public GameEngineView() { + super(new BorderPane(), MiniGamesActions.class); + } + + @Override + protected void initLayout() { + quitButton = new Button("Quit"); + quitButton.setPrefSize(100, 50); + + scoreLabel = new Label("Score: 0"); + timerLabel = new Label("00:00:60"); + rankLabel = new Label("Rank: E"); + + HBox statsDisplay = new HBox(40, scoreLabel, timerLabel, rankLabel); + statsDisplay.setAlignment(Pos.CENTER); + + topDashboardBar = new HBox(20, quitButton, statsDisplay); + topDashboardBar.setAlignment(Pos.CENTER_LEFT); + topDashboardBar.setPadding(new javafx.geometry.Insets(15)); + + getRootPane().setTop(topDashboardBar); + registerButton(MiniGamesActions.INGAME_QUIT, quitButton); + } + + /** + * Method for updating the game per tick with score, time and rank. + * + * @param score the score to show. + * @param time the time to show. + * @param rank the rank to show. + * */ + public void updateMetadataDisplay(final int score, + final String time, + final String rank) { + scoreLabel.setText("Score: " + score); + timerLabel.setText(time); + rankLabel.setText("Rank: " + rank); + } + + /** + * Sets the content of this view based on the game provided through the + * {@link GameGimmick} interface. + * + * @param gimmick a concrete implementation of the {@link GameGimmick} + * interface + * */ + public void setGameGimmickContent(final GameGimmick gimmick, final IntConsumer consumer) { + getRootPane().setCenter(gimmick.getCanvasNode()); + gimmick.initialize(consumer); + } + + @Override + protected void initStyling() { + getRootPane().setStyle("-fx-background-color: rgba(180, 180, 180, 0.85);"); + topDashboardBar.setStyle("-fx-background-color: transparent;"); + scoreLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: black;"); + timerLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: black;"); + rankLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: black;"); + } +}