Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jonas 2022-04-16 12:45:36 +02:00
commit 2f34de0136
3 changed files with 101 additions and 2 deletions

View File

@ -1,19 +1,28 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
public class ChatController implements Initializable { public class ChatController implements Initializable {
@FXML
private SplitPane chatPaneRoot;
@FXML @FXML
private VBox vBoxChatMessages; private VBox vBoxChatMessages;
@FXML @FXML
private Button sendButton; private Button sendButton;
@FXML @FXML
@ -21,6 +30,14 @@ public class ChatController implements Initializable {
@FXML @FXML
private TextArea chatMsgField; private TextArea chatMsgField;
private Client client;
private SimpleBooleanProperty whisperTargetChosen;
public ChatController(Client client) {
this.client = client;
whisperTargetChosen = new SimpleBooleanProperty();
}
/** /**
@ -33,5 +50,46 @@ public class ChatController implements Initializable {
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
vBoxChatMessages.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
Number newValue) {
vBoxChatMessages.setMaxHeight(newValue.doubleValue());
}
});
sendButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String msg = chatMsgField.getText();
if (!msg.isEmpty()) {
}
}
});
whisperTargetChosen.bind(whisperTargetSelectField.textProperty().isEmpty());
whisperTargetSelectField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue,
String newValue) {
whisperTargetSelectField.setText(newValue);
}
});
}
/**
* @return the client who's chat controller this is
*/
public Client getClient() {
return client;
}
/**
* @param client who's gui controller this should be
*/
public void setClient(Client client) {
this.client = client;
} }
} }

View File

@ -0,0 +1,41 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
public class outChatCmd implements ChangeListener {
private String cmd;
private static final Protocol prtcl = new Protocol();
private static final String whisper = Protocol.whisper;
private static final String chatToAll = Protocol.chatMsgToAll;
private static final String chatToLobby = Protocol.chatMsgToLobby
public outChatCmd(String cmd, String parameters) {
this.cmd = cmd;
this.parameters = parameters;
}
public String getCmd() {
return cmd;
}
public String getParameters() {
return parameters;
}
/**
* Called when the value of an {@link ObservableValue} changes.
* <p>
* In general, it is considered bad practice to modify the observed value in this method.
*
* @param observable The {@code ObservableValue} which value changed
* @param oldValue The old value
* @param newValue
*/
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
}
}

View File

@ -12,7 +12,7 @@
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController"> <fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController">
<children> <children>
<SplitPane dividerPositions="0.5" layoutX="214.0" layoutY="92.0" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <SplitPane fx:id ="chatPaneRoot" dividerPositions="0.5" layoutX="214.0" layoutY="92.0" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items> <items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children> <children>