Skip to content

Commit

Permalink
Feat: Added new UI for the ingame view
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 12, 2026
1 parent 8bd5c90 commit 393c6d5
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 34 deletions.
6 changes: 5 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 @@ -20,6 +20,7 @@

import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats.StatsView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import javafx.application.Application;
Expand Down Expand Up @@ -90,8 +91,11 @@ public void start(final Stage stage) throws Exception {
TopBarView topBarView = new TopBarView(summaryView);
new TopBarController(topBarView, eventManager);

// Stats page
StatsView statsView = new StatsView();

// In-game
InGameView inGameView = new InGameView(topBarView);
InGameView inGameView = new InGameView(topBarView, statsView.getRootPane());

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

public enum InGameActions {
BUY_SHARES,
SELL_SHARES;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame;

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

public class InGameController extends ViewController<InGameView> {

/**
* {@inheritDoc}.
*/
protected InGameController(final InGameView viewElement,
final EventManager eventManager)
throws IllegalArgumentException {
super(viewElement, eventManager);
}

@Override
protected void initInteractions() {

}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame;

import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import java.util.ArrayList;

public class InGameView extends ViewElement<VBox, InGameActions> {

TopBarView topBarView;
private final TopBarView topBarView;
private Node centerView;

public InGameView(final TopBarView topBarView) {
public InGameView(final TopBarView topBarView, final Node centerView) {
this.topBarView = topBarView;
this.centerView = centerView;
super(new VBox(), ViewEnum.IN_GAME, InGameActions.class);

}

@Override
protected void initLayout() {
getRootPane().getChildren().add(topBarView.getRootPane());
getRootPane().getChildren().addAll(topBarView.getRootPane(), centerView);
VBox.setVgrow(centerView, Priority.ALWAYS);
}

@Override
protected void initStyling() {

}

public void changeCenterView(final Node newCenterView) {
this.centerView = newCenterView;
getRootPane().getChildren().clear();
getRootPane().getChildren().addAll(topBarView.getRootPane(), centerView);
VBox.setVgrow(centerView, Priority.ALWAYS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ public SummaryView() {
protected void initLayout() {
getRootPane().setSpacing(20);
getRootPane().setAlignment(Pos.BOTTOM_CENTER);
getRootPane().setFillHeight(false);
getRootPane().setFillHeight(true);

getRootPane().setPrefHeight(100);
getRootPane().setMinHeight(80);
getRootPane().setMaxHeight(100);

VBox.setVgrow(getRootPane(), Priority.ALWAYS);

VBox balanceInfo = new VBox();

titleLabel = new Label("balance/investments");
balanceLabel = new Label("200$/2394$");
balanceLabel = new Label("10000$/0$");

balanceInfo.getChildren().addAll(titleLabel, balanceLabel);
Region spacerL = new Region();
VBox.setVgrow(spacerL, Priority.ALWAYS);

balanceInfo.getChildren().addAll(titleLabel, spacerL, balanceLabel);

NumberAxis xAxis = new NumberAxis(1, 22, 1);
xAxis.setMinorTickVisible(false);
Expand All @@ -54,9 +63,15 @@ protected void initLayout() {
chart.setVerticalGridLinesVisible(false);
chart.setAlternativeRowFillVisible(false);
chart.setAnimated(false);
chart.setPrefHeight(100);
chart.setMinHeight(100);
chart.setMaxHeight(100);
chart.setPrefHeight(250);
chart.setMinHeight(200);
chart.setMaxHeight(300);
chart.setMaxWidth(Double.MAX_VALUE);
chart.setMinWidth(0);
dataSeries = new XYChart.Series<>();
chart.prefHeightProperty().bind(getRootPane().heightProperty().divide(5));
chart.minHeightProperty().set(50);
chart.getData().add(dataSeries);

Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
Expand All @@ -65,20 +80,16 @@ protected void initLayout() {
Region leftSpacer = new Region();
HBox.setHgrow(leftSpacer, Priority.SOMETIMES);

dataSeries = new XYChart.Series<>();
chart.prefHeightProperty().bind(getRootPane().heightProperty().divide(5));
chart.minHeightProperty().set(50);
chart.getData().add(dataSeries);

VBox navInfo = new VBox();
navInfo.setAlignment(Pos.BOTTOM_RIGHT);
navInfo.setAlignment(Pos.TOP_CENTER);

nextBtn = new Button("next");

weekLabel = new Label("week: 0");
weekLabel.getStyleClass().add("week-label");
Region spacerR = new Region();
VBox.setVgrow(spacerR, Priority.ALWAYS);

navInfo.getChildren().addAll(nextBtn, weekLabel);
navInfo.getChildren().addAll(nextBtn, spacerR, weekLabel);

getRootPane().getChildren().addAll(balanceInfo, chart, navInfo);
registerButton(SummaryActions.NEXT_WEEK, nextBtn);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats;

public enum StatsActions {
BUY_SHARES,
SELL_SHARES;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats;

public class StatsController {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats;

import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import java.util.ArrayList;
import javafx.geometry.Pos;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

public class StatsView extends ViewElement<HBox, StatsActions> {
private LineChart<Number, Number> chart;
private XYChart.Series<Number, Number> dataSeries;
private VBox sidebar;
private ArrayList<Stock> stocks;
private ArrayList<String> stockStrings;
private ArrayList<Button> stockButtons;
private Label selectedStock;

public StatsView() {
super(new HBox(), StatsActions.class);
}

@Override
protected void initLayout() {
getRootPane().setAlignment(Pos.TOP_LEFT);
getRootPane().setFillHeight(true);

sidebar = new VBox(10);
sidebar.setPrefWidth(150);
sidebar.setMaxHeight(Double.MAX_VALUE);
VBox.setVgrow(sidebar, Priority.ALWAYS);

stocks = new ArrayList<>();

stockStrings = new ArrayList<>();
stockStrings.add("AAPL");
stockStrings.add("AALL");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");
stockStrings.add("NVID");



stockButtons = new ArrayList<>();
for (String t : stockStrings) {
Button btn = new Button(t);
stockButtons.add(btn);
sidebar.getChildren().add(btn);
}
ScrollPane scrollPane = new ScrollPane(sidebar);

scrollPane.setFitToWidth(true);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);

VBox.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.setMaxHeight(Double.MAX_VALUE);

VBox mainContent = new VBox(20);
mainContent.setAlignment(Pos.CENTER);
HBox.setHgrow(mainContent, Priority.ALWAYS);
mainContent.setMaxHeight(Double.MAX_VALUE);
VBox.setVgrow(mainContent, Priority.ALWAYS);

selectedStock = new Label("APL");

NumberAxis xAxis = new NumberAxis(1, 22, 1);
xAxis.setMinorTickVisible(false);
xAxis.setTickMarkVisible(true);
xAxis.setTickLabelsVisible(true);

NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickMarkVisible(false);
yAxis.setMinorTickVisible(false);

chart = new LineChart<>(xAxis, yAxis);
chart.setCreateSymbols(false);
chart.setLegendVisible(false);
chart.setHorizontalGridLinesVisible(false);
chart.setVerticalGridLinesVisible(false);
chart.setAlternativeRowFillVisible(false);
chart.setAnimated(false);
chart.setPrefHeight(250);
chart.setMinHeight(200);
chart.setMaxHeight(300);
chart.setMaxWidth(Double.MAX_VALUE);
chart.setMinWidth(0);
dataSeries = new XYChart.Series<>();
chart.prefHeightProperty().bind(getRootPane().heightProperty().divide(5));
chart.minHeightProperty().set(50);
chart.getData().add(dataSeries);

// Trade Buttons Row
HBox tradeActions = new HBox();
tradeActions.setAlignment(Pos.CENTER);
tradeActions.setSpacing(300); // Push buy/sell to opposite sides

Button buyBtn = new Button("buy");
buyBtn.getStyleClass().add("buy-button");
registerButton(StatsActions.BUY_SHARES, buyBtn);

Button sellBtn = new Button("sell");
sellBtn.getStyleClass().add("sell-button");
registerButton(StatsActions.SELL_SHARES, sellBtn);

tradeActions.getChildren().addAll(buyBtn, sellBtn);

mainContent.getChildren().addAll(selectedStock, chart, tradeActions);
getRootPane().getChildren().addAll(scrollPane, mainContent);
}

@Override
protected void initStyling() {
sidebar.getStyleClass().add("market-sidebar");
for (Button b : stockButtons) {
b.getStyleClass().add("stock-button");
}
selectedStock.getStyleClass().add("selected-stock-pill");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ public TopBarController(final TopBarView viewElement, final EventManager eventMa
@Override
protected void initInteractions() {
getViewElement().setOnAction(TopBarActions.EXIT, () -> changeScene(ViewEnum.MAIN_MENU));

getViewElement().setOnAction(TopBarActions.STATS, () -> changeScene(ViewEnum.MAIN_MENU));

getViewElement().setOnAction(TopBarActions.MARKET, () -> changeScene(ViewEnum.MAIN_MENU));

getViewElement().setOnAction(TopBarActions.SETTINGS, () -> changeScene(ViewEnum.MAIN_MENU));
}
}
Loading

0 comments on commit 393c6d5

Please sign in to comment.