Skip to content

Commit

Permalink
Feat: Overall changes
Browse files Browse the repository at this point in the history
Overall improvements across various classes.
Documentation and setting up simple helper methods, as well as disabling button pressing by pressing space or enter (key used in minigame(s)).
  • Loading branch information
tommyah committed May 24, 2026
1 parent 2172322 commit 355628e
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 77 deletions.
15 changes: 15 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.ConfigValues;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu.MainMenuController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu.MainMenuView;
Expand All @@ -19,6 +20,8 @@
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardController;
Expand Down Expand Up @@ -134,6 +137,10 @@ public void start(final Stage stage) throws Exception {
// In-game (Change "topBarView" to "topBarView2" if no summary section).
// Dashboard er default center-view.
InGameView inGameView = new InGameView(topBarView, dashBoardView.getRootPane());
InGameController inGameController = new InGameController(
inGameView,
eventManager
);

// Transaction history page
TransactionsView transactionsView = new TransactionsView();
Expand Down Expand Up @@ -189,6 +196,14 @@ public void start(final Stage stage) throws Exception {
viewManager.addView(inGameView);
viewManager.setScene(mainMenuView);

// Register all widgets
inGameController.addwidget(WidgetEnum.DASHBOARD, dashBoardView.getRootPane());
inGameController.addwidget(WidgetEnum.MARKET, marketView.getRootPane());
inGameController.addwidget(WidgetEnum.MINIGAMES_OVERVIEW, miniGamesView.getRootPane());
inGameController.addwidget(WidgetEnum.MINIGAMES_ENGINE, gameEngineView.getRootPane());
inGameController.addwidget(WidgetEnum.STATS, statsView.getRootPane());
inGameController.addwidget(WidgetEnum.TRANSACTIONS, transactionsView.getRootPane());

stage.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ public enum EventType implements EventChannel {
* @see edu.ntnu.idi.idatt2003.g40.mappe.view.ViewManager
*
*/
SCENE_CHANGE;
SCENE_CHANGE,

/**
* Event type representing events that causes the center view in the
* current {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView}
* object to change.
*
* <p>Primarily handled by the active
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController}
* object.</p>
*
* @see edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController
*
*/
CHANGE_INGAME_CENTER;

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ protected void changeScene(final ViewEnum viewName) {
invoke(eventData, eventManager);
}

/**
* Overloaded invoke method to reduce parameters, by using
* internal reference to event manager.
*
* @param <T> the type of data to send.
* @param data the data to send.
* */
protected <T> void invoke(final EventData<T> data) {
invoke(data, eventManager);
}

@Override
public final <T> void invoke(final EventData<T> data,
final EventManager eventManager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame;

import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import java.util.ArrayList;

public class InGameView extends ViewElement<VBox, InGameActions> {

private final TopBarView topBarView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected void initLayout() {
navInfo.setAlignment(Pos.TOP_CENTER);

nextBtn = new Button("next");
nextBtn.setFocusTraversable(false);
weekLabel = new Label("week: 1");
weekLabel.getStyleClass().add("week-label");
Region spacerR = new Region();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,75 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames;

import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import java.util.function.IntConsumer;
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 javafx.scene.layout.VBox;

import java.util.function.IntConsumer;
/**
* Minigame context class as described in the Strategy pattern.
*
* <p>Extends {@link ViewElement}</p>
* */
public final class GameEngineView
extends ViewElement<BorderPane, MiniGamesActions> {

public final class GameEngineView extends ViewElement<BorderPane, MiniGamesActions> {
/**
* Quit button (does not generate results).
* */
private Button quitButton;

/**
* Label for current score.
* */
private Label scoreLabel;

/**
* Label for time left.
* */
private Label timerLabel;

/**
* Label for current rank.
* */
private Label rankLabel;

/**
* Container for score, timer and rank.
* */
private HBox topDashboardBar;
private int curScore;

/**
* Container for final game status report.
* */
private VBox reportContainer;

/**
* Label for report title.
* */
private Label reportTitleLabel;

/**
* Label for result rank.
* */
private Label rankResultLabel;

/**
* Label for describing what effects on the stock will apply.
* */
private Label stockEffectLabel;

/**
* Return button on the report (generates results on the stock market).
* */
private Button closeReportBtn;

/**
* Constructor.
* */
public GameEngineView() {
super(new BorderPane(), MiniGamesActions.class);
}
Expand All @@ -32,12 +78,12 @@ public GameEngineView() {
* 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.
* @param time the time to show.
* @param rank the rank to show.
* */
public void updateMetadataDisplay(final int score,
final String time,
final String rank) {
final char rank) {
scoreLabel.setText("Score: " + score);
timerLabel.setText(time);
rankLabel.setText("Rank: " + rank);
Expand All @@ -58,35 +104,30 @@ public void setGameGimmickContent(final GameGimmick gimmick, final IntConsumer c
/**
* Displays the report after a minigames timers is finished.
*
* @param rank the rank the player got.
* @param stockSymbol the symbol of the affected stock.
* @param isPositive whether the change is positive or not.
* @param rank the rank the player got.
* @param effect the effect caused by the results.
* */
public void showGameReport(final String rank,
final String stockSymbol,
final boolean isPositive) {
public void showGameReport(final char rank,
final String effect) {
getRootPane().setCenter(null);

reportContainer = new VBox(25);
reportContainer.setAlignment(Pos.CENTER);
reportContainer.getStyleClass().add("minigames-report-box");
reportContainer = new VBox();
reportContainer.getStyleClass().add("gameEngine-report-box");

reportTitleLabel = new Label("GAME OVER - REPORT");
reportTitleLabel.setStyle("-fx-font-size: 32px; -fx-font-weight: bold;");
reportTitleLabel.getStyleClass().add("gameEngine-report-title");

rankResultLabel = new Label("Final Rank: " + rank);
rankResultLabel.setStyle("-fx-font-size: 24px;");
rankResultLabel.getStyleClass().add("gameEngine-report-rank-result");

String effectText = isPositive
/*String effectText = isPositive
? "Performance impact: Positive change for " + stockSymbol + " next week! 📈"
: "Performance impact: Negative change for " + stockSymbol + " next week... 📉";
stockEffectLabel = new Label(effectText);
stockEffectLabel.setStyle("-fx-font-size: 18px; -fx-text-fill: " + (isPositive ? "green;" : "red;"));
closeReportBtn = new Button("Return to Menu");
closeReportBtn.setPrefSize(200, 50);
registerButton(MiniGamesActions.CLOSE_REPORT, closeReportBtn);
stockEffectLabel.setStyle("-fx-font-size: 18px; -fx-text-fill: " + (isPositive ? "green;" : "red;"));*/
stockEffectLabel = new Label(effect);
stockEffectLabel.getStyleClass().add("gameEngine-report-effect");

reportContainer.getChildren().addAll(reportTitleLabel, rankResultLabel, stockEffectLabel, closeReportBtn);
getRootPane().setCenter(reportContainer);
Expand All @@ -96,6 +137,7 @@ public void showGameReport(final String rank,
protected void initLayout() {
quitButton = new Button("Quit");
quitButton.setPrefSize(100, 50);
quitButton.setFocusTraversable(false);

scoreLabel = new Label("Score: 0");
timerLabel = new Label("00:00:60");
Expand All @@ -107,17 +149,22 @@ protected void initLayout() {
topDashboardBar = new HBox(20, quitButton, statsDisplay);
topDashboardBar.setAlignment(Pos.CENTER_LEFT);
topDashboardBar.setPadding(new javafx.geometry.Insets(15));
closeReportBtn = new Button("Return");
closeReportBtn.setFocusTraversable(false);

getRootPane().setTop(topDashboardBar);

registerButton(MiniGamesActions.INGAME_QUIT, quitButton);
registerButton(MiniGamesActions.INGAME_RETURN, closeReportBtn);
}

@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;");
getRootPane().getStyleClass().add("gameEngine-root");
topDashboardBar.getStyleClass().add("gameEngine-topBar");
scoreLabel.getStyleClass().add("gameEngine-topBar-Label");
timerLabel.getStyleClass().add("gameEngine-topBar-Label");
rankLabel.getStyleClass().add("gameEngine-topBar-Label");
closeReportBtn.getStyleClass().add("gameEngine-report-closeButton");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public enum MiniGamesActions {
HELP,

/**
* Action called when quitting a minigame.
* Action called when quitting a minigame (no reward).
* */
INGAME_QUIT,

/**
* Action called when closing the report at the end of a minigame.
* Action for when a player returns from a minigame (with rewards).
* */
CLOSE_REPORT
INGAME_RETURN;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,55 @@
* <p>Extends {@link ViewController}</p>
* */
public final class MiniGamesController extends ViewController<MiniGamesView> {

/**
* The currently selected stock for the minigame.
* */
private Stock activeStock;

/**
* The game engine view to delegate games towards.
* */
private final GameEngineView gameEngineView;

/**
* The game engine controller.
* */
private final GameEngineController gameEngineController;

/**
* The clicker game instance.
* */
private final ClickerGame clickerGame;

/**
* The in game view.
* */
private final InGameView inGameView;

/**
* The find stock game instance.
* */
private final FindStockGame findStockGame;

/**
* The timed inputs game instance.
* */
private final TimeInputsGame timeInputsGame;

/**
* Constructor.
*
* @param viewElement the associated {@link MiniGamesView}.
* @param eventManager the associated {@link EventManager}.
* @param initialStock the initial selected stock.
* @param gameEngineView the game engine view.
* @param gameEngineController the game engine controller.
* @param clickerGame the clicker game instance.
* @param inGameView the in game view instance.
* @param findStockGame the find stock game instance.
* @param timeInputsGame the timed inputs game.
* */
public MiniGamesController(final MiniGamesView viewElement,
final EventManager eventManager,
final Stock initialStock,
Expand All @@ -30,7 +71,8 @@ public MiniGamesController(final MiniGamesView viewElement,
final ClickerGame clickerGame,
final InGameView inGameView,
final FindStockGame findStockGame,
final TimeInputsGame timeInputsGame) {
final TimeInputsGame timeInputsGame
) {
this.activeStock = initialStock;
this.gameEngineView = gameEngineView;
this.gameEngineController = gameEngineController;
Expand Down Expand Up @@ -71,6 +113,7 @@ protected void initInteractions() {
*/
public void setActiveStock(final Stock stock) {
this.activeStock = stock;
gameEngineController.setChosenStock(stock);
refresh();
}

Expand Down
Loading

0 comments on commit 355628e

Please sign in to comment.