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 1a1d865..5228eb9 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/controller/GameController.java +++ b/millions/src/main/java/no/ntnu/gruppe53/controller/GameController.java @@ -72,6 +72,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/FooterBar.java b/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java index 58cf825..52c37e6 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java +++ b/millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java @@ -20,6 +20,7 @@ import no.ntnu.gruppe53.service.LanguageManager; import no.ntnu.gruppe53.service.LanguageOption; import no.ntnu.gruppe53.service.LanguageRegistry; +import no.ntnu.gruppe53.model.Stock; /* Yellow Color, Hex: #ffe556 RGB(255, 229, 86) @@ -35,8 +36,14 @@ public class FooterBar extends HBox { private final Button advanceWeekButton; - private Label currentWeekLabel; - private Subscription currentWeekSubscription; + 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; private final LanguageManager lm = LanguageManager.getInstance(); @@ -97,6 +104,43 @@ protected void updateItem(LanguageOption item, boolean empty) { languageBox.setButtonCell(languageBox.getCellFactory().call(null)); + 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(); @@ -123,7 +167,7 @@ protected void updateItem(LanguageOption item, boolean empty) { advanceWeekButton.textProperty().bind(lm.bindString("advanceWeekButton")); advanceWeekButton.setStyle("-fx-background-color: #ffe556; -fx-text-fill: #303539;"); - this.getChildren().addAll(languageBox, spacer, currentWeekBox, advanceWeekButton); + this.getChildren().addAll(languageBox, loserBox, winnerBox, spacer, currentWeekBox, advanceWeekButton); } /** @@ -140,6 +184,26 @@ public void setExchange(Exchange exchange) { currentWeekLabel.setText("None"); } }); + + 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()); + }); } /** @@ -151,6 +215,7 @@ public void setExchange(Exchange exchange) { public void onAdvanceButtonClick(Runnable action) { advanceWeekButton.setOnAction(e -> action.run()); } +} /** * Exoposes the LanguageOption ComboButton to the controller. 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 e494941..16bbc9e 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 no.ntnu.gruppe53.service.LanguageManager; @@ -37,14 +38,20 @@ 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; @@ -75,6 +82,8 @@ public NavigationBar() { Region spacer = new Region(); HBox.setHgrow(spacer, Priority.ALWAYS); + + HBox playerBox = new HBox(); Label playerLabelText = new Label(); @@ -93,6 +102,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(); @@ -125,7 +150,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. @@ -188,4 +213,20 @@ 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; + + currentWeekSubscription = exchange.getCurrentWeekProperty().subscribe(newVal -> { + statusLabel.setText(player.getStatus(exchange)); + }); + } + + } 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