Merged with multi visualiser branch so now multiple visualisers can connect to the same host.

#story[1087]
main
zwu18 9 years ago
parent 88604df66d
commit 243c450790

@ -5,12 +5,17 @@ import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import mock.app.App; import mock.app.Event;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import visualiser.model.RaceConnection; import visualiser.model.RaceConnection;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
/** /**
@ -33,10 +38,20 @@ public class HostController extends Controller {
} }
public void hostGamePressed() throws IOException{ public void hostGamePressed() throws IOException{
new App().start(new Stage()); try {
System.out.println("Run mock"); Event game = Event.getEvent();
connectSocket(); game.start();
} connectSocket();
} catch (InvalidRaceDataException e) {
e.printStackTrace();
} catch (XMLReaderException e) {
e.printStackTrace();
} catch (InvalidBoatDataException e) {
e.printStackTrace();
} catch (InvalidRegattaDataException e) {
e.printStackTrace();
}}
public void connectSocket() { public void connectSocket() {
try{ try{

@ -32,28 +32,12 @@ public class TitleController extends Controller {
* @throws IOException if main has problems * @throws IOException if main has problems
*/ */
public void hostAGame() throws IOException { public void hostAGame() throws IOException {
// load up the main window
/*Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/visualiser/scenes/main.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 1200, 800);
scene.getStylesheets().add("/css/nightMode.css");
stage.setScene(scene);
stage.setTitle("RaceVision - Team 7");
stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("images/SailIcon.png")));
stage.show();
// close title screen
Stage stageOld = (Stage)btnJoin.getScene().getWindow();
stageOld.close();*/
titleWrapper.setVisible(false); titleWrapper.setVisible(false);
parent.hostGame(); parent.hostGame();
} }
public void enterTitle(){ public void enterTitle(){
titleWrapper.setVisible(true); titleWrapper.setVisible(true);
} }

@ -35,14 +35,12 @@ public class App extends Application {
System.exit(0); System.exit(0);
} }
}); });
FXMLLoader loader = new FXMLLoader(getClass().getResource FXMLLoader loader = new FXMLLoader(getClass().getResource("/visualiser/scenes/main.fxml"));
("/visualiser/scenes/main.fxml"));
Parent root = loader.load(); Parent root = loader.load();
stage.setResizable(false); stage.setResizable(false);
MainController mc = (MainController) loader.getController(); MainController mc = (MainController) loader.getController();
mc.enterTitle(); mc.enterTitle();
Scene scene = new Scene(root); Scene scene = new Scene(root);
System.out.println(scene.getHeight());
stage.setScene(scene); stage.setScene(scene);
stage.setTitle("RaceVision - Team 7"); stage.setTitle("RaceVision - Team 7");

@ -16,13 +16,13 @@ public class RaceConnection {
private final StringProperty status; private final StringProperty status;
private final StringProperty gamename; private final StringProperty gamename;
public RaceConnection(String hostname, int port, String gamename) {
/** /**
* Constructor for remote host connections. * Constructor for remote host connections.
* @param hostname URL for remote host * @param hostname URL for remote host
* @param port port for game feed * @param port port for game feed
*/ */
public RaceConnection(String hostname, int port) { public RaceConnection(String hostname, int port, String gamename) {
this.hostname = new SimpleStringProperty(hostname); this.hostname = new SimpleStringProperty(hostname);
this.port = port; this.port = port;
this.status = new SimpleStringProperty(""); this.status = new SimpleStringProperty("");
@ -34,7 +34,6 @@ public class RaceConnection {
* Tries to create a socket to hostname and port, indicates status after test. * Tries to create a socket to hostname and port, indicates status after test.
* @return true if socket can connect * @return true if socket can connect
*/ */
@SuppressWarnings("unused")
public boolean check() { public boolean check() {
//TODO the connection needs to be moved to its own thread, so it doesn't block fx thread. //TODO the connection needs to be moved to its own thread, so it doesn't block fx thread.
InetSocketAddress i = new InetSocketAddress(hostname.get(), port); InetSocketAddress i = new InetSocketAddress(hostname.get(), port);

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
<children> <children>
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.MainController">
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.MainController">
<children> <children>
<fx:include fx:id="race" source="race.fxml" /> <fx:include fx:id="race" source="race.fxml" />
<fx:include fx:id="start" source="start.fxml" /> <fx:include fx:id="start" source="start.fxml" />

@ -15,7 +15,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<AnchorPane fx:id="titleWrapper" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController"> <AnchorPane fx:id="titleWrapper" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController">
<children> <children>
<GridPane layoutY="39.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane layoutY="39.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

Loading…
Cancel
Save