mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
- Validation completely done
- Some documentation added. tags : #story[1245]
This commit is contained in:
@@ -27,31 +27,33 @@ import seng302.visualiser.controllers.cells.PlayerCell;
|
|||||||
|
|
||||||
public class LobbyController implements Initializable {
|
public class LobbyController implements Initializable {
|
||||||
|
|
||||||
|
//--------FXML BEGIN--------//
|
||||||
@FXML
|
@FXML
|
||||||
private VBox playerListVBox;
|
private VBox playerListVBox;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ScrollPane playerListScrollpane;
|
private ScrollPane playerListScrollPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton customizeButton, leaveLobbyButton, beginRaceButton;
|
private JFXButton customizeButton, leaveLobbyButton, beginRaceButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private StackPane serverListMainStackPane;
|
private StackPane serverListMainStackPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label serverName;
|
private Label serverName;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label mapName;
|
private Label mapName;
|
||||||
|
//---------FXML END---------//
|
||||||
|
|
||||||
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||||
private RaceState raceState;
|
private RaceState raceState;
|
||||||
private JFXDialog customizationDialog;
|
private JFXDialog customizationDialog;
|
||||||
|
private Color playersColor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
|
if (this.playersColor == null) {
|
||||||
|
this.playersColor = Colors.getColor(ViewManager.getInstance().getGameClient().getServerThread().getClientId() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
leaveLobbyButton.setOnMouseReleased(event -> leaveLobby());
|
leaveLobbyButton.setOnMouseReleased(event -> leaveLobby());
|
||||||
beginRaceButton.setOnMouseReleased(event -> beginRace());
|
beginRaceButton.setOnMouseReleased(event -> beginRace());
|
||||||
|
|
||||||
@@ -76,6 +78,9 @@ public class LobbyController implements Initializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void beginRace() {
|
private void beginRace() {
|
||||||
beginRaceButton.setDisable(true);
|
beginRaceButton.setDisable(true);
|
||||||
customizeButton.setDisable(true);
|
customizeButton.setDisable(true);
|
||||||
@@ -84,6 +89,9 @@ public class LobbyController implements Initializable {
|
|||||||
Platform.runLater(()-> ViewManager.getInstance().getGameClient().startGame());
|
Platform.runLater(()-> ViewManager.getInstance().getGameClient().startGame());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void refreshPlayerList() {
|
private void refreshPlayerList() {
|
||||||
playerListVBox.getChildren().clear();
|
playerListVBox.getChildren().clear();
|
||||||
|
|
||||||
@@ -106,19 +114,26 @@ public class LobbyController implements Initializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leaveLobby() {
|
/**
|
||||||
// TODO: 10/07/17 wmu16 - Finish function!
|
*
|
||||||
// for (LobbyController_old.LobbyCloseListener readyListener : lobbyListeners)
|
*/
|
||||||
// readyListener.notify(LobbyController_old.CloseStatus.LEAVE);
|
private void leaveLobby() {
|
||||||
ViewManager.getInstance().getGameClient().stopGame();
|
ViewManager.getInstance().getGameClient().stopGame();
|
||||||
ViewManager.getInstance().goToStartView();
|
ViewManager.getInstance().goToStartView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableReadyButton() {
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void disableReadyButton() {
|
||||||
this.beginRaceButton.setDisable(true);
|
this.beginRaceButton.setDisable(true);
|
||||||
this.beginRaceButton.setText("Waiting for host...");
|
this.beginRaceButton.setText("Waiting for host...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param raceState
|
||||||
|
*/
|
||||||
public void updateRaceState(RaceState raceState){
|
public void updateRaceState(RaceState raceState){
|
||||||
this.raceState = raceState;
|
this.raceState = raceState;
|
||||||
this.beginRaceButton.setText("Starting in: " + raceState.getRaceTimeStr());
|
this.beginRaceButton.setText("Starting in: " + raceState.getRaceTimeStr());
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import seng302.visualiser.ServerListenerDelegate;
|
|||||||
import seng302.visualiser.controllers.cells.ServerCell;
|
import seng302.visualiser.controllers.cells.ServerCell;
|
||||||
import seng302.visualiser.validators.HostNameFieldValidator;
|
import seng302.visualiser.validators.HostNameFieldValidator;
|
||||||
import seng302.visualiser.validators.NumberRangeValidator;
|
import seng302.visualiser.validators.NumberRangeValidator;
|
||||||
|
import seng302.visualiser.validators.ValidationTools;
|
||||||
|
|
||||||
public class ServerListController implements Initializable, ServerListenerDelegate {
|
public class ServerListController implements Initializable, ServerListenerDelegate {
|
||||||
|
|
||||||
@@ -42,11 +43,9 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
private ScrollPane serverListScrollPane;
|
private ScrollPane serverListScrollPane;
|
||||||
@FXML
|
@FXML
|
||||||
private StackPane serverListMainStackPane;
|
private StackPane serverListMainStackPane;
|
||||||
|
|
||||||
// Host Button
|
// Host Button
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton serverListHostButton;
|
private JFXButton serverListHostButton;
|
||||||
|
|
||||||
//Direct Connect
|
//Direct Connect
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton connectButton;
|
private JFXButton connectButton;
|
||||||
@@ -56,11 +55,6 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
private JFXTextField serverPortNumber;
|
private JFXTextField serverPortNumber;
|
||||||
//---------FXML END---------//
|
//---------FXML END---------//
|
||||||
|
|
||||||
//Validators
|
|
||||||
private HostNameFieldValidator hostNameValidator;
|
|
||||||
private NumberRangeValidator portNumberValidator;
|
|
||||||
|
|
||||||
|
|
||||||
private Label noServersFound;
|
private Label noServersFound;
|
||||||
private Logger logger = LoggerFactory.getLogger(ServerListController.class);
|
private Logger logger = LoggerFactory.getLogger(ServerListController.class);
|
||||||
|
|
||||||
@@ -85,12 +79,13 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validating the hostname
|
// Validating the hostname
|
||||||
hostNameValidator = new HostNameFieldValidator();
|
HostNameFieldValidator hostNameValidator = new HostNameFieldValidator();
|
||||||
hostNameValidator.setMessage("Host Name is Incorrect");
|
hostNameValidator.setMessage("Host name incorrect");
|
||||||
serverHostName.getValidators().add(hostNameValidator);
|
serverHostName.getValidators().add(hostNameValidator);
|
||||||
|
|
||||||
portNumberValidator = new NumberRangeValidator(1025, 65536);
|
// Validating the port number
|
||||||
portNumberValidator.setMessage("Port Number is Incorrect");
|
NumberRangeValidator portNumberValidator = new NumberRangeValidator(1025, 65536);
|
||||||
|
portNumberValidator.setMessage("Port number incorrect");
|
||||||
serverPortNumber.getValidators().add(portNumberValidator);
|
serverPortNumber.getValidators().add(portNumberValidator);
|
||||||
|
|
||||||
// Start listening for servers on network
|
// Start listening for servers on network
|
||||||
@@ -135,27 +130,17 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Boolean validateDirectConnection(String hostName, String portNumber) {
|
|
||||||
Boolean hostNameValid = validateTextField(serverHostName);
|
|
||||||
Boolean portNumberValid = validateTextField(serverPortNumber);
|
|
||||||
|
|
||||||
return hostNameValid && portNumberValid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @param hostName
|
||||||
|
* @param portNumber
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Boolean validateTextField(JFXTextField textField) {
|
private Boolean validateDirectConnection(String hostName, String portNumber) {
|
||||||
textField.validate();
|
Boolean hostNameValid = ValidationTools.validateTextField(serverHostName);
|
||||||
for (ValidatorBase validator : textField.getValidators()) {
|
Boolean portNumberValid = ValidationTools.validateTextField(serverPortNumber);
|
||||||
if (validator.getHasErrors()) {
|
|
||||||
return false;
|
return hostNameValid && portNumberValid;
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,16 +150,6 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
ViewManager.getInstance().getGameClient().runAsClient(serverHostName.getText(), Integer.parseInt(serverPortNumber.getText()));
|
ViewManager.getInstance().getGameClient().runAsClient(serverHostName.getText(), Integer.parseInt(serverPortNumber.getText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serverRemoved(List<ServerDescription> servers) {
|
|
||||||
Platform.runLater(() -> refreshServers(servers));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void serverDetected(ServerDescription serverDescription, List<ServerDescription> servers) {
|
|
||||||
Platform.runLater(() -> refreshServers(servers));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param servers
|
* @param servers
|
||||||
@@ -203,4 +178,14 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serverRemoved(List<ServerDescription> servers) {
|
||||||
|
Platform.runLater(() -> refreshServers(servers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serverDetected(ServerDescription serverDescription, List<ServerDescription> servers) {
|
||||||
|
Platform.runLater(() -> refreshServers(servers));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,15 @@ import java.util.ResourceBundle;
|
|||||||
|
|
||||||
public class StartScreenController implements Initializable{
|
public class StartScreenController implements Initializable{
|
||||||
|
|
||||||
|
//--------FXML BEGIN--------//
|
||||||
@FXML
|
@FXML
|
||||||
private Label headText;
|
private Label headText;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton startBtn;
|
private JFXButton startBtn;
|
||||||
|
//---------FXML END---------//
|
||||||
|
|
||||||
private Node serverList;
|
private Node serverList;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(StartScreenController.class);
|
private Logger logger = LoggerFactory.getLogger(StartScreenController.class);
|
||||||
|
|
||||||
private List<ServerDescription> servers;
|
private List<ServerDescription> servers;
|
||||||
private GameClient gameClient;
|
private GameClient gameClient;
|
||||||
// public void initialize(URL url, ResourceBundle resourceBundle) {
|
// public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
@@ -53,6 +52,17 @@ public class StartScreenController implements Initializable{
|
|||||||
//// gameClient = new GameClient(holder);
|
//// gameClient = new GameClient(holder);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
startBtn.setOnMousePressed(event -> startBtn.setText("LOADING..."));
|
||||||
|
startBtn.setOnMouseReleased(event -> goToServerBrowser());
|
||||||
|
|
||||||
|
setInitialDropShadow();
|
||||||
|
preloadServerListView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void setInitialDropShadow() {
|
private void setInitialDropShadow() {
|
||||||
DropShadow dropShadow = new DropShadow();
|
DropShadow dropShadow = new DropShadow();
|
||||||
dropShadow.setRadius(10.0);
|
dropShadow.setRadius(10.0);
|
||||||
@@ -62,6 +72,9 @@ public class StartScreenController implements Initializable{
|
|||||||
headText.setEffect(dropShadow);
|
headText.setEffect(dropShadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void preloadServerListView(){
|
private void preloadServerListView(){
|
||||||
try {
|
try {
|
||||||
serverList = FXMLLoader
|
serverList = FXMLLoader
|
||||||
@@ -72,6 +85,9 @@ public class StartScreenController implements Initializable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void goToServerBrowser() {
|
private void goToServerBrowser() {
|
||||||
try {
|
try {
|
||||||
ViewManager.getInstance().setScene(serverList);
|
ViewManager.getInstance().setScene(serverList);
|
||||||
@@ -80,16 +96,6 @@ public class StartScreenController implements Initializable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
|
||||||
startBtn.setOnMousePressed(event -> startBtn.setText("LOADING..."));
|
|
||||||
startBtn.setOnMouseReleased(event -> goToServerBrowser());
|
|
||||||
|
|
||||||
setInitialDropShadow();
|
|
||||||
preloadServerListView();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleMusic(ActionEvent actionEvent) {
|
public void toggleMusic(ActionEvent actionEvent) {
|
||||||
Sounds.toggleMuteMusic();
|
Sounds.toggleMuteMusic();
|
||||||
Sounds.playButtonClick();
|
Sounds.playButtonClick();
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ public class ViewManager {
|
|||||||
controller.setPlayerColor(playerColor);
|
controller.setPlayerColor(playerColor);
|
||||||
controller.setPlayerName(name);
|
controller.setPlayerName(name);
|
||||||
controller.setServerThread(gameClient.getServerThread());
|
controller.setServerThread(gameClient.getServerThread());
|
||||||
|
controller.setPlayerColor(lobbyController.playersColor);
|
||||||
|
|
||||||
|
|
||||||
return customizationDialog;
|
return customizationDialog;
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import javafx.scene.effect.DropShadow;
|
|||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerCell {
|
public class PlayerCell {
|
||||||
|
|
||||||
|
//--------FXML BEGIN--------//
|
||||||
@FXML
|
@FXML
|
||||||
private Label playerName;
|
private Label playerName;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private GridPane playerListCell;
|
private GridPane playerListCell;
|
||||||
|
//---------FXML END---------//
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ public class ServerCell implements Initializable {
|
|||||||
serverConnButton.setOnMouseReleased(event -> joinServer());
|
serverConnButton.setOnMouseReleased(event -> joinServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinServer() {
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void joinServer() {
|
||||||
System.out.println("Connecting to " + serverName.getText());
|
System.out.println("Connecting to " + serverName.getText());
|
||||||
ViewManager.getInstance().getGameClient().runAsClient(hostName, portNumber);
|
ViewManager.getInstance().getGameClient().runAsClient(hostName, portNumber);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package seng302.visualiser.controllers.dialogs;
|
|||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXColorPicker;
|
import com.jfoenix.controls.JFXColorPicker;
|
||||||
import com.jfoenix.controls.JFXTextField;
|
import com.jfoenix.controls.JFXTextField;
|
||||||
|
import com.jfoenix.validation.RequiredFieldValidator;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
@@ -14,56 +15,65 @@ import seng302.visualiser.ClientToServerThread;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import seng302.visualiser.controllers.LobbyController;
|
import seng302.visualiser.controllers.LobbyController;
|
||||||
|
import seng302.visualiser.validators.FieldLengthValidator;
|
||||||
|
import seng302.visualiser.validators.ValidationTools;
|
||||||
|
|
||||||
public class BoatCustomizeController implements Initializable{
|
public class BoatCustomizeController implements Initializable{
|
||||||
|
|
||||||
|
//--------FXML BEGIN--------//
|
||||||
@FXML
|
@FXML
|
||||||
private JFXColorPicker colorPicker;
|
private JFXColorPicker colorPicker;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXButton submitBtn;
|
private JFXButton submitBtn;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXTextField boatName;
|
private JFXTextField boatName;
|
||||||
private ClientToServerThread socketThread;
|
|
||||||
private LobbyController lobbyController;
|
|
||||||
|
|
||||||
|
|
||||||
public BoatCustomizeController(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void colorChanged(ActionEvent event) {
|
void colorChanged(ActionEvent event) {
|
||||||
Color color = colorPicker.getValue();
|
Color color = colorPicker.getValue();
|
||||||
}
|
}
|
||||||
|
//---------FXML END---------//
|
||||||
|
|
||||||
|
private ClientToServerThread socketThread;
|
||||||
|
private LobbyController lobbyController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
colorPicker.setValue(Color.BISQUE);
|
|
||||||
submitBtn.setOnMouseReleased(event -> {
|
submitBtn.setOnMouseReleased(event -> {
|
||||||
submitCustomization();
|
submitCustomization();
|
||||||
lobbyController.closeCustomizationDialog();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RequiredFieldValidator playerNameReqValidator = new RequiredFieldValidator();
|
||||||
|
playerNameReqValidator.setMessage("Player name required.");
|
||||||
|
|
||||||
|
FieldLengthValidator playerNameLengthValidator = new FieldLengthValidator(20);
|
||||||
|
playerNameLengthValidator.setMessage("Player name too long.");
|
||||||
|
|
||||||
|
boatName.setValidators(playerNameLengthValidator, playerNameReqValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
/**
|
||||||
public void submitCustomization() {
|
*
|
||||||
socketThread.sendCustomizationRequest(CustomizeRequestType.NAME, boatName.getText().getBytes());
|
*/
|
||||||
|
private void submitCustomization() {
|
||||||
|
|
||||||
Color color = colorPicker.getValue();
|
if (ValidationTools.validateTextField(boatName)) {
|
||||||
short red = (short) (color.getRed() * 255);
|
socketThread
|
||||||
short green = (short) (color.getGreen() * 255);
|
.sendCustomizationRequest(CustomizeRequestType.NAME, boatName.getText().getBytes());
|
||||||
short blue = (short) (color.getBlue() * 255);
|
|
||||||
|
|
||||||
byte[] colorArray = new byte[3];
|
Color color = colorPicker.getValue();
|
||||||
|
short red = (short) (color.getRed() * 255);
|
||||||
|
short green = (short) (color.getGreen() * 255);
|
||||||
|
short blue = (short) (color.getBlue() * 255);
|
||||||
|
|
||||||
colorArray[0] = (byte) red;
|
byte[] colorArray = new byte[3];
|
||||||
colorArray[1] = (byte) green;
|
|
||||||
colorArray[2] = (byte) blue;
|
|
||||||
|
|
||||||
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
|
colorArray[0] = (byte) red;
|
||||||
lobbyController.closeCustomizationDialog();
|
colorArray[1] = (byte) green;
|
||||||
|
colorArray[2] = (byte) blue;
|
||||||
|
|
||||||
|
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
|
||||||
|
lobbyController.closeCustomizationDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerName(String name) {
|
public void setPlayerName(String name) {
|
||||||
|
|||||||
+23
-14
@@ -13,6 +13,7 @@ import seng302.visualiser.validators.FieldLengthValidator;
|
|||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import seng302.visualiser.validators.ValidationTools;
|
||||||
|
|
||||||
public class ServerCreationController implements Initializable {
|
public class ServerCreationController implements Initializable {
|
||||||
|
|
||||||
@@ -27,34 +28,39 @@ public class ServerCreationController implements Initializable {
|
|||||||
private JFXButton submitBtn;
|
private JFXButton submitBtn;
|
||||||
//---------FXML END---------//
|
//---------FXML END---------//
|
||||||
|
|
||||||
FieldLengthValidator fieldLengthValidator;
|
|
||||||
RequiredFieldValidator fieldRequiredValidator;
|
|
||||||
|
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
updateMaxPlayerLabel();
|
updateMaxPlayerLabel();
|
||||||
maxPlayersSlider.valueProperty().addListener((observable, oldValue, newValue) -> {
|
maxPlayersSlider.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
updateMaxPlayerLabel();
|
updateMaxPlayerLabel();
|
||||||
});
|
});
|
||||||
|
|
||||||
fieldLengthValidator = new FieldLengthValidator(40);
|
FieldLengthValidator fieldLengthValidator = new FieldLengthValidator(40);
|
||||||
fieldLengthValidator.setMessage("Server Name Too Long");
|
fieldLengthValidator.setMessage("Server name too long.");
|
||||||
fieldRequiredValidator = new RequiredFieldValidator();
|
|
||||||
fieldRequiredValidator.setMessage("Server Name is Required.");
|
RequiredFieldValidator fieldRequiredValidator = new RequiredFieldValidator();
|
||||||
|
fieldRequiredValidator.setMessage("Server name is required.");
|
||||||
|
|
||||||
serverName.setValidators(fieldLengthValidator, fieldRequiredValidator);
|
serverName.setValidators(fieldLengthValidator, fieldRequiredValidator);
|
||||||
|
|
||||||
submitBtn.setOnMouseClicked(event -> submitBtn.setText("CREATING..."));
|
|
||||||
submitBtn.setOnMouseReleased(event -> validateServerSettings());
|
submitBtn.setOnMouseReleased(event -> validateServerSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void validateServerSettings() {
|
private void validateServerSettings() {
|
||||||
serverName.validate();
|
submitBtn.setText("CREATING...");
|
||||||
System.out.println(serverName.getActiveValidator());
|
if (ValidationTools.validateTextField(serverName)) {
|
||||||
createServer();
|
createServer();
|
||||||
|
} else {
|
||||||
|
submitBtn.setText("SUBMIT");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public void createServer() {
|
*
|
||||||
|
*/
|
||||||
|
private void createServer() {
|
||||||
ServerDescription serverDescription = ViewManager.getInstance().getGameClient()
|
ServerDescription serverDescription = ViewManager.getInstance().getGameClient()
|
||||||
.runAsHost("localhost", 4941, serverName.getText(), (int) maxPlayersSlider
|
.runAsHost("localhost", 4941, serverName.getText(), (int) maxPlayersSlider
|
||||||
.getValue());
|
.getValue());
|
||||||
@@ -63,6 +69,9 @@ public class ServerCreationController implements Initializable {
|
|||||||
ViewManager.getInstance().setProperty("mapName", serverDescription.getMapName());
|
ViewManager.getInstance().setProperty("mapName", serverDescription.getMapName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void updateMaxPlayerLabel() {
|
private void updateMaxPlayerLabel() {
|
||||||
maxPlayersSlider.setValue(Math.floor(maxPlayersSlider.getValue()));
|
maxPlayersSlider.setValue(Math.floor(maxPlayersSlider.getValue()));
|
||||||
maxPlayersLabel.setText(String.format("YOU SELECTED: %.0f", maxPlayersSlider.getValue()));
|
maxPlayersLabel.setText(String.format("YOU SELECTED: %.0f", maxPlayersSlider.getValue()));
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package seng302.visualiser.validators;
|
||||||
|
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXTextField;
|
||||||
|
import com.jfoenix.validation.base.ValidatorBase;
|
||||||
|
|
||||||
|
public class ValidationTools {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Boolean validateTextField(JFXTextField textField) {
|
||||||
|
textField.validate();
|
||||||
|
for (ValidatorBase validator : textField.getValidators()) {
|
||||||
|
if (validator.getHasErrors()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user