From f5d9a14c3e1f6596fe6b554922e4a337fc5de5b3 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 05:00:24 +0200 Subject: [PATCH 1/8] FIx: bug fix --- .../mappe/view/widgets/financialsummary/SummaryController.java | 1 - 1 file changed, 1 deletion(-) 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 28a6224..5d655df 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 @@ -121,7 +121,6 @@ public void handleEvent(final EventData data) { if (!player.getNetWorthHistory().isEmpty()) { playerNetWorthHistory.addAll(player.getNetWorthHistory()); } else { - playerNetWorthHistory.add(player.getStartingMoney()); playerNetWorthHistory.add(player.getNetWorth()); } From e658f845b6a385ffced3c3e8b89cdec3f4840b76 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 05:42:22 +0200 Subject: [PATCH 2/8] Docs: JavaDoc and AI declarations --- .../edu/ntnu/idi/idatt2003/g40/mappe/Main.java | 2 ++ .../g40/mappe/view/ingame/InGameActions.java | 6 ++++-- .../mappe/view/ingame/InGameController.java | 16 +++++++++++++++- .../g40/mappe/view/ingame/InGameView.java | 14 +++++--------- .../mappe/view/mainmenu/MainMenuActions.java | 14 ++++++++++++++ .../view/mainmenu/MainMenuController.java | 3 --- .../mappe/view/playgame/PlayGameActions.java | 15 +++++++++++++++ .../mappe/view/settings/SettingsActions.java | 18 ++++++++++++++++++ .../financialsummary/SummaryActions.java | 6 ++++++ .../financialsummary/SummaryController.java | 16 ++++++++++++++++ .../view/widgets/minigames/GameGimmick.java | 2 ++ .../minigames/games/TimeInputsGame.java | 2 ++ 12 files changed, 99 insertions(+), 15 deletions(-) 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 348cf5c..32de983 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 @@ -179,6 +179,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) { 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..d0b30d8 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,12 +6,20 @@ 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); /** @@ -24,6 +32,12 @@ public InGameController(final InGameView viewElement, 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); } 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..7027655 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; @@ -77,13 +82,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/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 b319a02..dfc7dff 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,8 +1,26 @@ package edu.ntnu.idi.idatt2003.g40.mappe.view.settings; +/** + * Action set for {@link SettingsView}. + * */ public enum SettingsActions { + /** + * Audio panel. + * */ AUDIO, + + /** + * Video panel. + * */ VIDEO, + + /** + * Hotkeys panel. + * */ HOTKEYS, + + /** + * Return to main menu. + * */ BACK; } 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 b103b6a..761c044 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; /** 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/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); From 5be283a162e29d3c5608ca3f6914059b75f6c0db Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 06:02:03 +0200 Subject: [PATCH 3/8] Docs: JavaDocs --- .../financialsummary/SummaryController.java | 5 +- .../widgets/financialsummary/SummaryView.java | 66 ++++++++++++++++++- .../view/widgets/topbar/TopBarActions.java | 26 ++++++++ .../view/widgets/topbar/TopBarController.java | 8 ++- .../mappe/view/widgets/topbar/TopBarView.java | 46 ++++++++++++- .../transactions/TransactionsView.java | 2 +- 6 files changed, 141 insertions(+), 12 deletions(-) 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 761c044..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 @@ -81,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. @@ -98,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()); 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/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 e338eb6..ef677b0 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 @@ -3,10 +3,14 @@ import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; 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 javafx.scene.Node; +/** + * Controller class for {@link TopBarView}. + * + *

Extends {@link ViewController}

+ * */ public class TopBarController extends ViewController { /** 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. From 76de2f176cdaa5224fceef7747efbab5f5faebff Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 06:17:41 +0200 Subject: [PATCH 4/8] Feat: Now possible to access stock via market. --- .../idatt2003/g40/mappe/service/event/EventType.java | 11 ++++++++++- .../view/widgets/dashboard/DashBoardController.java | 9 +++++++++ .../mappe/view/widgets/market/MarketController.java | 12 ++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) 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..ff2e13e 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,14 @@ 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; } 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/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, From db75c1599a6dc3a40d7472087c582dfae82ab1f1 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 06:46:41 +0200 Subject: [PATCH 5/8] Feat: Replaced market integration with pub/sub --- .../ntnu/idi/idatt2003/g40/mappe/Main.java | 6 - .../mappe/view/ingame/InGameController.java | 32 ++++- .../g40/mappe/view/ingame/InGameView.java | 12 ++ .../view/widgets/topbar/TopBarController.java | 135 +++++------------- 4 files changed, 81 insertions(+), 104 deletions(-) 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 32de983..99d33ce 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 @@ -213,12 +213,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/view/ingame/InGameController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.java index d0b30d8..f099411 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 @@ -5,6 +5,8 @@ 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.ViewData; +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum; import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum; import java.util.EnumMap; import javafx.scene.Node; @@ -23,12 +25,21 @@ public final class InGameController extends ViewController 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); } @@ -42,6 +53,14 @@ public void addwidget(final WidgetEnum widgetEnum, final Node widgetRoot) { widgetMap.put(widgetEnum, widgetRoot); } + /** + * Getter method for currently active widget. + * */ + private WidgetEnum getActiveWidget() { + return activeWidget; + } + + @Override protected void initInteractions() { @@ -53,5 +72,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) { + ViewData viewData = new ViewData(ViewEnum.MAIN_MENU); + EventData eventData = new EventData<>(EventType.SCENE_CHANGE, viewData); + 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 7027655..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 @@ -48,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(); @@ -57,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. * 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 ef677b0..e840703 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,9 +1,13 @@ 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 java.util.function.Consumer; + +import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum; import javafx.scene.Node; /** @@ -75,105 +79,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 { - 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); + } + ); } /** From 1aa1dcceb5de299e979a28e6b17271a3fb4040c3 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 08:25:23 +0200 Subject: [PATCH 6/8] Feat: Reduce coupling by using pub/sub --- .../ntnu/idi/idatt2003/g40/mappe/Main.java | 4 +-- .../minigames/MiniGamesController.java | 30 +++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) 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 99d33ce..77f119b 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 @@ -170,8 +170,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 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); }); } From 9da6f220892ff9fc89b80c73ecd9cb68bc7c1a3a Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 08:29:30 +0200 Subject: [PATCH 7/8] Fix: Dark and light mode settingsactions --- .../g40/mappe/view/settings/SettingsActions.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 dfc7dff..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 @@ -22,5 +22,15 @@ public enum SettingsActions { /** * Return to main menu. * */ - BACK; + BACK, + + /** + * Selecting dark mode. + */ + DARK_MODE, + + /** + * Selecting light mode. + * */ + LIGHT_MODE; } From da9852ec5ba86c7a1a428bcdf2ebd960515fd4fd Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 15:28:30 +0200 Subject: [PATCH 8/8] Feat: Fixed quit options --- .../g40/mappe/service/event/EventType.java | 11 ++++- .../mappe/view/ingame/InGameController.java | 14 +----- .../ingame/quit/QuitDialogController.java | 12 ++++- .../view/widgets/topbar/TopBarController.java | 44 ------------------- 4 files changed, 23 insertions(+), 58 deletions(-) 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 ff2e13e..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 @@ -99,5 +99,14 @@ public enum EventType implements EventChannel { * {@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; + 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/InGameController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameController.java index f099411..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 @@ -5,8 +5,6 @@ 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.ViewData; -import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum; import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum; import java.util.EnumMap; import javafx.scene.Node; @@ -53,14 +51,6 @@ public void addwidget(final WidgetEnum widgetEnum, final Node widgetRoot) { widgetMap.put(widgetEnum, widgetRoot); } - /** - * Getter method for currently active widget. - * */ - private WidgetEnum getActiveWidget() { - return activeWidget; - } - - @Override protected void initInteractions() { @@ -75,8 +65,8 @@ public void handleEvent(final EventData data) { if (data.data() == WidgetEnum.DASHBOARD) { getViewElement().getTopBarView().setQuitText("Quit"); if (activeWidget == WidgetEnum.DASHBOARD) { - ViewData viewData = new ViewData(ViewEnum.MAIN_MENU); - EventData eventData = new EventData<>(EventType.SCENE_CHANGE, viewData); + EventData eventData = + new EventData<>(EventType.SHOW_QUIT_OPTIONS, true); invoke(eventData); } } else { 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/widgets/topbar/TopBarController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/topbar/TopBarController.java index d79ccff..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 @@ -4,11 +4,7 @@ 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; -import javafx.scene.Node; /** * Controller class for {@link TopBarView}. @@ -17,46 +13,6 @@ * */ 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).