Skip to content

Commit

Permalink
Feat: Integrated view with top bar
Browse files Browse the repository at this point in the history
Made it possible to access transactions view using the top bar navigation. Also changes "Quit" to "Back" (like the market view)
  • Loading branch information
tommyah committed May 19, 2026
1 parent 9e60c5e commit 3265666
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
Expand Down Expand Up @@ -116,6 +118,9 @@ public void start(final Stage stage) throws Exception {
exchange,
stocksInFile);

TransactionsView transactionsView = new TransactionsView();
new TransactionsController(transactionsView, eventManager);

// In-game (Change "topBarView" to "topBarView2" if no summary section).
// Dashboard er default center-view.
InGameView inGameView = new InGameView(topBarView, dashBoardView.getRootPane());
Expand All @@ -124,7 +129,8 @@ public void start(final Stage stage) throws Exception {
topBarController.setMarketIntegration(
inGameView::changeCenterView,
dashBoardView.getRootPane(),
marketView.getRootPane()
marketView.getRootPane(),
transactionsView.getRootPane()
);

// Register all views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum TopBarActions {
EXIT,
STATS,
MARKET,
SETTINGS;
SETTINGS,
TRANSACTIONS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public class TopBarController extends ViewController<TopBarView> {
* */
private boolean inMarketView = false;

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

/**
* {@inheritDoc}.
*/
Expand Down Expand Up @@ -50,19 +58,22 @@ protected void initInteractions() {
* otherwise to the main menu.</li>
* </ul>
*
* @param centerSwitcher callback that swaps the center-view (typically
* {@code inGameView::changeCenterView}).
* @param dashboardCenter root pane of the dashboard widget.
* @param marketCenter root pane of the market widget.
* @param centerSwitcher callback that swaps the center-view (typically
* {@code inGameView::changeCenterView}).
* @param dashboardCenter root pane of the dashboard widget.
* @param marketCenter root pane of the market widget.
* @param transactionsCenter root pane of the transactions widget.
* */
public void setMarketIntegration(final Consumer<Node> centerSwitcher,
final Node dashboardCenter,
final Node marketCenter) {
final Node marketCenter,
final Node transactionsCenter) {
getViewElement().setOnAction(TopBarActions.EXIT, () -> {
if (inMarketView) {
if (inMarketView || inTransactionsView) {
centerSwitcher.accept(dashboardCenter);
getViewElement().setQuitText("Quit");
inMarketView = false;
inTransactionsView = false;
} else {
changeScene(ViewEnum.MAIN_MENU);
}
Expand All @@ -72,12 +83,21 @@ public void setMarketIntegration(final Consumer<Node> centerSwitcher,
centerSwitcher.accept(dashboardCenter);
getViewElement().setQuitText("Quit");
inMarketView = false;
inTransactionsView = false;
});

getViewElement().setOnAction(TopBarActions.MARKET, () -> {
centerSwitcher.accept(marketCenter);
getViewElement().setQuitText("Back");
inMarketView = true;
inTransactionsView = false;
});

getViewElement().setOnAction(TopBarActions.TRANSACTIONS, () -> {
centerSwitcher.accept(transactionsCenter);
getViewElement().setQuitText("Back");
inMarketView = false;
inTransactionsView = true;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public class TopBarView extends ViewElement<VBox, TopBarActions> {
private Button statsBtn;
private Button marketBtn;
private Button settingsBtn;
private Button transactionsBtn;
private SummaryView summaryView;


public TopBarView(final SummaryView summaryView) {
this.summaryView = summaryView;
super(new VBox(10), TopBarActions.class);
Expand Down Expand Up @@ -45,16 +47,18 @@ protected void initLayout() {
statsBtn = new Button("Stats");
marketBtn = new Button("Market");
settingsBtn = new Button("Settings");
transactionsBtn = new Button("Transactions");

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

navRow.getChildren().addAll(
quitBtn,
statsBtn,
marketBtn,
settingsBtn
settingsBtn,
transactionsBtn
);

if (summaryView != null) {
Expand All @@ -66,12 +70,13 @@ protected void initLayout() {
registerButton(TopBarActions.STATS, statsBtn);
registerButton(TopBarActions.MARKET, marketBtn);
registerButton(TopBarActions.SETTINGS, settingsBtn);
registerButton(TopBarActions.TRANSACTIONS, transactionsBtn);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions;

public enum TransactionsActions {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions;

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

public class TransactionsController extends ViewController<TransactionsView> {

/**
* {@inheritDoc}
*/
public TransactionsController(final TransactionsView viewElement, final EventManager eventManager)
throws IllegalArgumentException {
super(viewElement, eventManager);
}

@Override
protected void initInteractions() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions;

import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import javafx.scene.layout.VBox;

public class TransactionsView extends ViewElement<VBox, TransactionsActions> {

public TransactionsView() {
super(new VBox(), TransactionsActions.class);
}

@Override
protected void initLayout() {

}

@Override
protected void initStyling() {

}
}

0 comments on commit 3265666

Please sign in to comment.