Merge branch 'master' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into controllerSplit
# Conflicts: # racevisionGame/src/main/java/visualiser/Controllers/HostController.java # racevisionGame/src/main/java/visualiser/Controllers/MainController.java # racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java # racevisionGame/src/main/java/visualiser/Controllers/StartController.java # racevisionGame/src/main/java/visualiser/Controllers/TitleController.java # racevisionGame/src/main/resources/visualiser/scenes/raceView.fxml # racevisionGame/src/main/resources/visualiser/scenes/titleScreen.fxml
This commit is contained in:
@@ -12,6 +12,7 @@ import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.shape.MeshView;
|
||||
@@ -23,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.Sparkline;
|
||||
@@ -35,6 +36,7 @@ import visualiser.model.VisualiserRaceState;
|
||||
import visualiser.utils.GPSConverter;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -49,6 +51,10 @@ public class RaceViewController extends Controller {
|
||||
private KeyFactory keyFactory = new KeyFactory();
|
||||
private boolean infoTableShow = true; // shown or hidden
|
||||
private boolean isHost;
|
||||
private TutorialState currentState;
|
||||
private ArrayList<TutorialState> tutorialStates;
|
||||
private boolean isTutorial = false;
|
||||
private String keyToPress;
|
||||
private View3D view3D;
|
||||
private ObservableList<Subject3D> viewSubjects;
|
||||
|
||||
@@ -68,6 +74,9 @@ public class RaceViewController extends Controller {
|
||||
private @FXML TableColumn<VisualiserBoat, Number> boatSpeedColumn;
|
||||
private @FXML LineChart<Number, Number> sparklineChart;
|
||||
|
||||
private @FXML Label tutorialText;
|
||||
|
||||
|
||||
/**
|
||||
* Displays a specified race.
|
||||
* Intended to be called on loading the scene.
|
||||
@@ -101,11 +110,24 @@ public class RaceViewController 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, "RaceViewController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e);
|
||||
Logger.getGlobal().log(Level.WARNING, "RaceController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +167,7 @@ public class RaceViewController extends Controller {
|
||||
initialiseFps();
|
||||
initialiseInfoTable();
|
||||
initialiseView3D();
|
||||
initialiseArrow();
|
||||
initialiseRaceClock();
|
||||
raceTimer(); // start the timer
|
||||
new Sparkline(this.raceState, this.sparklineChart);
|
||||
@@ -212,9 +235,33 @@ public class RaceViewController 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;
|
||||
}
|
||||
@@ -222,6 +269,9 @@ public class RaceViewController 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.
|
||||
@@ -324,6 +374,45 @@ public class RaceViewController extends Controller {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Displays a specified race.
|
||||
* @param visualiserRace Object modelling the race.
|
||||
* @param controllerClient Socket Client that manipulates the controller.
|
||||
* @param isHost is user a host
|
||||
*/
|
||||
public void startRace(VisualiserRaceEvent visualiserRace, ControllerClient controllerClient, Boolean isHost) {
|
||||
|
||||
this.visualiserRace = visualiserRace;
|
||||
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.
|
||||
racePane.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transition from the race view to the finish view.
|
||||
*/
|
||||
@@ -333,6 +422,16 @@ public class RaceViewController extends Controller {
|
||||
fc.loadFinish(raceState.getBoats());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialises the arrow controller with data from the race to observe.
|
||||
* @param race The race to observe.
|
||||
*/
|
||||
private void initialiseArrow(VisualiserRaceEvent race) {
|
||||
arrowController.setWindProperty(race.getVisualiserRaceState().windProperty());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Timer which monitors the race.
|
||||
*/
|
||||
@@ -393,4 +492,108 @@ public class RaceViewController 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,28 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
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.
|
||||
@@ -16,6 +33,9 @@ import java.io.IOException;
|
||||
public class TitleController extends Controller {
|
||||
private @FXML RadioButton dayModeRD;
|
||||
private @FXML RadioButton nightModeRD;
|
||||
private @FXML Label tutorialLabel;
|
||||
private @FXML Pane menuPane;
|
||||
private @FXML ImageView imgSun;
|
||||
|
||||
/**
|
||||
* Method called when the 'host a game' button is pressed.
|
||||
@@ -40,7 +60,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);
|
||||
App.dayMode = true;
|
||||
}
|
||||
@@ -50,7 +73,10 @@ 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);
|
||||
App.dayMode = false;
|
||||
}
|
||||
@@ -67,4 +93,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