mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'develop' into story1275_host_customization
# Conflicts: # src/main/java/seng302/visualiser/GameView3D.java
This commit is contained in:
@@ -14,8 +14,6 @@ import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Pane;
|
||||
@@ -46,6 +44,7 @@ import seng302.utilities.XMLParser;
|
||||
import seng302.visualiser.controllers.LobbyController;
|
||||
import seng302.visualiser.controllers.RaceViewController;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
import seng302.visualiser.controllers.dialogs.PopupDialogController;
|
||||
|
||||
/**
|
||||
* This class is a client side instance of a yacht racing game in JavaFX. The game is instantiated
|
||||
@@ -171,10 +170,12 @@ public class GameClient {
|
||||
|
||||
private void showConnectionError (String message) {
|
||||
Platform.runLater(() -> {
|
||||
Alert alert = new Alert(AlertType.ERROR);
|
||||
alert.setHeaderText("Connection Error");
|
||||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
PopupDialogController controller = ViewManager.getInstance().showPopupDialog();
|
||||
controller.setHeader("Oops");
|
||||
controller.setContent(message);
|
||||
controller.setOptionButtonText("GO HOME");
|
||||
controller
|
||||
.setOptionButtonEventHandler(event -> ViewManager.getInstance().goToStartView());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package seng302.visualiser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -8,6 +10,7 @@ import javafx.animation.AnimationTimer;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.Camera;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
@@ -20,6 +23,9 @@ import javafx.scene.transform.Scale;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.gameServer.messages.RoundingSide;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.GameKeyBind;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.model.KeyAction;
|
||||
import seng302.model.Limit;
|
||||
import seng302.model.ScaledPoint;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
@@ -28,6 +34,11 @@ import seng302.model.mark.Mark;
|
||||
import seng302.model.token.Token;
|
||||
import seng302.utilities.GeoUtility;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.cameras.ChaseCamera;
|
||||
import seng302.visualiser.cameras.IsometricCamera;
|
||||
import seng302.visualiser.cameras.RaceCamera;
|
||||
import seng302.visualiser.cameras.TopDownCamera;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
import seng302.visualiser.fxObjects.MarkArrowFactory;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatObject;
|
||||
import seng302.visualiser.fxObjects.assets_3D.Marker3D;
|
||||
@@ -37,18 +48,19 @@ import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
||||
/**
|
||||
* Collection of animated3D assets that displays a race.
|
||||
*/
|
||||
|
||||
public class GameView3D extends GameView{
|
||||
|
||||
private final double FOV = 60;
|
||||
private final double DEFAULT_CAMERA_DEPTH = -125;
|
||||
private final double DEFAULT_CAMERA_X = 0;
|
||||
private final double DEFAULT_CAMERA_Y = 100;
|
||||
|
||||
private Group root3D;
|
||||
private SubScene view;
|
||||
private PerspectiveCamera camera;
|
||||
private Group raceBorder = new Group();
|
||||
// Cameras
|
||||
private PerspectiveCamera isometricCam;
|
||||
private PerspectiveCamera topDownCam;
|
||||
private PerspectiveCamera chaseCam;
|
||||
|
||||
/* 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. */
|
||||
@@ -63,21 +75,22 @@ public class GameView3D extends GameView{
|
||||
private Double windDir;
|
||||
|
||||
public GameView3D () {
|
||||
canvasWidth = canvasHeight = 220;
|
||||
camera = new PerspectiveCamera(true);
|
||||
camera.getTransforms().addAll(
|
||||
new Translate(DEFAULT_CAMERA_X, DEFAULT_CAMERA_Y, DEFAULT_CAMERA_DEPTH)
|
||||
);
|
||||
camera.setFarClip(600);
|
||||
camera.setNearClip(0.1);
|
||||
camera.setFieldOfView(FOV);
|
||||
isometricCam = new IsometricCamera(DEFAULT_CAMERA_X, DEFAULT_CAMERA_Y);
|
||||
topDownCam = new TopDownCamera();
|
||||
chaseCam = new ChaseCamera();
|
||||
|
||||
for (PerspectiveCamera pc : Arrays.asList(isometricCam, topDownCam, chaseCam)) {
|
||||
pc.setFarClip(600);
|
||||
pc.setNearClip(0.1);
|
||||
pc.setFieldOfView(FOV);
|
||||
}
|
||||
|
||||
gameObjects = new Group();
|
||||
root3D = new Group(camera, gameObjects);
|
||||
root3D = new Group(isometricCam, gameObjects);
|
||||
view = new SubScene(
|
||||
root3D, 1000, 1000, true, SceneAntialiasing.BALANCED
|
||||
);
|
||||
view.setCamera(camera);
|
||||
camera.getTransforms().add(new Rotate(30, new Point3D(1,0,0)));
|
||||
view.setCamera(isometricCam);
|
||||
|
||||
gameObjects.getChildren().addAll(
|
||||
ModelFactory.importModel(ModelType.OCEAN).getAssets(),
|
||||
@@ -88,6 +101,8 @@ public class GameView3D extends GameView{
|
||||
scene.addEventHandler(KeyEvent.KEY_PRESSED, this::cameraMovement);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,40 +260,45 @@ public class GameView3D extends GameView{
|
||||
}
|
||||
|
||||
public void cameraMovement(KeyEvent event) {
|
||||
switch (event.getCode()) {
|
||||
case NUMPAD8:
|
||||
camera.getTransforms().addAll(new Rotate(0.5, new Point3D(1,0,0)));
|
||||
GameKeyBind keyBinds = GameKeyBind.getInstance();
|
||||
KeyAction keyPressed = keyBinds.getKeyAction(event.getCode());
|
||||
switch (keyPressed) {
|
||||
case ZOOM_IN:
|
||||
((RaceCamera) view.getCamera()).zoomIn();
|
||||
break;
|
||||
case NUMPAD2:
|
||||
camera.getTransforms().addAll(new Rotate(-0.5, new Point3D(1,0,0)));
|
||||
case ZOOM_OUT:
|
||||
((RaceCamera) view.getCamera()).zoomOut();
|
||||
break;
|
||||
case NUMPAD4:
|
||||
camera.getTransforms().addAll(new Rotate(-0.5, new Point3D(0,1,0)));
|
||||
case FORWARD:
|
||||
((RaceCamera) view.getCamera()).panUp();
|
||||
break;
|
||||
case NUMPAD6:
|
||||
camera.getTransforms().addAll(new Rotate(0.5, new Point3D(0,1,0)));
|
||||
case BACKWARD:
|
||||
((RaceCamera) view.getCamera()).panDown();
|
||||
break;
|
||||
case Z:
|
||||
camera.getTransforms().addAll(new Translate(0, 0, 1.5));
|
||||
case LEFT:
|
||||
((RaceCamera) view.getCamera()).panLeft();
|
||||
break;
|
||||
case X:
|
||||
camera.getTransforms().addAll(new Translate(0, 0, -1.5));
|
||||
case RIGHT:
|
||||
((RaceCamera) view.getCamera()).panRight();
|
||||
break;
|
||||
case W:
|
||||
camera.getTransforms().addAll(new Translate(0, -1, 0));
|
||||
break;
|
||||
case S:
|
||||
camera.getTransforms().addAll(new Translate(0, 1, 0));
|
||||
break;
|
||||
case A:
|
||||
camera.getTransforms().addAll(new Translate(-1, 0, 0));
|
||||
break;
|
||||
case D:
|
||||
camera.getTransforms().addAll(new Translate(1, 0, 0));
|
||||
case VIEW:
|
||||
toggleCamera();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleCamera() {
|
||||
Camera currCamera = view.getCamera();
|
||||
|
||||
if (currCamera.equals(isometricCam)) {
|
||||
view.setCamera(topDownCam);
|
||||
} else if (currCamera.equals(topDownCam)) {
|
||||
view.setCamera(chaseCam);
|
||||
} else {
|
||||
view.setCamera(isometricCam);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws all the boats.
|
||||
* @param yachts The yachts to set in the race
|
||||
@@ -299,6 +319,12 @@ public class GameView3D extends GameView{
|
||||
Point2D p2d = scaledPoint.findScaledXY(lat, lon);
|
||||
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, windDir);
|
||||
});
|
||||
|
||||
if (clientYacht.getSourceId().equals(
|
||||
ViewManager.getInstance().getGameClient().getServerThread().getClientId())) {
|
||||
((ChaseCamera) chaseCam).setPlayerBoat(newBoat);
|
||||
((TopDownCamera) topDownCam).setPlayerBoat(newBoat);
|
||||
}
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
gameObjects.getChildren().addAll(wakes);
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package seng302.visualiser.cameras;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Transform;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatObject;
|
||||
|
||||
|
||||
public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
|
||||
private final Double VERTICAL_PAN_LIMIT = 20.0;
|
||||
private final Double NEAR_ZOOM_LIMIT = -15.0;
|
||||
private final Double FAR_ZOOM_LIMIT = -125.0;
|
||||
|
||||
private final Double ZOOM_STEP = 2.5;
|
||||
private final Double PAN_STEP = 2.5;
|
||||
|
||||
private ObservableList<Transform> transforms;
|
||||
private BoatObject playerBoat;
|
||||
|
||||
private Double zoomFactor;
|
||||
private Double horizontalPan;
|
||||
private Double verticalPan;
|
||||
|
||||
|
||||
public ChaseCamera() {
|
||||
super(true);
|
||||
transforms = this.getTransforms();
|
||||
|
||||
zoomFactor = (FAR_ZOOM_LIMIT + NEAR_ZOOM_LIMIT) / 2.0;
|
||||
this.horizontalPan = 0.0;
|
||||
this.verticalPan = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a player boat object to observe and update the camera with.
|
||||
*
|
||||
* @param playerBoat The player boat to be observed.
|
||||
*/
|
||||
public void setPlayerBoat(BoatObject playerBoat) {
|
||||
this.playerBoat = playerBoat;
|
||||
|
||||
for (DoubleProperty o : Arrays
|
||||
.asList(playerBoat.getRotationProperty(), playerBoat.layoutYProperty(),
|
||||
playerBoat.layoutXProperty())) {
|
||||
o.addListener((obs, oldVal, newVal) -> repositionCamera());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the camera to a new position after some change (Zooming or Panning)
|
||||
*/
|
||||
private void repositionCamera() {
|
||||
transforms.clear();
|
||||
transforms.addAll(
|
||||
new Translate(playerBoat.getLayoutX(), playerBoat.getLayoutY(), 0),
|
||||
new Rotate(playerBoat.getRotationProperty().getValue() + horizontalPan,
|
||||
new Point3D(0, 0, 1)),
|
||||
new Rotate(60 + verticalPan, new Point3D(1, 0, 0)),
|
||||
new Translate(0, 0, zoomFactor)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the zoom amount (camera depth) by some adjustment value
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustZoomFactor(Double adjustment) {
|
||||
if (zoomFactor + adjustment < NEAR_ZOOM_LIMIT && zoomFactor + adjustment > FAR_ZOOM_LIMIT) {
|
||||
zoomFactor = zoomFactor + adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the Vertical Panning of the Camera
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustVerticalPan(Double adjustment) {
|
||||
if (verticalPan + adjustment >= -VERTICAL_PAN_LIMIT
|
||||
&& verticalPan + adjustment <= VERTICAL_PAN_LIMIT) {
|
||||
verticalPan += adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the Horizontal Panning of the Camera.
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustHorizontalPan(Double adjustment) {
|
||||
this.horizontalPan += adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomIn() {
|
||||
adjustZoomFactor(ZOOM_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomOut() {
|
||||
adjustZoomFactor(-ZOOM_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panLeft() {
|
||||
adjustHorizontalPan(-PAN_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panRight() {
|
||||
adjustHorizontalPan(PAN_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panUp() {
|
||||
adjustVerticalPan(-PAN_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panDown() {
|
||||
adjustVerticalPan(PAN_STEP);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package seng302.visualiser.cameras;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Transform;
|
||||
import javafx.scene.transform.Translate;
|
||||
|
||||
public class IsometricCamera extends PerspectiveCamera implements RaceCamera {
|
||||
|
||||
private final Double MIN_X = -120.0;
|
||||
private final Double MAX_X = 125.0;
|
||||
|
||||
private final Double MIN_Y = 40.0;
|
||||
private final Double MAX_Y = 170.0;
|
||||
|
||||
private final Double PAN_LIMIT = 160.0;
|
||||
private final Double NEAR_ZOOM_LIMIT = -50.0;
|
||||
private final Double FAR_ZOOM_LIMIT = -160.0;
|
||||
|
||||
private Double horizontalPan;
|
||||
private Double verticalPan;
|
||||
private Double zoomFactor;
|
||||
|
||||
private ObservableList<Transform> transforms;
|
||||
|
||||
public IsometricCamera(Double cameraStartX, Double cameraStartY) {
|
||||
super(true);
|
||||
transforms = this.getTransforms();
|
||||
|
||||
zoomFactor = (FAR_ZOOM_LIMIT + NEAR_ZOOM_LIMIT) / 2.0;
|
||||
horizontalPan = cameraStartX;
|
||||
verticalPan = cameraStartY;
|
||||
|
||||
updateCamera();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the camera to a new position after some change (Zooming or Panning)
|
||||
*/
|
||||
private void updateCamera() {
|
||||
transforms.clear();
|
||||
transforms.addAll(
|
||||
new Translate(horizontalPan, verticalPan, zoomFactor),
|
||||
new Rotate(30, new Point3D(1, 0, 0))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the zoom amount (camera depth) by some adjustment value
|
||||
*
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustZoomFactor(Double adjustment) {
|
||||
if (zoomFactor + adjustment < NEAR_ZOOM_LIMIT && zoomFactor + adjustment > FAR_ZOOM_LIMIT) {
|
||||
zoomFactor = zoomFactor + adjustment;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the Vertical Panning of the Camera
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustVerticalPan(Double adjustment) {
|
||||
if (verticalPan + adjustment >= MIN_Y && verticalPan + adjustment <= MAX_Y) {
|
||||
verticalPan += adjustment;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the Horizontal Panning of the Camera.
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustHorizontalPan(Double adjustment) {
|
||||
if (horizontalPan + adjustment >= MIN_X && horizontalPan + adjustment <= MIN_Y) {
|
||||
this.horizontalPan += adjustment;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomIn() {
|
||||
adjustZoomFactor(-2.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomOut() {
|
||||
adjustZoomFactor(2.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panLeft() {
|
||||
adjustHorizontalPan(-2.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panRight() {
|
||||
adjustHorizontalPan(2.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panUp() {
|
||||
adjustVerticalPan(-2.5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panDown() {
|
||||
adjustVerticalPan(2.5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package seng302.visualiser.cameras;
|
||||
|
||||
|
||||
public interface RaceCamera {
|
||||
|
||||
void zoomIn();
|
||||
|
||||
void zoomOut();
|
||||
|
||||
void panLeft();
|
||||
|
||||
void panRight();
|
||||
|
||||
void panUp();
|
||||
|
||||
void panDown();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package seng302.visualiser.cameras;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.transform.Transform;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatObject;
|
||||
|
||||
public class TopDownCamera extends PerspectiveCamera implements RaceCamera {
|
||||
|
||||
private final Double PAN_LIMIT = 30.0;
|
||||
private final Double NEAR_ZOOM_LIMIT = -30.0;
|
||||
private final Double FAR_ZOOM_LIMIT = -130.0;
|
||||
private final Double ZOOM_STEP = 2.5;
|
||||
|
||||
private ObservableList<Transform> transforms;
|
||||
private BoatObject playerBoat;
|
||||
|
||||
private Double zoomFactor;
|
||||
private Double horizontalPan;
|
||||
private Double verticalPan;
|
||||
|
||||
public TopDownCamera() {
|
||||
super(true);
|
||||
transforms = this.getTransforms();
|
||||
|
||||
zoomFactor = (FAR_ZOOM_LIMIT + NEAR_ZOOM_LIMIT) / 2.0;
|
||||
horizontalPan = 0.0;
|
||||
verticalPan = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a player boat object to observe and update the camera with.
|
||||
*
|
||||
* @param playerBoat The player boat to be observed.
|
||||
*/
|
||||
public void setPlayerBoat(BoatObject playerBoat) {
|
||||
this.playerBoat = playerBoat;
|
||||
|
||||
for (DoubleProperty o : Arrays
|
||||
.asList(playerBoat.layoutXProperty(), playerBoat.layoutYProperty())) {
|
||||
o.addListener((obs, oldVal, newVal) -> updateCamera());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the camera to a new position after some change (Zooming or Panning)
|
||||
*/
|
||||
private void updateCamera() {
|
||||
transforms.clear();
|
||||
transforms.addAll(
|
||||
new Translate(playerBoat.getLayoutX() + horizontalPan,
|
||||
playerBoat.getLayoutY() + verticalPan, zoomFactor)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the zoom amount (camera depth) by some adjustment value
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustZoomFactor(Double adjustment) {
|
||||
if (zoomFactor + adjustment < NEAR_ZOOM_LIMIT && zoomFactor + adjustment > FAR_ZOOM_LIMIT) {
|
||||
zoomFactor = zoomFactor + adjustment;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the Vertical Panning of the Camera
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustVerticalPan(Double adjustment) {
|
||||
if (verticalPan + adjustment >= -PAN_LIMIT && verticalPan + adjustment <= PAN_LIMIT) {
|
||||
verticalPan += adjustment;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the Horizontal Panning of the Camera.
|
||||
* @param adjustment the adjustment to be made to the camera
|
||||
*/
|
||||
private void adjustHorizontalPan(Double adjustment) {
|
||||
if (horizontalPan + adjustment >= -PAN_LIMIT && horizontalPan + adjustment <= PAN_LIMIT) {
|
||||
horizontalPan += adjustment;
|
||||
updateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomIn() {
|
||||
adjustZoomFactor(ZOOM_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomOut() {
|
||||
adjustZoomFactor(-ZOOM_STEP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panLeft() {
|
||||
adjustHorizontalPan(-1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panRight() {
|
||||
adjustHorizontalPan(1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panUp() {
|
||||
adjustVerticalPan(-1.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panDown() {
|
||||
adjustVerticalPan(1.0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import seng302.utilities.BonjourInstallChecker;
|
||||
import seng302.utilities.Sounds;
|
||||
import seng302.visualiser.GameClient;
|
||||
import seng302.visualiser.controllers.dialogs.KeyBindingDialogController;
|
||||
import seng302.visualiser.controllers.dialogs.PopupDialogController;
|
||||
|
||||
public class ViewManager {
|
||||
|
||||
@@ -220,6 +221,7 @@ public class ViewManager {
|
||||
.getController();
|
||||
keyBindingDialogController.setGameClient(this.gameClient);
|
||||
keyBindingDialog.show();
|
||||
decorator.requestFocus();
|
||||
Sounds.playButtonClick();
|
||||
}
|
||||
}
|
||||
@@ -229,6 +231,26 @@ public class ViewManager {
|
||||
keyBindingDialog.close();
|
||||
}
|
||||
|
||||
public PopupDialogController showPopupDialog() {
|
||||
FXMLLoader dialogContent = new FXMLLoader(
|
||||
getClass().getResource("/views/dialogs/PopupDialog.fxml"));
|
||||
for (Node node : decorator.getChildren()) {
|
||||
if (node instanceof StackPane) {
|
||||
try {
|
||||
JFXDialog dialog = new JFXDialog((StackPane) node, dialogContent.load(),
|
||||
DialogTransition.CENTER);
|
||||
PopupDialogController popupDialogController = dialogContent.getController();
|
||||
popupDialogController.setPopupDialog(dialog);
|
||||
dialog.show();
|
||||
return popupDialogController;
|
||||
} catch (IOException e) {
|
||||
logger.error("Cannot load Popup dialog");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a snackbar at the bottom of the app for 1 second.
|
||||
*
|
||||
|
||||
+14
-5
@@ -48,6 +48,16 @@ public class KeyBindingDialogController implements Initializable {
|
||||
private Label downwindLabel;
|
||||
@FXML
|
||||
private JFXToggleButton turningToggle;
|
||||
@FXML
|
||||
private JFXButton viewButton;
|
||||
@FXML
|
||||
private JFXButton rightButton;
|
||||
@FXML
|
||||
private JFXButton leftButton;
|
||||
@FXML
|
||||
private JFXButton forwardButton;
|
||||
@FXML
|
||||
private JFXButton backwardButton;
|
||||
//---------FXML END---------//
|
||||
|
||||
private GameKeyBind gameKeyBind;
|
||||
@@ -60,7 +70,8 @@ public class KeyBindingDialogController implements Initializable {
|
||||
gameKeyBind = GameKeyBind.getInstance();
|
||||
buttons = new ArrayList<>();
|
||||
Collections.addAll(buttons,
|
||||
zoomInbtn, zoomOutBtn, vmgBtn, sailInOutBtn, tackGybeBtn, upwindBtn, downwindBtn);
|
||||
zoomInbtn, zoomOutBtn, vmgBtn, sailInOutBtn, tackGybeBtn, upwindBtn, downwindBtn,
|
||||
viewButton, rightButton, leftButton, forwardButton, backwardButton);
|
||||
bindButtonWithAction();
|
||||
loadKeyBind();
|
||||
|
||||
@@ -79,9 +90,6 @@ public class KeyBindingDialogController implements Initializable {
|
||||
});
|
||||
|
||||
closeLabel.setOnMouseClicked(event -> ViewManager.getInstance().closeKeyBindingDialog());
|
||||
|
||||
keyBindingDialogHeader.setFocusTraversable(true);
|
||||
keyBindingDialogHeader.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +114,7 @@ public class KeyBindingDialogController implements Initializable {
|
||||
*/
|
||||
private void bindButtonWithAction() {
|
||||
buttonActionMap = new HashMap<>();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
buttonActionMap.put(buttons.get(i), KeyAction.getType(i + 1));
|
||||
}
|
||||
}
|
||||
@@ -149,6 +157,7 @@ public class KeyBindingDialogController implements Initializable {
|
||||
+ "-fx-background-color: -fx-pp-front-color; "
|
||||
+ "-fx-text-fill: -fx-pp-theme-color; "
|
||||
+ "-fx-font-size: 13;");
|
||||
keyBindingDialogHeader.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package seng302.visualiser.controllers.dialogs;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDialog;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
|
||||
public class PopupDialogController implements Initializable {
|
||||
|
||||
@FXML
|
||||
private Label headerLabel;
|
||||
@FXML
|
||||
private Label contentLabel;
|
||||
@FXML
|
||||
private Label closeLabel;
|
||||
@FXML
|
||||
private JFXButton optionButton;
|
||||
|
||||
@FXML
|
||||
private JFXDialog popupDialog;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.contentLabel.setText(content);
|
||||
}
|
||||
|
||||
public void setHeader(String header) {
|
||||
this.headerLabel.setText(header);
|
||||
}
|
||||
|
||||
public void setOptionButton(JFXButton jfxButton) {
|
||||
this.optionButton = jfxButton;
|
||||
}
|
||||
|
||||
public void setOptionButtonText(String text) {
|
||||
this.optionButton.setText(text);
|
||||
}
|
||||
|
||||
public void setOptionButtonEventHandler(EventHandler<? super MouseEvent> eventHandler) {
|
||||
this.optionButton.setOnMouseClicked(eventHandler);
|
||||
}
|
||||
|
||||
public void setPopupDialog(JFXDialog popupDialog) {
|
||||
this.popupDialog = popupDialog;
|
||||
this.closeLabel.setOnMouseClicked(event -> this.popupDialog.close());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package seng302.visualiser.fxObjects.assets_3D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
@@ -30,12 +31,15 @@ public class BoatObject extends Group {
|
||||
private Boolean isSelected = false;
|
||||
private Rotate rotation = new Rotate(0, new Point3D(0,0,1));
|
||||
|
||||
private ReadOnlyDoubleWrapper rotationProperty;
|
||||
|
||||
private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a BoatGroup with the default triangular boat polygon.
|
||||
*/
|
||||
public BoatObject(BoatMeshType boatMeshType) {
|
||||
rotationProperty = new ReadOnlyDoubleWrapper(0.0);
|
||||
boatAssets = ModelFactory.boatGameView(boatMeshType, colour);
|
||||
boatAssets.hideSail();
|
||||
boatAssets.getAssets().getTransforms().addAll(
|
||||
@@ -83,6 +87,7 @@ public class BoatObject extends Group {
|
||||
|
||||
|
||||
private void rotateTo(double heading, boolean sailsIn, double windDir) {
|
||||
rotationProperty.set(heading);
|
||||
rotation.setAngle(heading);
|
||||
wake.getTransforms().setAll(new Rotate(heading, new Point3D(0,0,1)));
|
||||
if (sailsIn) {
|
||||
@@ -130,4 +135,8 @@ public class BoatObject extends Group {
|
||||
public void addSelectedBoatListener(SelectedBoatListener sbl) {
|
||||
selectedBoatListenerListeners.add(sbl);
|
||||
}
|
||||
|
||||
public ReadOnlyDoubleWrapper getRotationProperty() {
|
||||
return rotationProperty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user