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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user