Linked table to show games from received packets. #story[1188]
This commit is contained in:
@@ -8,12 +8,19 @@ import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import network.Messages.HostGame;
|
||||
import visualiser.model.RaceConnection;
|
||||
import visualiser.network.MatchBrowserClientRunnable;
|
||||
import visualiser.network.MatchBrowserInterface;
|
||||
import visualiser.network.MatchBrowserLobbyInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.URL;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
@@ -40,13 +47,18 @@ public class LobbyController extends Controller {
|
||||
|
||||
private ObservableList<RaceConnection> connections;
|
||||
|
||||
private ObservableList<RaceConnection> customConnections;
|
||||
|
||||
//the socket for match browser
|
||||
private DatagramSocket udpSocket;
|
||||
|
||||
private MatchBrowserLobbyInterface matchBrowserLobbyInterface;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
connections = FXCollections.observableArrayList();
|
||||
customConnections = FXCollections.observableArrayList();
|
||||
//connections.add(new RaceConnection("localhost", 4942, "Local Game"));
|
||||
|
||||
lobbyTable.setItems(connections);
|
||||
@@ -70,6 +82,7 @@ public class LobbyController extends Controller {
|
||||
* Refreshes the connections in the lobby
|
||||
*/
|
||||
public void refreshBtnPressed(){
|
||||
addServerGames();
|
||||
for(RaceConnection connection: connections) {
|
||||
connection.check();
|
||||
}
|
||||
@@ -97,6 +110,7 @@ public class LobbyController extends Controller {
|
||||
}
|
||||
|
||||
public void menuBtnPressed(){
|
||||
matchBrowserLobbyInterface.closeSocket();
|
||||
lobbyWrapper.setVisible(false);
|
||||
parent.enterTitle();
|
||||
}
|
||||
@@ -109,7 +123,8 @@ public class LobbyController extends Controller {
|
||||
String portString = portFld.getText();
|
||||
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){
|
||||
@@ -127,5 +142,29 @@ public class LobbyController extends Controller {
|
||||
public void enterLobby(DatagramSocket udpSocket){
|
||||
lobbyWrapper.setVisible(true);
|
||||
this.udpSocket = udpSocket;
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the games received from the server
|
||||
*/
|
||||
private void addServerGames() {
|
||||
connections.clear();
|
||||
connections.addAll(customConnections);
|
||||
for (HostGame game : matchBrowserLobbyInterface.getGames()) {
|
||||
connections.add(new RaceConnection(game.getIp(), game.getPort(), "Boat Game"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MainController extends Controller {
|
||||
public MainController() {
|
||||
this.matchBrowserInterface = new MatchBrowserInterface();
|
||||
try{
|
||||
this.udpSocket = matchBrowserInterface.setupMatchBowserConnection();
|
||||
this.udpSocket = matchBrowserInterface.setupMatchBrowserConnection();
|
||||
}catch (IOException e){
|
||||
System.err.println("Error in setting up connection with match browser");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user