Merge branch 'loading_screens' into 'develop'

Loading screens

# Changes
- Fixed a bug with sound not being muted consistently (the music would play when you press play again even if the music was muted)
- Added a splash screen to show for ~2 seconds on launch, doesn't repeat again while playing the same instance
- Added a loading screen which disappears when the race view has finished being set up (boats in place etc)

# Testing
- Manual testing done, few irrelevant bugs have been found, will log in issue tracker

See merge request !78
This commit is contained in:
Alistair McIntyre
2017-09-27 15:05:36 +13:00
9 changed files with 429 additions and 277 deletions
+1 -1
View File
@@ -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);
}
@@ -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();
}
}
@@ -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());
}
});
}
}
@@ -29,12 +29,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;
@@ -78,6 +74,10 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private static final Double ICON_BLINK_TIMEOUT_RATIO = 0.6;
private static final Integer ICON_BLINK_PERIOD = 500;
@FXML
private AnchorPane loadingScreenPane;
@FXML
private ImageView loadingScreen;
@FXML
private Pane basePane;
@FXML
@@ -147,6 +147,24 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
private ImageView iconToDisplay;
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();
@@ -218,6 +236,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.
*/
@@ -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(2000);
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();
}
}
}
}
@@ -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;
@@ -56,10 +57,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.
*/
@@ -67,7 +76,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();
@@ -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;
}
+12 -3
View File
@@ -23,11 +23,12 @@
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<StackPane fx:id="contentStackPane" maxHeight="1.7976931348623157E308"
<StackPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" style="-fx-background-color: skyblue;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.RaceViewController">
<children>
<StackPane fx:id="contentStackPane" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0"
prefWidth="1200.0" style="-fx-background-color: skyblue;" xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="seng302.visualiser.controllers.RaceViewController">
xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
prefHeight="800.0" prefWidth="1200.0">
@@ -292,6 +293,14 @@
</children>
</GridPane>
</children>
</StackPane>
</children>
<AnchorPane fx:id="loadingScreenPane">
<children>
<ImageView fx:id="loadingScreen" fitHeight="672.0" fitWidth="1200.0" pickOnBounds="true" preserveRatio="true" />
<JFXSpinner layoutX="566.0" layoutY="692.0" radius="30.0" />
</children>
</AnchorPane>
<stylesheets>
<String fx:value="/css/Master.css"/>
<String fx:value="/css/RaceView.css"/>
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<StackPane id="background" fx:id="rootPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.SplashScreenController">
<stylesheets>
<String fx:value="/css/Master.css" />
<String fx:value="/css/SplashScreenView.css" />
</stylesheets>
<children>
<ImageView fitHeight="296.0" fitWidth="295.0" pickOnBounds="true" preserveRatio="true" StackPane.alignment="TOP_CENTER">
<image>
<Image url="@../PP.png" />
</image>
<StackPane.margin>
<Insets top="20.0" />
</StackPane.margin>
</ImageView>
<Text fx:id="headText" strokeType="OUTSIDE" strokeWidth="0.0" text="Party Parrots at Sea" StackPane.alignment="BOTTOM_CENTER">
<font>
<Font name="System Bold" size="42.0" />
</font>
<StackPane.margin>
<Insets bottom="20.0" />
</StackPane.margin>
</Text>
</children>
</StackPane>