mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Reverting some new graphics classes back to how they were on master.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package seng302.model.mark;
|
||||
|
||||
import com.sun.deploy.util.StringUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -31,9 +30,13 @@ public class CompoundMark {
|
||||
*/
|
||||
@Override
|
||||
public String toString(){
|
||||
String info = String.format("CompoundMark: %d (%s), [", compoundMarkId, name);
|
||||
info += StringUtils.join(marks, ", ") + "]";
|
||||
return info;
|
||||
String info = String.format(
|
||||
"CompoundMark: %d (%s), [%s", compoundMarkId, name, marks.get(0).toString()
|
||||
);
|
||||
if (marks.size() > 1) {
|
||||
info += String.format(", %s", marks.get(1).toString());
|
||||
}
|
||||
return info + "]";
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
||||
@@ -43,5 +43,4 @@ public class RaceXMLData {
|
||||
public List<Limit> getCourseLimit() {
|
||||
return courseLimit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ public class ClientToServerThread implements Runnable {
|
||||
clientLog(e.getMessage(), 1);
|
||||
return;
|
||||
}
|
||||
System.out.println("streamPackets.size() = " + streamPackets.size());
|
||||
}
|
||||
closeSocket();
|
||||
clientLog("Closed connection to Server", 0);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.visualiser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Map;
|
||||
@@ -12,6 +13,11 @@ import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.model.RaceState;
|
||||
@@ -173,7 +179,18 @@ public class GameClient {
|
||||
break;
|
||||
|
||||
case RACE_XML:
|
||||
System.out.println("RACE XML");
|
||||
try {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(new DOMSource(StreamParser.extractXmlMessage(packet)),
|
||||
new StreamResult(writer));
|
||||
// String output = writer.getBuffer().toString().replaceAll("\n|\r", "");
|
||||
System.out.println(writer.getBuffer().toString());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
courseData = XMLParser.parseRace(
|
||||
StreamParser.extractXmlMessage(packet)
|
||||
);
|
||||
|
||||
@@ -59,13 +59,16 @@ public class GameView extends Pane {
|
||||
/* Note that if either of these is null then values for it have not been added and the other
|
||||
should be used as the limits of the map. */
|
||||
private List<Limit> borderPoints;
|
||||
private List<CompoundMark> course;
|
||||
private Map<Mark, Marker> markerObjects;
|
||||
|
||||
private Map<Yacht, BoatObject> boatObjects = new HashMap<>();
|
||||
private Map<Yacht, AnnotationBox> annotations = new HashMap<>();
|
||||
private List<Corner> markSequence;
|
||||
private ObservableList<Node> gameObjects;
|
||||
private Group annotationsGroup = new Group();
|
||||
private Group wakesGroup = new Group();
|
||||
private Group boatObjectGroup = new Group();
|
||||
private Group trails = new Group();
|
||||
private Group markers = new Group();
|
||||
|
||||
private ImageView mapImage = new ImageView();
|
||||
|
||||
@@ -93,6 +96,7 @@ public class GameView extends Pane {
|
||||
fpsDisplay.setStrokeWidth(2);
|
||||
gameObjects.add(fpsDisplay);
|
||||
gameObjects.add(raceBorder);
|
||||
gameObjects.add(markers);
|
||||
initializeTimer();
|
||||
// this.widthProperty().addListener(resize -> {
|
||||
// canvasWidth = this.getWidth();
|
||||
@@ -182,12 +186,12 @@ public class GameView extends Pane {
|
||||
* @param newCourse the mark objects that make up the course.
|
||||
*/
|
||||
public void updateCourse(List<CompoundMark> newCourse, List<Corner> sequence) {
|
||||
course = newCourse;
|
||||
this.markSequence = sequence;
|
||||
markerObjects = new HashMap<>();
|
||||
Paint colour = Color.BLACK;
|
||||
markers.getChildren().clear();
|
||||
//Creates new markers
|
||||
for (CompoundMark cMark : course) {
|
||||
System.out.println(newCourse.size());
|
||||
for (CompoundMark cMark : newCourse) {
|
||||
//Set start and end colour
|
||||
if (cMark.getId() == sequence.get(0).getCompoundMarkID()) {
|
||||
colour = Color.GREEN;
|
||||
@@ -209,6 +213,7 @@ public class GameView extends Pane {
|
||||
}
|
||||
}
|
||||
colour = Color.BLACK;
|
||||
System.out.println("cMark.toString() = " + cMark.toString());
|
||||
}
|
||||
//Set X,Y co-ordinates
|
||||
if (borderPoints == null) {
|
||||
@@ -222,6 +227,7 @@ public class GameView extends Pane {
|
||||
marker.setCenterX(p2d.getX());
|
||||
marker.setCenterY(p2d.getY());
|
||||
}));
|
||||
markers.getChildren().addAll(markerObjects.values());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,6 +267,7 @@ public class GameView extends Pane {
|
||||
gate.endYProperty().bind(
|
||||
m2.centerYProperty()
|
||||
);
|
||||
markers.getChildren().addAll(gate);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,18 +300,13 @@ public class GameView extends Pane {
|
||||
findMinMaxPoint(limitingCoordinates);
|
||||
double minLonToMaxLon = scaleRaceExtremities();
|
||||
calculateReferencePointLocation(minLonToMaxLon);
|
||||
drawGoogleMap();
|
||||
// drawGoogleMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws all the boats.
|
||||
*/
|
||||
public void setBoats(List<Yacht> yachts) {
|
||||
Group annotationsGroup = new Group();
|
||||
Group wakesGroup = new Group();
|
||||
Group boatObjectGroup = new Group();
|
||||
Group trails = new Group();
|
||||
|
||||
BoatObject newBoat;
|
||||
for (Yacht yacht : yachts) {
|
||||
newBoat = new BoatObject();
|
||||
@@ -314,6 +316,7 @@ public class GameView extends Pane {
|
||||
BoatObject bo = boatObjects.get(boat);
|
||||
Point2D p2d = findScaledXY(lat, lon);
|
||||
bo.moveTo(p2d.getX(), p2d.getY(), heading);
|
||||
annotations.get(boat).setLocation(p2d.getX(), p2d.getY());
|
||||
bo.setTrajectory(
|
||||
heading,
|
||||
velocity,
|
||||
@@ -331,6 +334,18 @@ public class GameView extends Pane {
|
||||
gameObjects.addAll(boatObjectGroup);
|
||||
}
|
||||
|
||||
// private void updateBoatObject (Yacht correspondingYacht) {
|
||||
// BoatObject bo = boatObjects.get(correspondingYacht);
|
||||
// Point2D p2d = findScaledXY(lat, lon);
|
||||
// bo.moveTo(p2d.getX(), p2d.getY(), heading);
|
||||
// annotations.get(boat).moveTo(p2d.getX(), p2d.getY());
|
||||
// bo.setTrajectory(
|
||||
// heading,
|
||||
// velocity,
|
||||
// metersPerPixelX,
|
||||
// metersPerPixelY);
|
||||
// }
|
||||
|
||||
private void createAndBindAnnotationBox (Yacht yacht) {
|
||||
AnnotationBox newAnnotation;
|
||||
newAnnotation = new AnnotationBox();
|
||||
@@ -339,7 +354,7 @@ public class GameView extends Pane {
|
||||
newAnnotation.addAnnotation(
|
||||
"velocity",
|
||||
yacht.getVelocityProperty(),
|
||||
(velocity) -> String.format("%.2f ms", velocity.doubleValue())
|
||||
(velocity) -> String.format("Speed: %.2f ms", velocity.doubleValue())
|
||||
);
|
||||
newAnnotation.addAnnotation(
|
||||
"nextMark",
|
||||
@@ -477,7 +492,7 @@ public class GameView extends Pane {
|
||||
distanceFromReference = GeoUtility.getDistance(
|
||||
minLatPoint, new GeoPoint(unscaledLat, unscaledLon)
|
||||
);
|
||||
System.out.println("distanceFromReference = " + distanceFromReference);
|
||||
// System.out.println("distanceFromReference = " + distanceFromReference);
|
||||
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
|
||||
xAxisLocation += Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
|
||||
yAxisLocation -= Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
|
||||
@@ -497,8 +512,8 @@ public class GameView extends Pane {
|
||||
if(horizontalInversion) {
|
||||
xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize);
|
||||
}
|
||||
System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat);
|
||||
System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon);
|
||||
// System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat);
|
||||
// System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon);
|
||||
return new Point2D(xAxisLocation, yAxisLocation);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package seng302.visualiser.fxObjects;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
@@ -80,7 +79,7 @@ public class AnnotationBox extends Group{
|
||||
private Map<String, Annotation> annotationsByName = new HashMap<>();
|
||||
|
||||
public AnnotationBox() {
|
||||
this.setCache(true);
|
||||
// this.setCache(true);
|
||||
background.setX(BACKGROUND_X);
|
||||
background.setY(BACKGROUND_Y);
|
||||
background.setWidth(backgroundWidth);
|
||||
@@ -90,8 +89,8 @@ public class AnnotationBox extends Group{
|
||||
background.setFill(new Color(1, 1, 1, 0.75));
|
||||
background.setStroke(theme);
|
||||
background.setStrokeWidth(2);
|
||||
background.setCache(true);
|
||||
background.setCacheHint(CacheHint.SPEED);
|
||||
// background.setCache(true);
|
||||
// background.setCacheHint(CacheHint.SPEED);
|
||||
this.getChildren().add(background);
|
||||
}
|
||||
|
||||
@@ -99,11 +98,15 @@ public class AnnotationBox extends Group{
|
||||
annotationsByName.put(annotationName, annotation);
|
||||
this.getChildren().add(annotation.getText());
|
||||
visibleAnnotations++;
|
||||
update();
|
||||
}
|
||||
|
||||
public void addAnnotation (String annotationName, String annotationText) {
|
||||
Text text = getTextObject();
|
||||
annotationsByName.put(annotationName, new Annotation(text, annotationText));
|
||||
this.getChildren().add(text);
|
||||
visibleAnnotations++;
|
||||
update();
|
||||
}
|
||||
|
||||
public <E> void addAnnotation (String annotationName, ObservableValue<E> observable) {
|
||||
@@ -116,6 +119,7 @@ public class AnnotationBox extends Group{
|
||||
annotationsByName.put(annotationName, new Annotation<>(newText, observable, formatter));
|
||||
this.getChildren().add(newText);
|
||||
visibleAnnotations++;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setAnnotationVisibility (String annotationName, boolean visibility) {
|
||||
@@ -144,8 +148,8 @@ public class AnnotationBox extends Group{
|
||||
}
|
||||
|
||||
public void setLocation (double x, double y) {
|
||||
this.setLayoutX(x);
|
||||
this.setLayoutY(y);
|
||||
this.setTranslateX(x);
|
||||
this.setTranslateY(y);
|
||||
}
|
||||
|
||||
public void setWidth (double width) {
|
||||
@@ -172,8 +176,8 @@ public class AnnotationBox extends Group{
|
||||
Text text = new Text();
|
||||
text.setFill(theme);
|
||||
text.setStrokeWidth(2);
|
||||
text.setCacheHint(CacheHint.SPEED);
|
||||
text.setCache(true);
|
||||
// text.setCacheHint(CacheHint.SPEED);
|
||||
// text.setCache(true);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ public class BoatObject extends Group {
|
||||
boatPoly.setStroke(Color.BLACK);
|
||||
});
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
boatPoly.setCache(true);
|
||||
boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
// boatPoly.setCache(true);
|
||||
// boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
|
||||
// annotationBox = new AnnotationBox();
|
||||
// annotationBox.setFill(colour);
|
||||
|
||||
Reference in New Issue
Block a user