|
|
|
|
@ -9,6 +9,7 @@ import javafx.scene.control.TableColumn;
|
|
|
|
|
import javafx.scene.control.TableView;
|
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
|
import network.Messages.Enums.RequestToJoinEnum;
|
|
|
|
|
import javafx.scene.media.AudioClip;
|
|
|
|
|
import network.Messages.HostGame;
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
@ -35,6 +36,7 @@ public class LobbyController extends Controller {
|
|
|
|
|
private @FXML TableColumn<RaceConnection, String> hostNameColumn;
|
|
|
|
|
private @FXML TableColumn<RaceConnection, String> statusColumn;
|
|
|
|
|
private @FXML Button joinGameBtn;
|
|
|
|
|
private @FXML Button spectateButton;
|
|
|
|
|
private @FXML TextField addressFld;
|
|
|
|
|
private @FXML TextField portFld;
|
|
|
|
|
|
|
|
|
|
@ -62,11 +64,14 @@ public class LobbyController extends Controller {
|
|
|
|
|
lobbyTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
|
|
|
|
|
if (curr != null && curr.statusProperty().getValue().equals("Ready")) {
|
|
|
|
|
joinGameBtn.setDisable(false);
|
|
|
|
|
spectateButton.setDisable(false);
|
|
|
|
|
} else {
|
|
|
|
|
joinGameBtn.setDisable(true);
|
|
|
|
|
spectateButton.setDisable(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
joinGameBtn.setDisable(true);
|
|
|
|
|
spectateButton.setDisable(true);
|
|
|
|
|
|
|
|
|
|
receiveMatchData();
|
|
|
|
|
}
|
|
|
|
|
@ -84,22 +89,41 @@ public class LobbyController extends Controller {
|
|
|
|
|
try {
|
|
|
|
|
if (lobbyTable.getSelectionModel().getSelectedItem().statusProperty().getValue().equals("Ready")) {
|
|
|
|
|
joinGameBtn.setDisable(false);
|
|
|
|
|
spectateButton.setDisable(false);
|
|
|
|
|
} else {
|
|
|
|
|
joinGameBtn.setDisable(true);
|
|
|
|
|
spectateButton.setDisable(true);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ignored){}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Connect to a connection.
|
|
|
|
|
* @param joinType How the client wishes to join (e.g., participant).
|
|
|
|
|
* @throws IOException socket error
|
|
|
|
|
*/
|
|
|
|
|
public void connectSocket() throws IOException {
|
|
|
|
|
public void connectSocket(RequestToJoinEnum joinType) throws IOException {
|
|
|
|
|
httpMatchBrowserClient.interrupt();
|
|
|
|
|
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
|
|
|
|
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
|
|
|
|
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 {
|
|
|
|
|
|