Researched and implemented a way for the game to listen for key presses. When one of the valid key controls are pressed, feedback is given in the console. Has yet to be connected to a method which will create and send a message to the server.

#pair[kre39,zyt10] #story[988]
This commit is contained in:
Kusal Ekanayake
2017-07-11 16:32:15 +12:00
parent ba761e4951
commit ef61a687d6
5 changed files with 49 additions and 5 deletions
@@ -8,6 +8,7 @@ import javafx.scene.Group;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
@@ -109,6 +110,7 @@ public class CanvasController {
// Bind canvas size to stack pane size.
canvas.widthProperty().bind(new SimpleDoubleProperty(CANVAS_WIDTH));
canvas.heightProperty().bind(new SimpleDoubleProperty(CANVAS_HEIGHT));
}
public void initializeCanvas (){
@@ -525,4 +527,5 @@ public class CanvasController {
List<MarkGroup> getMarkGroups() {
return markGroups;
}
}
@@ -1,8 +1,11 @@
package seng302.controllers;
import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
@@ -35,5 +38,39 @@ public class Controller implements Initializable {
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
setContentPane("/views/StartScreenView.fxml");
StreamParser.boatLocations.clear();
}
/** Handle the key-pressed event from the text field. */
public void keyPressed(KeyEvent e) {
switch (e.getCode()){
case SPACE: // align with vmg
System.out.println("Key pressed = space");
break;
case PAGE_UP: // upwind
System.out.println("Key pressed = page up");
break;
case PAGE_DOWN: // downwind
System.out.println("Key pressed = page down");
break;
case ENTER: // tack/gybe
System.out.println("Key pressed = enter");
break;
case Z: // zoom in
System.out.println("Key pressed = z");
break;
case X: // zoom out
System.out.println("Key pressed = x");
break;
}
}
public void keyReleased(KeyEvent e) {
switch (e.getCode()) {
case SHIFT: // sails in/sails out
System.out.println("Key pressed = shift");
break;
}
}
}
@@ -4,6 +4,7 @@ import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Point2D;
@@ -16,6 +17,7 @@ import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
@@ -103,6 +105,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
initialiseBoatSelectionComboBox();
includedCanvasController.timer.start();
selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
}
@@ -136,7 +139,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
Scene scene = new Scene(fxmlLoader.load(), 469, 298);
scene.getStylesheets().add(getClass().getResource("/css/master.css").toString());
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
stage.show();
@@ -637,4 +639,5 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
public static boolean sparkLineStatus(Integer yachtId) {
return sparkLineData.containsKey(yachtId);
}
}