Review fixes for merge request.

PlayerCell now takes in the yacht for construction rather than taking in a whole lot of values extracted from the yacht

Reduced boiler plate in BoatCustomizeController

#story[1274]
This commit is contained in:
William Muir
2017-09-22 20:44:06 +12:00
parent c4a6113f6c
commit da8c91f5c1
4 changed files with 24 additions and 30 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ import java.util.Observer;
*/ */
public class ServerYacht { public class ServerYacht {
private Logger logger = LoggerFactory.getLogger(ClientYacht.class); private Logger logger = LoggerFactory.getLogger(ServerYacht.class);
public static final Double TURN_STEP = 5.0; public static final Double TURN_STEP = 5.0;
@@ -205,7 +205,7 @@ public class LobbyController implements Initializable {
FXMLLoader loader = new FXMLLoader( FXMLLoader loader = new FXMLLoader(
getClass().getResource("/views/cells/PlayerCell.fxml")); getClass().getResource("/views/cells/PlayerCell.fxml"));
loader.setController(new PlayerCell(playerId, yacht.getBoatName(), yacht.getColour(), yacht.getBoatType())); loader.setController(new PlayerCell(playerId, yacht));
try { try {
pane = loader.load(); pane = loader.load();
@@ -6,6 +6,7 @@ import javafx.scene.control.Label;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import seng302.model.ClientYacht;
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType; import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
import seng302.visualiser.fxObjects.assets_3D.BoatModel; import seng302.visualiser.fxObjects.assets_3D.BoatModel;
import seng302.visualiser.fxObjects.assets_3D.ModelFactory; import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
@@ -24,13 +25,13 @@ public class PlayerCell {
private String name; private String name;
private Color boatColor; private Color boatColor;
private Integer playerId; private Integer playerId;
private BoatMeshType boatype; private BoatMeshType boatType;
public PlayerCell(Integer playerId, String playerName, Color color, String boatType) { public PlayerCell(Integer playerId, ClientYacht yacht) {
this.playerId = playerId; this.playerId = playerId;
this.name = playerName; this.name = yacht.getBoatName();
this.boatColor = color; this.boatColor = yacht.getColour();
this.boatype = BoatMeshType.getBoatMeshType(boatType); this.boatType = BoatMeshType.getBoatMeshType(yacht.getBoatType());
} }
public void initialize() { public void initialize() {
@@ -39,7 +40,7 @@ public class PlayerCell {
// Add Rotating Boat to Player Cell with players color on it. // Add Rotating Boat to Player Cell with players color on it.
Group group = new Group(); Group group = new Group();
boatPane.getChildren().add(group); boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatIconView(this.boatype, this.boatColor); BoatModel bo = ModelFactory.boatIconView(boatType, boatColor);
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
} }
@@ -6,7 +6,6 @@ import com.jfoenix.controls.JFXTextField;
import com.jfoenix.validation.RequiredFieldValidator; import com.jfoenix.validation.RequiredFieldValidator;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Insets; import javafx.geometry.Insets;
@@ -40,9 +39,8 @@ public class BoatCustomizeController implements Initializable{
@FXML @FXML
private Pane boatPane; private Pane boatPane;
@FXML @FXML
void colorChanged(ActionEvent event) { void colorChanged() {
Color color = colorPicker.getValue(); refreshBoat();
RefreshBoat();
} }
//---------FXML END---------// //---------FXML END---------//
@@ -62,6 +60,8 @@ public class BoatCustomizeController implements Initializable{
playerNameLengthValidator.setMessage("Player name too long."); playerNameLengthValidator.setMessage("Player name too long.");
boatName.setValidators(playerNameLengthValidator, playerNameReqValidator); boatName.setValidators(playerNameLengthValidator, playerNameReqValidator);
boatPane.setBackground(
new Background(new BackgroundFill(Color.SKYBLUE, CornerRadii.EMPTY, Insets.EMPTY)));
submitBtn.setOnMouseReleased(event -> { submitBtn.setOnMouseReleased(event -> {
Sounds.playButtonClick(); Sounds.playButtonClick();
@@ -69,7 +69,6 @@ public class BoatCustomizeController implements Initializable{
}); });
submitBtn.setOnMouseEntered(e -> Sounds.playHoverSound()); submitBtn.setOnMouseEntered(e -> Sounds.playHoverSound());
} }
/** /**
@@ -113,36 +112,30 @@ public class BoatCustomizeController implements Initializable{
} }
public void setCurrentBoat(String boatType) { public void setCurrentBoat(String boatType) {
Group group = new Group(); currentBoat = BoatMeshType.getBoatMeshType(boatType);
this.currentBoat = BoatMeshType.getBoatMeshType(boatType); displayCurrentBoat();
boatPane.setBackground(new Background(new BackgroundFill(Color.SKYBLUE, CornerRadii.EMPTY, Insets.EMPTY)));
boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight());
} }
public void nextBoat(ActionEvent actionEvent) { public void nextBoat() {
boatPane.getChildren().clear();
Group group = new Group();
boatPane.getChildren().add(group);
currentBoat = BoatMeshType.getNextBoatType(currentBoat); currentBoat = BoatMeshType.getNextBoatType(currentBoat);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); displayCurrentBoat();
group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight());
} }
public void prevBoat(ActionEvent actionEvent) { public void prevBoat() {
boatPane.getChildren().clear();
Group group = new Group();
boatPane.getChildren().add(group);
currentBoat = BoatMeshType.getPrevBoatType(currentBoat); currentBoat = BoatMeshType.getPrevBoatType(currentBoat);
displayCurrentBoat();
}
private void displayCurrentBoat() {
boatPane.getChildren().clear();
Group group = new Group();
boatPane.getChildren().add(group);
BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue()); BoatModel bo = ModelFactory.boatCustomiseView(currentBoat, colorPicker.getValue());
group.getChildren().add(bo.getAssets()); group.getChildren().add(bo.getAssets());
group.getChildren().add(new PointLight()); group.getChildren().add(new PointLight());
} }
private void RefreshBoat() { private void refreshBoat() {
boatPane.getChildren().clear(); boatPane.getChildren().clear();
Group group = new Group(); Group group = new Group();
boatPane.getChildren().add(group); boatPane.getChildren().add(group);