From 98abe64f007469e07fe2158f14a67cf3375afe4e Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Tue, 26 Sep 2017 17:07:02 +1300 Subject: [PATCH 1/3] Added splash and loading screen --- src/main/java/seng302/App.java | 2 +- src/main/java/seng302/utilities/Sounds.java | 4 + .../java/seng302/visualiser/GameClient.java | 3 +- .../controllers/RaceViewController.java | 42 +- .../controllers/SplashScreenController.java | 58 +++ .../visualiser/controllers/ViewManager.java | 12 +- src/main/resources/css/SplashScreenView.css | 10 + src/main/resources/views/RaceView.fxml | 407 ++++++++---------- src/main/resources/views/SplashScreen.fxml | 32 ++ 9 files changed, 336 insertions(+), 234 deletions(-) create mode 100644 src/main/java/seng302/visualiser/controllers/SplashScreenController.java create mode 100644 src/main/resources/css/SplashScreenView.css create mode 100644 src/main/resources/views/SplashScreen.fxml diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 3c654f77..2052bbc4 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -63,7 +63,7 @@ public class App extends Application { @Override public void start(Stage primaryStage) throws Exception { - ViewManager.getInstance().initialStartView(primaryStage); + ViewManager.getInstance().initialiseSplashScreen(primaryStage); } diff --git a/src/main/java/seng302/utilities/Sounds.java b/src/main/java/seng302/utilities/Sounds.java index f8257b1f..b7db0439 100644 --- a/src/main/java/seng302/utilities/Sounds.java +++ b/src/main/java/seng302/utilities/Sounds.java @@ -101,6 +101,10 @@ public class Sounds { musicPlayer.setCycleCount(MediaPlayer.INDEFINITE); musicPlayer.setVolume(0.3); musicPlayer.play(); + musicPlayer.setMute(musicMuted); + if (soundEffect != null) { + soundEffect.stop(); + } } diff --git a/src/main/java/seng302/visualiser/GameClient.java b/src/main/java/seng302/visualiser/GameClient.java index ad3a37d6..8f7b2118 100644 --- a/src/main/java/seng302/visualiser/GameClient.java +++ b/src/main/java/seng302/visualiser/GameClient.java @@ -275,12 +275,13 @@ public class GameClient { ClientYacht player = allBoatsMap.get(socketThread.getClientId()); raceView.loadRace(allBoatsMap, courseData, raceState, player); - + raceView.showView(); raceView.getSendPressedProperty().addListener((obs, old, isPressed) -> { if (isPressed) { formatAndSendChatMessage(raceView.readChatInput()); } }); + } } diff --git a/src/main/java/seng302/visualiser/controllers/RaceViewController.java b/src/main/java/seng302/visualiser/controllers/RaceViewController.java index 3d011a0d..99b092ca 100644 --- a/src/main/java/seng302/visualiser/controllers/RaceViewController.java +++ b/src/main/java/seng302/visualiser/controllers/RaceViewController.java @@ -27,12 +27,8 @@ import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart.Data; import javafx.scene.chart.XYChart.Series; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.control.Slider; -import javafx.scene.control.TextField; +import javafx.scene.control.*; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; @@ -68,6 +64,10 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel private final int CHAT_LIMIT = 128; + @FXML + private AnchorPane loadingScreenPane; + @FXML + private ImageView loadingScreen; @FXML private Pane basePane; @FXML @@ -131,6 +131,24 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel private FinishDialogController finishDialogController; public void initialize() { + contentStackPane.setVisible(false); + Image loadingImage = new Image("PP.png"); + loadingScreen.setImage(loadingImage); + //Centers the Image within the image view + double w = 0; + double h = 0; + double ratioX = loadingScreen.getFitWidth() / loadingImage.getWidth(); + double ratioY = loadingScreen.getFitHeight() / loadingImage.getHeight(); + double reduceRatio = 0; + if(ratioX >= ratioY) { + reduceRatio = ratioY; + } else { + reduceRatio = ratioX; + } + w = loadingImage.getWidth() * reduceRatio; + h = loadingImage.getHeight() * reduceRatio; + loadingScreen.setX((loadingScreen.getFitWidth() - w) / 2); + loadingScreen.setY((loadingScreen.getFitHeight() - h) / 2); Sounds.stopMusic(); Sounds.playRaceMusic(); @@ -202,6 +220,18 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel createFinishDialog(finishedBoats); } + public void showView(){ + loadingScreenPane.setVisible(false); + contentStackPane.setVisible(true); + + Platform.runLater(new Runnable() { + @Override + public void run() { + contentStackPane.requestFocus(); + } + }); + } + /** * Create finishScreenDialog and set up finishDialogController. */ diff --git a/src/main/java/seng302/visualiser/controllers/SplashScreenController.java b/src/main/java/seng302/visualiser/controllers/SplashScreenController.java new file mode 100644 index 00000000..a3df3b4b --- /dev/null +++ b/src/main/java/seng302/visualiser/controllers/SplashScreenController.java @@ -0,0 +1,58 @@ +package seng302.visualiser.controllers; + +import com.jfoenix.controls.JFXDecorator; +import com.jfoenix.controls.JFXSnackbar; +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.SceneAntialiasing; +import javafx.scene.image.Image; +import javafx.scene.layout.StackPane; +import javafx.stage.Stage; +import seng302.gameServer.ServerAdvertiser; +import seng302.utilities.Sounds; +import seng302.visualiser.GameClient; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +/** + * Created by Kusal on 26-Sep-17. + */ +public class SplashScreenController implements Initializable{ + + @FXML + private StackPane rootPane; + + @Override + public void initialize(URL location, ResourceBundle resources) { + new SplashScreen().start(); + } + + + class SplashScreen extends Thread { + public void run(){ + try { + Thread.sleep(1000); + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + Stage stage = new Stage(); + ViewManager.getInstance().initialStartView(stage); + } catch (Exception e) { + e.printStackTrace(); + } + rootPane.getScene().getWindow().hide(); + } + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/seng302/visualiser/controllers/ViewManager.java b/src/main/java/seng302/visualiser/controllers/ViewManager.java index 8f98824c..7e126884 100644 --- a/src/main/java/seng302/visualiser/controllers/ViewManager.java +++ b/src/main/java/seng302/visualiser/controllers/ViewManager.java @@ -21,6 +21,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.stage.Stage; +import javafx.stage.StageStyle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import seng302.gameServer.ServerAdvertiser; @@ -55,10 +56,18 @@ public class ViewManager { if (instance == null) { instance = new ViewManager(); } - return instance; } + public void initialiseSplashScreen(Stage stage) throws IOException { + this.stage = stage; + Parent root = FXMLLoader.load(getClass().getResource("/views/SplashScreen.fxml")); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.initStyle(StageStyle.UNDECORATED); + stage.show(); + } + /** * Initialize the start view in the given stage. */ @@ -66,7 +75,6 @@ public class ViewManager { this.stage = stage; Parent root = FXMLLoader.load(getClass().getResource("/views/StartScreenView.fxml")); stage.setTitle("Party Parrots At Sea"); - JFXDecorator decorator = new JFXDecorator(stage, root, false, true, true); decorator.setCustomMaximize(true); decorator.applyCss(); diff --git a/src/main/resources/css/SplashScreenView.css b/src/main/resources/css/SplashScreenView.css new file mode 100644 index 00000000..a4d1d68d --- /dev/null +++ b/src/main/resources/css/SplashScreenView.css @@ -0,0 +1,10 @@ +#background { + -fx-background-color: #E7F1F8; +} + +#headText { + -fx-background-color: transparent; + -fx-font-size: 52px; + -fx-text-fill: -fx-pp-light-text-color; + -fx-effect: -fx-pp-dropshadow-headers; +} \ No newline at end of file diff --git a/src/main/resources/views/RaceView.fxml b/src/main/resources/views/RaceView.fxml index 879b2f22..5c295725 100644 --- a/src/main/resources/views/RaceView.fxml +++ b/src/main/resources/views/RaceView.fxml @@ -1,5 +1,12 @@ + + + + + + + @@ -14,232 +21,184 @@ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + diff --git a/src/main/resources/views/SplashScreen.fxml b/src/main/resources/views/SplashScreen.fxml new file mode 100644 index 00000000..31449b7e --- /dev/null +++ b/src/main/resources/views/SplashScreen.fxml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 671efcaf080cb095d4c4d71f2e2d25c783ea0d82 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Tue, 26 Sep 2017 17:25:57 +1300 Subject: [PATCH 2/3] Adding spinners to the loading screen. --- src/main/resources/views/RaceView.fxml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/views/RaceView.fxml b/src/main/resources/views/RaceView.fxml index 5c295725..f42c5fa9 100644 --- a/src/main/resources/views/RaceView.fxml +++ b/src/main/resources/views/RaceView.fxml @@ -193,7 +193,8 @@ - + + From edbfb2f84f022900c0379189799e8d7e75e79635 Mon Sep 17 00:00:00 2001 From: Kusal Ekanayake Date: Wed, 27 Sep 2017 14:16:27 +1300 Subject: [PATCH 3/3] Modified timings for load screen. --- .../controllers/SplashScreenController.java | 2 +- src/main/resources/views/RaceView.fxml | 543 +++++++++--------- 2 files changed, 277 insertions(+), 268 deletions(-) diff --git a/src/main/java/seng302/visualiser/controllers/SplashScreenController.java b/src/main/java/seng302/visualiser/controllers/SplashScreenController.java index a3df3b4b..442d4083 100644 --- a/src/main/java/seng302/visualiser/controllers/SplashScreenController.java +++ b/src/main/java/seng302/visualiser/controllers/SplashScreenController.java @@ -37,7 +37,7 @@ public class SplashScreenController implements Initializable{ class SplashScreen extends Thread { public void run(){ try { - Thread.sleep(1000); + Thread.sleep(2000); Platform.runLater(new Runnable() { @Override public void run() { diff --git a/src/main/resources/views/RaceView.fxml b/src/main/resources/views/RaceView.fxml index 2d0769af..56ca5ad5 100644 --- a/src/main/resources/views/RaceView.fxml +++ b/src/main/resources/views/RaceView.fxml @@ -23,275 +23,284 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +