Skip to content

Commit

Permalink
Merge pull request #142 from Team-40-IDATT2003/141-market-integration…
Browse files Browse the repository at this point in the history
…-fix

141 market integration fix
  • Loading branch information
etsorens authored May 26, 2026
2 parents 51a188b + da9852e commit b82d63a
Show file tree
Hide file tree
Showing 22 changed files with 375 additions and 217 deletions.
12 changes: 4 additions & 8 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ 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
// that handles STATE_RESET events. These events are
// 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 <T> void handleEvent(final EventData<T> eventData) {
Expand Down Expand Up @@ -215,12 +217,6 @@ public <T> void handleEvent(final EventData<T> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.</p>
* */
STATE_RESET;
STATE_RESET,

/**
* Event for selecting a specific stock on the dashboard.
*
* <p>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}</p>
* */
SELECT_STOCK_FOR_DASHBOARD,

/**
* Event for showing quit options.
*
* <p>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}.</p>
* */
SHOW_QUIT_OPTIONS;

}
Original file line number Diff line number Diff line change
@@ -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.
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
* <p>Extends {@link ViewController}</p>
* */
public final class InGameController extends ViewController<InGameView>
implements EventSubscriber {

/**
* Map of widgets, used to identify and switch between center nodes.
* */
private final EnumMap<WidgetEnum, Node> 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);
}
Expand All @@ -39,5 +62,16 @@ public <T> void handleEvent(final EventData<T> 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<Boolean> eventData =
new EventData<>(EventType.SHOW_QUIT_OPTIONS, true);
invoke(eventData);
}
} else {
getViewElement().getTopBarView().setQuitText("Back");
}
activeWidget = (WidgetEnum) data.data();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

/**
* In game view.
*
* <p>Extends {@link ViewElement}</p>
* */
public class InGameView extends ViewElement<VBox, InGameActions> {

private final TopBarView topBarView;
Expand Down Expand Up @@ -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();
Expand All @@ -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.
*
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +33,8 @@
* no-op rather than an error, since there's nothing meaningful to write.</p>
* */
public final class QuitDialogController
extends ViewController<QuitDialogView> {
extends ViewController<QuitDialogView>
implements EventSubscriber {

/** The in-game view hosting this overlay. */
private final InGameView inGameView;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -185,4 +190,9 @@ private boolean performSave() {
return false;
}
}

@Override
public <T> void handleEvent(EventData<T> data) {
show();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.settings;

/**
* User-triggered actions available on the main-menu settings view.
*
* <p>{@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.</p>
* 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -259,5 +260,13 @@ public <T> void handleEvent(final EventData<T> 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()
);
}

}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit b82d63a

Please sign in to comment.