Merge branch 'master' into new_issue#19
# Conflicts: # racevisionGame/src/main/java/visualiser/Controllers/TitleController.java
This commit is contained in:
+1
@@ -7,6 +7,7 @@ import shared.exceptions.BoatNotFoundException;
|
||||
import shared.exceptions.MarkNotFoundException;
|
||||
import shared.model.GPSCoordinate;
|
||||
import shared.model.Mark;
|
||||
import visualiser.model.ThisBoat;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
import mock.app.Event;
|
||||
import org.xml.sax.SAXException;
|
||||
import mock.exceptions.EventConstructionException;
|
||||
@@ -12,14 +10,12 @@ import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import visualiser.model.RaceConnection;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -7,7 +7,6 @@ import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import visualiser.model.RaceConnection;
|
||||
|
||||
|
||||
@@ -125,8 +125,8 @@ public class RaceController extends Controller {
|
||||
ControlKey controlKey = keyFactory.getKey(codeString);
|
||||
if(controlKey != null) {
|
||||
try {
|
||||
controllerClient.sendKey(controlKey);
|
||||
controlKey.onAction(); // Change key state if applicable
|
||||
controllerClient.sendKey(controlKey);
|
||||
event.consume();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
@@ -12,7 +12,6 @@ import visualiser.gameController.Keys.ControlKey;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import visualiser.model.ThisBoat;
|
||||
|
||||
/**
|
||||
* Key to toggle the sails
|
||||
@@ -13,7 +14,7 @@ public class SailsToggleKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public SailsToggleKey(String name) {
|
||||
super(name, BoatActionEnum.SAILS_IN);
|
||||
super(name, BoatActionEnum.NOT_A_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,10 +22,12 @@ public class SailsToggleKey extends ControlKey {
|
||||
*/
|
||||
@Override
|
||||
public void onAction() {
|
||||
if(protocolCode == BoatActionEnum.SAILS_IN) {
|
||||
protocolCode = BoatActionEnum.SAILS_OUT;
|
||||
} else {
|
||||
if(ThisBoat.getInstance().isSailsOut()) {
|
||||
protocolCode = BoatActionEnum.SAILS_IN;
|
||||
ThisBoat.getInstance().setSailsOut(false);
|
||||
} else {
|
||||
protocolCode = BoatActionEnum.SAILS_OUT;
|
||||
ThisBoat.getInstance().setSailsOut(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* key to zoom into the game
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package visualiser.model;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
@@ -3,10 +3,6 @@ package visualiser.model;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* Connection for Races
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package visualiser.model;
|
||||
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.LinearGradient;
|
||||
import javafx.scene.paint.Paint;
|
||||
@@ -35,6 +36,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
*/
|
||||
private RaceMap map;
|
||||
|
||||
private Image sailsRight = new Image("/images/sailsRight.png");
|
||||
private Image sailsLeft = new Image("/images/sailsLeft.png");
|
||||
private Image sailsLuff = new Image("/images/sailsLuff.gif", 25, 10, false, false);
|
||||
|
||||
/**
|
||||
* The race we read data from and draw.
|
||||
*/
|
||||
@@ -336,8 +341,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draws a given boat on the canvas.
|
||||
* @param boat The boat to draw.
|
||||
@@ -375,7 +378,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
gc.fillPolygon(x, y, x.length);
|
||||
gc.restore();
|
||||
|
||||
|
||||
if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
|
||||
drawSails(boat);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,6 +418,70 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws sails for a given boat on the canvas. Sail position is
|
||||
* determined by the boats heading and the current wind direction
|
||||
* according to the "points of sail".
|
||||
* @param boat boat to display sails for
|
||||
*/
|
||||
private void drawSails(VisualiserBoat boat) {
|
||||
GraphCoordinate boatPos =
|
||||
this.map.convertGPS(boat.getPosition());
|
||||
double xPos = boatPos.getX(); // x pos of sail (on boat)
|
||||
double yPos = boatPos.getY() - 6; // y pos of sail (on boat)
|
||||
double boatBearing = boat.getBearing().degrees();
|
||||
double windDirection = 0; //visualiserRace.getWindDirection().degrees();
|
||||
double sailRotateAngle = 0; // rotation for correct sail display
|
||||
Image sailImage = null;
|
||||
Boolean rightSail = true;
|
||||
|
||||
// Getting the correct Points of Sail
|
||||
if (ThisBoat.getInstance().isSailsOut()){
|
||||
// correct sail and sailRotateAngle start depending on wind+bearing
|
||||
if ((windDirection + 180) > 360) {
|
||||
if ((boatBearing < windDirection) &&
|
||||
(boatBearing > windDirection - 180)) {
|
||||
rightSail = false;
|
||||
} else {
|
||||
if (boatBearing < 180) {
|
||||
sailRotateAngle = -180;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!((boatBearing > windDirection) &&
|
||||
(boatBearing < windDirection + 180))) {
|
||||
rightSail = false;
|
||||
if (boatBearing > 180) {
|
||||
sailRotateAngle = -180;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rightSail) {
|
||||
sailImage = sailsRight;
|
||||
xPos -= 1; // right align sail to boat edge on canvas
|
||||
} else {
|
||||
sailImage = sailsLeft;
|
||||
xPos -= 5; // left align sail to boat edge on canvas
|
||||
}
|
||||
sailRotateAngle += ((boatBearing + windDirection) * 0.5);
|
||||
}
|
||||
// Sails in = luffing sail
|
||||
else {
|
||||
xPos -= 6;
|
||||
yPos += 1;
|
||||
sailImage = sailsLuff;
|
||||
sailRotateAngle = boatBearing + 90;
|
||||
}
|
||||
|
||||
gc.save();
|
||||
|
||||
// rotate sails based on boats current heading
|
||||
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
||||
gc.drawImage(sailImage, xPos, yPos);
|
||||
|
||||
gc.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the wake for a given boat.
|
||||
@@ -756,4 +825,4 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package visualiser.model;
|
||||
|
||||
/**
|
||||
* The properties of the boat currently being controlled by the player. Singleton.
|
||||
*/
|
||||
public class ThisBoat {
|
||||
private VisualiserBoat boat;
|
||||
private static ThisBoat instance = new ThisBoat();
|
||||
|
||||
private ThisBoat(){}
|
||||
|
||||
public static ThisBoat getInstance(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setSailsOut(boolean sailsOut) {
|
||||
this.boat.setSailsOut(sailsOut);
|
||||
}
|
||||
|
||||
public boolean isSailsOut() {
|
||||
return this.boat.isSailsOut();
|
||||
}
|
||||
|
||||
public int getSourceID() {
|
||||
return this.boat.getSourceID();
|
||||
}
|
||||
|
||||
public void setBoat(VisualiserBoat boat) {
|
||||
this.boat = boat;
|
||||
}
|
||||
}
|
||||
@@ -205,6 +205,7 @@ public class VisualiserRaceState extends RaceState {
|
||||
|
||||
if (boat.getSourceID() == getPlayerBoatID()) {
|
||||
boat.setClientBoat(true);
|
||||
ThisBoat.getInstance().setBoat(boat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user