Merge branch 'story_speedometer' into 'master'

Story speedometer

AC's:
-Current speed of boat is displayed on the race UI
-Current placing of boat is displayed

See merge request !62
main
Connor Taylor Brown 8 years ago
commit 666e9d0ad9

@ -29,6 +29,12 @@
<version>2.9.0</version> <version>2.9.0</version>
</dependency> </dependency>
<dependency>
<groupId>eu.hansolo</groupId>
<artifactId>Medusa</artifactId>
<version>7.9</version>
</dependency>
<!-- Maven Dependencies block START--> <!-- Maven Dependencies block START-->
<dependency> <dependency>
<groupId>net.bytebuddy</groupId> <groupId>net.bytebuddy</groupId>

@ -1,6 +1,9 @@
package visualiser.Controllers; package visualiser.Controllers;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter; import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import eu.hansolo.medusa.*;
import eu.hansolo.medusa.events.UpdateEvent;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@ -20,6 +23,7 @@ import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Material; import javafx.scene.paint.Material;
import javafx.scene.paint.PhongMaterial; import javafx.scene.paint.PhongMaterial;
import javafx.scene.paint.Stop;
import javafx.scene.shape.MeshView; import javafx.scene.shape.MeshView;
import javafx.scene.shape.Shape3D; import javafx.scene.shape.Shape3D;
import javafx.scene.transform.Translate; import javafx.scene.transform.Translate;
@ -39,10 +43,7 @@ import visualiser.utils.GPSConverter;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -63,6 +64,10 @@ public class RaceViewController extends Controller {
private View3D view3D; private View3D view3D;
private WindCompass windCompass; private WindCompass windCompass;
private ObservableList<Subject3D> viewSubjects; private ObservableList<Subject3D> viewSubjects;
private Gauge gauge;
private FGauge fGauge;
private long positionDelay = 1000;
private long positionTime = 0;
private ResizableRaceCanvas raceCanvas; private ResizableRaceCanvas raceCanvas;
private boolean mapToggle = true; private boolean mapToggle = true;
@ -94,6 +99,8 @@ public class RaceViewController extends Controller {
private @FXML Label tutorialText; private @FXML Label tutorialText;
private @FXML AnchorPane infoWrapper; private @FXML AnchorPane infoWrapper;
private @FXML AnchorPane lineChartWrapper; private @FXML AnchorPane lineChartWrapper;
private @FXML StackPane speedPane;
private @FXML AnchorPane raceAnchorPane;
/** /**
* Displays a specified race. * Displays a specified race.
@ -205,6 +212,78 @@ public class RaceViewController extends Controller {
}); });
} }
/**
* Create speedometer
*/
private void initialiseSpeedometer() {
//Create the Medusa Gauge
gauge = GaugeBuilder.create()
.prefSize(200,200)
.foregroundBaseColor(Color.WHITE)
.title("Title")
.subTitle("Speed")
.unit("Knots")
.decimals(2)
.lcdVisible(true)
.lcdDesign(LcdDesign.STANDARD)
.lcdFont(LcdFont.DIGITAL_BOLD)
.scaleDirection(Gauge.ScaleDirection.CLOCKWISE)
.minValue(0)
.maxValue(50)
.startAngle(320)
.angleRange(280)
.tickLabelDecimals(0)
.tickLabelLocation(TickLabelLocation.INSIDE)
.tickLabelOrientation(TickLabelOrientation.ORTHOGONAL)
.onlyFirstAndLastTickLabelVisible(false)
.tickLabelSectionsVisible(false)
.tickLabelColor(Color.BLACK)
.tickMarkSectionsVisible(false)
.majorTickMarksVisible(true)
.majorTickMarkType(TickMarkType.TRAPEZOID)
.mediumTickMarksVisible(false)
.mediumTickMarkType(TickMarkType.LINE)
.minorTickMarksVisible(true)
.minorTickMarkType(TickMarkType.LINE)
.ledVisible(false)
.ledType(Gauge.LedType.STANDARD)
.ledColor(Color.rgb(255, 200, 0))
.ledBlinking(false)
.needleShape(Gauge.NeedleShape.ANGLED)
.needleSize(Gauge.NeedleSize.STANDARD)
.needleColor(Color.CRIMSON)
.startFromZero(false)
.returnToZero(false)
.knobType(Gauge.KnobType.METAL)
.knobColor(Color.LIGHTGRAY)
.interactive(false)
.thresholdVisible(true)
.threshold(50)
.thresholdColor(Color.RED)
.checkThreshold(true)
.gradientBarEnabled(true)
.gradientBarStops(new Stop(0.0, Color.BLUE),
new Stop(0.25, Color.CYAN),
new Stop(0.5, Color.LIME),
new Stop(0.75, Color.YELLOW),
new Stop(1.0, Color.RED))
.markersVisible(true)
.build();
//Create a gauge with a frame and background that utilizes a Medusa gauge
fGauge = FGaugeBuilder
.create()
.prefSize(200, 200)
.gauge(gauge)
.gaugeDesign(GaugeDesign.METAL)
.gaugeBackground(GaugeDesign.GaugeBackground.CARBON)
.foregroundVisible(true)
.build();
speedPane.getChildren().add(fGauge);
}
/** /**
* Initialises the various UI components to listen to the {@link #visualiserRace}. * Initialises the various UI components to listen to the {@link #visualiserRace}.
*/ */
@ -227,7 +306,9 @@ public class RaceViewController extends Controller {
initialiseInfoTable(); initialiseInfoTable();
initialiseView3D(this.visualiserRace); initialiseView3D(this.visualiserRace);
initialiseRaceClock(); initialiseRaceClock();
initialiseSpeedometer();
raceTimer(); // start the timer raceTimer(); // start the timer
speedometerLoop();
new Sparkline(this.raceState, this.sparklineChart); new Sparkline(this.raceState, this.sparklineChart);
timeZone.setText(this.raceState.getRaceClock().getTimeZone()); timeZone.setText(this.raceState.getRaceClock().getTimeZone());
arrowController.setWindProperty(this.raceState.windProperty()); arrowController.setWindProperty(this.raceState.windProperty());
@ -324,11 +405,12 @@ public class RaceViewController extends Controller {
// Position and add each boat to view // Position and add each boat to view
for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) { for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) {
/*if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) { // MeshView mesh;
mesh = new MeshView(importer.getImport()); // if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
} else { // mesh = new MeshView(importer.getImport());
mesh = new MeshView(importerBurgerBoat.getImport()); // } else {
}*/ // mesh = new MeshView(importerBurgerBoat.getImport());
// }
Shape3D mesh = Assets3D.getBoat(); Shape3D mesh = Assets3D.getBoat();
PhongMaterial boatColorMat = new PhongMaterial(boat.getColor()); PhongMaterial boatColorMat = new PhongMaterial(boat.getColor());
@ -727,6 +809,39 @@ public class RaceViewController extends Controller {
}.start(); }.start();
} }
/**
* Animation timer loop for the speedometer
*/
private void speedometerLoop(){
new AnimationTimer(){
@Override
public void handle(long arg0){
if (raceState.getRaceStatusEnum() == RaceStatusEnum.FINISHED) {
stop(); // stop the timer
} else {
try {
//Set the current speed value of the boat
gauge.setValue(raceState.getBoat(raceState.getPlayerBoatID()).getCurrentSpeed());
fGauge.getGauge().setValue(raceState.getBoat(raceState.getPlayerBoatID()).getCurrentSpeed());
//Create list with sorted boat placements
List<VisualiserBoat> boatList = boatInfoTable.getItems();
for (VisualiserBoat boat : boatList){
if(raceState.getPlayerBoatID()==boat.getSourceID()){
//Set boat current placement value as title of speedometer
gauge.titleProperty().setValue("Position: " + (boatInfoTable.getItems().indexOf(boat)+1));
fGauge.getGauge().titleProperty().setValue("Position: " + (boatInfoTable.getItems().indexOf(boat)+1));
}
}
} catch (BoatNotFoundException e) {
e.printStackTrace();
}
}
}
}.start();
}
/** /**
* toggles if the info table is shown * toggles if the info table is shown
*/ */

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.chart.LineChart?> <?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?> <?import javafx.scene.chart.NumberAxis?>
@ -22,11 +28,11 @@
<?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<SplitPane fx:id="racePane" prefHeight="431.0" prefWidth="610.0" visible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceViewController"> <SplitPane fx:id="racePane" prefHeight="431.0" prefWidth="610.0" visible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceViewController">
<items> <items>
<StackPane fx:id="newPane" prefHeight="150.0" prefWidth="200.0"> <StackPane fx:id="newPane" prefHeight="150.0" prefWidth="200.0">
<children> <children>
<AnchorPane focusTraversable="true"> <AnchorPane fx:id="raceAnchorPane" focusTraversable="true">
<children> <children>
<GridPane fx:id="canvasBase" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="canvasBase" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>
@ -103,6 +109,10 @@
</children> </children>
</StackPane> </StackPane>
<Label fx:id="tutorialText" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" style="-fx-border-color: orange; -fx-border-radius: 5px; -fx-background-color: #ffffcc; -fx-text-fill: #3399ff; -fx-border-width: 3; -fx-border-insets: -3;" text="This is the tutorial text" visible="false" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="150.0" AnchorPane.topAnchor="100.0" /> <Label fx:id="tutorialText" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" style="-fx-border-color: orange; -fx-border-radius: 5px; -fx-background-color: #ffffcc; -fx-text-fill: #3399ff; -fx-border-width: 3; -fx-border-insets: -3;" text="This is the tutorial text" visible="false" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="150.0" AnchorPane.topAnchor="100.0" />
<StackPane fx:id="speedPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="20.0">
<padding>
<Insets right="20.0" />
</padding></StackPane>
<AnchorPane maxHeight="200.0" maxWidth="200.0" mouseTransparent="true" opacity="0.6" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"> <AnchorPane maxHeight="200.0" maxWidth="200.0" mouseTransparent="true" opacity="0.6" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0">
<children> <children>
<AnchorPane maxHeight="200.0" maxWidth="200.0" prefHeight="200.0" prefWidth="216.0"> <AnchorPane maxHeight="200.0" maxWidth="200.0" prefHeight="200.0" prefWidth="216.0">

@ -28,11 +28,7 @@
<?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<SplitPane fx:id="racePane" dividerPositions="1.0" prefHeight="431.0" <SplitPane fx:id="racePane" dividerPositions="1.0" prefHeight="431.0" prefWidth="610.0" visible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceViewController">
prefWidth="610.0" visible="true" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8.0.65"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceViewController">
<items> <items>
<StackPane fx:id="newPane" prefHeight="150.0" prefWidth="200.0"> <StackPane fx:id="newPane" prefHeight="150.0" prefWidth="200.0">
<children> <children>
@ -89,17 +85,27 @@
</Accordion> </Accordion>
</children> </children>
</Pane> </Pane>
<Label fx:id="timer" maxHeight="20.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0"> <StackPane fx:id="arrowPane" alignment="TOP_RIGHT" mouseTransparent="true" prefHeight="150.0" prefWidth="150.0" snapToPixel="false" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<fx:include fx:id="arrow" source="arrow.fxml" />
</children>
</StackPane>
<Label fx:id="tutorialText" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" style="-fx-border-color: orange; -fx-border-radius: 5px; -fx-background-color: #ffffcc; -fx-text-fill: #3399ff; -fx-border-width: 3; -fx-border-insets: -3;" text="This is the tutorial text" visible="false" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="150.0" AnchorPane.topAnchor="100.0" />
<StackPane fx:id="speedPane" prefHeight="150.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<Label text="HELLO!" />
</children></StackPane>
<Label fx:id="timer" alignment="CENTER" maxHeight="20.0" text="0:0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<font> <font>
<Font name="System Bold" size="15.0" /> <Font name="System Bold" size="15.0" />
</font> </font>
</Label> </Label>
<Label fx:id="FPS" text="FPS: 0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"> <Label fx:id="FPS" text="FPS: 000" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<font> <font>
<Font name="System Bold" size="15.0" /> <Font name="System Bold" size="15.0" />
</font> </font>
</Label> </Label>
<Label fx:id="timeZone" text="Label" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0"> <Label fx:id="timeZone" layoutX="8.0" layoutY="-6.0" text="Label" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<font> <font>
<Font name="System Bold" size="15.0" /> <Font name="System Bold" size="15.0" />
</font> </font>
@ -107,12 +113,6 @@
<Insets bottom="20.0" /> <Insets bottom="20.0" />
</padding> </padding>
</Label> </Label>
<StackPane fx:id="arrowPane" alignment="TOP_RIGHT" mouseTransparent="true" prefHeight="150.0" prefWidth="150.0" snapToPixel="false" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<fx:include fx:id="arrow" source="arrow.fxml" />
</children>
</StackPane>
<Label fx:id="tutorialText" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" style="-fx-border-color: orange; -fx-border-radius: 5px; -fx-background-color: #ffffcc; -fx-text-fill: #3399ff; -fx-border-width: 3; -fx-border-insets: -3;" text="This is the tutorial text" visible="false" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="150.0" AnchorPane.topAnchor="100.0" />
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?> <?import javafx.scene.control.RadioButton?>
@ -13,7 +18,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<AnchorPane fx:id="titleWrapper" maxHeight="600.0" maxWidth="800.0" minHeight="600.0" minWidth="800.0" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController"> <AnchorPane fx:id="titleWrapper" maxHeight="600.0" maxWidth="800.0" minHeight="600.0" minWidth="800.0" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController">
<children> <children>
<GridPane layoutY="39.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane layoutY="39.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

Loading…
Cancel
Save