all functionality handled

This commit is contained in:
Clément
2025-03-12 21:34:55 +01:00
parent 11fc2e2ac8
commit bfd3c10e9e
2 changed files with 32 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import javafx.scene.control.ButtonType;
import javafx.scene.control.TextField;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import network.protocol.packets.ServerResponsePacket;
@@ -33,6 +34,9 @@ public class ClientGuiController implements ClientListener {
@FXML
private VBox chatList;
@FXML
private HBox chatInput;
public void setClient(Client client) {
this.client = client;
}
@@ -43,6 +47,7 @@ public void initialize() throws SocketException {
Platform.runLater(() -> {
Stage stage = (Stage) vueContainer.getScene().getWindow();
stage.setOnCloseRequest(event -> {
connected = false;
client.close();
});
});
@@ -55,15 +60,17 @@ public void initialize() throws SocketException {
@Override
public void handleConnexionError() {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Connection");
alert.setHeaderText("Connection failed");
Optional<ButtonType> res = alert.showAndWait();
if (res.isPresent() && res.get() == ButtonType.OK) {
((Stage) vueContainer.getScene().getWindow()).close();
}
});
if(connected) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Connection");
alert.setHeaderText("Connection failed");
Optional<ButtonType> res = alert.showAndWait();
if (res.isPresent() && res.get() == ButtonType.OK) {
((Stage) vueContainer.getScene().getWindow()).close();
}
});
}
}
@Override
@@ -77,7 +84,12 @@ public void initialize() throws SocketException {
}
@Override
public void handleChatMessage(Instant time, String chatter, String content) {
Platform.runLater(() -> {
VBox msg = new VBox();
msg.getChildren().add(new TextField(chatter + " : " + content));
chatList.getChildren().add(msg);
// chatList.getChildren().add()
});
}
@Override
@@ -100,17 +112,23 @@ public void initialize() throws SocketException {
// <Button fx:id="sendButton" text="Send" styleClass="send-button"/>
Platform.runLater(() -> {
chatList.getChildren().clear();
chatInput.getChildren().clear();
Button leaveButton = new Button("Leave room");
leaveButton.setOnAction(event -> {
client.SendLeaveRoom();
chatList.getChildren().clear();
chatInput.getChildren().clear();
});
chatList.getChildren().add(leaveButton);
TextField messageInput = new TextField();
messageInput.setPromptText("Type a message...");
messageInput.getStyleClass().add("message-input");
chatList.getChildren().add(messageInput);
messageInput.onActionProperty().set(event -> {
client.SendChatMessage(messageInput.getText());
messageInput.clear();
});
chatInput.getChildren().add(messageInput);
Button sendButton = new Button("Send");
sendButton.getStyleClass().add("send-button");
@@ -118,7 +136,7 @@ public void initialize() throws SocketException {
client.SendChatMessage(messageInput.getText());
messageInput.clear();
});
chatList.getChildren().add(sendButton);
chatInput.getChildren().add(sendButton);
});
}

View File

@@ -34,9 +34,8 @@
</left>
<center>
<ScrollPane styleClass="chat-pane" fx:id="chatPane">
<VBox fx:id="chat" spacing="10.0">
<Label text="Chat" style="-fx-font-size: 18px;"/>
<VBox fx:id="chatList" styleClass="chat-list" spacing="5.0"/>
<VBox fx:id="chat" spacing="10.0" prefWidth="Infinity">
<VBox fx:id="chatList" styleClass="chat-list" spacing="5.0" VBox.vgrow="ALWAYS"/>
<HBox fx:id="chatInput" styleClass="chat-input" spacing="5.0" />
</VBox>
</ScrollPane>