Browse Source

add cards to player deck in gui

main
fdai7736 11 months ago
parent
commit
db662d3a3a
  1. 19
      src/main/java/de/hsfulda/onses/controllers/PlayerController.java

19
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");

Loading…
Cancel
Save