From 3956d8efa7943cb01d318c215581f0afdb9535a7 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 00:11:37 +0100 Subject: [PATCH] show all playe stats in toolbar --- .../java/pp/monopoly/client/MonopolyApp.java | 5 +++ .../java/pp/monopoly/client/gui/Toolbar.java | 37 +++++++++++-------- .../monopoly/game/server/PlayerHandler.java | 5 ++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index 934890f..c6b44c0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -493,4 +493,9 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga public void disconnect() { serverConnection.disconnect(); } + + public int getId() { + if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId(); + return 0; + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 68e2b9d..c2b8dfe 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -16,6 +16,8 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.game.server.Player; +import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.notification.Sound; /** @@ -52,32 +54,37 @@ public class Toolbar extends Dialog { ); toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); // Volle Breite - - // Füge Buttons zur Toolbar hinzu - //initializeButtons(); - + PlayerHandler playerHandler = app.getGameLogic().getPlayerHandler(); // Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten" Container accountContainer = toolbarContainer.addChild(new Container()); accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold"))); - accountContainer.addChild(new Label("6666€", new ElementId("label-Text"))); //TODO Variable hier einsetzen + accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", new ElementId("label-Text"))); //TODO Variable hier einsetzen accountContainer.addChild(new Label("Gulag Frei Karten", new ElementId("label-Bold"))); + accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getNumJailCard()+"", new ElementId("label-Text"))); accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); - // Add a spacer between accountContainer and overviewContainer - Panel spacer = new Panel(); // Create an empty panel as a spacer - spacer.setPreferredSize(new Vector3f(5, 0, 0)); // Adjust the width as needed - spacer.setBackground(null); - toolbarContainer.addChild(spacer); + // // Add a spacer between accountContainer and overviewContainer + // Panel spacer = new Panel(); // Create an empty panel as a spacer + // spacer.setPreferredSize(new Vector3f(5, 0, 0)); // Adjust the width as needed + // spacer.setBackground(null); + // toolbarContainer.addChild(spacer); // Menü-Container: Ein Container für Übersicht Container overviewContainer = toolbarContainer.addChild(new Container()); overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold"))); - overviewContainer.addChild(new Label("„Spieler 1“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen - overviewContainer.addChild(new Label("„Spieler 2“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen - overviewContainer.addChild(new Label("„Spieler 3“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen - overviewContainer.addChild(new Label("„Spieler 4“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen - overviewContainer.addChild(new Label("„Spieler 5“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen + + for (Player player : playerHandler.getPlayers()) { + if (player.getId() != app.getId()) { // Skip the current player (host) + overviewContainer.addChild(new Label( + player.getName() + ": " + player.getAccountBalance() + " EUR", + new ElementId("label-Text") + )); + } + } + + + overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Menü-Container: Ein Container für Würfel diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index d9a8326..c1f8793 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -3,6 +3,7 @@ package pp.monopoly.game.server; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; @@ -15,7 +16,7 @@ import pp.monopoly.model.LimitedLinkedList; */ @Serializable public class PlayerHandler { - private List players = new LimitedLinkedList<>(6); + private List players = new LinkedList<>(); private Set readyPlayers = new HashSet<>(); private transient ServerGameLogic logic; private Player hostPlayer; @@ -165,8 +166,10 @@ public class PlayerHandler { * @return the player with the required id */ public Player getPlayerById(int id) { + System.out.println("TEST"); for (Player player : players) { if (player.getId() == id) return player; + System.out.println(player.getId()); } throw new NoSuchElementException("Player mit id "+id+" existiert nicht"); }