From db662d3a3ad07bb5dea114317d73f767419989aa Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 7 Feb 2024 16:44:53 +0100 Subject: [PATCH] add cards to player deck in gui --- .../onses/controllers/PlayerController.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 72497b8..1757520 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -1,12 +1,15 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; +import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Player; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.control.Label; +import javafx.scene.layout.HBox; import java.io.IOException; +import java.util.ArrayList; import java.util.Objects; public class PlayerController implements Controller { @@ -20,6 +23,22 @@ public class PlayerController implements Controller { public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/player.fxml"))); final Label playerNameLabel = (Label) parent.lookup("#playerNameLabel"); + final HBox cards = (HBox) parent.lookup("#cardsHBox"); + + for(Card card : player.getPlayerDeck()) { + cards.getChildren().add(new CardController(card).render()); + } + + player.listeners().addPropertyChangeListener(Player.PROPERTY_PLAYER_DECK, e -> { + cards.getChildren().clear(); + for(Card card : player.getPlayerDeck()) { + try { + cards.getChildren().add(new CardController(card).render()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + }); playerNameLabel.setText("Test");