@ -12,7 +12,6 @@ import javafx.scene.chart.LineChart;
import javafx.scene.control.* ;
import javafx.scene.control.* ;
import javafx.scene.input.KeyCode ;
import javafx.scene.input.KeyCode ;
import javafx.scene.input.KeyEvent ;
import javafx.scene.input.KeyEvent ;
import javafx.scene.layout.AnchorPane ;
import javafx.scene.layout.GridPane ;
import javafx.scene.layout.GridPane ;
import javafx.scene.layout.StackPane ;
import javafx.scene.layout.StackPane ;
import javafx.scene.shape.MeshView ;
import javafx.scene.shape.MeshView ;
@ -27,6 +26,7 @@ import visualiser.app.App;
import visualiser.enums.TutorialState ;
import visualiser.enums.TutorialState ;
import visualiser.gameController.ControllerClient ;
import visualiser.gameController.ControllerClient ;
import visualiser.gameController.Keys.ControlKey ;
import visualiser.gameController.Keys.ControlKey ;
import visualiser.gameController.Keys.KeyFactory ;
import visualiser.layout.Subject3D ;
import visualiser.layout.Subject3D ;
import visualiser.layout.View3D ;
import visualiser.layout.View3D ;
import visualiser.model.Sparkline ;
import visualiser.model.Sparkline ;
@ -34,9 +34,12 @@ import visualiser.model.VisualiserBoat;
import visualiser.model.VisualiserRaceEvent ;
import visualiser.model.VisualiserRaceEvent ;
import visualiser.model.VisualiserRaceState ;
import visualiser.model.VisualiserRaceState ;
import visualiser.utils.GPSConverter ;
import visualiser.utils.GPSConverter ;
import java.io.IOException ;
import java.io.IOException ;
import java.net.URL ;
import java.net.URL ;
import java.util.* ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Map ;
import java.util.Optional ;
import java.util.Optional ;
import java.util.logging.Level ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
import java.util.logging.Logger ;
@ -73,7 +76,6 @@ public class RaceViewController extends Controller {
private @FXML TableColumn < VisualiserBoat , Leg > boatMarkColumn ;
private @FXML TableColumn < VisualiserBoat , Leg > boatMarkColumn ;
private @FXML TableColumn < VisualiserBoat , Number > boatSpeedColumn ;
private @FXML TableColumn < VisualiserBoat , Number > boatSpeedColumn ;
private @FXML LineChart < Number , Number > sparklineChart ;
private @FXML LineChart < Number , Number > sparklineChart ;
private @FXML Label tutorialText ;
private @FXML Label tutorialText ;
@ -91,10 +93,35 @@ public class RaceViewController extends Controller {
this . isHost = isHost ;
this . isHost = isHost ;
keyFactory . load ( ) ;
keyFactory . load ( ) ;
tutorialCheck ( ) ;
initKeypressHandler ( ) ;
initKeypressHandler ( ) ;
initialiseRaceVisuals ( ) ;
initialiseRaceVisuals ( ) ;
}
}
/ * *
* Checks if the current game is a tutorial race and sets up initial
* tutorial displays if it is .
* /
private void tutorialCheck ( ) {
if ( App . gameType = = 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 ) ;
}
}
/ * *
/ * *
* Sets up the listener and actions that occur when a key is pressed .
* Sets up the listener and actions that occur when a key is pressed .
* /
* /
@ -167,7 +194,6 @@ public class RaceViewController extends Controller {
initialiseFps ( ) ;
initialiseFps ( ) ;
initialiseInfoTable ( ) ;
initialiseInfoTable ( ) ;
initialiseView3D ( ) ;
initialiseView3D ( ) ;
initialiseArrow ( ) ;
initialiseRaceClock ( ) ;
initialiseRaceClock ( ) ;
raceTimer ( ) ; // start the timer
raceTimer ( ) ; // start the timer
new Sparkline ( this . raceState , this . sparklineChart ) ;
new Sparkline ( this . raceState , this . sparklineChart ) ;
@ -374,45 +400,6 @@ 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 .
* Transition from the race view to the finish view .
* /
* /
@ -422,16 +409,6 @@ public class RaceViewController extends Controller {
fc . loadFinish ( raceState . getBoats ( ) ) ;
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 .
* Timer which monitors the race .
* /
* /
@ -581,19 +558,16 @@ public class RaceViewController extends Controller {
alert . setContentText ( "Now you know the controls you are ready to race!" ) ;
alert . setContentText ( "Now you know the controls you are ready to race!" ) ;
Optional < ButtonType > result = alert . showAndWait ( ) ;
Optional < ButtonType > result = alert . showAndWait ( ) ;
if ( result . get ( ) = = ButtonType . OK ) {
if ( result . get ( ) = = ButtonType . OK ) {
parent . endEvent ( ) ;
App . game . endEvent ( ) ;
racePane . setVisible ( false ) ;
loadTitleScreen ( ) ;
App . app . showMainStage ( App . getStage ( ) ) ;
}
}
break ;
break ;
default :
default :
//State not found. Exit tutorial to title menu
//State not found. Exit tutorial to title menu
parent . endEvent ( ) ;
App . game . endEvent ( ) ;
racePane . setVisible ( false ) ;
loadTitleScreen ( ) ;
App . app . showMainStage ( App . getStage ( ) ) ;
break ;
break ;
}
}
}
}
}
}