|
|
|
@ -7,6 +7,7 @@ import javafx.scene.control.Button;
|
|
|
|
import javafx.scene.control.TableColumn;
|
|
|
|
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 network.Messages.Enums.RequestToJoinEnum;
|
|
|
|
import network.Messages.HostGame;
|
|
|
|
import network.Messages.HostGame;
|
|
|
|
import visualiser.app.MatchBrowserSingleton;
|
|
|
|
import visualiser.app.MatchBrowserSingleton;
|
|
|
|
import visualiser.model.RaceConnection;
|
|
|
|
import visualiser.model.RaceConnection;
|
|
|
|
@ -28,6 +29,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;
|
|
|
|
|
|
|
|
|
|
|
|
@ -53,11 +55,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();
|
|
|
|
@ -74,21 +79,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 {
|
|
|
|
|