diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
index d0bbca3..fef87da 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
@@ -174,8 +174,8 @@ public void start(final Stage stage) throws Exception {
MiniGamesView miniGamesView = new MiniGamesView();
MiniGamesController miniGamesController =
new MiniGamesController(
- miniGamesView, eventManager, stocksInFile.getFirst(), gameEngineView,
- gameEngineController, clickerGame, inGameView, findStockGame, timeInputsGame
+ miniGamesView, eventManager, stocksInFile.getFirst(),
+ gameEngineController, clickerGame, findStockGame, timeInputsGame
);
// Adds a generic event subscriber to the event manager
@@ -183,6 +183,8 @@ public void start(final Stage stage) throws Exception {
// triggered when a new save file is loaded.
// We define this implementation here, because
// this class has the highest level overview of the application.
+ // SOLUTION SUGGESTED BY AI.
+ // REVIEWED AND TESTED BY THE TEAM BEFORE IMPLEMENTATION.
eventManager.addSubscriber(new EventSubscriber() {
@Override
public void handleEvent(final EventData eventData) {
@@ -215,12 +217,6 @@ public void handleEvent(final EventData eventData) {
}
}, EventType.STATE_RESET);
- topBarController.setMarketIntegration(
- inGameView::changeCenterView, dashBoardView.getRootPane(), marketView.getRootPane(),
- statsView.getRootPane(), transactionsView.getRootPane(), transactionsController::refresh,
- miniGamesView.getRootPane()
- );
-
InGameSettingsView inGameSettingsView = new InGameSettingsView();
InGameSettingsController inGameSettingsController =
new InGameSettingsController(inGameSettingsView, eventManager, inGameView);
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/event/EventType.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/event/EventType.java
index 825e9bc..bc8b9b1 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/event/EventType.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/event/EventType.java
@@ -90,5 +90,23 @@ public enum EventType implements EventChannel {
* edu.ntnu.idi.idatt2003.g40.mappe.model.SaveGame} that was loaded
* but most listeners don't inspect it.
* */
- STATE_RESET;
+ STATE_RESET,
+
+ /**
+ * Event for selecting a specific stock on the dashboard.
+ *
+ * Published by
+ * {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketController}
+ * and handled by {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardController}
+ * */
+ SELECT_STOCK_FOR_DASHBOARD,
+
+ /**
+ * Event for showing quit options.
+ *
+ * Published by the {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController}.
+ * Handled by the {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.quit.QuitDialogController}.
+ * */
+ SHOW_QUIT_OPTIONS;
+
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameActions.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameActions.java
index 03ddd1a..37151cd 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameActions.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameActions.java
@@ -1,6 +1,8 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame;
+/**
+ * Action set for the in game controller.
+ * */
public enum InGameActions {
- BUY_SHARES,
- SELL_SHARES;
+ // Empty, no direct actions.
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.java
index 6c84780..2402aaf 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.java
@@ -6,24 +6,47 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
-import javafx.scene.Node;
import java.util.EnumMap;
+import javafx.scene.Node;
+/**
+ * Controller for {@link InGameView}.
+ *
+ * Extends {@link ViewController}
+ * */
public final class InGameController extends ViewController
implements EventSubscriber {
+ /**
+ * Map of widgets, used to identify and switch between center nodes.
+ * */
private final EnumMap widgetMap = new EnumMap<>(WidgetEnum.class);
/**
- * {@inheritDoc}.
+ * Value representing currently active widget.
+ */
+ private WidgetEnum activeWidget;
+
+ /**
+ * Constructor.
+ *
+ * @param viewElement the associated {@link InGameView}.
+ * @param eventManager the active {@link EventManager}.
*/
public InGameController(final InGameView viewElement,
final EventManager eventManager)
throws IllegalArgumentException {
super(viewElement, eventManager);
+ activeWidget = WidgetEnum.DASHBOARD;
eventManager.addSubscriber(this, EventType.CHANGE_INGAME_CENTER);
}
+ /**
+ * Adds a widget to the widget map.
+ *
+ * @param widgetEnum the name of the widget.
+ * @param widgetRoot the root node of the widget.
+ * */
public void addwidget(final WidgetEnum widgetEnum, final Node widgetRoot) {
widgetMap.put(widgetEnum, widgetRoot);
}
@@ -39,5 +62,16 @@ public void handleEvent(final EventData data) {
throw new IllegalArgumentException("Invalid event thrown!");
}
getViewElement().changeCenterView(widgetMap.get(data.data()));
+ if (data.data() == WidgetEnum.DASHBOARD) {
+ getViewElement().getTopBarView().setQuitText("Quit");
+ if (activeWidget == WidgetEnum.DASHBOARD) {
+ EventData eventData =
+ new EventData<>(EventType.SHOW_QUIT_OPTIONS, true);
+ invoke(eventData);
+ }
+ } else {
+ getViewElement().getTopBarView().setQuitText("Back");
+ }
+ activeWidget = (WidgetEnum) data.data();
}
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java
index 6ef94b2..1055ac3 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java
@@ -8,6 +8,11 @@
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
+/**
+ * In game view.
+ *
+ * Extends {@link ViewElement}
+ * */
public class InGameView extends ViewElement {
private final TopBarView topBarView;
@@ -43,6 +48,11 @@ protected void initStyling() {
getRootPane().getStyleClass().add("in-game-root");
}
+ /**
+ * Changes the center of the in-game view wrapper to a new widget view element.
+ *
+ * @param newCenterView the root node of the new center to set.
+ * */
public void changeCenterView(final Node newCenterView) {
this.centerView = newCenterView;
centerStack.getChildren().clear();
@@ -52,6 +62,13 @@ public void changeCenterView(final Node newCenterView) {
}
}
+ /**
+ * Getter method for top bar.
+ * */
+ public TopBarView getTopBarView() {
+ return topBarView;
+ }
+
/**
* Shows a settings overlay on top of the current center view.
*
@@ -77,13 +94,4 @@ public void hideSettingsOverlay() {
settingsOverlay = null;
}
}
-
- /**
- * Returns whether a settings overlay is currently shown.
- *
- * @return {@code true} if the settings overlay is visible.
- * */
- public boolean isSettingsOverlayVisible() {
- return settingsOverlay != null;
- }
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/quit/QuitDialogController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/quit/QuitDialogController.java
index 52a4e90..0d12399 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/quit/QuitDialogController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/quit/QuitDialogController.java
@@ -3,7 +3,10 @@
import edu.ntnu.idi.idatt2003.g40.mappe.model.SaveGame;
import edu.ntnu.idi.idatt2003.g40.mappe.service.GameStateLoader;
import edu.ntnu.idi.idatt2003.g40.mappe.service.SaveGameService;
+import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
+import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber;
+import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView;
@@ -30,7 +33,8 @@
* no-op rather than an error, since there's nothing meaningful to write.
* */
public final class QuitDialogController
- extends ViewController {
+ extends ViewController
+ implements EventSubscriber {
/** The in-game view hosting this overlay. */
private final InGameView inGameView;
@@ -67,6 +71,7 @@ public QuitDialogController(final QuitDialogView view,
this.gameStateLoader = gameStateLoader;
this.saveGameService = saveGameService;
super(view, eventManager);
+ eventManager.addSubscriber(this, EventType.SHOW_QUIT_OPTIONS);
if (inGameView == null
|| gameStateLoader == null
|| saveGameService == null) {
@@ -185,4 +190,9 @@ private boolean performSave() {
return false;
}
}
+
+ @Override
+ public void handleEvent(EventData data) {
+ show();
+ }
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuActions.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuActions.java
index 37ad15c..45e8914 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuActions.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuActions.java
@@ -1,7 +1,21 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu;
+/**
+ * Action set for the main menu.
+ * */
public enum MainMenuActions {
+ /**
+ * Action for starting the game.
+ * */
START_GAME,
+
+ /**
+ * Action for opening the settings panel.
+ * */
SETTINGS,
+
+ /**
+ * Action for exiting the application.
+ * */
EXIT;
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java
index a9343a1..c2176b6 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java
@@ -1,10 +1,7 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu;
-import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
-import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
-import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewData;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import javafx.application.Platform;
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/playgame/PlayGameActions.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/playgame/PlayGameActions.java
index aa52832..7b8ce7a 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/playgame/PlayGameActions.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/playgame/PlayGameActions.java
@@ -1,7 +1,22 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.playgame;
+/**
+ * Action set in the {@link PlayGameView} section.
+ * */
public enum PlayGameActions {
+
+ /**
+ * Creating a new game.
+ * */
NEW_GAME,
+
+ /**
+ * Returning to the main menu.
+ * */
BACK,
+
+ /**
+ * Uploading a save file.
+ * */
UPLOAD_SAVE,
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/settings/SettingsActions.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/settings/SettingsActions.java
index 767bf2e..73fb1fa 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/settings/SettingsActions.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/settings/SettingsActions.java
@@ -1,30 +1,36 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.settings;
/**
- * User-triggered actions available on the main-menu settings view.
- *
- * {@link #AUDIO}, {@link #VIDEO} and {@link #HOTKEYS} are kept for
- * backwards compatibility with the older sidebar/tab layout - they no
- * longer correspond to user-pressable buttons in the redesigned view,
- * but the {@code SettingsController} still wires no-op handlers to
- * them so existing call sites keep compiling.
+ * Action set for {@link SettingsView}.
* */
public enum SettingsActions {
- /** Legacy audio-tab action. No longer triggered by the redesigned view. */
+ /**
+ * Audio panel.
+ * */
AUDIO,
- /** Legacy video-tab action. No longer triggered by the redesigned view. */
+ /**
+ * Video panel.
+ * */
VIDEO,
- /** Legacy hot-keys-tab action. No longer triggered by the redesigned view. */
+ /**
+ * Hotkeys panel.
+ * */
HOTKEYS,
- /** Returns to the main menu. */
+ /**
+ * Return to main menu.
+ * */
BACK,
- /** Selects the dark theme. */
+ /**
+ * Selecting dark mode.
+ */
DARK_MODE,
- /** Selects the light theme. */
+ /**
+ * Selecting light mode.
+ * */
LIGHT_MODE;
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java
index 9a5cd9c..001ff85 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardController.java
@@ -65,6 +65,7 @@ public DashBoardController(final DashBoardView viewElement,
this.selectedTimeRange = DashBoardTimeRange.DEFAULT;
super(viewElement, eventManager);
eventManager.addSubscriber(this, EventType.STATE_RESET);
+ eventManager.addSubscriber(this, EventType.SELECT_STOCK_FOR_DASHBOARD);
}
/**
@@ -259,5 +260,13 @@ public void handleEvent(final EventData data) {
getViewElement().setCurrentStock(first, owned.floatValue());
}
getViewElement().updateGraph(selectedTimeRange);
+
+ if(data.channel() == EventType.SELECT_STOCK_FOR_DASHBOARD && data.data() instanceof Stock s) {
+ handleStockSelection(
+ s,
+ player.getPortfolio().getTotalShareQuantityBySymbol(s.getSymbol()).floatValue()
+ );
+ }
+
}
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryActions.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryActions.java
index a9c93c7..4a5c4ee 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryActions.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryActions.java
@@ -1,5 +1,11 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary;
+/**
+ * Action set for {@link SummaryView}.
+ * */
public enum SummaryActions {
+ /**
+ * Advance week.
+ * */
NEXT_WEEK;
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java
index ca060f3..9b5aa5c 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java
@@ -11,11 +11,27 @@
import java.util.ArrayList;
import java.util.List;
+/**
+ * Controller for the {@link SummaryView}.
+ *
+ * Extends {@link ViewController}
+ * */
public class SummaryController extends ViewController
implements EventSubscriber {
+ /**
+ * Exchange to call when advancing week.
+ * */
private Exchange exchange;
+
+ /**
+ * Player object.
+ * */
private Player player;
+
+ /**
+ * Player net-worth history.
+ * */
private List playerNetWorthHistory;
/**
@@ -65,7 +81,7 @@ protected void initInteractions() {
}
/**
- * Synchronizes the controller pointers with the active game engine state references.
+ * Synchronizes the controller pointers with the active exchange and player objects.
*
* @param criticalExchange the current active exchange engine.
* @param activePlayer the current active player context profile.
@@ -82,16 +98,13 @@ public void handleContextUpdate(final Exchange criticalExchange, final Player ac
}
this.playerNetWorthHistory.clear();
- // 1. Recover history from the updated player instance if available
if (this.player.getNetWorthHistory() != null && !this.player.getNetWorthHistory().isEmpty()) {
this.playerNetWorthHistory.addAll(this.player.getNetWorthHistory());
} else {
- // Safe fallback trajectory baseline points
this.playerNetWorthHistory.add(this.player.getStartingMoney());
this.playerNetWorthHistory.add(this.player.getNetWorth());
}
- // Flush updates directly into view layer
getViewElement().setWeek(this.exchange.getWeek());
getViewElement().updateChart(this.playerNetWorthHistory.stream().map(BigDecimal::floatValue).toList());
getViewElement().setBalance(this.player.getMoney().floatValue(), this.player.getNetWorth().floatValue());
@@ -127,9 +140,10 @@ public void handleEvent(final EventData data) {
} else {
playerNetWorthHistory.add(player.getNetWorth());
}
+
+ getViewElement().setWeek(exchange.getWeek());
getViewElement().updateChart(playerNetWorthHistory.stream().map(BigDecimal::floatValue).toList());
getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue());
- getViewElement().setWeek(exchange.getWeek());
getViewElement().setStatus(player.getStatus());
}
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java
index 74a3c55..e95e0e1 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java
@@ -2,6 +2,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.model.PlayerStatus;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
+import java.util.List;
import javafx.geometry.Pos;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
@@ -12,19 +13,63 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
-import java.util.List;
+/**
+ * Summary view is a view that is found under the topbar.
+ * It includes balance, status, current week, and a chart
+ * representing net worth over time.
+ *
+ * Extends {@link ViewElement}
+ * */
public class SummaryView extends ViewElement {
+ /**
+ * Current balance.
+ * */
private Label balanceLabel;
+
+ /**
+ * Current {@link PlayerStatus}.
+ * */
private Label statusLabel;
+
+ /**
+ * Current week.
+ * */
private Label weekLabel;
+
+ /**
+ * Balance title ("Balance/NetWorth").
+ * */
private Label titleLabel;
+
+ /**
+ * Chart representing net worth over time.
+ * */
private LineChart chart;
+
+ /**
+ * Data series for chart.
+ * */
private XYChart.Series dataSeries;
+
+ /**
+ * Next week button (advances week).
+ * */
private Button nextBtn;
+
+ /**
+ * X axis for chart.
+ * */
private NumberAxis xAxis;
+
+ /**
+ * Y axis for chart.
+ * */
private NumberAxis yAxis;
+ /**
+ * Constructor.
+ * */
public SummaryView() {
super(new HBox(), SummaryActions.class);
}
@@ -43,7 +88,7 @@ protected void initLayout() {
VBox balanceInfo = new VBox();
- titleLabel = new Label("Networth");
+ titleLabel = new Label("Balance/NetWorth");
balanceLabel = new Label("0$");
statusLabel = new Label(PlayerStatus.NOOB.getDisplayName());
@@ -113,6 +158,12 @@ protected void initStyling() {
nextBtn.getStyleClass().add("next-button");
}
+ /**
+ * Sets the current balance and money label values.
+ *
+ * @param money the current balance.
+ * @param netWorth the current total networth.
+ * */
public void setBalance(final float money, final float netWorth) {
balanceLabel.setText(Math.round(money*100f)/100f + "NOK / " + Math.round(netWorth*100f)/100f + "NOK");
}
@@ -137,10 +188,21 @@ public void setStatus(final PlayerStatus status) {
statusLabel.getStyleClass().add("status-tier-" + status.name().toLowerCase());
}
+ /**
+ * Sets the week label text to a new week.
+ *
+ * @param week week to set.
+ * */
public void setWeek(int week) {
weekLabel.setText("week: " + week);
}
+ /**
+ * Updates the chart based on player net worth history.
+ *
+ * @param playerNetWorthHistory list of float values
+ * representing all net worth values.
+ * */
public void updateChart(final List playerNetWorthHistory) {
dataSeries.getData().clear();
xAxis.setLowerBound(Math.max(1, playerNetWorthHistory.size() - 10));
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/market/MarketController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/market/MarketController.java
index b8ab2dc..fce33d8 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/market/MarketController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/market/MarketController.java
@@ -10,6 +10,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.Validator;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
+import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import java.math.BigDecimal;
import java.util.List;
@@ -63,6 +64,17 @@ protected void initInteractions() {
getViewElement().setOwnedLookup(this::ownedQuantity);
getViewElement().setStocks(stockList);
+ getViewElement().setOnStockSelected(
+ (stock) -> {
+ EventData eventData =
+ new EventData<>(EventType.SELECT_STOCK_FOR_DASHBOARD, stock);
+ EventData changeViewData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.DASHBOARD);
+ invoke(eventData);
+ invoke(changeViewData);
+ }
+ );
+
getViewElement().setOnAction(MarketActions.SORT_TICKER,
() -> getViewElement().setSort(MarketSort.TICKER));
getViewElement().setOnAction(MarketActions.SORT_PRICE,
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameGimmick.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameGimmick.java
index e1add25..0f09224 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameGimmick.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameGimmick.java
@@ -6,6 +6,8 @@
/**
* Strategy interface defining the central
* logic and layout for individual minigames.
+ *
+ * DESIGN SUGGESTED BY AI
*/
public interface GameGimmick {
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesController.java
index acad65a..adafb12 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/MiniGamesController.java
@@ -6,7 +6,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
-import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView;
+import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.ClickerGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.FindStockGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.TimeInputsGame;
@@ -25,11 +25,6 @@ public final class MiniGamesController
* */
private Stock activeStock;
- /**
- * The game engine view to delegate games towards.
- * */
- private final GameEngineView gameEngineView;
-
/**
* The game engine controller.
* */
@@ -40,11 +35,6 @@ public final class MiniGamesController
* */
private final ClickerGame clickerGame;
- /**
- * The in game view.
- * */
- private final InGameView inGameView;
-
/**
* The find stock game instance.
* */
@@ -61,28 +51,22 @@ public final class MiniGamesController
* @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,
- final GameEngineView gameEngineView,
final GameEngineController gameEngineController,
final ClickerGame clickerGame,
- final InGameView inGameView,
final FindStockGame findStockGame,
final TimeInputsGame timeInputsGame
) {
this.activeStock = initialStock;
- this.gameEngineView = gameEngineView;
this.gameEngineController = gameEngineController;
this.clickerGame = clickerGame;
- this.inGameView = inGameView;
this.findStockGame = findStockGame;
this.timeInputsGame = timeInputsGame;
super(viewElement, eventManager);
@@ -97,17 +81,23 @@ protected void initInteractions() {
});
getViewElement().setOnAction(MiniGamesActions.CLICKER_GAME, () -> {
- inGameView.changeCenterView(gameEngineView.getRootPane());
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.MINIGAMES_ENGINE);
+ invoke(eventData);
gameEngineController.launchGimmickSession(clickerGame);
});
getViewElement().setOnAction(MiniGamesActions.FIND_STOCK, () -> {
- inGameView.changeCenterView(gameEngineView.getRootPane());
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.MINIGAMES_ENGINE);
+ invoke(eventData);
gameEngineController.launchGimmickSession(findStockGame);
});
getViewElement().setOnAction(MiniGamesActions.TIME_CLICKS, () -> {
- inGameView.changeCenterView(gameEngineView.getRootPane());
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.MINIGAMES_ENGINE);
+ invoke(eventData);
gameEngineController.launchGimmickSession(timeInputsGame);
});
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/TimeInputsGame.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/TimeInputsGame.java
index 85aabc9..91eeb8d 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/TimeInputsGame.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/TimeInputsGame.java
@@ -118,6 +118,8 @@ private void renderCanvas() {
gc.strokeArc(centerX - radius, centerY - radius, radius * 2, radius * 2, successZoneStart, successZoneExtent, javafx.scene.shape.ArcType.OPEN);
// Calculates and draws the indicator line based on radius and angle.
+ // ROTATION ALGORITHM SUGGESTED BY AI.
+ // CODE HAS BEEN REVIEWED AND TESTED.
double rad = Math.toRadians(-indicatorAngle);
double startX = centerX + (radius - 15) * Math.cos(rad);
double startY = centerY + (radius - 15) * Math.sin(rad);
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarActions.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarActions.java
index 6f07799..ec6f530 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarActions.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarActions.java
@@ -1,10 +1,36 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar;
+/**
+ * Action set for top bar.
+ * */
public enum TopBarActions {
+ /**
+ * Returns to main menu.
+ * */
EXIT,
+
+ /**
+ * Go to stats page.
+ * */
STATS,
+
+ /**
+ * Go to market page.
+ * */
MARKET,
+
+ /**
+ * Go to settings page.
+ * */
SETTINGS,
+
+ /**
+ * Go to transactions page.
+ * */
TRANSACTIONS,
+
+ /**
+ * Go to minigames page.
+ * */
MINIGAMES;
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarController.java
index f647c49..442c315 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarController.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarController.java
@@ -1,54 +1,18 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar;
+import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
+import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
-import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
-import javafx.scene.Node;
-
-import java.util.function.Consumer;
+import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
+/**
+ * Controller class for {@link TopBarView}.
+ *
+ * Extends {@link ViewController}
+ * */
public class TopBarController extends ViewController {
- /**
- * Whether the market is currently the active center-view.
- *
- *
- * When true, the quit/back button returns to the dashboard instead
- * of exiting to the main menu.
- *
- */
- private boolean inMarketView = false;
-
- /**
- * Whether the stats screen is currently the active center-view.
- *
- *
- * When true, the quit/back button returns to the dashboard instead
- * of exiting to the main menu.
- *
- */
- private boolean inStatsView = false;
-
- /**
- * Whether the transactions screen is currently the active center-view.
- *
- *
- * When true, the quit/back button returns to the dashboard instead
- * of exiting to the main menu.
- *
- */
- private boolean inTransactionsView = false;
-
- /**
- * Whether the minigames screen is currently the active center-view.
- *
- *
- * When true, the quit/back button returns to the dashboard instead
- * of exiting to the main menu.
- *
- */
- private boolean inMinigamesView = false;
-
/**
* Optional hook invoked just before the in-game session is left
* (when the quit/back button returns to the main menu).
@@ -87,111 +51,42 @@ public TopBarController(final TopBarView viewElement, final EventManager eventMa
@Override
protected void initInteractions() {
getViewElement().setOnAction(TopBarActions.EXIT, () -> {
- onQuitToMainMenu.run();
- changeScene(ViewEnum.MAIN_MENU);
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.DASHBOARD);
+ invoke(eventData);
});
- getViewElement().setOnAction(TopBarActions.STATS, () -> changeScene(ViewEnum.MAIN_MENU));
-
- getViewElement().setOnAction(TopBarActions.MARKET, () -> changeScene(ViewEnum.MAIN_MENU));
-
- getViewElement().setOnAction(TopBarActions.SETTINGS, () -> changeScene(ViewEnum.MAIN_MENU));
- }
-
- /**
- * Wires the top bar buttons to swap between the dashboard, stats,
- * market and transactions center-views inside the in-game view.
- *
- *
- * After this method is called:
- *
- *
- * - {@code STATS} swaps the center to the stats view and switches
- * the quit/back button to "Back".
- * - {@code MARKET} swaps the center to the market and switches the
- * button to "Back".
- * - {@code TRANSACTIONS} swaps the center to the transactions view
- * and switches the button to "Back".
- * - {@code EXIT} returns to the dashboard if any sub-view is open,
- * otherwise to the main menu.
- *
- *
- * @param centerSwitcher callback that swaps the center-view (typically
- * {@code inGameView::changeCenterView}).
- * @param dashboardCenter root pane of the dashboard widget (home).
- * @param marketCenter root pane of the market widget.
- * @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 centerSwitcher,
- final Node dashboardCenter,
- final Node marketCenter,
- final Node statsCenter,
- final Node transactionsCenter,
- final Runnable onTransactionUpdate,
- final Node minigamesCenter
- ) {
- getViewElement().setOnAction(TopBarActions.EXIT, () -> {
- if (inMarketView
- || inStatsView
- || inTransactionsView
- || inMinigamesView) {
- centerSwitcher.accept(dashboardCenter);
- getViewElement().setQuitText("Quit");
- inMarketView = false;
- inStatsView = false;
- inTransactionsView = false;
- inMinigamesView = false;
- } else if (onQuitRequested != null) {
- // From the dashboard, hand control over to the application's
- // quit-confirmation flow (typically a popup with continue /
- // save / save-and-quit choices). The hook is responsible for
- // any auto-save and scene change after the player chooses.
- onQuitRequested.run();
- } else {
- onQuitToMainMenu.run();
- changeScene(ViewEnum.MAIN_MENU);
- }
- });
-
- getViewElement().setOnAction(TopBarActions.STATS, () -> {
- centerSwitcher.accept(statsCenter);
- getViewElement().setQuitText("Back");
- inMarketView = false;
- inStatsView = true;
- inTransactionsView = false;
- inMinigamesView = false;
- });
-
- getViewElement().setOnAction(TopBarActions.MARKET, () -> {
- centerSwitcher.accept(marketCenter);
- getViewElement().setQuitText("Back");
- inMarketView = true;
- inStatsView = false;
- inTransactionsView = false;
- inMinigamesView = false;
- });
-
- getViewElement().setOnAction(TopBarActions.TRANSACTIONS, () -> {
- centerSwitcher.accept(transactionsCenter);
- onTransactionUpdate.run();
- getViewElement().setQuitText("Back");
- 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;
- });
+ getViewElement().setOnAction(TopBarActions.STATS,
+ () -> {
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.STATS);
+ invoke(eventData);
+ }
+ );
+
+ getViewElement().setOnAction(TopBarActions.MARKET,
+ () -> {
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.MARKET);
+ invoke(eventData);
+ }
+ );
+
+ getViewElement().setOnAction(TopBarActions.TRANSACTIONS,
+ () -> {
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.TRANSACTIONS);
+ invoke(eventData);
+ }
+ );
+
+ getViewElement().setOnAction(TopBarActions.MINIGAMES,
+ () -> {
+ EventData eventData =
+ new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.MINIGAMES_OVERVIEW);
+ invoke(eventData);
+ }
+ );
}
/**
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarView.java
index bf9beb6..2000276 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarView.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarView.java
@@ -2,6 +2,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
+import java.util.stream.Stream;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
@@ -9,23 +10,62 @@
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
-import java.util.stream.Stream;
-
+/**
+ * View element containing navigation buttons and summary.
+ *
+ * Extends {@link ViewElement}
+ * */
public class TopBarView extends ViewElement {
+ /**
+ * Quit button.
+ * */
private Button quitBtn;
+
+ /**
+ * Stats button.
+ * */
private Button statsBtn;
+
+ /**
+ * Market button.
+ * */
private Button marketBtn;
+
+ /**
+ * Settings button.
+ * */
private Button settingsBtn;
+
+ /**
+ * Transactions button.
+ * */
private Button transactionsBtn;
+
+ /**
+ * Minigames button.
+ * */
private Button minigamesBtn;
- private SummaryView summaryView;
+ /**
+ * Summary section.
+ *
+ * @see SummaryView
+ * */
+ private SummaryView summaryView;
+ /**
+ * Constructor.
+ *
+ * @param summaryView the {@link SummaryView} section to include.
+ * */
public TopBarView(final SummaryView summaryView) {
this.summaryView = summaryView;
super(new VBox(10), TopBarActions.class);
}
+ /**
+ * Constructor without summary section.
+ * */
public TopBarView() {
super(new VBox(10), TopBarActions.class);
}
diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/transactions/TransactionsView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/transactions/TransactionsView.java
index 632b8b0..b55efd3 100644
--- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/transactions/TransactionsView.java
+++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/transactions/TransactionsView.java
@@ -1,6 +1,7 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
+import java.util.List;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
@@ -9,7 +10,6 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
-import java.util.List;
/**
* View for displaying a history of all transactions for the active player.