Skip to content

51 integrate topgainers and toplosers into view #57

Merged
merged 4 commits into from
May 25, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void startNewGame() {
transactionArchiveView.setPlayer(player);

sharedNav.bindPlayer(player);
sharedNav.bindExchange(exchange);
sharedFooter.setExchange(exchange);

vm.addView("portfolio", portfolioView);
Expand Down
71 changes: 68 additions & 3 deletions millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}

/**
Expand All @@ -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());
});
}

/**
Expand All @@ -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.
Expand Down
43 changes: 42 additions & 1 deletion millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -75,6 +82,8 @@ public NavigationBar() {
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);



HBox playerBox = new HBox();

Label playerLabelText = new Label();
Expand All @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -188,4 +213,20 @@ public void bindPlayer(Player player) {

}
}

/**
* Binds a subscription/observer to a {@link Exchange}.
* <p>It specifically listens to week changes so that it can update the player status.</p>
*
* @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));
});
}


}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down