mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
fixed being able to zoom while chatting by holding shift and then pressing z and x #story[1246]
This commit is contained in:
@@ -64,6 +64,7 @@ public class GameView extends Pane {
|
||||
private double metersPerPixelX, metersPerPixelY;
|
||||
|
||||
final double SCALE_DELTA = 1.1;
|
||||
private boolean isZoom = false;
|
||||
|
||||
private Text fpsDisplay = new Text();
|
||||
private Polygon raceBorder = new CourseBoundary();
|
||||
@@ -101,7 +102,7 @@ public class GameView extends Pane {
|
||||
|
||||
private void zoomOut() {
|
||||
scaleFactor = 0.1;
|
||||
if (this.getScaleX() > 0.5) {
|
||||
if (this.isZoom && this.getScaleX() > 0.5) {
|
||||
this.setScaleX(this.getScaleX() - scaleFactor);
|
||||
this.setScaleY(this.getScaleY() - scaleFactor);
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public class GameView extends Pane {
|
||||
|
||||
private void zoomIn() {
|
||||
scaleFactor = 0.10;
|
||||
if (this.getScaleX() < 2.5) {
|
||||
if (this.isZoom && this.getScaleX() < 2.5) {
|
||||
this.setScaleX(this.getScaleX() + scaleFactor);
|
||||
this.setScaleY(this.getScaleY() + scaleFactor);
|
||||
}
|
||||
@@ -142,6 +143,13 @@ public class GameView extends Pane {
|
||||
gameObjects.add(raceBorder);
|
||||
gameObjects.add(markers);
|
||||
initializeTimer();
|
||||
this.sceneProperty().addListener(((observable, oldValue, scene) -> {
|
||||
if (scene != null) {
|
||||
setupZoom();
|
||||
} else {
|
||||
disableZoom();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void initializeTimer() {
|
||||
@@ -439,8 +447,7 @@ public class GameView extends Pane {
|
||||
/**
|
||||
* Enables zoom. Has to be called after this is added to a scene.
|
||||
*/
|
||||
public void enableZoom () {
|
||||
if (this.getScene() != null) {
|
||||
private void setupZoom() {
|
||||
this.getScene().addEventHandler(KeyEvent.KEY_PRESSED, (event) -> {
|
||||
if (event.getCode() == KeyCode.Z) {
|
||||
zoomIn();
|
||||
@@ -448,8 +455,17 @@ public class GameView extends Pane {
|
||||
zoomOut();
|
||||
}
|
||||
});
|
||||
enableZoom();
|
||||
}
|
||||
|
||||
public void enableZoom() {
|
||||
isZoom = true;
|
||||
}
|
||||
|
||||
public void disableZoom() {
|
||||
isZoom = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rescales the race to the size of the window.
|
||||
*
|
||||
|
||||
@@ -160,7 +160,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
gameView.updateCourse(
|
||||
new ArrayList<>(raceData.getCompoundMarks().values()), raceData.getMarkSequence()
|
||||
);
|
||||
gameView.enableZoom();
|
||||
gameView.setBoatAsPlayer(player);
|
||||
gameView.startRace();
|
||||
|
||||
@@ -175,6 +174,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
updateWindDirection(raceState.windDirectionProperty().doubleValue());
|
||||
updateWindSpeed(raceState.getWindSpeed());
|
||||
gameView.setWindDir(raceState.windDirectionProperty().doubleValue());
|
||||
chatInput.focusedProperty().addListener((obs, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
gameView.disableZoom();
|
||||
} else {
|
||||
gameView.enableZoom();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user