Compare commits

...

2 Commits

Author SHA1 Message Date
Clément
67124f4731 labelled the name of the room when in it 2025-03-12 23:34:08 +01:00
Clément
631cd25a9d updates the rooms every second 2025-03-12 23:29:22 +01:00
2 changed files with 35 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
package client; package client;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
@@ -7,6 +9,7 @@ import javafx.scene.layout.*;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.scene.text.TextFlow; import javafx.scene.text.TextFlow;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration;
import network.protocol.packets.ServerResponsePacket; import network.protocol.packets.ServerResponsePacket;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@@ -41,6 +44,9 @@ public class ClientGuiController implements ClientListener {
@FXML @FXML
private ScrollPane chatPane; private ScrollPane chatPane;
@FXML
private Label roomName;
public void setClient(Client client) { public void setClient(Client client) {
this.client = client; this.client = client;
} }
@@ -57,6 +63,19 @@ public class ClientGuiController implements ClientListener {
}); });
chatList.heightProperty().addListener((obs, oldVal, newVal) -> chatPane.setVvalue(1.0)); chatList.heightProperty().addListener((obs, oldVal, newVal) -> chatPane.setVvalue(1.0));
}); });
requestRoomsRegularly();
}
/**
* Request the list of rooms from the server every second.
*/
private void requestRoomsRegularly() {
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(1), event -> {
client.RequestRoomList();
}));
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
} }
@Override @Override
@@ -167,11 +186,13 @@ public class ClientGuiController implements ClientListener {
*/ */
private void createChatEnv(String roomName) { private void createChatEnv(String roomName) {
Platform.runLater(() -> { Platform.runLater(() -> {
this.roomName.setText("Room: " + roomName);
chatList.getChildren().clear(); chatList.getChildren().clear();
chatInput.getChildren().clear(); chatInput.getChildren().clear();
Button leaveButton = new Button("Leave room"); Button leaveButton = new Button("Leave room");
leaveButton.setOnAction(event -> { leaveButton.setOnAction(event -> {
client.SendLeaveRoom(); client.SendLeaveRoom();
this.roomName.setText("");
chatList.getChildren().clear(); chatList.getChildren().clear();
chatInput.getChildren().clear(); chatInput.getChildren().clear();
}); });

View File

@@ -12,7 +12,7 @@
<BorderPane xmlns="http://javafx.com/javafx" <BorderPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml" xmlns:fx="http://javafx.com/fxml"
fx:controller="client.ClientGuiController" fx:controller="client.ClientGuiController"
prefHeight="400.0" prefWidth="600.0" styleClass="vue-container" fx:id="vueContainer"> prefHeight="400.0" prefWidth="600.0" fx:id="vueContainer">
<top> <top>
<HBox alignment="CENTER" styleClass="logo-box"> <HBox alignment="CENTER" styleClass="logo-box">
<padding> <padding>
@@ -25,8 +25,8 @@
</HBox> </HBox>
</top> </top>
<left> <left>
<ScrollPane prefWidth="200.0" styleClass="rooms-pane" fx:id="roomsPane" fitToWidth="true"> <ScrollPane prefWidth="200.0" fitToWidth="true">
<VBox fx:id="rooms" spacing="10.0" alignment="CENTER" VBox.vgrow="ALWAYS"> <VBox spacing="10.0" alignment="CENTER" VBox.vgrow="ALWAYS">
<Label text="Rooms" styleClass="rooms-label"/> <Label text="Rooms" styleClass="rooms-label"/>
<VBox fx:id="roomList" styleClass="rooms-list" spacing="5.0" VBox.vgrow="ALWAYS" alignment="CENTER"/> <VBox fx:id="roomList" styleClass="rooms-list" spacing="5.0" VBox.vgrow="ALWAYS" alignment="CENTER"/>
</VBox> </VBox>
@@ -34,15 +34,23 @@
</left> </left>
<center> <center>
<BorderPane> <BorderPane>
<top>
<HBox alignment="CENTER">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<Label fx:id="roomName" style="-fx-font-size: 18px; -fx-font-weight: bold;"/>
</HBox>
</top>
<center> <center>
<ScrollPane styleClass="chat-pane" fx:id="chatPane" fitToWidth="true"> <ScrollPane fx:id="chatPane" fitToWidth="true">
<VBox fx:id="chat" spacing="10.0"> <VBox spacing="10.0">
<VBox fx:id="chatList" styleClass="chat-list" spacing="5.0" VBox.vgrow="ALWAYS"/> <VBox fx:id="chatList" styleClass="chat-list" spacing="5.0" VBox.vgrow="ALWAYS"/>
</VBox> </VBox>
</ScrollPane> </ScrollPane>
</center> </center>
<bottom> <bottom>
<HBox fx:id="chatInput" styleClass="chat-input" spacing="5.0" style="-fx-padding: 10;" /> <HBox fx:id="chatInput" spacing="5.0" style="-fx-padding: 10;" />
</bottom> </bottom>
</BorderPane> </BorderPane>
</center> </center>