Merge remote-tracking branch 'remotes/origin/master' into story77
# Conflicts: # racevisionGame/src/main/java/shared/model/Constants.java # racevisionGame/src/main/java/visualiser/Controllers/HostController.java # racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml
This commit is contained in:
@@ -1,16 +1,31 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.Stage;
|
||||
import mock.app.Event;
|
||||
import org.xml.sax.SAXException;
|
||||
import mock.exceptions.EventConstructionException;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
import shared.exceptions.InvalidRegattaDataException;
|
||||
import shared.exceptions.XMLReaderException;
|
||||
import visualiser.network.MatchBrowserInterface;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -30,21 +45,39 @@ public class HostController extends Controller {
|
||||
@FXML
|
||||
AnchorPane hostWrapper;
|
||||
|
||||
@FXML
|
||||
Button previousButton;
|
||||
|
||||
@FXML
|
||||
Button nextButton;
|
||||
|
||||
@FXML
|
||||
ImageView mapImage;
|
||||
|
||||
private Event game;
|
||||
private DatagramSocket udpSocket;
|
||||
|
||||
private ArrayList<Image> listOfMaps;
|
||||
private int currentMapIndex = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
Image ac35Map = new Image(getClass().getClassLoader().getResourceAsStream("images/AC35_Racecourse_MAP.png"));
|
||||
Image oMap = new Image(getClass().getClassLoader().getResourceAsStream("images/oMapLayout.png"));
|
||||
Image iMap = new Image(getClass().getClassLoader().getResourceAsStream("images/iMapLayout.png"));
|
||||
Image mMap = new Image(getClass().getClassLoader().getResourceAsStream("images/mMapLayout.png"));
|
||||
|
||||
listOfMaps = new ArrayList(Arrays.asList(ac35Map, oMap, iMap, mMap));
|
||||
mapImage.setImage(listOfMaps.get(currentMapIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosts a game
|
||||
* @throws IOException if socket cannot be connected to
|
||||
*/
|
||||
public void hostGamePressed() throws IOException{
|
||||
public void hostGamePressed() {
|
||||
try {
|
||||
this.game = new Event(false);
|
||||
this.game = new Event(false, currentMapIndex);
|
||||
connectSocket("localhost", 4942);
|
||||
alertMatchBrowser();
|
||||
} catch (EventConstructionException e) {
|
||||
@@ -90,6 +123,7 @@ public class HostController extends Controller {
|
||||
* Hosts a game.
|
||||
*/
|
||||
public void hostGame(DatagramSocket udpSocket){
|
||||
mapImage.fitWidthProperty().bind(((Stage) mapImage.getScene().getWindow()).widthProperty().multiply(0.6));
|
||||
hostWrapper.setVisible(true);
|
||||
this.udpSocket = udpSocket;
|
||||
}
|
||||
@@ -99,4 +133,27 @@ public class HostController extends Controller {
|
||||
parent.enterTitle();
|
||||
}
|
||||
|
||||
public void nextImage(){
|
||||
increaseIndex();
|
||||
mapImage.setImage(listOfMaps.get(currentMapIndex));
|
||||
}
|
||||
|
||||
public void previousImage(){
|
||||
decreaseIndex();
|
||||
mapImage.setImage(listOfMaps.get(currentMapIndex));
|
||||
}
|
||||
private void increaseIndex(){
|
||||
currentMapIndex = (currentMapIndex + 1)%listOfMaps.size();
|
||||
}
|
||||
|
||||
private void decreaseIndex(){
|
||||
currentMapIndex = ((((currentMapIndex - 1)%listOfMaps.size())+listOfMaps.size())%listOfMaps.size());
|
||||
}
|
||||
|
||||
public void setGameType(int gameType){
|
||||
this.currentMapIndex = gameType;
|
||||
}
|
||||
|
||||
public int getGameType(){ return this.currentMapIndex; }
|
||||
|
||||
}
|
||||
|
||||
@@ -107,6 +107,20 @@ public class MainController extends Controller {
|
||||
*/
|
||||
public void startCss(){titleController.setDayMode();}
|
||||
|
||||
/**
|
||||
* host controller host a game
|
||||
* @throws IOException throws exception
|
||||
*/
|
||||
public void beginGame() throws IOException {
|
||||
hostController.hostGamePressed();
|
||||
}
|
||||
|
||||
public void setGameType(int gameType){
|
||||
hostController.setGameType(gameType);
|
||||
}
|
||||
|
||||
public int getGameType(){ return hostController.getGameType(); }
|
||||
|
||||
/**
|
||||
* Main Controller for the applications will house the menu and the displayed pane.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,7 @@ import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.shape.MeshView;
|
||||
@@ -24,9 +24,9 @@ import shared.dataInput.RaceDataSource;
|
||||
import shared.model.Leg;
|
||||
import shared.model.Mark;
|
||||
import visualiser.app.App;
|
||||
import visualiser.enums.TutorialState;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
import visualiser.layout.Subject3D;
|
||||
import visualiser.layout.View3D;
|
||||
import visualiser.model.*;
|
||||
@@ -34,8 +34,7 @@ import visualiser.utils.GPSConverter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -58,6 +57,15 @@ public class RaceController extends Controller {
|
||||
|
||||
private boolean isHost;
|
||||
|
||||
private TutorialState currentState;
|
||||
|
||||
private ArrayList<TutorialState> tutorialStates;
|
||||
|
||||
private boolean isTutorial = false;
|
||||
|
||||
private String keyToPress;
|
||||
|
||||
|
||||
/**
|
||||
* state of the info table
|
||||
*/
|
||||
@@ -75,6 +83,9 @@ public class RaceController extends Controller {
|
||||
|
||||
@FXML private SplitPane racePane;
|
||||
|
||||
@FXML private Label tutorialText;
|
||||
|
||||
|
||||
/**
|
||||
* This is the pane we place the actual arrow control inside of.
|
||||
*/
|
||||
@@ -110,13 +121,27 @@ public class RaceController extends Controller {
|
||||
if(controlKey != null) {
|
||||
try {
|
||||
controlKey.onAction(); // Change key state if applicable
|
||||
|
||||
//Check if current race is a tutorial
|
||||
if (isTutorial){
|
||||
//Check if current tutorial state has the same boat protocol code as key press
|
||||
if (controlKey.getProtocolCode().equals(currentState.getAction())){
|
||||
//Update tutorial
|
||||
checkTutorialState();
|
||||
}
|
||||
}
|
||||
|
||||
controllerClient.sendKey(controlKey);
|
||||
event.consume();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
Logger.getGlobal().log(Level.WARNING, "RaceController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(event.getCode() == KeyCode.ESCAPE) {
|
||||
|
||||
try {
|
||||
@@ -189,6 +214,7 @@ public class RaceController extends Controller {
|
||||
view3D.setYaw(0);
|
||||
view3D.setPitch(60);
|
||||
view3D.enableTracking();
|
||||
//newPane.getChildren().add(view3D);
|
||||
canvasBase.add(view3D, 0, 0);
|
||||
|
||||
// Set up projection from GPS to view
|
||||
@@ -235,9 +261,33 @@ public class RaceController extends Controller {
|
||||
if(key != null) {
|
||||
switch (key.toString()) {
|
||||
case "Zoom In":
|
||||
//Check if race is a tutorial
|
||||
if (isTutorial) {
|
||||
//Check if the current tutorial state is zoom-in
|
||||
if (currentState.equals(TutorialState.ZOOMIN)) {
|
||||
try {
|
||||
//Update tutorial
|
||||
checkTutorialState();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
view3D.updateDistance(-10);
|
||||
break;
|
||||
case "Zoom Out":
|
||||
//Check if race is a tutorial
|
||||
if(isTutorial) {
|
||||
//Check if current tutorial state is zoom-out
|
||||
if (currentState.equals(TutorialState.ZOOMOUT)) {
|
||||
try {
|
||||
//Update tutorial
|
||||
checkTutorialState();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
view3D.updateDistance(10);
|
||||
break;
|
||||
}
|
||||
@@ -246,6 +296,8 @@ public class RaceController extends Controller {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialises the frame rate functionality. This allows for toggling the frame rate, and connect the fps label to the race's fps property.
|
||||
* @param visualiserRace The race to connect the fps label to.
|
||||
@@ -422,6 +474,25 @@ public class RaceController extends Controller {
|
||||
this.controllerClient = controllerClient;
|
||||
this.isHost = isHost;
|
||||
|
||||
|
||||
//Check if the game is a tutorial
|
||||
if (parent.getGameType()==4){
|
||||
isTutorial = true;
|
||||
tutorialText.setVisible(true);
|
||||
tutorialStates = new ArrayList<>(Arrays.asList(TutorialState.values()));
|
||||
|
||||
currentState = tutorialStates.get(0);
|
||||
tutorialStates.remove(0);
|
||||
|
||||
searchMapForKey("Upwind");
|
||||
|
||||
tutorialText.setText("Welcome to the tutorial! Exit at anytime with ESC. \nWe will first learn how to turn upwind. Press " + keyToPress + " to turn upwind.");
|
||||
|
||||
} else {
|
||||
isTutorial = false;
|
||||
tutorialText.setVisible(false);
|
||||
}
|
||||
|
||||
initialiseRace();
|
||||
|
||||
//Display this controller.
|
||||
@@ -519,4 +590,108 @@ public class RaceController extends Controller {
|
||||
infoTableShow = !infoTableShow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next tutorial state
|
||||
*/
|
||||
private void updateTutorialState(){
|
||||
//Next tutorial state is popped from list
|
||||
currentState = tutorialStates.get(0);
|
||||
tutorialStates.remove(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search key map for key given string of command
|
||||
* @param command the command of the key
|
||||
*/
|
||||
private void searchMapForKey(String command){
|
||||
//For loop through keyFactory
|
||||
for (Map.Entry<String, ControlKey> entry: keyFactory.getKeyState().entrySet()){
|
||||
if(entry.getValue().toString().equals(command)){
|
||||
|
||||
//Found next key required to press
|
||||
keyToPress = entry.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates tutorial state and gui display for tutorial text
|
||||
* @throws Exception Exception thrown
|
||||
*/
|
||||
private void checkTutorialState() throws Exception {
|
||||
//Switch statement to check what the current tutorial state is
|
||||
switch (currentState){
|
||||
case UPWIND:
|
||||
//Set next key to press as the downwind key
|
||||
searchMapForKey("Downwind");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! To turn downwind press " + keyToPress + ".");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case DOWNWIND:
|
||||
//Set next key to press as the tack/gybe key
|
||||
searchMapForKey("Tack/Gybe");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! To tack or gybe press " + keyToPress + ".");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case TACKGYBE:
|
||||
//Set next key to press as the VMG key
|
||||
searchMapForKey("VMG");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! To use VMG press " + keyToPress + ". This will turn the boat.");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case VMG:
|
||||
//Set next key to press as the sails-in key
|
||||
searchMapForKey("Toggle Sails");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! To sails in press " + keyToPress + ". This will stop the boat.");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case SAILSIN:
|
||||
//Set next key to press as the sails-out key
|
||||
searchMapForKey("Toggle Sails");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! To sails out press " + keyToPress + " again. The will start moving again.");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case SAILSOUT:
|
||||
//Set next key to press as the zoom-in key
|
||||
searchMapForKey("Zoom In");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! To zoom in press " + keyToPress + ".");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case ZOOMIN:
|
||||
//Set next key to press as the zoom-out key
|
||||
searchMapForKey("Zoom Out");
|
||||
//Update tutorial text
|
||||
tutorialText.setText("Nice! You will also be able to zoom into boats and marks by clicking them. To zoom out press " + keyToPress + ".");
|
||||
updateTutorialState();
|
||||
break;
|
||||
case ZOOMOUT:
|
||||
//Finished tutorial. Display pop-up for exiting the tutorial
|
||||
tutorialText.setText("Congratulations! You're done!");
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle("Finished Tutorial");
|
||||
alert.setHeaderText("You have finished the tutorial.");
|
||||
alert.setContentText("Now you know the controls you are ready to race!");
|
||||
Optional<ButtonType> result = alert.showAndWait();
|
||||
if (result.get() == ButtonType.OK) {
|
||||
parent.endEvent();
|
||||
racePane.setVisible(false);
|
||||
App.app.showMainStage(App.getStage());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//State not found. Exit tutorial to title menu
|
||||
parent.endEvent();
|
||||
racePane.setVisible(false);
|
||||
App.app.showMainStage(App.getStage());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -86,9 +86,6 @@ public class StartController extends Controller {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Ctor.
|
||||
*/
|
||||
@@ -218,29 +215,30 @@ public class StartController extends Controller {
|
||||
* Countdown timer until race starts.
|
||||
*/
|
||||
private void countdownTimer() {
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
|
||||
//Get the current race status.
|
||||
RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum();
|
||||
//Get the current race status.
|
||||
RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum();
|
||||
|
||||
//If the race has reached the preparatory phase, or has started...
|
||||
if (raceStatus == RaceStatusEnum.WARNING
|
||||
|| raceStatus == RaceStatusEnum.PREPARATORY
|
||||
|| raceStatus == RaceStatusEnum.STARTED) {
|
||||
//Stop this timer.
|
||||
stop();
|
||||
//If the race has reached the preparatory phase, or has started...
|
||||
if (raceStatus == RaceStatusEnum.WARNING
|
||||
|| raceStatus == RaceStatusEnum.PREPARATORY
|
||||
|| raceStatus == RaceStatusEnum.STARTED) {
|
||||
//Stop this timer.
|
||||
stop();
|
||||
|
||||
//Hide this, and display the race controller.
|
||||
startWrapper.setVisible(false);
|
||||
//start.setVisible(false);//TODO is this needed?
|
||||
//Hide this, and display the race controller.
|
||||
startWrapper.setVisible(false);
|
||||
//start.setVisible(false);//TODO is this needed?
|
||||
|
||||
parent.beginRace(visualiserRaceEvent, controllerClient, isHost);
|
||||
parent.beginRace(visualiserRaceEvent, controllerClient, isHost);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,16 +6,24 @@ import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.RadioButton;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import mock.app.Event;
|
||||
import mock.exceptions.EventConstructionException;
|
||||
import javafx.stage.WindowEvent;
|
||||
import visualiser.app.App;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Controller for the opening title window.
|
||||
@@ -33,6 +41,12 @@ public class TitleController extends Controller {
|
||||
RadioButton dayModeRD;
|
||||
@FXML
|
||||
RadioButton nightModeRD;
|
||||
@FXML
|
||||
Label tutorialLabel;
|
||||
@FXML
|
||||
Pane menuPane;
|
||||
@FXML
|
||||
ImageView imgSun;
|
||||
|
||||
/**
|
||||
* Method called when the 'host a game' button is pressed.
|
||||
@@ -42,6 +56,7 @@ public class TitleController extends Controller {
|
||||
*/
|
||||
public void hostAGame() throws IOException {
|
||||
titleWrapper.setVisible(false);
|
||||
parent.setGameType(0);
|
||||
parent.hostGame();
|
||||
App.getStage().setResizable(true);
|
||||
}
|
||||
@@ -68,7 +83,10 @@ public class TitleController extends Controller {
|
||||
*/
|
||||
public void setDayMode(){
|
||||
dayModeRD.getScene().getStylesheets().clear();
|
||||
menuPane.getStylesheets().clear();
|
||||
imgSun.setImage(new Image(getClass().getResource("/visualiser/images/sun.png").toExternalForm()));
|
||||
dayModeRD.getScene().getStylesheets().add("/css/dayMode.css");
|
||||
menuPane.setStyle("-fx-background-color: #6be6ff;");
|
||||
nightModeRD.setSelected(false);
|
||||
}
|
||||
|
||||
@@ -77,12 +95,17 @@ public class TitleController extends Controller {
|
||||
*/
|
||||
public void setNightMode(){
|
||||
nightModeRD.getScene().getStylesheets().clear();
|
||||
menuPane.getStylesheets().clear();
|
||||
imgSun.setImage(new Image(getClass().getResource("/visualiser/images/sunsleep.png").toExternalForm()));
|
||||
nightModeRD.getScene().getStylesheets().add("/css/nightMode.css");
|
||||
menuPane.setStyle("-fx-background-color: #1f2c60;");
|
||||
dayModeRD.setSelected(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
tutorialLabel.setWrapText(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,4 +137,12 @@ public class TitleController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void tutorialStartPressed() throws IOException {
|
||||
titleWrapper.setVisible(false);
|
||||
parent.setGameType(4);
|
||||
parent.beginGame();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user