all functionality handled
This commit is contained in:
@@ -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,6 +60,7 @@ public void initialize() throws SocketException {
|
||||
|
||||
@Override
|
||||
public void handleConnexionError() {
|
||||
if(connected) {
|
||||
Platform.runLater(() -> {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("Connection");
|
||||
@@ -65,6 +71,7 @@ public void initialize() throws SocketException {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleConnect() {
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user