Added clickable players

This commit is contained in:
Bas de Jong
2025-10-06 22:59:18 +02:00
parent 501b411e34
commit 046a59e915

View File

@@ -1,5 +1,6 @@
package org.toop.app.layer.layers; package org.toop.app.layer.layers;
import javafx.application.Platform;
import org.toop.app.layer.Container; import org.toop.app.layer.Container;
import org.toop.app.layer.Layer; import org.toop.app.layer.Layer;
import org.toop.app.layer.NodeBuilder; import org.toop.app.layer.NodeBuilder;
@@ -26,12 +27,13 @@ public final class ConnectedLayer extends Layer {
this.clientId = clientId; this.clientId = clientId;
this.user = user; this.user = user;
reload();
new EventFlow().addPostEvent(new NetworkEvents.SendLogin(this.clientId, this.user)).postEvent(); new EventFlow().addPostEvent(new NetworkEvents.SendLogin(this.clientId, this.user)).postEvent();
new EventFlow().listen(this::handleReceivedChallenge); new EventFlow().listen(this::handleReceivedChallenge);
new Thread(this::populatePlayerList).start(); new Thread(this::populatePlayerList).start();
reload();
} }
private void populatePlayerList() { private void populatePlayerList() {
@@ -50,6 +52,7 @@ public final class ConnectedLayer extends Layer {
TimerTask task = new TimerTask() { TimerTask task = new TimerTask() {
public void run() { public void run() {
sendGetPlayerList.postEvent(); sendGetPlayerList.postEvent();
Platform.runLater(() -> reload());
} }
}; };
@@ -75,9 +78,10 @@ public final class ConnectedLayer extends Layer {
ListView<Label> players = new ListView<>(); ListView<Label> players = new ListView<>();
for (int i = 0; i < onlinePlayers.size(); i++) { for (int i = 0; i < onlinePlayers.size(); i++) {
players.getItems().add(NodeBuilder.button(onlinePlayers.get(i), () -> { int finalI = i;
// get clicked player name with: onlinePlayers.get(i) players.getItems().add(NodeBuilder.button(onlinePlayers.get(i), () -> {
// connection logic here var clickedPlayer = onlinePlayers.get(finalI);
sendChallenge(clickedPlayer, "tic-tac-toe");
})); }));
} }