Merge branch 'spectate_mode_basic' into 'master'
Spectate mode basic Client can now select spectate when connecting to a race. - The "Join game" button has been split into "Participate" and "Spectate". - Selecting spectate should join the game, but not assign a boat. - Spectator cannot control any boats, or have an effect on game. - Can spectate a game even if it is full. See merge request !49
This commit is contained in:
@@ -8,6 +8,7 @@ import javafx.scene.image.Image;
|
|||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import mock.app.Event;
|
import mock.app.Event;
|
||||||
import mock.exceptions.EventConstructionException;
|
import mock.exceptions.EventConstructionException;
|
||||||
|
import network.Messages.Enums.RequestToJoinEnum;
|
||||||
import visualiser.app.App;
|
import visualiser.app.App;
|
||||||
import visualiser.app.MatchBrowserSingleton;
|
import visualiser.app.MatchBrowserSingleton;
|
||||||
import visualiser.network.MatchBrowserInterface;
|
import visualiser.network.MatchBrowserInterface;
|
||||||
@@ -98,7 +99,7 @@ public class HostGameController extends Controller {
|
|||||||
public void connectSocket(String address, int port) throws IOException {
|
public void connectSocket(String address, int port) throws IOException {
|
||||||
Socket socket = new Socket(address, port);
|
Socket socket = new Socket(address, port);
|
||||||
InGameLobbyController iglc = (InGameLobbyController)loadScene("gameLobby.fxml");
|
InGameLobbyController iglc = (InGameLobbyController)loadScene("gameLobby.fxml");
|
||||||
iglc.enterGameLobby(socket, true);
|
iglc.enterGameLobby(socket, true, RequestToJoinEnum.PARTICIPANT);//TODO may want to let the host spectate if they wish.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -267,10 +267,16 @@ public class InGameLobbyController extends Controller {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enterGameLobby(Socket socket, boolean isHost){
|
/**
|
||||||
|
* Joins a game and enters the game lobby for it.
|
||||||
|
* @param socket Socket to connect to.
|
||||||
|
* @param isHost Whether this client is the host.
|
||||||
|
* @param joinType How the client wishes to join (e.g., participant).
|
||||||
|
*/
|
||||||
|
public void enterGameLobby(Socket socket, boolean isHost, RequestToJoinEnum joinType){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
this.visualiserRaceEvent = new VisualiserRaceEvent(socket, RequestToJoinEnum.PARTICIPANT);
|
this.visualiserRaceEvent = new VisualiserRaceEvent(socket, joinType);
|
||||||
this.isHost = isHost;
|
this.isHost = isHost;
|
||||||
this.controllerClient = visualiserRaceEvent.getControllerClient();
|
this.controllerClient = visualiserRaceEvent.getControllerClient();
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import javafx.scene.control.TableColumn;
|
|||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import network.Messages.Enums.RequestToJoinEnum;
|
||||||
import javafx.scene.media.AudioClip;
|
import javafx.scene.media.AudioClip;
|
||||||
import network.Messages.HostGame;
|
import network.Messages.HostGame;
|
||||||
import visualiser.app.MatchBrowserSingleton;
|
import visualiser.app.MatchBrowserSingleton;
|
||||||
@@ -30,6 +31,7 @@ public class LobbyController extends Controller {
|
|||||||
private @FXML TableColumn<RaceConnection, String> hostNameColumn;
|
private @FXML TableColumn<RaceConnection, String> hostNameColumn;
|
||||||
private @FXML TableColumn<RaceConnection, String> statusColumn;
|
private @FXML TableColumn<RaceConnection, String> statusColumn;
|
||||||
private @FXML Button joinGameBtn;
|
private @FXML Button joinGameBtn;
|
||||||
|
private @FXML Button spectateButton;
|
||||||
private @FXML TextField addressFld;
|
private @FXML TextField addressFld;
|
||||||
private @FXML TextField portFld;
|
private @FXML TextField portFld;
|
||||||
|
|
||||||
@@ -57,11 +59,14 @@ public class LobbyController extends Controller {
|
|||||||
lobbyTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
|
lobbyTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
|
||||||
if (curr != null && curr.statusProperty().getValue().equals("Ready")) {
|
if (curr != null && curr.statusProperty().getValue().equals("Ready")) {
|
||||||
joinGameBtn.setDisable(false);
|
joinGameBtn.setDisable(false);
|
||||||
|
spectateButton.setDisable(false);
|
||||||
} else {
|
} else {
|
||||||
joinGameBtn.setDisable(true);
|
joinGameBtn.setDisable(true);
|
||||||
|
spectateButton.setDisable(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
joinGameBtn.setDisable(true);
|
joinGameBtn.setDisable(true);
|
||||||
|
spectateButton.setDisable(true);
|
||||||
|
|
||||||
this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket();
|
this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket();
|
||||||
receiveMatchData();
|
receiveMatchData();
|
||||||
@@ -80,21 +85,40 @@ public class LobbyController extends Controller {
|
|||||||
try {
|
try {
|
||||||
if (lobbyTable.getSelectionModel().getSelectedItem().statusProperty().getValue().equals("Ready")) {
|
if (lobbyTable.getSelectionModel().getSelectedItem().statusProperty().getValue().equals("Ready")) {
|
||||||
joinGameBtn.setDisable(false);
|
joinGameBtn.setDisable(false);
|
||||||
|
spectateButton.setDisable(false);
|
||||||
} else {
|
} else {
|
||||||
joinGameBtn.setDisable(true);
|
joinGameBtn.setDisable(true);
|
||||||
|
spectateButton.setDisable(true);
|
||||||
}
|
}
|
||||||
} catch (Exception ignored){}
|
} catch (Exception ignored){}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a connection.
|
* Connect to a connection.
|
||||||
|
* @param joinType How the client wishes to join (e.g., participant).
|
||||||
* @throws IOException socket error
|
* @throws IOException socket error
|
||||||
*/
|
*/
|
||||||
public void connectSocket() throws IOException {
|
public void connectSocket(RequestToJoinEnum joinType) throws IOException {
|
||||||
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
||||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||||
InGameLobbyController iglc = (InGameLobbyController)loadScene("gameLobby.fxml");
|
InGameLobbyController iglc = (InGameLobbyController)loadScene("gameLobby.fxml");
|
||||||
iglc.enterGameLobby(socket, false);
|
iglc.enterGameLobby(socket, false, joinType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests to join the game as a participant.
|
||||||
|
* @throws IOException socket error.
|
||||||
|
*/
|
||||||
|
public void connectParticipate() throws IOException {
|
||||||
|
connectSocket(RequestToJoinEnum.PARTICIPANT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests to join the game as a spectator.
|
||||||
|
* @throws IOException socket error.
|
||||||
|
*/
|
||||||
|
public void connectSpectate() throws IOException {
|
||||||
|
connectSocket(RequestToJoinEnum.SPECTATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void menuBtnPressed() throws IOException {
|
public void menuBtnPressed() throws IOException {
|
||||||
|
|||||||
@@ -14,15 +14,25 @@ public class ThisBoat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSailsOut(boolean sailsOut) {
|
public void setSailsOut(boolean sailsOut) {
|
||||||
|
if (this.boat != null) {
|
||||||
this.boat.setSailsOut(sailsOut);
|
this.boat.setSailsOut(sailsOut);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSailsOut() {
|
public boolean isSailsOut() {
|
||||||
|
if (this.boat != null) {
|
||||||
return this.boat.isSailsOut();
|
return this.boat.isSailsOut();
|
||||||
|
} else {
|
||||||
|
return true;//TODO junk value to allow the client to spectate.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSourceID() {
|
public int getSourceID() {
|
||||||
|
if (this.boat != null) {
|
||||||
return this.boat.getSourceID();
|
return this.boat.getSourceID();
|
||||||
|
} else {
|
||||||
|
return 0;//TODO junk value to allow the client to spectate.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoat(VisualiserBoat boat) {
|
public void setBoat(VisualiserBoat boat) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
<?import javafx.scene.layout.GridPane?>
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<AnchorPane fx:id="lobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.LobbyController">
|
<AnchorPane fx:id="lobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.LobbyController">
|
||||||
@@ -40,30 +41,6 @@
|
|||||||
<Font size="36.0" />
|
<Font size="36.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<GridPane fx:id="buttonsGridPane" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<Button fx:id="joinGameBtn" mnemonicParsing="false" onAction="#connectSocket" text="Connect to Game" GridPane.columnIndex="2">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets right="20.0" />
|
|
||||||
</GridPane.margin></Button>
|
|
||||||
<Button mnemonicParsing="false" onAction="#refreshBtnPressed" text="Refresh" GridPane.columnIndex="1">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets left="10.0" right="10.0" />
|
|
||||||
</GridPane.margin></Button>
|
|
||||||
<Button mnemonicParsing="false" onAction="#addConnectionPressed" text="Add">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets left="20.0" />
|
|
||||||
</GridPane.margin></Button>
|
|
||||||
</children>
|
|
||||||
</GridPane>
|
|
||||||
<GridPane fx:id="ipPortGridPane" GridPane.rowIndex="2">
|
<GridPane fx:id="ipPortGridPane" GridPane.rowIndex="2">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
@@ -79,16 +56,44 @@
|
|||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
<opaqueInsets>
|
<opaqueInsets>
|
||||||
<Insets />
|
<Insets />
|
||||||
</opaqueInsets></TextField>
|
</opaqueInsets>
|
||||||
|
</TextField>
|
||||||
<TextField fx:id="portFld" promptText="Port Number" GridPane.columnIndex="1">
|
<TextField fx:id="portFld" promptText="Port Number" GridPane.columnIndex="1">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets left="20.0" right="20.0" />
|
<Insets left="20.0" right="20.0" />
|
||||||
</GridPane.margin></TextField>
|
</GridPane.margin>
|
||||||
|
</TextField>
|
||||||
</children>
|
</children>
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets />
|
<Insets />
|
||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
|
<GridPane fx:id="buttonsGridPane" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Button mnemonicParsing="false" onAction="#refreshBtnPressed" text="Refresh" GridPane.columnIndex="1">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="10.0" right="10.0" />
|
||||||
|
</GridPane.margin></Button>
|
||||||
|
<Button mnemonicParsing="false" onAction="#addConnectionPressed" text="Add">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets left="20.0" />
|
||||||
|
</GridPane.margin></Button>
|
||||||
|
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.columnIndex="2">
|
||||||
|
<children>
|
||||||
|
<Button fx:id="joinGameBtn" mnemonicParsing="false" onAction="#connectParticipate" text="Participate!" />
|
||||||
|
<Button fx:id="spectateButton" mnemonicParsing="false" onAction="#connectSpectate" text="Spectate!" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
<Button mnemonicParsing="false" onAction="#menuBtnPressed" text="Main Menu">
|
<Button mnemonicParsing="false" onAction="#menuBtnPressed" text="Main Menu">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets left="50.0" />
|
<Insets left="50.0" />
|
||||||
|
|||||||
Reference in New Issue
Block a user