Began work on ConnectionController for selecting active hosts on startup via GUI.

#story[782]
This commit is contained in:
cbt24
2017-05-03 00:35:46 +12:00
parent 577dea2a56
commit ad58407021
7 changed files with 113 additions and 6 deletions
+2 -2
View File
@@ -22,9 +22,9 @@ public class App extends Application {
}
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/scenes/main.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/scenes/connect.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 1200, 800);
Scene scene = new Scene(root, 600, 400);
stage.setScene(scene);
stage.show();
}
@@ -0,0 +1,21 @@
package seng302.Controllers;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javax.swing.text.TableView;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by cbt24 on 3/05/17.
*/
public class ConnectionController extends Controller {
@FXML
TableView connectionTable;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
@@ -16,6 +16,8 @@ public class MainController extends Controller {
StartController startController;
@FXML
RaceController raceController;
@FXML
ConnectionController connectionController;
public void beginRace(VisualiserInput visualiserInput) {
raceController.startRace(visualiserInput);
@@ -32,6 +34,7 @@ public class MainController extends Controller {
public void initialize(URL location, ResourceBundle resources) {
startController.setParent(this);
raceController.setParent(this);
connectionController.setParent(this);
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0);
AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0);
@@ -1,5 +1,6 @@
package seng302.Mock;
import javafx.animation.AnimationTimer;
import javafx.collections.FXCollections;
import org.geotools.referencing.GeodeticCalculator;
import seng302.*;
@@ -12,6 +13,7 @@ import seng302.Networking.Utils.Enums.BoatStatus;
import seng302.Networking.Utils.BoatLocationMessage;
import java.awt.geom.Point2D;
import java.time.Instant;
import java.util.*;
/**
@@ -99,4 +101,39 @@ public class StreamedRace extends Race {
boat.setCurrentPosition(coordinate);
}
@Override
protected void countdownTimer() {
new AnimationTimer() {
long minutes;
long currentTimeInSeconds;
long remainingSeconds;
long hours;
long timeLeft;
@Override
public void handle(long arg0) {
long currentTime = Instant.now().getEpochSecond();
long startTime = visualiserInput.getRaceStatus().getExpectedStartTime();
timeLeft = startTime - currentTime;
System.out.println(timeLeft);
if (timeLeft <= 0 && controller != null) {
updateTime("Race is starting...");
stop();
simulateRace();
} else {
currentTimeInSeconds = (timeLeft*scaleFactor) / 1000;
minutes = currentTimeInSeconds / 60;
remainingSeconds = currentTimeInSeconds % 60;
hours = minutes / 60;
minutes = minutes % 60;
if (controller != null) {
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
}
}
currentTime = System.currentTimeMillis();
}
}.start();
}
}
@@ -27,11 +27,10 @@ public abstract class Race implements Runnable {
protected RaceController controller;
protected int boatsFinished = 0;
protected long totalTimeElapsed;
private int lastFPS = 20;
protected int scaleFactor;
protected int PRERACE_TIME = 0; //time in milliseconds to pause during pre-race
private int lastFPS = 20;
private int PRERACE_TIME = 0; //time in milliseconds to pause during pre-race
private boolean timerEnabled = true; //boolean to determine if timer is ran
/**
@@ -196,7 +195,7 @@ public abstract class Race implements Runnable {
* Starts the Race Simulation, playing the race start to finish with the timescale.
* This prints the boats participating, the order that the events occur in time order, and the respective information of the events.
*/
private void simulateRace() {
protected final void simulateRace() {
System.setProperty("javafx.animation.fullspeed", "true");
@@ -0,0 +1,14 @@
package seng302;
/**
* Created by cbt24 on 3/05/17.
*/
public class RaceConnection {
private String hostname;
private int port;
public RaceConnection(String hostname, int port) {
this.hostname = hostname;
this.port = port;
}
}