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 {
|
||||
|
||||
//--------FXML BEGIN--------//
|
||||
@FXML
|
||||
private VBox playerListVBox;
|
||||
|
||||
@FXML
|
||||
private ScrollPane playerListScrollpane;
|
||||
|
||||
private ScrollPane playerListScrollPane;
|
||||
@FXML
|
||||
private JFXButton customizeButton, leaveLobbyButton, beginRaceButton;
|
||||
|
||||
@FXML
|
||||
private StackPane serverListMainStackPane;
|
||||
|
||||
@FXML
|
||||
private Label serverName;
|
||||
|
||||
@FXML
|
||||
private Label mapName;
|
||||
//---------FXML END---------//
|
||||
|
||||
private List<LobbyController_old.LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||
private RaceState raceState;
|
||||
private JFXDialog customizationDialog;
|
||||
private Color playersColor;
|
||||
|
||||
@Override
|
||||
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());
|
||||
beginRaceButton.setOnMouseReleased(event -> beginRace());
|
||||
|
||||
@@ -76,6 +78,9 @@ public class LobbyController implements Initializable {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void beginRace() {
|
||||
beginRaceButton.setDisable(true);
|
||||
customizeButton.setDisable(true);
|
||||
@@ -84,6 +89,9 @@ public class LobbyController implements Initializable {
|
||||
Platform.runLater(()-> ViewManager.getInstance().getGameClient().startGame());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void refreshPlayerList() {
|
||||
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().goToStartView();
|
||||
}
|
||||
|
||||
public void disableReadyButton() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void disableReadyButton() {
|
||||
this.beginRaceButton.setDisable(true);
|
||||
this.beginRaceButton.setText("Waiting for host...");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param raceState
|
||||
*/
|
||||
public void updateRaceState(RaceState raceState){
|
||||
this.raceState = raceState;
|
||||
this.beginRaceButton.setText("Starting in: " + raceState.getRaceTimeStr());
|
||||
|
||||
@@ -31,6 +31,7 @@ import seng302.visualiser.ServerListenerDelegate;
|
||||
import seng302.visualiser.controllers.cells.ServerCell;
|
||||
import seng302.visualiser.validators.HostNameFieldValidator;
|
||||
import seng302.visualiser.validators.NumberRangeValidator;
|
||||
import seng302.visualiser.validators.ValidationTools;
|
||||
|
||||
public class ServerListController implements Initializable, ServerListenerDelegate {
|
||||
|
||||
@@ -42,11 +43,9 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
private ScrollPane serverListScrollPane;
|
||||
@FXML
|
||||
private StackPane serverListMainStackPane;
|
||||
|
||||
// Host Button
|
||||
@FXML
|
||||
private JFXButton serverListHostButton;
|
||||
|
||||
//Direct Connect
|
||||
@FXML
|
||||
private JFXButton connectButton;
|
||||
@@ -56,11 +55,6 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
private JFXTextField serverPortNumber;
|
||||
//---------FXML END---------//
|
||||
|
||||
//Validators
|
||||
private HostNameFieldValidator hostNameValidator;
|
||||
private NumberRangeValidator portNumberValidator;
|
||||
|
||||
|
||||
private Label noServersFound;
|
||||
private Logger logger = LoggerFactory.getLogger(ServerListController.class);
|
||||
|
||||
@@ -85,12 +79,13 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
}
|
||||
|
||||
// Validating the hostname
|
||||
hostNameValidator = new HostNameFieldValidator();
|
||||
hostNameValidator.setMessage("Host Name is Incorrect");
|
||||
HostNameFieldValidator hostNameValidator = new HostNameFieldValidator();
|
||||
hostNameValidator.setMessage("Host name incorrect");
|
||||
serverHostName.getValidators().add(hostNameValidator);
|
||||
|
||||
portNumberValidator = new NumberRangeValidator(1025, 65536);
|
||||
portNumberValidator.setMessage("Port Number is Incorrect");
|
||||
// Validating the port number
|
||||
NumberRangeValidator portNumberValidator = new NumberRangeValidator(1025, 65536);
|
||||
portNumberValidator.setMessage("Port number incorrect");
|
||||
serverPortNumber.getValidators().add(portNumberValidator);
|
||||
|
||||
// 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
|
||||
*/
|
||||
private Boolean validateTextField(JFXTextField textField) {
|
||||
textField.validate();
|
||||
for (ValidatorBase validator : textField.getValidators()) {
|
||||
if (validator.getHasErrors()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
private Boolean validateDirectConnection(String hostName, String portNumber) {
|
||||
Boolean hostNameValid = ValidationTools.validateTextField(serverHostName);
|
||||
Boolean portNumberValid = ValidationTools.validateTextField(serverPortNumber);
|
||||
|
||||
return hostNameValid && portNumberValid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,16 +150,6 @@ public class ServerListController implements Initializable, ServerListenerDelega
|
||||
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
|
||||
@@ -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{
|
||||
|
||||
//--------FXML BEGIN--------//
|
||||
@FXML
|
||||
private Label headText;
|
||||
|
||||
@FXML
|
||||
private JFXButton startBtn;
|
||||
//---------FXML END---------//
|
||||
|
||||
private Node serverList;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(StartScreenController.class);
|
||||
|
||||
private List<ServerDescription> servers;
|
||||
private GameClient gameClient;
|
||||
// public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
@@ -53,6 +52,17 @@ public class StartScreenController implements Initializable{
|
||||
//// 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() {
|
||||
DropShadow dropShadow = new DropShadow();
|
||||
dropShadow.setRadius(10.0);
|
||||
@@ -62,6 +72,9 @@ public class StartScreenController implements Initializable{
|
||||
headText.setEffect(dropShadow);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void preloadServerListView(){
|
||||
try {
|
||||
serverList = FXMLLoader
|
||||
@@ -72,6 +85,9 @@ public class StartScreenController implements Initializable{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void goToServerBrowser() {
|
||||
try {
|
||||
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) {
|
||||
Sounds.toggleMuteMusic();
|
||||
Sounds.playButtonClick();
|
||||
|
||||
@@ -182,6 +182,7 @@ public class ViewManager {
|
||||
controller.setPlayerColor(playerColor);
|
||||
controller.setPlayerName(name);
|
||||
controller.setServerThread(gameClient.getServerThread());
|
||||
controller.setPlayerColor(lobbyController.playersColor);
|
||||
|
||||
|
||||
return customizationDialog;
|
||||
|
||||
@@ -6,13 +6,14 @@ import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
|
||||
public class PlayerCell {
|
||||
|
||||
//--------FXML BEGIN--------//
|
||||
@FXML
|
||||
private Label playerName;
|
||||
|
||||
@FXML
|
||||
private GridPane playerListCell;
|
||||
//---------FXML END---------//
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
@@ -67,7 +67,10 @@ public class ServerCell implements Initializable {
|
||||
serverConnButton.setOnMouseReleased(event -> joinServer());
|
||||
}
|
||||
|
||||
public void joinServer() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void joinServer() {
|
||||
System.out.println("Connecting to " + serverName.getText());
|
||||
ViewManager.getInstance().getGameClient().runAsClient(hostName, portNumber);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package seng302.visualiser.controllers.dialogs;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXColorPicker;
|
||||
import com.jfoenix.controls.JFXTextField;
|
||||
import com.jfoenix.validation.RequiredFieldValidator;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
@@ -14,56 +15,65 @@ import seng302.visualiser.ClientToServerThread;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import seng302.visualiser.controllers.LobbyController;
|
||||
import seng302.visualiser.validators.FieldLengthValidator;
|
||||
import seng302.visualiser.validators.ValidationTools;
|
||||
|
||||
public class BoatCustomizeController implements Initializable{
|
||||
|
||||
//--------FXML BEGIN--------//
|
||||
@FXML
|
||||
private JFXColorPicker colorPicker;
|
||||
|
||||
@FXML
|
||||
private JFXButton submitBtn;
|
||||
|
||||
@FXML
|
||||
private JFXTextField boatName;
|
||||
private ClientToServerThread socketThread;
|
||||
private LobbyController lobbyController;
|
||||
|
||||
|
||||
public BoatCustomizeController(){
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
void colorChanged(ActionEvent event) {
|
||||
Color color = colorPicker.getValue();
|
||||
}
|
||||
//---------FXML END---------//
|
||||
|
||||
private ClientToServerThread socketThread;
|
||||
private LobbyController lobbyController;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
colorPicker.setValue(Color.BISQUE);
|
||||
submitBtn.setOnMouseReleased(event -> {
|
||||
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();
|
||||
short red = (short) (color.getRed() * 255);
|
||||
short green = (short) (color.getGreen() * 255);
|
||||
short blue = (short) (color.getBlue() * 255);
|
||||
if (ValidationTools.validateTextField(boatName)) {
|
||||
socketThread
|
||||
.sendCustomizationRequest(CustomizeRequestType.NAME, boatName.getText().getBytes());
|
||||
|
||||
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;
|
||||
colorArray[1] = (byte) green;
|
||||
colorArray[2] = (byte) blue;
|
||||
byte[] colorArray = new byte[3];
|
||||
|
||||
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
|
||||
lobbyController.closeCustomizationDialog();
|
||||
colorArray[0] = (byte) red;
|
||||
colorArray[1] = (byte) green;
|
||||
colorArray[2] = (byte) blue;
|
||||
|
||||
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
|
||||
lobbyController.closeCustomizationDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerName(String name) {
|
||||
|
||||
+23
-14
@@ -13,6 +13,7 @@ import seng302.visualiser.validators.FieldLengthValidator;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import seng302.visualiser.validators.ValidationTools;
|
||||
|
||||
public class ServerCreationController implements Initializable {
|
||||
|
||||
@@ -27,34 +28,39 @@ public class ServerCreationController implements Initializable {
|
||||
private JFXButton submitBtn;
|
||||
//---------FXML END---------//
|
||||
|
||||
FieldLengthValidator fieldLengthValidator;
|
||||
RequiredFieldValidator fieldRequiredValidator;
|
||||
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
updateMaxPlayerLabel();
|
||||
maxPlayersSlider.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||
updateMaxPlayerLabel();
|
||||
});
|
||||
|
||||
fieldLengthValidator = new FieldLengthValidator(40);
|
||||
fieldLengthValidator.setMessage("Server Name Too Long");
|
||||
fieldRequiredValidator = new RequiredFieldValidator();
|
||||
fieldRequiredValidator.setMessage("Server Name is Required.");
|
||||
FieldLengthValidator fieldLengthValidator = new FieldLengthValidator(40);
|
||||
fieldLengthValidator.setMessage("Server name too long.");
|
||||
|
||||
RequiredFieldValidator fieldRequiredValidator = new RequiredFieldValidator();
|
||||
fieldRequiredValidator.setMessage("Server name is required.");
|
||||
|
||||
serverName.setValidators(fieldLengthValidator, fieldRequiredValidator);
|
||||
|
||||
submitBtn.setOnMouseClicked(event -> submitBtn.setText("CREATING..."));
|
||||
submitBtn.setOnMouseReleased(event -> validateServerSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void validateServerSettings() {
|
||||
serverName.validate();
|
||||
System.out.println(serverName.getActiveValidator());
|
||||
createServer();
|
||||
submitBtn.setText("CREATING...");
|
||||
if (ValidationTools.validateTextField(serverName)) {
|
||||
createServer();
|
||||
} else {
|
||||
submitBtn.setText("SUBMIT");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createServer() {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void createServer() {
|
||||
ServerDescription serverDescription = ViewManager.getInstance().getGameClient()
|
||||
.runAsHost("localhost", 4941, serverName.getText(), (int) maxPlayersSlider
|
||||
.getValue());
|
||||
@@ -63,6 +69,9 @@ public class ServerCreationController implements Initializable {
|
||||
ViewManager.getInstance().setProperty("mapName", serverDescription.getMapName());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void updateMaxPlayerLabel() {
|
||||
maxPlayersSlider.setValue(Math.floor(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