From 2fdcd77d44ebaeac0a3c36d5a2794a1ee43a656d Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Tue, 26 May 2026 04:33:30 +0200 Subject: [PATCH] player status --- .../g40/mappe/model/PlayerStatus.java | 44 ++++++++++++++----- .../financialsummary/SummaryController.java | 5 +++ .../widgets/financialsummary/SummaryView.java | 26 ++++++++++- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatus.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatus.java index d34c54e..7e4aeb1 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatus.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/PlayerStatus.java @@ -4,38 +4,41 @@ * Enum representing a players' current status. * *

The player has the responsibility for getting - * a status.

+ * a status. Each status has a percent-increase threshold + * (measured against the players' starting capital) and a + * human-readable, socio-economic display name used by + * the UI.

* */ public enum PlayerStatus { - /** Status representing a beginner. */ - NOOB(0), + /** Status representing a beginner / lowest tier. */ + NOOB(0, "Really Poor"), /** * Status representing a player who has increased * their net worth by at least 20 percent. */ - NOVICE(20), + NOVICE(20, "Poor"), /** * Status representing a player who has increased * their net worth by at least 50 percent. */ - GOOD(50), + GOOD(50, "Middle Class"), /** Status representing a player who has at least doubled their net worth. */ - TRYHARD(100), + TRYHARD(100, "Wealthy"), /** Status representing a player who has at least tripled their net worth. */ - PRO(200), + PRO(200, "Rich"), /** * Status representing a player who has at least quintupled their * net worth. */ - SEER(400), + SEER(400, "Elite"), /** * Status representing a player who has at least dectupled their * net worth. */ - OMNIPOTENT(900); + OMNIPOTENT(900, "Tycoon"); /** * Value representing percent increase @@ -43,13 +46,21 @@ public enum PlayerStatus { * */ private final int percentIncreaseNeeded; + /** + * Human-readable, socio-economic label shown in the UI + * (e.g. "Really Poor", "Middle Class", "Tycoon"). + * */ + private final String displayName; + /** * Constructor. * * @param percentIncreaseNeeded the increase needed to get the status. + * @param displayName the socio-economic label shown in the UI. * */ - PlayerStatus(final int percentIncreaseNeeded) { + PlayerStatus(final int percentIncreaseNeeded, final String displayName) { this.percentIncreaseNeeded = percentIncreaseNeeded; + this.displayName = displayName; } /** @@ -60,5 +71,16 @@ public enum PlayerStatus { public int getPercentIncreaseNeeded() { return percentIncreaseNeeded; } -} + /** + * Returns the human-readable, socio-economic label + * for this status (e.g. "Really Poor", "Middle Class", + * "Tycoon"). Used by the UI to label the players' + * current income/investment tier. + * + * @return the display name. + * */ + public String getDisplayName() { + return displayName; + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java index d4234e5..6c9940e 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryController.java @@ -32,6 +32,7 @@ public SummaryController(final SummaryView viewElement, eventManager.addSubscriber(this, EventType.STATE_RESET); eventManager.addSubscriber(this, EventType.PRE_LOAD_SAVE); getViewElement().setBalance(player.getStartingMoney().floatValue(), player.getStartingMoney().floatValue()); + getViewElement().setStatus(player.getStatus()); } @Override @@ -46,14 +47,17 @@ protected void initInteractions() { playerNetWorthHistory.add(player.getNetWorth().floatValue()); getViewElement().updateChart(playerNetWorthHistory); getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue()); + getViewElement().setStatus(player.getStatus()); }); player.getNetWorthAsFloatProperty().addListener((observable, o, n) -> { getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue()); + getViewElement().setStatus(player.getStatus()); }); player.getMoneyAsFloatProperty().addListener((observable, o, n) -> { getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue()); + getViewElement().setStatus(player.getStatus()); }); } @@ -99,5 +103,6 @@ public void handleEvent(final EventData data) { getViewElement().updateChart(playerNetWorthHistory); getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue()); + getViewElement().setStatus(player.getStatus()); } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java index 9c3b899..74a3c55 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/financialsummary/SummaryView.java @@ -1,5 +1,6 @@ package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary; +import edu.ntnu.idi.idatt2003.g40.mappe.model.PlayerStatus; import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement; import javafx.geometry.Pos; import javafx.scene.chart.LineChart; @@ -15,6 +16,7 @@ public class SummaryView extends ViewElement { private Label balanceLabel; + private Label statusLabel; private Label weekLabel; private Label titleLabel; private LineChart chart; @@ -43,11 +45,12 @@ protected void initLayout() { titleLabel = new Label("Networth"); balanceLabel = new Label("0$"); + statusLabel = new Label(PlayerStatus.NOOB.getDisplayName()); Region spacerL = new Region(); VBox.setVgrow(spacerL, Priority.ALWAYS); - balanceInfo.getChildren().addAll(titleLabel, spacerL, balanceLabel); + balanceInfo.getChildren().addAll(titleLabel, spacerL, balanceLabel, statusLabel); xAxis = new NumberAxis(1, 10, 1); xAxis.setMinorTickVisible(false); @@ -106,6 +109,7 @@ protected void initStyling() { getRootPane().getStyleClass().add("summary-container"); titleLabel.getStyleClass().add("balance-title"); balanceLabel.getStyleClass().add("balance-value"); + statusLabel.getStyleClass().add("player-status-label"); nextBtn.getStyleClass().add("next-button"); } @@ -113,6 +117,26 @@ public void setBalance(final float money, final float netWorth) { balanceLabel.setText(Math.round(money*100f)/100f + "NOK / " + Math.round(netWorth*100f)/100f + "NOK"); } + /** + * Updates the displayed socio-economic status label. + * + *

Shows the players' current income/investment tier + * (e.g. "Really Poor", "Middle Class", "Tycoon") as + * computed by {@link edu.ntnu.idi.idatt2003.g40.mappe.controller.PlayerStatusController}.

+ * + * @param status the players' current status. Null is ignored. + * */ + public void setStatus(final PlayerStatus status) { + if (status == null) { + return; + } + statusLabel.setText(status.getDisplayName()); + // Swap CSS pseudo/style class so each tier can be themed + // independently (e.g. red for "Really Poor", gold for "Tycoon"). + statusLabel.getStyleClass().removeIf(c -> c.startsWith("status-tier-")); + statusLabel.getStyleClass().add("status-tier-" + status.name().toLowerCase()); + } + public void setWeek(int week) { weekLabel.setText("week: " + week); }