Merge branch 'master' into storyD-3D
# Conflicts: # .gitignore # racevisionGame/src/main/java/mock/model/RaceServer.java # racevisionGame/src/main/java/mock/model/collider/Collider.java # racevisionGame/src/main/java/mock/xml/RaceXMLCreator.java # racevisionGame/src/main/java/shared/model/Boat.java # racevisionGame/src/main/java/shared/model/Mark.java # racevisionGame/src/main/java/visualiser/Controllers/HostController.java # racevisionGame/src/main/java/visualiser/Controllers/LobbyController.java # racevisionGame/src/main/java/visualiser/Controllers/MainController.java # racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java # racevisionGame/src/main/java/visualiser/Controllers/TitleController.java # racevisionGame/src/main/java/visualiser/layout/Plane3D.java # racevisionGame/src/main/java/visualiser/layout/SeaSurface.java # racevisionGame/src/main/java/visualiser/layout/View3D.java # racevisionGame/src/main/java/visualiser/utils/PerlinNoiseGenerator.java # racevisionGame/src/main/resources/visualiser/scenes/title.fxml
This commit is contained in:
@@ -9,47 +9,47 @@ import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.media.AudioClip;
|
||||
import network.Messages.HostGame;
|
||||
import visualiser.app.MatchBrowserSingleton;
|
||||
import visualiser.model.RaceConnection;
|
||||
import visualiser.network.MatchBrowserLobbyInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.net.SocketException;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
/**
|
||||
* Controller for the Lobby for entering games
|
||||
*/
|
||||
public class LobbyController extends Controller {
|
||||
|
||||
@FXML
|
||||
private AnchorPane lobbyWrapper;
|
||||
@FXML
|
||||
private TableView<RaceConnection> lobbyTable;
|
||||
@FXML
|
||||
private TableColumn<RaceConnection, String> gameNameColumn;
|
||||
@FXML
|
||||
private TableColumn<RaceConnection, String> hostNameColumn;
|
||||
@FXML
|
||||
private TableColumn<RaceConnection, String> statusColumn;
|
||||
@FXML
|
||||
private Button joinGameBtn;
|
||||
@FXML
|
||||
private TextField addressFld;
|
||||
@FXML
|
||||
private TextField portFld;
|
||||
private @FXML TableView<RaceConnection> lobbyTable;
|
||||
private @FXML TableColumn<RaceConnection, String> gameNameColumn;
|
||||
private @FXML TableColumn<RaceConnection, String> hostNameColumn;
|
||||
private @FXML TableColumn<RaceConnection, String> statusColumn;
|
||||
private @FXML Button joinGameBtn;
|
||||
private @FXML TextField addressFld;
|
||||
private @FXML TextField portFld;
|
||||
|
||||
private ObservableList<RaceConnection> connections;
|
||||
private ObservableList<RaceConnection> customConnections;
|
||||
|
||||
private AudioClip sound;
|
||||
|
||||
//the socket for match browser
|
||||
private DatagramSocket udpSocket;
|
||||
private MatchBrowserLobbyInterface matchBrowserLobbyInterface;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
public void initialize() {
|
||||
// set up the connection table
|
||||
connections = FXCollections.observableArrayList();
|
||||
customConnections = FXCollections.observableArrayList();
|
||||
//connections.add(new RaceConnection("localhost", 4942, "Local Game"));
|
||||
|
||||
lobbyTable.setItems(connections);
|
||||
|
||||
gameNameColumn.setCellValueFactory(cellData -> cellData.getValue().gamenameProperty());
|
||||
hostNameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
|
||||
statusColumn.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
|
||||
@@ -57,12 +57,14 @@ public class LobbyController extends Controller {
|
||||
lobbyTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
|
||||
if (curr != null && curr.statusProperty().getValue().equals("Ready")) {
|
||||
joinGameBtn.setDisable(false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
joinGameBtn.setDisable(true);
|
||||
}
|
||||
});
|
||||
joinGameBtn.setDisable(true);
|
||||
|
||||
this.udpSocket = MatchBrowserSingleton.getInstance().getUdpSocket();
|
||||
receiveMatchData();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,6 +73,7 @@ public class LobbyController extends Controller {
|
||||
public void refreshBtnPressed(){
|
||||
sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/buttonpress.wav").toExternalForm());
|
||||
sound.play();
|
||||
addServerGames();
|
||||
for(RaceConnection connection: connections) {
|
||||
connection.check();
|
||||
}
|
||||
@@ -80,28 +83,25 @@ public class LobbyController extends Controller {
|
||||
} else {
|
||||
joinGameBtn.setDisable(true);
|
||||
}
|
||||
} catch (Exception e){}
|
||||
} catch (Exception ignored){}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a connection.
|
||||
* @throws IOException socket error
|
||||
*/
|
||||
public void connectSocket() {
|
||||
try{
|
||||
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||
lobbyWrapper.setVisible(false);
|
||||
parent.enterLobby(socket, false);
|
||||
} catch (IOException e) { /* Never reached */
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void connectSocket() throws IOException {
|
||||
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||
InGameLobbyController iglc = (InGameLobbyController)loadScene("gameLobby.fxml");
|
||||
iglc.enterGameLobby(socket, false);
|
||||
}
|
||||
|
||||
public void menuBtnPressed(){
|
||||
public void menuBtnPressed() throws IOException {
|
||||
sound = new AudioClip(this.getClass().getResource("/visualiser/sounds/buttonpress.wav").toExternalForm());
|
||||
sound.play();
|
||||
lobbyWrapper.setVisible(false);
|
||||
parent.enterTitle();
|
||||
matchBrowserLobbyInterface.closeSocket();
|
||||
loadScene("title.fxml");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,24 +112,41 @@ public class LobbyController extends Controller {
|
||||
sound.play();
|
||||
String hostName = addressFld.getText();
|
||||
String portString = portFld.getText();
|
||||
try{
|
||||
try {
|
||||
int port = Integer.parseInt(portString);
|
||||
connections.add(new RaceConnection(hostName, port, "Boat Game"));
|
||||
customConnections.add(new RaceConnection(hostName, port, "Boat Game"));
|
||||
connections.addAll(customConnections);
|
||||
addressFld.clear();
|
||||
portFld.clear();
|
||||
}catch(NumberFormatException e){
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Port number entered is not a number");
|
||||
}
|
||||
}
|
||||
|
||||
public AnchorPane startWrapper(){
|
||||
return lobbyWrapper;
|
||||
public void receiveMatchData(){
|
||||
matchBrowserLobbyInterface = new MatchBrowserLobbyInterface();
|
||||
try {
|
||||
matchBrowserLobbyInterface.startReceivingHostData(new DatagramSocket(4941));
|
||||
Observer o = new Observer() {
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
refreshBtnPressed();
|
||||
}
|
||||
};
|
||||
matchBrowserLobbyInterface.addObserver(o);
|
||||
} catch (SocketException e) {
|
||||
System.err.println("Socket 4941 in use");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter the lobby page.
|
||||
* Adds the games received from the server
|
||||
*/
|
||||
public void enterLobby(){
|
||||
lobbyWrapper.setVisible(true);
|
||||
private void addServerGames() {
|
||||
connections.clear();
|
||||
connections.addAll(customConnections);
|
||||
for (HostGame game : matchBrowserLobbyInterface.getGames()) {
|
||||
connections.add(new RaceConnection(game.getIp(), 4942, "Boat Game"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user