From e8ae661a749c7928b734a08ab321f29ea341867e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Sk=C3=B8ien?= Date: Mon, 18 May 2026 15:41:37 +0200 Subject: [PATCH] add player status to in-game UI in the bottom bar --- .../DesktopViewController.java | 13 ++++++---- .../idi/idatt2003/gruppe42/Model/Player.java | 24 ++++++++++++------- .../Views/Components/DesktopBottomBar.java | 11 ++++++++- .../gruppe42/View/Views/DesktopView.java | 5 ++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java index bfebd27..343d335 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java @@ -179,26 +179,29 @@ private void setupDesktopUI() { } private void setupListeners() { - timeAndWeatherController.hourProperty().addListener((o, ov, nv) -> + timeAndWeatherController.hourProperty().addListener((obs, ov, nv) -> desktopView.updateClock(timeAndWeatherController.getTimeString())); - timeAndWeatherController.dayIndexProperty().addListener((o, ov, nv) -> { + timeAndWeatherController.dayIndexProperty().addListener((obs, ov, nv) -> { String dayName = timeAndWeatherController.getDayOfWeekString(); desktopView.updateDay(dayName, dayName.equals("SUN")); }); - timeAndWeatherController.weekIndexProperty().addListener((o, ov, nv) -> + timeAndWeatherController.weekIndexProperty().addListener((obs, ov, nv) -> desktopView.updateWeek(timeAndWeatherController.getWeekString())); - timeAndWeatherController.weatherProperty().addListener((o, ov, nv) -> + timeAndWeatherController.weatherProperty().addListener((obs, ov, nv) -> desktopView.updateWeather(nv)); - timeAndWeatherController.temperatureProperty().addListener((o, ov, nv) -> + timeAndWeatherController.temperatureProperty().addListener((obs, ov, nv) -> desktopView.updateTemperature(String.valueOf(nv))); player.getNameProperty().addListener((obs, ov, nv) -> desktopView.updatePlayerName(nv)); + player.getStatusProperty().addListener((obs, ov, nv) -> + desktopView.updatePlayerStatus(nv.name())); + desktopView.updateClock(timeAndWeatherController.getTimeString()); String startDay = timeAndWeatherController.getDayOfWeekString(); desktopView.updateDay(startDay, startDay.equals("SUN")); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java index 3ff6577..1fcf6e3 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java @@ -3,10 +3,8 @@ import edu.ntnu.idi.idatt2003.gruppe42.Model.Exceptions.InsufficientFunds; import edu.ntnu.idi.idatt2003.gruppe42.Model.Transaction.TransactionArchive; import java.math.BigDecimal; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; + +import javafx.beans.property.*; /** Represents a player. */ public class Player { @@ -19,6 +17,7 @@ public class Player { private final Portfolio portfolio; private final TransactionArchive transactionArchive; private final IntegerProperty lives = new SimpleIntegerProperty(MAX_LIVES); + private final ObjectProperty status = new SimpleObjectProperty<>(Status.NOVICE); public Player(final String name, final BigDecimal startingMoney) { this.name.set(name); @@ -53,6 +52,10 @@ public BigDecimal getMoney() { return money; } + public String getStatus() { + return status.get().name(); + } + /** Adds money. */ public void addMoney(final BigDecimal amount) { money = money.add(amount); @@ -110,7 +113,7 @@ public TransactionArchive getTransactionArchive() { /** @return player status. */ - public Status getStatus() { + public ObjectProperty getStatusProperty() { final int investorWeeks = 10; final int speculatorWeeks = 20; final double investorMult = 1.2; @@ -127,8 +130,13 @@ public Status getStatus() { boolean isInvestor = weeksActive >= investorWeeks && netWorth.compareTo(investorTarget) >= 0; - if (isSpeculator) return Status.SPECULATOR; - if (isInvestor) return Status.INVESTOR; - return Status.NOVICE; + if (isSpeculator) { + status.set(Status.SPECULATOR); + } else if (isInvestor) { + status.set(Status.INVESTOR); + } else { + status.set(Status.NOVICE); + } + return status; } } \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/DesktopBottomBar.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/DesktopBottomBar.java index af35d30..7893164 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/DesktopBottomBar.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/DesktopBottomBar.java @@ -19,6 +19,7 @@ public final class DesktopBottomBar extends HBox { private static final int HEART_COUNT = 3; private final Label playerLabel; + private final Label playerStatusLabel; private final Label weatherLabel; private final Label tempLabel; private final Label dayLabel; @@ -45,6 +46,10 @@ public DesktopBottomBar(Player player) { playerLabel.getStyleClass().add("desktop-label-bold"); playerLabel.setMinWidth(Region.USE_PREF_SIZE); + playerStatusLabel = new Label("Status: " + player.getStatus()); + playerStatusLabel.getStyleClass().add("desktop-label-bold"); + playerStatusLabel.setMinWidth(Region.USE_PREF_SIZE); + HBox heartsBox = buildHeartsBox(player); nextWeekButton = new Button("Advance to next week"); @@ -66,7 +71,7 @@ public DesktopBottomBar(Player player) { statusBox.setMinWidth(Region.USE_PREF_SIZE); getChildren().addAll( - settingsButton, playerLabel, heartsBox, + settingsButton, playerLabel, playerStatusLabel, heartsBox, spacerLeft, nextWeekButton, spacerRight, statusBox ); @@ -108,6 +113,10 @@ public Label getPlayerLabel() { return playerLabel; } + public Label getPlayerStatusLabel() { + return playerStatusLabel; + } + public Label getWeatherLabel() { return weatherLabel; } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/DesktopView.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/DesktopView.java index e475aef..ce812f1 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/DesktopView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/DesktopView.java @@ -315,6 +315,11 @@ public void updatePlayerName(final String name) { Platform.runLater(() -> bottomBar.getPlayerLabel().setText("User: " + name)); } + /** Updates player status. */ + public void updatePlayerStatus(final String status) { + Platform.runLater(() -> bottomBar.getPlayerStatusLabel().setText("Status: " + status)); + } + /** Updates clock. */ public void updateClock(final String time) { Platform.runLater(() -> bottomBar.getClockLabel().setText(time));