Compare commits
2 Commits
dfdaae163b
...
67124f4731
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67124f4731 | ||
|
|
631cd25a9d |
@@ -1,5 +1,7 @@
|
||||
package client;
|
||||
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
@@ -7,6 +9,7 @@ import javafx.scene.layout.*;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextFlow;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import network.protocol.packets.ServerResponsePacket;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -41,6 +44,9 @@ public class ClientGuiController implements ClientListener {
|
||||
@FXML
|
||||
private ScrollPane chatPane;
|
||||
|
||||
@FXML
|
||||
private Label roomName;
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
@@ -57,6 +63,19 @@ public class ClientGuiController implements ClientListener {
|
||||
});
|
||||
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
|
||||
@@ -167,11 +186,13 @@ public class ClientGuiController implements ClientListener {
|
||||
*/
|
||||
private void createChatEnv(String roomName) {
|
||||
Platform.runLater(() -> {
|
||||
this.roomName.setText("Room: " + roomName);
|
||||
chatList.getChildren().clear();
|
||||
chatInput.getChildren().clear();
|
||||
Button leaveButton = new Button("Leave room");
|
||||
leaveButton.setOnAction(event -> {
|
||||
client.SendLeaveRoom();
|
||||
this.roomName.setText("");
|
||||
chatList.getChildren().clear();
|
||||
chatInput.getChildren().clear();
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
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>
|
||||
<HBox alignment="CENTER" styleClass="logo-box">
|
||||
<padding>
|
||||
@@ -25,8 +25,8 @@
|
||||
</HBox>
|
||||
</top>
|
||||
<left>
|
||||
<ScrollPane prefWidth="200.0" styleClass="rooms-pane" fx:id="roomsPane" fitToWidth="true">
|
||||
<VBox fx:id="rooms" spacing="10.0" alignment="CENTER" VBox.vgrow="ALWAYS">
|
||||
<ScrollPane prefWidth="200.0" fitToWidth="true">
|
||||
<VBox spacing="10.0" alignment="CENTER" VBox.vgrow="ALWAYS">
|
||||
<Label text="Rooms" styleClass="rooms-label"/>
|
||||
<VBox fx:id="roomList" styleClass="rooms-list" spacing="5.0" VBox.vgrow="ALWAYS" alignment="CENTER"/>
|
||||
</VBox>
|
||||
@@ -34,15 +34,23 @@
|
||||
</left>
|
||||
<center>
|
||||
<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>
|
||||
<ScrollPane styleClass="chat-pane" fx:id="chatPane" fitToWidth="true">
|
||||
<VBox fx:id="chat" spacing="10.0">
|
||||
<ScrollPane fx:id="chatPane" fitToWidth="true">
|
||||
<VBox spacing="10.0">
|
||||
<VBox fx:id="chatList" styleClass="chat-list" spacing="5.0" VBox.vgrow="ALWAYS"/>
|
||||
</VBox>
|
||||
</ScrollPane>
|
||||
</center>
|
||||
<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>
|
||||
</BorderPane>
|
||||
</center>
|
||||
|
||||
Reference in New Issue
Block a user