Adding Wrapper Classes for Controlls and corresponding EventHandlers. added different fxml views.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
public class ClientListViewController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
public class LobbySceneViewController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||
|
||||
public class ServerMessageViewController {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.buttons;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
public class ChangeNameButton extends Button {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.buttons;
|
||||
|
||||
import java.awt.Button;
|
||||
|
||||
public class JoinGameButton extends Button {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.buttons;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
public class LeaveServerButton extends Button {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.buttons;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
public class NewGameButton extends Button {
|
||||
|
||||
}
|
||||
@@ -4,6 +4,8 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
import com.sun.javafx.scene.control.Properties;
|
||||
import com.sun.javafx.scene.control.inputmap.KeyBinding;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.application.Platform;
|
||||
@@ -15,16 +17,22 @@ import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Background;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.TextFlow;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -33,6 +41,12 @@ public class ChatController implements Initializable {
|
||||
public static final Logger LOGGER = LogManager.getLogger(ChatController.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
@FXML
|
||||
private Group vboxGroup;
|
||||
@FXML
|
||||
private GridPane vBoxGridPane;
|
||||
@FXML
|
||||
private ScrollPane ChatScrollPane;
|
||||
@FXML
|
||||
private VBox vBoxServerMessage;
|
||||
@FXML
|
||||
@@ -103,32 +117,23 @@ public class ChatController implements Initializable {
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
|
||||
Number newValue) {
|
||||
vBoxChatMessages.setMaxHeight(newValue.doubleValue());
|
||||
ChatScrollPane.setMaxHeight(newValue.doubleValue()*2);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Initialize what happens when the send button is pressed
|
||||
*/
|
||||
sendButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
String msg = chatMsgField.getText().split("\\R")[0]; //cut off extra lines, if present.
|
||||
if (!msg.isEmpty()) {
|
||||
client.getClient().sendMsgToServer(cmd.toString() + msg);
|
||||
LOGGER.info("Message trying to send is: " + cmd.toString() + msg);
|
||||
Label l;
|
||||
if (cmd.startsWith(whisper)) {
|
||||
l = new Label("You whispered to " + whisperTargetSelectField.getText() + ": " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDERBLUSH));
|
||||
} else {
|
||||
l = new Label(client.getUsername() + " (you): " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDER));
|
||||
}
|
||||
vBoxChatMessages.getChildren().add(l);
|
||||
chatMsgField.clear();
|
||||
} else {
|
||||
LOGGER.debug("Trying to send an empty message.");
|
||||
}
|
||||
sendChatMsg();
|
||||
}
|
||||
});
|
||||
|
||||
chatMsgField.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
sendChatMsg();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -158,6 +163,29 @@ public class ChatController implements Initializable {
|
||||
});
|
||||
}
|
||||
|
||||
private void sendChatMsg() {
|
||||
String msg = chatMsgField.getText();//.split("\\R")[0]; //cut off extra lines, if present.
|
||||
if (!msg.isEmpty()) {
|
||||
client.getClient().sendMsgToServer(cmd.toString() + msg);
|
||||
LOGGER.info("Message trying to send is: " + cmd.toString() + msg);
|
||||
Label l;
|
||||
if (cmd.startsWith(whisper)) {
|
||||
l = new Label("You whispered to " + whisperTargetSelectField.getText() + ": " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDERBLUSH));
|
||||
} else {
|
||||
l = new Label(client.getUsername() + " (you): " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDER));
|
||||
l.setWrapText(true);
|
||||
l.setMaxHeight(Double.MAX_VALUE);
|
||||
l.setScaleShape(true);
|
||||
}
|
||||
vBoxChatMessages.getChildren().add(l);
|
||||
chatMsgField.clear();
|
||||
} else {
|
||||
LOGGER.debug("Trying to send an empty message.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ClientModel whose chat controller this is
|
||||
*/
|
||||
@@ -185,6 +213,8 @@ public class ChatController implements Initializable {
|
||||
*/
|
||||
public void addChatMsgToView(String msg) {
|
||||
Label l = new Label(msg);
|
||||
l.setWrapText(true);
|
||||
l.setMaxHeight(Double.MAX_VALUE);
|
||||
if (msg.contains("whispers")) {
|
||||
l.setBackground(Background.fill(Color.SLATEBLUE));
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
public class ChangeNameButtonPressedEventHandler implements EventHandler<ActionEvent> {
|
||||
|
||||
/**
|
||||
* Invoked when a specific event of the type for which this handler is registered happens.
|
||||
*
|
||||
* @param event the event which occurred
|
||||
*/
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
public class JoinGameButtonPressedEventHandler implements EventHandler<ActionEvent> {
|
||||
|
||||
/**
|
||||
* Invoked when a specific event of the type for which this handler is registered happens.
|
||||
*
|
||||
* @param event the event which occurred
|
||||
*/
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
public class LeaveServerButtonPressedEventHandler implements EventHandler<ActionEvent> {
|
||||
|
||||
/**
|
||||
* Invoked when a specific event of the type for which this handler is registered happens.
|
||||
*
|
||||
* @param event the event which occurred
|
||||
*/
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.events;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
|
||||
public class NewGameButtonPressedEventHandler implements EventHandler<ActionEvent> {
|
||||
|
||||
/**
|
||||
* Invoked when a specific event of the type for which this handler is registered happens.
|
||||
*
|
||||
* @param event the event which occurred
|
||||
*/
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge;
|
||||
|
||||
public class LoungeSceneViewController {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user