mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Created a start screen with a timer which shows the race progress
#story[572]
This commit is contained in:
@@ -1,14 +1,25 @@
|
|||||||
package seng302.controllers;
|
package seng302.controllers;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.paint.*;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import seng302.models.parsers.StreamPacket;
|
||||||
|
import seng302.models.parsers.StreamParser;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by michaelrausch on 21/03/17.
|
* Created by michaelrausch on 21/03/17.
|
||||||
@@ -16,6 +27,12 @@ import java.util.ResourceBundle;
|
|||||||
public class Controller implements Initializable {
|
public class Controller implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane contentPane;
|
private AnchorPane contentPane;
|
||||||
|
@FXML
|
||||||
|
private Label timeTillLive;
|
||||||
|
@FXML
|
||||||
|
private Button streamButton;
|
||||||
|
@FXML
|
||||||
|
private Button switchToRaceViewButton;
|
||||||
|
|
||||||
private void setContentPane(String jfxUrl){
|
private void setContentPane(String jfxUrl){
|
||||||
try{
|
try{
|
||||||
@@ -33,6 +50,38 @@ public class Controller implements Initializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startStream() {
|
||||||
|
if (StreamParser.isStreamStatus()) {
|
||||||
|
streamButton.setVisible(false);
|
||||||
|
timeTillLive.setVisible(true);
|
||||||
|
timeTillLive.setTextFill(Color.GREEN);
|
||||||
|
timeTillLive.setText("Connecting...");
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
if (StreamParser.getTimeSinceStart() != 0) {
|
||||||
|
timeTillLive.setTextFill(Color.BLACK);
|
||||||
|
switchToRaceViewButton.setDisable(false);
|
||||||
|
Long timerMinute = -1 * StreamParser.getTimeSinceStart() / 60;
|
||||||
|
Long timerSecond = -1 * StreamParser.getTimeSinceStart() % 60;
|
||||||
|
String timerString = timerMinute + "." + timerSecond + " minutes";
|
||||||
|
timeTillLive.setText(timerString);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 0, 500);
|
||||||
|
} else {
|
||||||
|
timeTillLive.setText("Stream not available.");
|
||||||
|
timeTillLive.setTextFill(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchToRaceView() {
|
||||||
setContentPane("/views/RaceView.fxml");
|
setContentPane("/views/RaceView.fxml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,11 @@ public class StreamParser extends Thread{
|
|||||||
|
|
||||||
public static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<Long,Point3D> boatPositions = new ConcurrentHashMap<>();
|
||||||
public static ConcurrentHashMap<Long,Double> boatSpeeds = new ConcurrentHashMap<>();
|
public static ConcurrentHashMap<Long,Double> boatSpeeds = new ConcurrentHashMap<>();
|
||||||
private String threadName;
|
private String threadName;
|
||||||
private Thread t;
|
private Thread t;
|
||||||
private static boolean raceStarted = false;
|
private static boolean raceStarted = false;
|
||||||
|
private static boolean streamStatus = false;
|
||||||
|
private static long timeSinceStart = 0;
|
||||||
|
|
||||||
public StreamParser(String threadName){
|
public StreamParser(String threadName){
|
||||||
this.threadName = threadName;
|
this.threadName = threadName;
|
||||||
@@ -44,6 +46,7 @@ public class StreamParser extends Thread{
|
|||||||
public void run(){
|
public void run(){
|
||||||
try {
|
try {
|
||||||
System.out.println("START OF STREAM");
|
System.out.println("START OF STREAM");
|
||||||
|
streamStatus = true;
|
||||||
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
}
|
}
|
||||||
@@ -152,7 +155,7 @@ public class StreamParser extends Thread{
|
|||||||
}
|
}
|
||||||
if (timeTillStart % 10 == 0){
|
if (timeTillStart % 10 == 0){
|
||||||
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
||||||
|
timeSinceStart = timeTillStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
||||||
@@ -400,5 +403,32 @@ public class StreamParser extends Thread{
|
|||||||
}
|
}
|
||||||
return partialLong;
|
return partialLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns false if race not started, true otherwise
|
||||||
|
*
|
||||||
|
* @return race started status
|
||||||
|
*/
|
||||||
|
public static boolean isRaceStarted() {
|
||||||
|
return raceStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns false if stream not connected, true otherwise
|
||||||
|
*
|
||||||
|
* @return stream started status
|
||||||
|
*/
|
||||||
|
public static boolean isStreamStatus() {
|
||||||
|
return streamStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns race timer
|
||||||
|
*
|
||||||
|
* @return race timer in long
|
||||||
|
*/
|
||||||
|
public static long getTimeSinceStart() {
|
||||||
|
return timeSinceStart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,48 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
<?import javafx.scene.canvas.*?>
|
<?import javafx.scene.canvas.*?>
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller">
|
<AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller">
|
||||||
<children>
|
<children>
|
||||||
<!--<fx:include source="RaceView.fxml" fx:id="raceView"/>-->
|
<GridPane alignment="CENTER" prefHeight="1080.0" prefWidth="1920.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints maxHeight="403.0" minHeight="0.0" prefHeight="170.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="444.0" minHeight="0.0" prefHeight="47.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="432.0" minHeight="10.0" prefHeight="190.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="635.0" minHeight="10.0" prefHeight="69.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="599.0" minHeight="10.0" prefHeight="599.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER" text="Welcome to Race Vision" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
|
||||||
|
<font>
|
||||||
|
<Font size="40.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label text="Your live AC35 livestream" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label text="Livestream Status:" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
|
||||||
|
<font>
|
||||||
|
<Font size="28.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
||||||
|
<font>
|
||||||
|
<Font size="27.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||||
|
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|||||||
Reference in New Issue
Block a user