[WIP] Adding player position, boat speed, boat heading

#story[1245]
This commit is contained in:
Zhi You Tan
2017-09-12 18:25:46 +12:00
parent b25c3367a9
commit f0fc75feec
5 changed files with 96 additions and 15 deletions
+1 -1
View File
@@ -253,7 +253,7 @@ public class ClientYacht extends Observable {
public void updateLocation(double lat, double lng, double heading, double velocity) { public void updateLocation(double lat, double lng, double heading, double velocity) {
setLocation(lat, lng); setLocation(lat, lng);
this.heading = heading; this.heading = heading;
// this.currentVelocity = velocity; this.currentVelocity = velocity;
updateVelocityProperty(velocity); updateVelocityProperty(velocity);
for (YachtLocationListener yll : locationListeners) { for (YachtLocationListener yll : locationListeners) {
yll.notifyLocation(this, lat, lng, heading, sailIn, velocity); yll.notifyLocation(this, lat, lng, heading, sailIn, velocity);
@@ -150,7 +150,7 @@ public class GameView3D {
System.out.println(camera.getTranslateY()); System.out.println(camera.getTranslateY());
System.out.println(camera.getTranslateZ()); System.out.println(camera.getTranslateZ());
camera.setTranslateZ(-80); camera.setTranslateZ(-80);
camera.setTranslateY(150); camera.setTranslateY(170);
Sphere red = new Sphere(1); Sphere red = new Sphere(1);
red.setMaterial(new PhongMaterial(Color.RED)); red.setMaterial(new PhongMaterial(Color.RED));
red.setLayoutX(0); red.setLayoutX(0);
@@ -103,6 +103,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private Label windDirectionLabel; private Label windDirectionLabel;
@FXML @FXML
private Label windSpeedLabel; private Label windSpeedLabel;
@FXML
private Label positionLabel, boatSpeedLabel, boatHeadingLabel;
//Race Data //Race Data
private Map<Integer, ClientYacht> participants; private Map<Integer, ClientYacht> participants;
@@ -119,6 +121,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private ImportantAnnotationsState importantAnnotations; private ImportantAnnotationsState importantAnnotations;
private Polyline windArrow = new WindArrow(Color.LIGHTGRAY); private Polyline windArrow = new WindArrow(Color.LIGHTGRAY);
private ObservableList<ClientYacht> selectionComboBoxList = FXCollections.observableArrayList(); private ObservableList<ClientYacht> selectionComboBoxList = FXCollections.observableArrayList();
private ClientYacht player;
public void initialize() { public void initialize() {
Sounds.stopMusic(); Sounds.stopMusic();
@@ -181,6 +184,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
this.courseData = raceData; this.courseData = raceData;
this.markers = raceData.getCompoundMarks(); this.markers = raceData.getCompoundMarks();
this.raceState = raceState; this.raceState = raceState;
this.player = player;
raceState.getPlayerPositions().addListener((ListChangeListener<ClientYacht>) c -> { raceState.getPlayerPositions().addListener((ListChangeListener<ClientYacht>) c -> {
while (c.next()) { while (c.next()) {
@@ -434,6 +438,9 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
@Override @Override
public void run() { public void run() {
Platform.runLater(() -> updatePosition());
Platform.runLater(() -> updateBoatSpeed());
Platform.runLater(() -> updateBoatHeading());
Platform.runLater(() -> updateRaceTime()); Platform.runLater(() -> updateRaceTime());
} }
}, 0, 1000); }, 0, 1000);
@@ -497,6 +504,43 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
} }
} }
private void updatePosition() {
if (player.getPosition() == null) {
positionLabel.setText("Position:\n0");
} else {
switch (player.getPosition()) {
case 1:
positionLabel.setText("Position:\n1st");
break;
case 2:
positionLabel.setText("Position:\n2nd");
break;
case 3:
positionLabel.setText("Position:\n3rd");
break;
case 21:
positionLabel.setText("Position:\n21st");
break;
case 22:
positionLabel.setText("Position:\n22nd");
break;
case 23:
positionLabel.setText("Position:\n23rd");
break;
default:
positionLabel.setText("Position:\n" + player.getPosition() + "th");
}
}
}
private void updateBoatSpeed() {
boatSpeedLabel.setText("Boat Speed:\n" + String.valueOf(player.getVelocityProperty().toString()));
}
private void updateBoatHeading() {
boatHeadingLabel.setText("Boat Heading:\n" + String.valueOf(player.getHeading()));
}
/** /**
* Updates the order of the yachts as from the StreamParser and sets them in the yacht order * Updates the order of the yachts as from the StreamParser and sets them in the yacht order
* section * section
+8
View File
@@ -26,6 +26,14 @@
} }
#windGridPane {
-fx-background-color: rgba(255, 255, 255, 0.6);
}
#windHolder {
}
#chatSend { #chatSend {
-fx-background-color: -fx-pp-front-color; -fx-background-color: -fx-pp-front-color;
-fx-text-fill: -fx-pp-theme-color; -fx-text-fill: -fx-pp-theme-color;
+42 -13
View File
@@ -104,32 +104,61 @@
</JFXTextField> </JFXTextField>
</children> </children>
</GridPane> </GridPane>
<GridPane GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM"> <GridPane fx:id="windGridPane" prefHeight="161.0" prefWidth="240.0" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="110.0" minWidth="110.0" prefWidth="110.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="110.0" minWidth="110.0" prefWidth="110.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="132.0" minWidth="10.0" prefWidth="132.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="132.0" minWidth="10.0" prefWidth="132.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="100.0" minHeight="100.0" prefHeight="100.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="120.0" minHeight="120.0" prefHeight="120.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="90.0" minHeight="90.0" prefHeight="90.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<ImageView fx:id="windImageView" fitHeight="92.0" fitWidth="109.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" /> <Label fx:id="positionLabel" text="Position:" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2" GridPane.valignment="TOP">
<Label fx:id="windDirectionLabel" text="180.0°" GridPane.halignment="LEFT" GridPane.rowIndex="2" GridPane.valignment="CENTER"> <padding>
<GridPane.margin> <Insets bottom="5.0" left="10.0" right="5.0" top="5.0" />
<Insets left="5.0" /> </padding>
</GridPane.margin></Label> </Label>
<Label fx:id="windSpeedLabel" text="0.0 Knots" GridPane.halignment="RIGHT" GridPane.rowIndex="2" GridPane.valignment="CENTER"> <Label fx:id="boatSpeedLabel" text="Boat Speed:" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2" GridPane.valignment="CENTER">
<GridPane.margin> <opaqueInsets>
<Insets right="5.0" /> <Insets />
</GridPane.margin></Label> </opaqueInsets>
<padding>
<Insets bottom="5.0" left="10.0" right="5.0" top="5.0" />
</padding></Label>
<Label fx:id="boatHeadingLabel" text="Boat Heading:" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2" GridPane.valignment="BOTTOM">
<padding>
<Insets bottom="5.0" left="10.0" right="5.0" top="5.0" />
</padding>
</Label>
<GridPane fx:id="windHolder" GridPane.rowSpan="2">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="120.0" minHeight="120.0" prefHeight="120.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<ImageView fx:id="windImageView" fitHeight="92.0" fitWidth="109.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="CENTER" GridPane.rowSpan="2" GridPane.valignment="CENTER" />
<Label fx:id="windSpeedLabel" text="0.0 Knots" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<GridPane.margin>
<Insets right="5.0" />
</GridPane.margin>
</Label>
<Label fx:id="windDirectionLabel" text="180.0°" GridPane.halignment="LEFT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<GridPane.margin>
<Insets left="5.0" />
</GridPane.margin>
</Label>
</children>
</GridPane>
</children> </children>
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
<GridPane.margin> <GridPane.margin>
<Insets bottom="10.0" left="10.0" /> <Insets bottom="10.0" left="10.0" top="40.0" />
</GridPane.margin> </GridPane.margin>
</GridPane> </GridPane>
</children> </children>