Skip to content

Commit

Permalink
Feat: Added main minigames page
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 23, 2026
1 parent cde71bc commit dd0b867
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats.StatsController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats.StatsView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarController;
Expand Down Expand Up @@ -139,6 +141,13 @@ public void start(final Stage stage) throws Exception {
eventManager,
player.getTransactionArchive());

MiniGamesView miniGamesView = new MiniGamesView();
new MiniGamesController(
miniGamesView,
eventManager,
stocksInFile.getFirst()
);

// Wire top bar buttons til å bytte mellom dashboard / stats / market /
// transactions. Stats-knappen tar deg til stats-siden.
topBarController.setMarketIntegration(
Expand All @@ -147,7 +156,9 @@ public void start(final Stage stage) throws Exception {
marketView.getRootPane(),
statsView.getRootPane(),
transactionsView.getRootPane(),
transactionsController::refresh);
transactionsController::refresh,
miniGamesView.getRootPane()
);

// Register all views
viewManager.addView(mainMenuView);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames;

/**
* Action set for the associated {@link MiniGamesView}.
* */
public enum MiniGamesActions {
/**
* Action when selecting clicker game.
* */
CLICKER_GAME,

/**
* Action when selecting "find stock" game.
* */
FIND_STOCK,

/**
* Action when selecting "time click" game.
* */
TIME_CLICKS,

/**
* Action when clicking the question mark box (help section).
* */
HELP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames;

import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;

/**
* Controller class for the associated {@link MiniGamesView} object.
*
* <p>Extends {@link ViewController}</p>
* */
public final class MiniGamesController extends ViewController<MiniGamesView> {
private Stock activeStock;

public MiniGamesController(final MiniGamesView viewElement,
final EventManager eventManager,
final Stock initialStock) {
super(viewElement, eventManager);
this.activeStock = initialStock;
refresh();
}

@Override
protected void initInteractions() {
getViewElement().setOnAction(MiniGamesActions.HELP, () -> {
// Implement help dialog or print logic
});

getViewElement().setOnAction(MiniGamesActions.CLICKER_GAME, () -> {
// Logic for launching Clicker Game
});

getViewElement().setOnAction(MiniGamesActions.FIND_STOCK, () -> {
// Logic for launching Find Stock Game
});

getViewElement().setOnAction(MiniGamesActions.TIME_CLICKS, () -> {
// Logic for launching Time Clicks Game
});
}

/**
* Sets the target stock context for the minigames.
*
* @param stock Chosen active layout context stock.
*/
public void setActiveStock(final Stock stock) {
this.activeStock = stock;
refresh();
}

/**
* Syncs the current model status with view text properties.
*/
public void refresh() {
if (activeStock != null) {
getViewElement().setSelectedStockText(activeStock.getSymbol());
} else {
getViewElement().setSelectedStockText("None");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
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.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

/**
* Minigames view in the in game section of the application.
* */
public final class MiniGamesView extends ViewElement<VBox, MiniGamesActions> {

private HBox headerBar;
private HBox gamesContainer;

private Label titleLabel;
private Label selectedStockLabel;
private Label stockValueLabel;

private Button helpBtn;
private Button clickerGameBtn;
private Button findStockBtn;
private Button timeClicksBtn;

/**
* Constructor.
*/
public MiniGamesView() throws IllegalArgumentException {
super(new VBox(), MiniGamesActions.class);
}

@Override
protected void initLayout() {
// Top header layout
headerBar = new HBox();
headerBar.setAlignment(Pos.TOP_LEFT);

VBox titleSection = new VBox();
titleLabel = new Label("Mini games");

HBox stockSelectionRow = new HBox();
stockSelectionRow.setAlignment(Pos.CENTER_LEFT);
selectedStockLabel = new Label("Selected stock: ");
stockValueLabel = new Label("AAPL");
stockSelectionRow.getChildren().addAll(selectedStockLabel, stockValueLabel);

titleSection.getChildren().addAll(titleLabel, stockSelectionRow);

Region topSpacer = new Region();
HBox.setHgrow(topSpacer, Priority.ALWAYS);

helpBtn = new Button("?");
headerBar.getChildren().addAll(titleSection, topSpacer, helpBtn);

// Main central row container for games
gamesContainer = new HBox();
gamesContainer.setAlignment(Pos.CENTER);

clickerGameBtn = new Button("Clicker game");
findStockBtn = new Button("Find correct\nstock");
timeClicksBtn = new Button("Time your clicks");

// Make buttons fill equal proportions
HBox.setHgrow(clickerGameBtn, Priority.ALWAYS);
HBox.setHgrow(findStockBtn, Priority.ALWAYS);
HBox.setHgrow(timeClicksBtn, Priority.ALWAYS);

// Equal constraints on dimensions
configureGameButton(clickerGameBtn);
configureGameButton(findStockBtn);
configureGameButton(timeClicksBtn);

gamesContainer.getChildren().addAll(clickerGameBtn, findStockBtn, timeClicksBtn);

// Assemble view layers
VBox.setVgrow(gamesContainer, Priority.ALWAYS);
getRootPane().getChildren().addAll(headerBar, gamesContainer);

// Map interactions
registerButton(MiniGamesActions.HELP, helpBtn);
registerButton(MiniGamesActions.CLICKER_GAME, clickerGameBtn);
registerButton(MiniGamesActions.FIND_STOCK, findStockBtn);
registerButton(MiniGamesActions.TIME_CLICKS, timeClicksBtn);
}

private void configureGameButton(final Button btn) {
btn.setMaxWidth(Double.MAX_VALUE);
btn.setMaxHeight(Double.MAX_VALUE);
btn.setAlignment(Pos.CENTER);
}

/**
* Updates the selected stock text.
*
* @param symbol the symbol representing the stock selected.
*/
public void setSelectedStockText(final String symbol) {
stockValueLabel.setText(symbol);
}

@Override
protected void initStyling() {
getRootPane().getStyleClass().add("minigames-root");
headerBar.getStyleClass().add("minigames-headerBar");
titleLabel.getStyleClass().add("minigames-titleLabel");
selectedStockLabel.getStyleClass().add("minigames-stockLabel");
stockValueLabel.getStyleClass().add("minigames-stockValue");

helpBtn.getStyleClass().add("minigames-helpBtn");
gamesContainer.getStyleClass().add("minigames-container");

clickerGameBtn.getStyleClass().add("minigames-cardBtn");
findStockBtn.getStyleClass().add("minigames-cardBtn");
timeClicksBtn.getStyleClass().add("minigames-cardBtn");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum TopBarActions {
STATS,
MARKET,
SETTINGS,
TRANSACTIONS;
TRANSACTIONS,
MINIGAMES;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public class TopBarController extends ViewController<TopBarView> {
*/
private boolean inTransactionsView = false;

/**
* Whether the minigames screen is currently the active center-view.
*
* <p>
* When true, the quit/back button returns to the dashboard instead
* of exiting to the main menu.
* </p>
*/
private boolean inMinigamesView = false;


/**
* {@inheritDoc}.
*/
Expand Down Expand Up @@ -83,20 +94,27 @@ protected void initInteractions() {
* @param statsCenter root pane of the stats widget.
* @param transactionsCenter root pane of the transactions widget.
* @param onTransactionUpdate callback invoked when entering transactions.
* @param minigamesCenter root pane of the minigames widget.
*/
public void setMarketIntegration(final Consumer<Node> centerSwitcher,
final Node dashboardCenter,
final Node marketCenter,
final Node statsCenter,
final Node transactionsCenter,
final Runnable onTransactionUpdate) {
final Runnable onTransactionUpdate,
final Node minigamesCenter
) {
getViewElement().setOnAction(TopBarActions.EXIT, () -> {
if (inMarketView || inStatsView || inTransactionsView) {
if (inMarketView
|| inStatsView
|| inTransactionsView
|| inMinigamesView) {
centerSwitcher.accept(dashboardCenter);
getViewElement().setQuitText("Quit");
inMarketView = false;
inStatsView = false;
inTransactionsView = false;
inMinigamesView = false;
} else {
changeScene(ViewEnum.MAIN_MENU);
}
Expand All @@ -108,6 +126,7 @@ public void setMarketIntegration(final Consumer<Node> centerSwitcher,
inMarketView = false;
inStatsView = true;
inTransactionsView = false;
inMinigamesView = false;
});

getViewElement().setOnAction(TopBarActions.MARKET, () -> {
Expand All @@ -116,6 +135,7 @@ public void setMarketIntegration(final Consumer<Node> centerSwitcher,
inMarketView = true;
inStatsView = false;
inTransactionsView = false;
inMinigamesView = false;
});

getViewElement().setOnAction(TopBarActions.TRANSACTIONS, () -> {
Expand All @@ -125,6 +145,16 @@ public void setMarketIntegration(final Consumer<Node> centerSwitcher,
inMarketView = false;
inStatsView = false;
inTransactionsView = true;
inMinigamesView = false;
});

getViewElement().setOnAction(TopBarActions.MINIGAMES, () -> {
centerSwitcher.accept(minigamesCenter);
getViewElement().setQuitText("Back");
inMarketView = false;
inStatsView = false;
inTransactionsView = false;
inMinigamesView = true;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TopBarView extends ViewElement<VBox, TopBarActions> {
private Button marketBtn;
private Button settingsBtn;
private Button transactionsBtn;
private Button minigamesBtn;
private SummaryView summaryView;


Expand Down Expand Up @@ -48,8 +49,10 @@ protected void initLayout() {
marketBtn = new Button("Market");
settingsBtn = new Button("Settings");
transactionsBtn = new Button("Transactions");
minigamesBtn = new Button("Minigames");

Stream.of(quitBtn, statsBtn, marketBtn, settingsBtn, transactionsBtn).forEach(b -> {

Stream.of(quitBtn, statsBtn, marketBtn, settingsBtn, transactionsBtn, minigamesBtn).forEach(b -> {
HBox.setHgrow(b, Priority.ALWAYS);
});

Expand All @@ -58,7 +61,8 @@ protected void initLayout() {
statsBtn,
marketBtn,
settingsBtn,
transactionsBtn
transactionsBtn,
minigamesBtn
);

if (summaryView != null) {
Expand All @@ -71,12 +75,13 @@ protected void initLayout() {
registerButton(TopBarActions.MARKET, marketBtn);
registerButton(TopBarActions.SETTINGS, settingsBtn);
registerButton(TopBarActions.TRANSACTIONS, transactionsBtn);
registerButton(TopBarActions.MINIGAMES, minigamesBtn);
}

@Override
protected void initStyling() {
getRootPane().getStyleClass().add("top-bar");
Stream.of(quitBtn, statsBtn, marketBtn, settingsBtn, transactionsBtn)
Stream.of(quitBtn, statsBtn, marketBtn, settingsBtn, transactionsBtn, minigamesBtn)
.forEach(b -> b.getStyleClass().add("menu-button"));
}

Expand Down
Loading

0 comments on commit dd0b867

Please sign in to comment.