Commit to make sure everything is here as I accidentally deleted large portions of my local code.
This commit is contained in:
parent
8e434e3e14
commit
504aa9aef2
@ -1,5 +1,26 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
|
||||
public class ClientModel {
|
||||
|
||||
private String username;
|
||||
private Client client;
|
||||
//private Number;
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
|
||||
public class CmdProperty extends SimpleBooleanProperty {
|
||||
|
||||
private String cmd;
|
||||
|
||||
//TODO private void updateCmd();
|
||||
}
|
||||
@ -1,10 +1,13 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
@ -12,10 +15,15 @@ import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ColorPicker;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.Background;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
|
||||
public class ChatController implements Initializable {
|
||||
|
||||
@ -30,13 +38,22 @@ public class ChatController implements Initializable {
|
||||
@FXML
|
||||
private TextArea chatMsgField;
|
||||
|
||||
private Client client;
|
||||
private ClientModel client;
|
||||
|
||||
private SimpleBooleanProperty whisperTargetChosen;
|
||||
private SimpleStringProperty cmd;
|
||||
|
||||
public ChatController(Client client) {
|
||||
private static final String whisper = Protocol.whisper;
|
||||
private static final String chatToAll = Protocol.chatMsgToAll;
|
||||
private static final String chatToLobby = Protocol.chatMsgToLobby;
|
||||
|
||||
|
||||
|
||||
public ChatController(ClientModel client) {
|
||||
this.client = client;
|
||||
whisperTargetChosen = new SimpleBooleanProperty();
|
||||
cmd = new SimpleStringProperty();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +67,16 @@ public class ChatController implements Initializable {
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
|
||||
|
||||
vBoxChatMessages.heightProperty().addListener(new ChangeListener<Number>() {
|
||||
/**
|
||||
* TODO: implement
|
||||
* Adjust the hight when new messages come in.
|
||||
* @param observable
|
||||
* @param oldValue
|
||||
* @param newValue
|
||||
*/
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
|
||||
Number newValue) {
|
||||
@ -59,14 +85,29 @@ public class ChatController implements Initializable {
|
||||
});
|
||||
|
||||
sendButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
/**
|
||||
* control what to do when the "SendButton" is pressed
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
String msg = chatMsgField.getText();
|
||||
if (!msg.isEmpty()) {
|
||||
|
||||
client.getClient().sendMsgToServer(cmd.toString() + msg);
|
||||
Label l = new Label(client.getUsername() + " (you): " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDER));
|
||||
vBoxChatMessages.getChildren().add(l);
|
||||
chatMsgField.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
chatMsgField.textProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observable, String oldValue,
|
||||
String newValue) {
|
||||
chatMsgField.setText(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
whisperTargetChosen.bind(whisperTargetSelectField.textProperty().isEmpty());
|
||||
|
||||
@ -82,14 +123,18 @@ public class ChatController implements Initializable {
|
||||
/**
|
||||
* @return the client who's chat controller this is
|
||||
*/
|
||||
public Client getClient() {
|
||||
public ClientModel getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param client who's gui controller this should be
|
||||
*/
|
||||
public void setClient(Client client) {
|
||||
public void setClient(ClientModel client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public SplitPane getChatPaneRoot() {
|
||||
return chatPaneRoot;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user