parent
6ae23f039b
commit
83ac3e4e33
@ -1,7 +0,0 @@
|
|||||||
package seng302.Controllers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controller for the main window fxml of the Game Controller
|
|
||||||
*/
|
|
||||||
public class MainWindowController {
|
|
||||||
}
|
|
||||||
@ -1,101 +0,0 @@
|
|||||||
package seng302;
|
|
||||||
|
|
||||||
import javafx.animation.AnimationTimer;
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entry point for the controller side of the application
|
|
||||||
*/
|
|
||||||
public class Main extends Application {
|
|
||||||
//holds a boolean state for each important key to show if pressed down or not
|
|
||||||
private HashMap<String, Boolean> currentlyActiveKeys = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entry point for running the programme
|
|
||||||
*
|
|
||||||
* @param args for starting the programme
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage stage) {
|
|
||||||
try {
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("mainWindow.fxml"));
|
|
||||||
Parent root = loader.load();
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 200, 100);
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.setTitle("Controller");
|
|
||||||
|
|
||||||
scene.setOnKeyPressed(event -> {
|
|
||||||
String codeString = event.getCode().toString();
|
|
||||||
if (!currentlyActiveKeys.containsKey(codeString)) {
|
|
||||||
currentlyActiveKeys.put(codeString, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
scene.setOnKeyReleased(event ->
|
|
||||||
currentlyActiveKeys.remove(event.getCode().toString())
|
|
||||||
);
|
|
||||||
|
|
||||||
new AnimationTimer() {
|
|
||||||
@Override
|
|
||||||
public void handle(long now) {
|
|
||||||
if (removeActiveKey("Z")) {
|
|
||||||
System.out.println("zoom in");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeActiveKey("X")) {
|
|
||||||
System.out.println("zoom out");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeActiveKey("SPACE")) {
|
|
||||||
System.out.println("VMG");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeActiveKey("SHIFT")) {
|
|
||||||
System.out.println("sails in/out");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeActiveKey("Enter")) {
|
|
||||||
System.out.println("tack/gybe");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeActiveKey("PAGE_UP")) {
|
|
||||||
System.out.println("up wind");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removeActiveKey("PAGE_DOWN")) {
|
|
||||||
System.out.println("down wind");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
|
|
||||||
stage.show();
|
|
||||||
} catch (IOException e) {
|
|
||||||
//Catch all exceptions, print, and exit.
|
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean removeActiveKey(String codeString) {
|
|
||||||
Boolean isActive = currentlyActiveKeys.get(codeString);
|
|
||||||
|
|
||||||
if (isActive != null && isActive) {
|
|
||||||
currentlyActiveKeys.put(codeString, false);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.layout.BorderPane?>
|
|
||||||
<?import javafx.scene.text.Text?>
|
|
||||||
|
|
||||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.MainWindowController">
|
|
||||||
<center>
|
|
||||||
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Controller Is running" BorderPane.alignment="CENTER" />
|
|
||||||
</center>
|
|
||||||
</BorderPane>
|
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import javafx.animation.AnimationTimer;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for checking what keys are currently being used
|
||||||
|
*/
|
||||||
|
public class InputChecker {
|
||||||
|
private HashMap<String, Boolean> currentlyActiveKeys = new HashMap<>();
|
||||||
|
|
||||||
|
public void runWithScene(Scene scene){
|
||||||
|
scene.setOnKeyPressed(event -> {
|
||||||
|
String codeString = event.getCode().toString();
|
||||||
|
if (!currentlyActiveKeys.containsKey(codeString)) {
|
||||||
|
currentlyActiveKeys.put(codeString, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
scene.setOnKeyReleased(event ->
|
||||||
|
currentlyActiveKeys.remove(event.getCode().toString())
|
||||||
|
);
|
||||||
|
|
||||||
|
new AnimationTimer() {
|
||||||
|
@Override
|
||||||
|
public void handle(long now) {
|
||||||
|
for (String key : InputKeys.listOfKeys){
|
||||||
|
if (removeActiveKey(key)) {
|
||||||
|
System.out.println(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeActiveKey(String codeString) {
|
||||||
|
Boolean isActive = currentlyActiveKeys.get(codeString);
|
||||||
|
|
||||||
|
if (isActive != null && isActive) {
|
||||||
|
currentlyActiveKeys.put(codeString, false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to store the basic keys used by this controller
|
||||||
|
*/
|
||||||
|
public class InputKeys {
|
||||||
|
protected static String zoomIn = "Z";
|
||||||
|
protected static String zoomOut = "X";
|
||||||
|
protected static String vmg = "SPACE";
|
||||||
|
protected static String sailsToggle = "SHIFT";
|
||||||
|
protected static String tackGybe = "Enter";
|
||||||
|
protected static String upWind = "PAGE_UP";
|
||||||
|
protected static String downWind = "Page_Down";
|
||||||
|
|
||||||
|
protected static List<String> listOfKeys = Arrays.asList(zoomIn, zoomOut, vmg,
|
||||||
|
sailsToggle, tackGybe, upWind, downWind);
|
||||||
|
}
|
||||||
Loading…
Reference in new issue