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.control.TextField;
|
||||||
import javafx.scene.layout.Border;
|
import javafx.scene.layout.Border;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import network.protocol.packets.ServerResponsePacket;
|
import network.protocol.packets.ServerResponsePacket;
|
||||||
@@ -33,6 +34,9 @@ public class ClientGuiController implements ClientListener {
|
|||||||
@FXML
|
@FXML
|
||||||
private VBox chatList;
|
private VBox chatList;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private HBox chatInput;
|
||||||
|
|
||||||
public void setClient(Client client) {
|
public void setClient(Client client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
@@ -43,6 +47,7 @@ public void initialize() throws SocketException {
|
|||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Stage stage = (Stage) vueContainer.getScene().getWindow();
|
Stage stage = (Stage) vueContainer.getScene().getWindow();
|
||||||
stage.setOnCloseRequest(event -> {
|
stage.setOnCloseRequest(event -> {
|
||||||
|
connected = false;
|
||||||
client.close();
|
client.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -55,15 +60,17 @@ public void initialize() throws SocketException {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleConnexionError() {
|
public void handleConnexionError() {
|
||||||
Platform.runLater(() -> {
|
if(connected) {
|
||||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
Platform.runLater(() -> {
|
||||||
alert.setTitle("Connection");
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
alert.setHeaderText("Connection failed");
|
alert.setTitle("Connection");
|
||||||
Optional<ButtonType> res = alert.showAndWait();
|
alert.setHeaderText("Connection failed");
|
||||||
if (res.isPresent() && res.get() == ButtonType.OK) {
|
Optional<ButtonType> res = alert.showAndWait();
|
||||||
((Stage) vueContainer.getScene().getWindow()).close();
|
if (res.isPresent() && res.get() == ButtonType.OK) {
|
||||||
}
|
((Stage) vueContainer.getScene().getWindow()).close();
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,7 +84,12 @@ public void initialize() throws SocketException {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void handleChatMessage(Instant time, String chatter, String content) {
|
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
|
@Override
|
||||||
@@ -100,17 +112,23 @@ public void initialize() throws SocketException {
|
|||||||
// <Button fx:id="sendButton" text="Send" styleClass="send-button"/>
|
// <Button fx:id="sendButton" text="Send" styleClass="send-button"/>
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
chatList.getChildren().clear();
|
chatList.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();
|
||||||
chatList.getChildren().clear();
|
chatList.getChildren().clear();
|
||||||
|
chatInput.getChildren().clear();
|
||||||
});
|
});
|
||||||
chatList.getChildren().add(leaveButton);
|
chatList.getChildren().add(leaveButton);
|
||||||
|
|
||||||
TextField messageInput = new TextField();
|
TextField messageInput = new TextField();
|
||||||
messageInput.setPromptText("Type a message...");
|
messageInput.setPromptText("Type a message...");
|
||||||
messageInput.getStyleClass().add("message-input");
|
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");
|
Button sendButton = new Button("Send");
|
||||||
sendButton.getStyleClass().add("send-button");
|
sendButton.getStyleClass().add("send-button");
|
||||||
@@ -118,7 +136,7 @@ public void initialize() throws SocketException {
|
|||||||
client.SendChatMessage(messageInput.getText());
|
client.SendChatMessage(messageInput.getText());
|
||||||
messageInput.clear();
|
messageInput.clear();
|
||||||
});
|
});
|
||||||
chatList.getChildren().add(sendButton);
|
chatInput.getChildren().add(sendButton);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,8 @@
|
|||||||
</left>
|
</left>
|
||||||
<center>
|
<center>
|
||||||
<ScrollPane styleClass="chat-pane" fx:id="chatPane">
|
<ScrollPane styleClass="chat-pane" fx:id="chatPane">
|
||||||
<VBox fx:id="chat" spacing="10.0">
|
<VBox fx:id="chat" spacing="10.0" prefWidth="Infinity">
|
||||||
<Label text="Chat" style="-fx-font-size: 18px;"/>
|
<VBox fx:id="chatList" styleClass="chat-list" spacing="5.0" VBox.vgrow="ALWAYS"/>
|
||||||
<VBox fx:id="chatList" styleClass="chat-list" spacing="5.0"/>
|
|
||||||
<HBox fx:id="chatInput" styleClass="chat-input" spacing="5.0" />
|
<HBox fx:id="chatInput" styleClass="chat-input" spacing="5.0" />
|
||||||
</VBox>
|
</VBox>
|
||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
|
|||||||
Reference in New Issue
Block a user