From 37d00612e76ac5a135818b55c34b07fc062dc47f Mon Sep 17 00:00:00 2001 From: Arelodgaard Date: Mon, 25 May 2026 17:49:03 +0200 Subject: [PATCH 1/3] Added biggest loser and winner to the footer --- .../java/no/ntnu/gruppe53/view/FooterBar.java | 65 ++++++++++++++++++- .../no/ntnu/gruppe53/view/NavigationBar.java | 8 +++ .../compile/default-compile/createdFiles.lst | 3 + .../compile/default-compile/inputFiles.lst | 3 + 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java b/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java index efea8a3..b5cc00c 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java @@ -13,6 +13,7 @@ import no.ntnu.gruppe53.model.Player; import no.ntnu.gruppe53.controller.GameController; import no.ntnu.gruppe53.model.Exchange; +import no.ntnu.gruppe53.model.Stock; /* Yellow Color, Hex: #ffe556 RGB(255, 229, 86) @@ -28,7 +29,13 @@ public class FooterBar extends HBox { private final Button advanceWeekButton; private Label currentWeekLabel; + private Label biggestLoserLabel; + private Label biggestLoserPriceLabel; + private Label biggestWinnerLabel; + private Label biggestWinnerPriceLabel; private Subscription currentWeekSubscription; + private Subscription biggestLoserSubscription; + private Subscription biggestWinnerSubscription; private Exchange exchange; @@ -42,7 +49,43 @@ public FooterBar() { "-fx-border-color: #303539 transparent transparent transparent;" + "-fx-border-width: 5 0 0 0;"); + HBox loserBox = new HBox(); + Label biggestLoserLabelText = new Label("Biggest Loser: "); + biggestLoserLabel = new Label(); + biggestLoserPriceLabel = new Label(); + biggestLoserPriceLabel.setStyle("-fx-text-fill: red;"); + + loserBox.setStyle("-fx-background-color: #ffe556;" + + "-fx-text-fill: #303539;" + + "-fx-background-radius: 8;" + + "-fx-border-color: #303539;" + + "-fx-border-radius: 8;" + ); + + loserBox.setPadding(new Insets(8, 14, 8, 14)); + loserBox.setAlignment(Pos.CENTER); + + loserBox.getChildren().addAll(biggestLoserLabelText, biggestLoserLabel, biggestLoserPriceLabel); + + HBox winnerBox = new HBox(); + + Label biggestWinnerLabelText = new Label("Biggest Winner: "); + biggestWinnerLabel = new Label(); + biggestWinnerPriceLabel = new Label(); + biggestWinnerPriceLabel.setStyle("-fx-text-fill: green;"); + + winnerBox.setStyle("-fx-background-color: #ffe556;" + + "-fx-text-fill: #303539;" + + "-fx-background-radius: 8;" + + "-fx-border-color: #303539;" + + "-fx-border-radius: 8;" + ); + + winnerBox.setPadding(new Insets(8, 14, 8, 14)); + winnerBox.setAlignment(Pos.CENTER); + + winnerBox.getChildren().addAll(biggestWinnerLabelText, biggestWinnerLabel, biggestWinnerPriceLabel); Region spacer = new Region(); @@ -68,7 +111,7 @@ public FooterBar() { advanceWeekButton = new Button("Advance Week"); advanceWeekButton.setStyle("-fx-background-color: #ffe556; -fx-text-fill: #303539;"); - this.getChildren().addAll(spacer, currentWeekBox, advanceWeekButton); + this.getChildren().addAll(loserBox, winnerBox, spacer, currentWeekBox, advanceWeekButton); } public void setExchange(Exchange exchange) { @@ -81,6 +124,26 @@ public void setExchange(Exchange exchange) { } }); + if (biggestLoserSubscription != null) { + biggestLoserSubscription.unsubscribe(); + } + + biggestLoserSubscription = exchange.getCurrentWeekProperty().subscribe(newWeek -> { + Stock loser = exchange.getLosers(1).getFirst(); + biggestLoserLabel.setText(loser.getSymbol() + " - " + loser.getCompany()); + biggestLoserPriceLabel.setText(" $" + loser.getLatestPriceChange()); + }); + + if (biggestWinnerSubscription != null) { + biggestWinnerSubscription.unsubscribe(); + } + + biggestWinnerSubscription = exchange.getCurrentWeekProperty().subscribe(newWeek -> { + Stock winner = exchange.getGainers(1).getFirst(); + biggestWinnerLabel.setText(winner.getSymbol() + " - " + winner.getCompany()); + biggestWinnerPriceLabel.setText(" $" + winner.getLatestPriceChange()); + }); + } /** diff --git a/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java b/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java index d6f7415..d7ef3df 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java @@ -8,6 +8,7 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.util.Subscription; +import no.ntnu.gruppe53.model.Exchange; import no.ntnu.gruppe53.model.Player; import java.math.RoundingMode; @@ -36,7 +37,9 @@ public class NavigationBar extends HBox { private Subscription moneySubscription; + private Player player; + //Navigation Buttons @@ -46,6 +49,7 @@ public class NavigationBar extends HBox { private Label moneyLabel; + public NavigationBar() { this.setPadding(new Insets(15, 12, 15, 12)); @@ -66,6 +70,8 @@ public NavigationBar() { Region spacer = new Region(); HBox.setHgrow(spacer, Priority.ALWAYS); + + HBox playerBox = new HBox(); Label playerLabelText = new Label("Player: "); @@ -176,4 +182,6 @@ public void bindPlayer(Player player) { } } + + } diff --git a/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 4eae7af..471bd6d 100644 --- a/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,3 +1,6 @@ no/ntnu/gruppe53/controller/ViewController.class no/ntnu/gruppe53/controller/GameController.class +no/ntnu/gruppe53/model/SaleFactory.class +no/ntnu/gruppe53/model/PurchaseFactory.class +no/ntnu/gruppe53/model/TransactionFactory.class no/ntnu/gruppe53/controller/StartViewController.class diff --git a/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 98c166d..c3b6ad4 100644 --- a/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/millions/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -8,13 +8,16 @@ /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/Portfolio.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/Purchase.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/PurchaseCalculator.java +/home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/PurchaseFactory.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/Sale.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/SaleCalculator.java +/home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/SaleFactory.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/Share.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/Stock.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/Transaction.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/TransactionArchive.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/TransactionCalculator.java +/home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/model/TransactionFactory.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/service/FileHandler.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/service/FormatBigDecimal.java /home/alodgaard/Programmering/Skole/Prog 2/Millions/millions/src/main/java/no/ntnu/gruppe53/service/StockLineChartService.java From 8cd9ef094147cb8f72d03a215ba21fb0a2ae95b8 Mon Sep 17 00:00:00 2001 From: Arelodgaard Date: Mon, 25 May 2026 18:25:42 +0200 Subject: [PATCH 2/3] Added PlayerStatus update in navbar --- .../gruppe53/controller/GameController.java | 1 + .../no/ntnu/gruppe53/view/NavigationBar.java | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/millions/src/main/java/no/ntnu/gruppe53/controller/GameController.java b/millions/src/main/java/no/ntnu/gruppe53/controller/GameController.java index 6bc40d8..1147e1f 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/controller/GameController.java +++ b/millions/src/main/java/no/ntnu/gruppe53/controller/GameController.java @@ -69,6 +69,7 @@ public void startNewGame() { transactionArchiveView.setPlayer(player); sharedNav.bindPlayer(player); + sharedNav.bindExchange(exchange); sharedFooter.setExchange(exchange); vm.addView("portfolio", portfolioView); diff --git a/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java b/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java index d7ef3df..72cac0a 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java @@ -35,21 +35,26 @@ public class NavigationBar extends HBox { private final Button historyButton; private Subscription netWorthSubscription; private Subscription moneySubscription; + private Subscription currentWeekSubscription; + private Player player; + private Exchange exchange; //Navigation Buttons //Dynamic Labels private Label playerLabel; + private Label statusLabel; private Label netWorthLabel; private Label moneyLabel; + public NavigationBar() { this.setPadding(new Insets(15, 12, 15, 12)); @@ -89,6 +94,22 @@ public NavigationBar() { playerBox.getChildren().addAll(playerLabelText, playerLabel); + HBox statusBox = new HBox(); + + Label statusLabelText = new Label("Status: "); + statusLabel = new Label(); + + statusBox.setStyle("-fx-background-color: #ffe556;" + + "-fx-text-fill: #303539;" + + "-fx-background-radius: 8;" + + "-fx-border-color: #303539;" + + "-fx-border-radius: 8;" + ); + statusBox.setPadding(new Insets(8, 14, 8, 14)); + statusBox.setAlignment(Pos.CENTER); + + statusBox.getChildren().addAll(statusLabelText, statusLabel); + HBox moneyBox = new HBox(); Label moneyLabelText = new Label("Money: "); @@ -119,7 +140,7 @@ public NavigationBar() { networthBox.setAlignment(Pos.CENTER); networthBox.getChildren().addAll(networthLabelText, netWorthLabel); - this.getChildren().addAll(marketButton, portfolioButton, historyButton, spacer, playerBox, moneyBox, networthBox); + this.getChildren().addAll(marketButton, portfolioButton, historyButton, spacer, playerBox, statusBox, moneyBox, networthBox); } /** * Exposes the marketButton to the GameController. @@ -183,5 +204,13 @@ public void bindPlayer(Player player) { } } + public void bindExchange(Exchange exchange) { + this.exchange = exchange; + + currentWeekSubscription = exchange.getCurrentWeekProperty().subscribe(newVal -> { + statusLabel.setText(player.getStatus(exchange)); + }); + } + } From 84ba81cddd89875d28d2eb20523695313fd745ae Mon Sep 17 00:00:00 2001 From: Arelodgaard Date: Mon, 25 May 2026 18:26:59 +0200 Subject: [PATCH 3/3] Some comments --- .../src/main/java/no/ntnu/gruppe53/view/NavigationBar.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java b/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java index 72cac0a..77dddfb 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java @@ -204,6 +204,12 @@ public void bindPlayer(Player player) { } } + /** + * Binds a subscription/observer to a {@link Exchange}. + *

It specifically listens to week changes so that it can update the player status.

+ * + * @param exchange the exchange object to be observed + */ public void bindExchange(Exchange exchange) { this.exchange = exchange;