mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Fixed scaling issues.
#fix
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
package seng302.visualiser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import seng302.gameServer.messages.RoundingSide;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.model.Limit;
|
||||
@@ -20,9 +24,9 @@ import seng302.model.mark.Corner;
|
||||
import seng302.model.mark.Mark;
|
||||
import seng302.utilities.GeoUtility;
|
||||
import seng302.visualiser.fxObjects.MarkArrowFactory;
|
||||
import seng302.visualiser.fxObjects.assets_2D.*;
|
||||
|
||||
import java.util.*;
|
||||
import seng302.visualiser.fxObjects.assets_2D.CourseBoundary;
|
||||
import seng302.visualiser.fxObjects.assets_2D.Gate;
|
||||
import seng302.visualiser.fxObjects.assets_2D.Marker2D;
|
||||
|
||||
/**
|
||||
* Created by cir27 on 20/07/17.
|
||||
@@ -73,44 +77,22 @@ public class GameView extends Pane {
|
||||
gameObjects = this.getChildren();
|
||||
gameObjects.addAll(mapImage, raceBorder, markers, tokens);
|
||||
this.parentProperty().addListener((obs, old, parent) -> {
|
||||
if (old != null) {
|
||||
((Pane) old).heightProperty().removeListener(heightChangeListener);
|
||||
}
|
||||
if (parent != null) {
|
||||
heightChangeListener = (observableValue, oldHeight, newHeight) -> {
|
||||
canvasWidth = ((Pane) parent).getWidth();
|
||||
canvasHeight = newHeight.doubleValue();
|
||||
updateBorder(borderPoints);
|
||||
updateCourse(compoundMarks, courseOrder);
|
||||
};
|
||||
((Pane) parent).heightProperty().addListener(heightChangeListener);
|
||||
// }
|
||||
// if (parent != null) {
|
||||
// canvasWidth = parent.prefWidth(1);
|
||||
// canvasHeight = parent.prefHeight(1);
|
||||
// rescaleRace(borderPoints);
|
||||
// System.out.println("parent = " + parent.maxWidth(100));
|
||||
// System.out.println("parent.minWidth(1) = " + parent.minWidth(100));
|
||||
// System.out.println(canvasWidth);
|
||||
// System.out.println(canvasHeight);
|
||||
canvasWidth = ((Pane) parent).getHeight();
|
||||
canvasWidth = ((Pane) parent).getWidth();
|
||||
System.out.println("canvasWidth = " + canvasWidth);
|
||||
System.out.println("canvasHeight = " + canvasHeight);
|
||||
this.getChildren().add(new Circle(canvasWidth / 2, canvasHeight / 2, 7, Color.GREENYELLOW));
|
||||
this.getChildren().add(new Circle(canvasWidth, canvasHeight, 7, Color.GREENYELLOW));
|
||||
this.getChildren().add(new Circle(0,0, 7, Color.GREENYELLOW));
|
||||
this.getChildren().add(new Circle(canvasWidth, 0, 7, Color.GREENYELLOW));
|
||||
this.getChildren().add(new Circle(0,canvasHeight, 7, Color.GREENYELLOW));
|
||||
Rectangle r = new Rectangle(canvasWidth, canvasHeight, Color.TRANSPARENT);
|
||||
r.setStroke(Color.BLACK);
|
||||
this.getChildren().add(r);
|
||||
canvasWidth = parent.prefWidth(1);
|
||||
canvasHeight = parent.prefHeight(1);
|
||||
updateBorder(borderPoints);
|
||||
updateCourse(compoundMarks, courseOrder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setSize(double width, double height) {
|
||||
canvasHeight = height;
|
||||
canvasWidth = width;
|
||||
updateBorder(borderPoints);
|
||||
updateCourse(compoundMarks, courseOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a orderedMarks to the GameView. The view is scaled accordingly unless a border is set in which
|
||||
* case the orderedMarks is added relative ot the border.
|
||||
@@ -512,12 +494,6 @@ public class GameView extends Pane {
|
||||
return new Point2D(xAxisLocation, yAxisLocation);
|
||||
}
|
||||
|
||||
|
||||
public void setSize(Double width, Double height){
|
||||
this.canvasWidth = width;
|
||||
this.canvasHeight = height;
|
||||
}
|
||||
|
||||
public void setHorizontalBuffer(Double buff){
|
||||
this.horizontalBuffer = buff;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ import seng302.visualiser.controllers.dialogs.BoatCustomizeController;
|
||||
|
||||
public class LobbyController implements Initializable {
|
||||
|
||||
private final double INITIAL_MAP_HEIGHT = 770d;
|
||||
private final double INITIAL_MAP_WIDTH = 574d;
|
||||
|
||||
//--------FXML BEGIN--------//
|
||||
@FXML
|
||||
private VBox playerListVBox;
|
||||
@@ -56,7 +59,8 @@ public class LobbyController implements Initializable {
|
||||
private JFXDialog customizationDialog;
|
||||
public Color playersColor;
|
||||
private Map<Integer, ClientYacht> playerBoats;
|
||||
private Double mapWidth, mapHeight;
|
||||
|
||||
private Double mapWidth = INITIAL_MAP_WIDTH, mapHeight = INITIAL_MAP_HEIGHT;
|
||||
private GameView gameView;
|
||||
|
||||
@Override
|
||||
@@ -104,16 +108,7 @@ public class LobbyController implements Initializable {
|
||||
leaveLobbyButton.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
customizeButton.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
beginRaceButton.setOnMouseEntered(e -> Sounds.playHoverSound());
|
||||
serverMap.setPrefWidth(serverMap.getWidth());
|
||||
serverMap.setPrefHeight(serverMap.getHeight());
|
||||
serverMap.widthProperty().addListener((obs, oldVal, newVal) -> {
|
||||
System.out.println("LISTEN " + newVal);
|
||||
serverMap.setPrefWidth(newVal.doubleValue());
|
||||
});
|
||||
serverMap.heightProperty().addListener((obs, oldVal, newVal) -> {
|
||||
System.out.println("LISTEN HEIUGHT "+newVal);
|
||||
serverMap.setPrefHeight(newVal.doubleValue());
|
||||
});
|
||||
|
||||
initMapPreview();
|
||||
}
|
||||
|
||||
@@ -141,52 +136,30 @@ public class LobbyController implements Initializable {
|
||||
return customizationDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void refreshMapView(){
|
||||
RaceXMLData raceData = ViewManager.getInstance().getGameClient().getCourseData();
|
||||
List<Limit> border = raceData.getCourseLimit();
|
||||
List<CompoundMark> marks = new ArrayList<CompoundMark>(raceData.getCompoundMarks().values());
|
||||
List<Corner> corners = raceData.getMarkSequence();
|
||||
|
||||
gameView.setSize(mapWidth, mapHeight);
|
||||
|
||||
// Update game view
|
||||
gameView.updateBorder(border);
|
||||
gameView.updateCourse(marks, corners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a top down preview of the race course map.
|
||||
*/
|
||||
private void initMapPreview() {
|
||||
// gameView = new GameView(marks, corners, border);
|
||||
// gameView.setHorizontalBuffer(330d);
|
||||
|
||||
// mapWidth = 770d;
|
||||
// mapHeight = 574d;
|
||||
|
||||
// Add game view
|
||||
RaceXMLData raceData = ViewManager.getInstance().getGameClient().getCourseData();
|
||||
List<Limit> border = raceData.getCourseLimit();
|
||||
List<CompoundMark> marks = new ArrayList<CompoundMark>(raceData.getCompoundMarks().values());
|
||||
List<CompoundMark> marks = new ArrayList<>(raceData.getCompoundMarks().values());
|
||||
List<Corner> corners = raceData.getMarkSequence();
|
||||
// gameView.updateBorder(border);
|
||||
// gameView.updateCourse(marks, corners);
|
||||
|
||||
gameView = new GameView(marks, corners, border);
|
||||
serverMap.getChildren().clear();
|
||||
serverMap.getChildren().add(gameView);
|
||||
|
||||
// serverMap.widthProperty().addListener((observable, oldValue, newValue) -> {
|
||||
// mapWidth = newValue.doubleValue();
|
||||
// refreshMapView();
|
||||
// });
|
||||
gameView.setSize(mapWidth, mapHeight);
|
||||
|
||||
serverMap.widthProperty().addListener((observable, oldValue, newValue) -> {
|
||||
mapWidth = newValue.doubleValue();
|
||||
gameView.setSize(mapWidth, mapHeight);
|
||||
});
|
||||
//
|
||||
// serverMap.heightProperty().addListener((observable, oldValue, newValue) -> {
|
||||
// mapHeight = newValue.doubleValue();
|
||||
// refreshMapView();
|
||||
// });
|
||||
serverMap.heightProperty().addListener((observable, oldValue, newValue) -> {
|
||||
mapHeight = newValue.doubleValue();
|
||||
gameView.setSize(mapWidth, mapHeight);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user