@ -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 {