Merge remote-tracking branch 'origin/raceView_UI' into nightmode
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
package visualiser.Commands.VisualiserRaceCommands;
|
||||
|
||||
import mock.model.commandFactory.Command;
|
||||
import network.Messages.BoatState;
|
||||
import shared.exceptions.BoatNotFoundException;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
|
||||
/**
|
||||
* Updates boats on visualiser when their health changes
|
||||
*/
|
||||
public class BoatStateCommand implements Command {
|
||||
private BoatState boatState;
|
||||
private VisualiserRaceState visualiserRace;
|
||||
|
||||
public BoatStateCommand(BoatState boatState, VisualiserRaceState visualiserRace) {
|
||||
this.boatState = boatState;
|
||||
this.visualiserRace = visualiserRace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
VisualiserBoat boat = visualiserRace.getBoat(boatState.getSourceID());
|
||||
boat.setHealth(boatState.getBoatHealth());
|
||||
} catch (BoatNotFoundException e) {
|
||||
// Fail silently
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,6 @@ public class VisualiserRaceCommandFactory {
|
||||
switch (message.getType()) {
|
||||
|
||||
case BOATLOCATION:
|
||||
//System.out.println("Boat location received");
|
||||
return new BoatLocationCommand((BoatLocation) message, visualiserRace);
|
||||
|
||||
case RACESTATUS: return new RaceStatusCommand((RaceStatus) message, visualiserRace);
|
||||
@@ -36,7 +35,8 @@ public class VisualiserRaceCommandFactory {
|
||||
case YACHTEVENTCODE:
|
||||
return new BoatCollisionCommand((YachtEvent) message, visualiserRace);
|
||||
|
||||
|
||||
case BOATSTATE:
|
||||
return new BoatStateCommand((BoatState) message, visualiserRace);
|
||||
|
||||
default: throw new CommandConstructionException("Could not create VisualiserRaceCommand. Unrecognised or unsupported MessageType: " + message.getType());
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@ import javafx.scene.AmbientLight;
|
||||
import javafx.scene.PointLight;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.media.AudioClip;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Material;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
@@ -28,6 +31,7 @@ import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.transform.Translate;
|
||||
import javafx.util.Callback;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import shared.dataInput.RaceDataSource;
|
||||
import shared.exceptions.BoatNotFoundException;
|
||||
@@ -42,6 +46,7 @@ import visualiser.model.*;
|
||||
import visualiser.utils.GPSConverter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
@@ -70,6 +75,9 @@ public class RaceViewController extends Controller {
|
||||
private long positionTime = 0;
|
||||
private ResizableRaceCanvas raceCanvas;
|
||||
private boolean mapToggle = true;
|
||||
private GPSConverter gpsConverter;
|
||||
private ArrayList<HealthEffect> healthEffectList = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Arrow pointing to next mark in third person
|
||||
@@ -98,12 +106,17 @@ public class RaceViewController extends Controller {
|
||||
private @FXML TableColumn<VisualiserBoat, String> boatTeamColumn;
|
||||
private @FXML TableColumn<VisualiserBoat, Leg> boatMarkColumn;
|
||||
private @FXML TableColumn<VisualiserBoat, Number> boatSpeedColumn;
|
||||
private @FXML TableColumn<VisualiserBoat, Number> boatHealthColumn;
|
||||
private @FXML LineChart<Number, Number> sparklineChart;
|
||||
private @FXML Label tutorialText;
|
||||
private @FXML AnchorPane infoWrapper;
|
||||
private @FXML AnchorPane lineChartWrapper;
|
||||
private @FXML StackPane speedPane;
|
||||
private @FXML AnchorPane raceAnchorPane;
|
||||
private @FXML GridPane playerHealthContainer;
|
||||
private @FXML ImageView imageView;
|
||||
private @FXML AnchorPane deathTransPane;
|
||||
private @FXML StackPane deathPane;
|
||||
|
||||
/**
|
||||
* Displays a specified race.
|
||||
@@ -118,10 +131,13 @@ public class RaceViewController extends Controller {
|
||||
this.controllerClient = controllerClient;
|
||||
this.isHost = isHost;
|
||||
keyFactory.load();
|
||||
|
||||
deathPane.setDisable(false);
|
||||
deathPane.setVisible(false);
|
||||
tutorialCheck();
|
||||
initKeypressHandler();
|
||||
healthLoop();
|
||||
initialiseRaceVisuals();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +149,6 @@ public class RaceViewController extends Controller {
|
||||
isTutorial = true;
|
||||
tutorialText.setVisible(true);
|
||||
tutorialStates = new ArrayList<>(Arrays.asList(TutorialState.values()));
|
||||
|
||||
currentState = tutorialStates.get(0);
|
||||
tutorialStates.remove(0);
|
||||
searchMapForKey("Upwind");
|
||||
@@ -294,6 +309,7 @@ public class RaceViewController extends Controller {
|
||||
initialiseFps();
|
||||
initialiseInfoTable();
|
||||
initialiseView3D(this.visualiserRace);
|
||||
initialiseHealthPane();
|
||||
initialiseRaceClock();
|
||||
initialiseSpeedometer();
|
||||
initialiseRaceCanvas();
|
||||
@@ -301,8 +317,23 @@ public class RaceViewController extends Controller {
|
||||
//nextMarkPane.toFront();
|
||||
speedometerLoop();
|
||||
new Sparkline(this.raceState, this.sparklineChart);
|
||||
timeZone.setText(this.raceState.getRaceClock().getTimeZone());
|
||||
arrowController.setWindProperty(this.raceState.windProperty());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initialiseHealthPane() {
|
||||
InputStream tomato = this.getClass().getClassLoader().getResourceAsStream("visualiser/images/tomato.png");
|
||||
HealthSlider healthSlider = new HealthSlider(new Image(tomato));
|
||||
playerHealthContainer.add(healthSlider, 0, 0);
|
||||
|
||||
try {
|
||||
VisualiserBoat player = raceState.getBoat(raceState.getPlayerBoatID());
|
||||
player.healthProperty().addListener((o, prev, curr) -> {
|
||||
healthSlider.setCrop((double)curr/100.0);
|
||||
});
|
||||
} catch (BoatNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initialiseView3D(VisualiserRaceEvent race) {
|
||||
@@ -357,7 +388,7 @@ public class RaceViewController extends Controller {
|
||||
|
||||
// Set up projection from GPS to view
|
||||
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
||||
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);
|
||||
gpsConverter = new GPSConverter(raceData, 450, 450);
|
||||
|
||||
SkyBox skyBox = new SkyBox(750, 200, 250, 0, 210);
|
||||
viewSubjects.addAll(skyBox.getSkyBoxPlanes());
|
||||
@@ -438,6 +469,11 @@ public class RaceViewController extends Controller {
|
||||
viewSubjects.add(boatModel);
|
||||
}
|
||||
|
||||
//Create health effect
|
||||
HealthEffect healthEffect = new HealthEffect(boat.getSourceID(), System.currentTimeMillis());
|
||||
viewSubjects.add(healthEffect);
|
||||
healthEffectList.add(healthEffect);
|
||||
|
||||
//add sail
|
||||
Sails3D sails3D = new Sails3D();
|
||||
Subject3D sailsSubject = new Subject3D(sails3D, 0);
|
||||
@@ -518,6 +554,14 @@ public class RaceViewController extends Controller {
|
||||
boatModel.setHeading(boat.getBearing().degrees());
|
||||
boatModel.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
|
||||
boatModel.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||
boatModel.getMesh().toFront();
|
||||
|
||||
//Fire follows boat
|
||||
healthEffect.setHeading(boat.getBearing().degrees());
|
||||
healthEffect.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
|
||||
healthEffect.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||
healthEffect.setY(0);
|
||||
|
||||
}
|
||||
};
|
||||
trackBoat.start();
|
||||
@@ -710,13 +754,17 @@ public class RaceViewController extends Controller {
|
||||
// set table data
|
||||
boatInfoTable.setItems(sortedBoats);
|
||||
boatTeamColumn.setCellValueFactory(
|
||||
cellData -> cellData.getValue().nameProperty());
|
||||
cellData -> cellData.getValue().nameProperty()
|
||||
);
|
||||
boatSpeedColumn.setCellValueFactory(
|
||||
cellData -> cellData.getValue().currentSpeedProperty());
|
||||
cellData -> cellData.getValue().currentSpeedProperty()
|
||||
);
|
||||
boatMarkColumn.setCellValueFactory(
|
||||
cellData -> cellData.getValue().legProperty());
|
||||
boatPlacingColumn.setCellValueFactory(
|
||||
cellData -> cellData.getValue().placingProperty());
|
||||
cellData -> cellData.getValue().legProperty()
|
||||
);
|
||||
boatHealthColumn.setCellValueFactory(
|
||||
cellData -> cellData.getValue().healthProperty()
|
||||
);
|
||||
|
||||
//Kind of ugly, but allows for formatting an observed speed.
|
||||
boatSpeedColumn.setCellFactory(
|
||||
@@ -848,6 +896,64 @@ public class RaceViewController extends Controller {
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Animation timer for health
|
||||
*/
|
||||
private void healthLoop(){
|
||||
new AnimationTimer(){
|
||||
@Override
|
||||
public void handle(long arg0){
|
||||
if (raceState.getRaceStatusEnum() == RaceStatusEnum.FINISHED) {
|
||||
stop(); // stop the timer
|
||||
} else {
|
||||
try {
|
||||
//Check if boat is dead
|
||||
if(raceState.getBoat(raceState.getPlayerBoatID()).getHealth()<=0){
|
||||
if(!deathPane.isDisable()) {
|
||||
deathPane.setVisible(true);
|
||||
}
|
||||
}
|
||||
} catch (BoatNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(VisualiserBoat boat : raceState.getBoats()){
|
||||
for (HealthEffect fp : healthEffectList){
|
||||
|
||||
if(fp.getSourceID()==boat.getSourceID()){
|
||||
if(boat.getHealth()<=0){
|
||||
//Boat is dead. Don't check it anymore for hp
|
||||
fp.displayDeath(fp.getSourceID()==raceState.getPlayerBoatID());
|
||||
fp.setSourceID(0);
|
||||
try {
|
||||
raceState.getBoat(boat.getSourceID()).setStatus(BoatStatusEnum.DNF);
|
||||
|
||||
raceState.updateBoatPositions(raceState.getBoats());
|
||||
} catch (BoatNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
//Speed up tick when <=10 hp
|
||||
if(boat.getHealth()<=10){
|
||||
fp.flash(System.currentTimeMillis(), 300, boat.getSourceID()==raceState.getPlayerBoatID());
|
||||
}
|
||||
else
|
||||
//Visual indication of low hp
|
||||
if(boat.getHealth()<=20) {
|
||||
//fp.setVisible(true);
|
||||
fp.flash(System.currentTimeMillis(), 500, boat.getSourceID()==raceState.getPlayerBoatID());
|
||||
} else {
|
||||
fp.setVisible(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* toggles if the info table is shown
|
||||
@@ -1004,4 +1110,12 @@ public class RaceViewController extends Controller {
|
||||
mapToggle = !mapToggle;
|
||||
}
|
||||
|
||||
/**
|
||||
* FXML method for death button
|
||||
*/
|
||||
public void deathOKPressed(){
|
||||
deathPane.setDisable(true);
|
||||
deathPane.setVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.media.AudioClip;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.*;
|
||||
import javafx.scene.transform.Rotate;
|
||||
|
||||
/**
|
||||
* Created by zwu18 on 24/09/17.
|
||||
*/
|
||||
public class HealthEffect extends Subject3D {
|
||||
|
||||
private int sourceID;
|
||||
private long currentTime;
|
||||
private AudioClip warningSound = new AudioClip(this.getClass().getResource("/visualiser/sounds/warning.mp3").toExternalForm());
|
||||
private AudioClip deadSound = new AudioClip(this.getClass().getResource("/visualiser/sounds/dead1.wav").toExternalForm());
|
||||
|
||||
public HealthEffect(int sourceID, long currentTime){
|
||||
super(createEffect(), 0);
|
||||
this.sourceID = sourceID;
|
||||
this.currentTime = currentTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the mesh view with image
|
||||
* @return Mesh view
|
||||
*/
|
||||
private static Shape3D createEffect(){
|
||||
|
||||
Image image = new Image(HealthEffect.class.getClassLoader().getResourceAsStream("images/warning.png"));
|
||||
|
||||
Plane3D plane = new Plane3D(20, 20, 10, 10);
|
||||
|
||||
PhongMaterial material = new PhongMaterial();
|
||||
material.setDiffuseColor(Color.web("#FFFFFF"));
|
||||
material.setSpecularColor(Color.web("#000000"));
|
||||
material.setDiffuseMap(image);
|
||||
|
||||
MeshView imageSurface = new MeshView(plane);
|
||||
|
||||
|
||||
imageSurface.setMaterial(material);
|
||||
imageSurface.setMouseTransparent(true);
|
||||
//imageSurface.toFront(); this.flashInterval = flashInterval;
|
||||
|
||||
return imageSurface;
|
||||
}
|
||||
|
||||
public void rotateView(Double angle, Double pivotX, Double pivotY, Double pivotZ, Point3D axis){
|
||||
Rotate rotate = new Rotate(angle, axis);
|
||||
rotate.setPivotX(pivotX);
|
||||
rotate.setPivotY(pivotY);
|
||||
rotate.setPivotZ(pivotZ);
|
||||
this.getMesh().getTransforms().add(rotate);
|
||||
}
|
||||
|
||||
public void setVisible(boolean bool){
|
||||
this.getMesh().setVisible(bool);
|
||||
}
|
||||
|
||||
|
||||
public int getSourceID(){
|
||||
return sourceID;
|
||||
}
|
||||
|
||||
public void setSourceID(int id){
|
||||
this.sourceID = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display visual indication when boat dies
|
||||
* @param player boolean if player is current user or not
|
||||
*/
|
||||
public void displayDeath(boolean player){
|
||||
Image image = new Image(HealthEffect.class.getClassLoader().getResourceAsStream("images/warning2.png"));
|
||||
PhongMaterial material = (PhongMaterial) this.getMesh().getMaterial();
|
||||
material.setDiffuseColor(Color.web("#FFFFFF"));
|
||||
material.setSpecularColor(Color.web("#000000"));
|
||||
material.setDiffuseMap(image);
|
||||
this.getMesh().setMaterial(material);
|
||||
if(player) {
|
||||
deadSound.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flash the mesh view at a certain interval
|
||||
* @param checkTime The current time of flash
|
||||
* @param flashInterval Desired flash interval
|
||||
* @param playerBoat Whether or not this effect is for the player's boat.
|
||||
*/
|
||||
public void flash(long checkTime, long flashInterval, boolean playerBoat){
|
||||
if(checkTime >= (currentTime+flashInterval)){
|
||||
this.currentTime = checkTime;
|
||||
if(this.getMesh().isVisible()){
|
||||
this.setVisible(false);
|
||||
} else {
|
||||
if(playerBoat) {
|
||||
warningSound.setVolume(0.1);
|
||||
warningSound.play();
|
||||
}
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.WritableImage;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Created by connortaylorbrown on 21/09/17.
|
||||
*/
|
||||
public class HealthSlider extends Pane {
|
||||
/**
|
||||
* Image used to fill health slider
|
||||
*/
|
||||
private Image fillImage;
|
||||
/**
|
||||
* Size of background for image configuration
|
||||
*/
|
||||
private BackgroundSize backgroundSize;
|
||||
/**
|
||||
* Percentage of image cropped out from top
|
||||
*/
|
||||
private double crop;
|
||||
|
||||
public HealthSlider(Image fillImage) {
|
||||
this.fillImage = fillImage;
|
||||
this.crop = 1;
|
||||
this.backgroundSize = new BackgroundSize(
|
||||
100,
|
||||
100,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false);
|
||||
drawSlider();
|
||||
}
|
||||
|
||||
public void setCrop(double crop) {
|
||||
this.crop = crop;
|
||||
drawSlider();
|
||||
}
|
||||
|
||||
private void drawSlider() {
|
||||
int top = Math.max(0,(int)(fillImage.getHeight() - crop * fillImage.getHeight()));
|
||||
|
||||
WritableImage croppedImage = new WritableImage(
|
||||
fillImage.getPixelReader(),
|
||||
0,
|
||||
top,
|
||||
(int)fillImage.getWidth(),
|
||||
(int)fillImage.getHeight() - top
|
||||
);
|
||||
|
||||
BackgroundImage backgroundImage = new BackgroundImage(
|
||||
croppedImage,
|
||||
BackgroundRepeat.NO_REPEAT,
|
||||
BackgroundRepeat.NO_REPEAT,
|
||||
BackgroundPosition.CENTER,
|
||||
backgroundSize
|
||||
);
|
||||
|
||||
this.setBackground(new Background(backgroundImage));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package visualiser.model;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.scene.paint.Color;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
import shared.model.*;
|
||||
@@ -65,6 +62,7 @@ public class VisualiserBoat extends Boat {
|
||||
private ObjectProperty<GPSCoordinate> positionProperty;
|
||||
private ObjectProperty<Bearing> bearingProperty;
|
||||
private BooleanProperty hasCollided;
|
||||
private DoubleProperty healthProperty;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,6 +76,7 @@ public class VisualiserBoat extends Boat {
|
||||
|
||||
this.color = color;
|
||||
this.hasCollided = new SimpleBooleanProperty(false);
|
||||
this.healthProperty = new SimpleDoubleProperty(100);
|
||||
}
|
||||
|
||||
|
||||
@@ -284,4 +283,18 @@ public class VisualiserBoat extends Boat {
|
||||
public void setHasCollided(boolean hasCollided) {
|
||||
this.hasCollided.set(hasCollided);
|
||||
}
|
||||
|
||||
public DoubleProperty healthProperty() {
|
||||
return healthProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealth() {
|
||||
return healthProperty.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealth(double healthProperty) {
|
||||
this.healthProperty.set((int)healthProperty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,6 @@ public class VisualiserRaceState extends RaceState {
|
||||
|
||||
|
||||
if ((boat.getStatus() == BoatStatusEnum.DNF) || (boat.getStatus() == BoatStatusEnum.PRESTART) || (boat.getCurrentLeg().getLegNumber() < 0)) {
|
||||
|
||||
boat.setPlacing("-");
|
||||
|
||||
} else {
|
||||
|
||||
@@ -297,6 +297,7 @@ public class ServerConnection implements RunnableWithFramePeriod {
|
||||
this.messageRouter.addRoute(MessageType.MARKROUNDING, incomingMessages);
|
||||
this.messageRouter.addRoute(MessageType.XMLMESSAGE, incomingMessages);
|
||||
this.messageRouter.addRoute(MessageType.ASSIGN_PLAYER_BOAT, incomingMessages);
|
||||
this.messageRouter.addRoute(MessageType.BOATSTATE, incomingMessages);
|
||||
this.messageRouter.removeDefaultRoute(); //We no longer want to keep un-routed messages.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user