experimenting with map scaling

#implement
This commit is contained in:
Calum
2017-09-25 22:57:45 +13:00
parent 35b50d1436
commit c12f7408ad
5 changed files with 55 additions and 25 deletions
@@ -48,7 +48,7 @@ public class ClientToServerThread implements Runnable {
@FunctionalInterface @FunctionalInterface
public interface DisconnectedFromHostListener { public interface DisconnectedFromHostListener {
void notifYDisconnection (String message); void notifyDisconnection(String message);
} }
private class ByteReadException extends Exception { private class ByteReadException extends Exception {
@@ -170,7 +170,7 @@ public class ClientToServerThread implements Runnable {
private void notifyDisconnectListeners (String message) { private void notifyDisconnectListeners (String message) {
if (socketOpen) { if (socketOpen) {
for (DisconnectedFromHostListener listener : disconnectionListeners) { for (DisconnectedFromHostListener listener : disconnectionListeners) {
listener.notifYDisconnection(message); listener.notifyDisconnection(message);
} }
} }
} }
+25 -6
View File
@@ -1,6 +1,7 @@
package seng302.visualiser; package seng302.visualiser;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.*; import javafx.scene.*;
@@ -54,6 +55,8 @@ public class GameView extends Pane {
private List<CompoundMark> compoundMarks = new ArrayList<>(); private List<CompoundMark> compoundMarks = new ArrayList<>();
private List<Corner> courseOrder = new ArrayList<>(); private List<Corner> courseOrder = new ArrayList<>();
private ChangeListener<? super Number> heightChangeListener;
private ImageView mapImage = new ImageView(); private ImageView mapImage = new ImageView();
private enum ScaleDirection { private enum ScaleDirection {
@@ -70,14 +73,30 @@ public class GameView extends Pane {
gameObjects = this.getChildren(); gameObjects = this.getChildren();
gameObjects.addAll(mapImage, raceBorder, markers, tokens); gameObjects.addAll(mapImage, raceBorder, markers, tokens);
this.parentProperty().addListener((obs, old, parent) -> { this.parentProperty().addListener((obs, old, parent) -> {
if (old != null) {
((Pane) old).heightProperty().removeListener(heightChangeListener);
}
if (parent != null) { if (parent != null) {
canvasWidth = parent.prefWidth(1) * 1.5; heightChangeListener = (observableValue, oldHeight, newHeight) -> {
canvasHeight = parent.prefHeight(1) * 1.5; 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); // rescaleRace(borderPoints);
System.out.println("parent = " + parent.maxWidth(100)); // System.out.println("parent = " + parent.maxWidth(100));
System.out.println("parent.minWidth(1) = " + parent.minWidth(100)); // System.out.println("parent.minWidth(1) = " + parent.minWidth(100));
System.out.println(canvasWidth); // System.out.println(canvasWidth);
System.out.println(canvasHeight); // 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 / 2, canvasHeight / 2, 7, Color.GREENYELLOW));
this.getChildren().add(new Circle(canvasWidth, canvasHeight, 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(0,0, 7, Color.GREENYELLOW));
@@ -2,6 +2,12 @@ package seng302.visualiser.controllers;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialog; import com.jfoenix.controls.JFXDialog;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@@ -9,7 +15,7 @@ import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
@@ -27,13 +33,6 @@ import seng302.visualiser.GameView;
import seng302.visualiser.controllers.cells.PlayerCell; import seng302.visualiser.controllers.cells.PlayerCell;
import seng302.visualiser.controllers.dialogs.BoatCustomizeController; import seng302.visualiser.controllers.dialogs.BoatCustomizeController;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
public class LobbyController implements Initializable { public class LobbyController implements Initializable {
//--------FXML BEGIN--------// //--------FXML BEGIN--------//
@@ -50,7 +49,7 @@ public class LobbyController implements Initializable {
@FXML @FXML
private Label mapName; private Label mapName;
@FXML @FXML
private Pane serverMap; private AnchorPane serverMap;
//---------FXML END---------// //---------FXML END---------//
private RaceState raceState; private RaceState raceState;
@@ -105,7 +104,16 @@ public class LobbyController implements Initializable {
leaveLobbyButton.setOnMouseEntered(e -> Sounds.playHoverSound()); leaveLobbyButton.setOnMouseEntered(e -> Sounds.playHoverSound());
customizeButton.setOnMouseEntered(e -> Sounds.playHoverSound()); customizeButton.setOnMouseEntered(e -> Sounds.playHoverSound());
beginRaceButton.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(); initMapPreview();
} }
+9 -6
View File
@@ -5,9 +5,9 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?> <?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
@@ -78,11 +78,14 @@
<Insets bottom="15.0" left="7.0" right="15.0" top="15.0" /> <Insets bottom="15.0" left="7.0" right="15.0" top="15.0" />
</GridPane.margin> </GridPane.margin>
</ScrollPane> </ScrollPane>
<Pane fx:id="serverMap" prefHeight="370.0" prefWidth="0.0" style="-fx-background-color: skyblue;"> <AnchorPane fx:id="serverMap" prefHeight="370.0" prefWidth="478.0" style="-fx-background-color: skyblue;">
<GridPane.margin> <opaqueInsets>
<Insets bottom="15.0" left="15.0" right="7.0" top="15.0" /> <Insets />
</GridPane.margin> </opaqueInsets>
</Pane> <GridPane.margin>
<Insets bottom="15.0" left="15.0" right="7.0" top="15.0" />
</GridPane.margin>
</AnchorPane>
</children> </children>
</GridPane> </GridPane>
</children> </children>
@@ -153,7 +153,7 @@
</rowConstraints> </rowConstraints>
<children> <children>
<Label fx:id="mapNameLabel" text="MAP NAME" GridPane.halignment="CENTER" /> <Label fx:id="mapNameLabel" text="MAP NAME" GridPane.halignment="CENTER" />
<AnchorPane fx:id="mapHolder" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1" /> <AnchorPane fx:id="mapHolder" prefHeight="333.0" prefWidth="404.0" GridPane.rowIndex="1" />
</children> </children>
</GridPane> </GridPane>
</children> </children>