mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Split Start Screen out from Main View view and controller.
#story[923]
This commit is contained in:
@@ -27,26 +27,6 @@ import java.util.TimerTask;
|
||||
public class Controller implements Initializable {
|
||||
@FXML
|
||||
private AnchorPane contentPane;
|
||||
@FXML
|
||||
private Label timeTillLive;
|
||||
@FXML
|
||||
private Button streamButton;
|
||||
@FXML
|
||||
private Button switchToRaceViewButton;
|
||||
@FXML
|
||||
private TableView<Yacht> teamList;
|
||||
@FXML
|
||||
private TableColumn<Yacht, String> boatNameCol;
|
||||
@FXML
|
||||
private TableColumn<Yacht, String> shortNameCol;
|
||||
@FXML
|
||||
private TableColumn<Yacht, String> countryCol;
|
||||
@FXML
|
||||
private TableColumn<Yacht, String> posCol;
|
||||
@FXML
|
||||
private Label realTime;
|
||||
|
||||
private boolean switchedToRaceView = false;
|
||||
|
||||
private void setContentPane(String jfxUrl){
|
||||
try{
|
||||
@@ -66,93 +46,6 @@ public class Controller implements Initializable {
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
teamList.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Running a timer to update the livestream status on welcome screen. Update interval is 1 second.
|
||||
*/
|
||||
public void startStream() {
|
||||
if (StreamParser.isStreamStatus()) {
|
||||
streamButton.setVisible(false);
|
||||
realTime.setVisible(true);
|
||||
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.isRaceStarted()) {
|
||||
if (!switchedToRaceView) {
|
||||
switchToRaceView();
|
||||
}
|
||||
timer.cancel();
|
||||
}
|
||||
if (StreamParser.isRaceFinished()) {
|
||||
realTime.setText(StreamParser.getCurrentTimeString());
|
||||
timeTillLive.setTextFill(Color.RED);
|
||||
timeTillLive.setText("Race finished! Waiting for new race...");
|
||||
switchToRaceViewButton.setDisable(true);
|
||||
} else if (StreamParser.getTimeSinceStart() > 0) {
|
||||
realTime.setText(StreamParser.getCurrentTimeString());
|
||||
updateTeamList();
|
||||
timeTillLive.setTextFill(Color.RED);
|
||||
switchToRaceViewButton.setDisable(false);
|
||||
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60);
|
||||
String timerSecond = Long.toString(StreamParser.getTimeSinceStart() % 60);
|
||||
if (timerSecond.length() == 1) {
|
||||
timerSecond = "0" + timerSecond;
|
||||
}
|
||||
String timerString = "-" + timerMinute + ":" + timerSecond;
|
||||
timeTillLive.setText(timerString);
|
||||
} else {
|
||||
realTime.setText(StreamParser.getCurrentTimeString());
|
||||
updateTeamList();
|
||||
timeTillLive.setTextFill(Color.BLACK);
|
||||
switchToRaceViewButton.setDisable(false);
|
||||
String timerMinute = Long.toString(-1 * StreamParser.getTimeSinceStart() / 60);
|
||||
String timerSecond = Long.toString(-1 * StreamParser.getTimeSinceStart() % 60);
|
||||
if (timerSecond.length() == 1) {
|
||||
timerSecond = "0" + timerSecond;
|
||||
}
|
||||
String timerString = timerMinute + ":" + timerSecond;
|
||||
timeTillLive.setText(timerString);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 0, 1000);
|
||||
} else {
|
||||
timeTillLive.setText("Stream not available.");
|
||||
timeTillLive.setTextFill(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
public void switchToRaceView() {
|
||||
switchedToRaceView = true;
|
||||
setContentPane("/views/RaceView.fxml");
|
||||
}
|
||||
|
||||
private void updateTeamList() {
|
||||
ObservableList<Yacht> data = FXCollections.observableArrayList();
|
||||
|
||||
teamList.setItems(data);
|
||||
|
||||
boatNameCol.setCellValueFactory(
|
||||
new PropertyValueFactory<>("boatName")
|
||||
);
|
||||
shortNameCol.setCellValueFactory(
|
||||
new PropertyValueFactory<>("shortName")
|
||||
);
|
||||
countryCol.setCellValueFactory(
|
||||
new PropertyValueFactory<>("country")
|
||||
);
|
||||
posCol.setCellValueFactory(
|
||||
new PropertyValueFactory<>("position")
|
||||
);
|
||||
|
||||
data.addAll(StreamParser.getBoatsPos().values());
|
||||
teamList.refresh();
|
||||
setContentPane("/views/StartScreenView.fxml");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user