|
|
|
|
@ -1,8 +1,17 @@
|
|
|
|
|
package visualiser.Controllers;
|
|
|
|
|
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
|
import javafx.scene.control.TableColumn;
|
|
|
|
|
import javafx.scene.control.TableView;
|
|
|
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
|
import visualiser.model.RaceConnection;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.Socket;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
|
|
|
|
@ -13,10 +22,53 @@ public class LobbyController extends Controller {
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
private ObservableList<RaceConnection> connections;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
|
|
|
connections = 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());
|
|
|
|
|
|
|
|
|
|
lobbyTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
|
|
|
|
|
if (curr != null && ((RaceConnection)curr).check())
|
|
|
|
|
{joinGameBtn.setDisable(false);}
|
|
|
|
|
|
|
|
|
|
else {joinGameBtn.setDisable(true);}
|
|
|
|
|
});
|
|
|
|
|
joinGameBtn.setDisable(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void refreshBtnPressed(){
|
|
|
|
|
for(RaceConnection connection: connections) {
|
|
|
|
|
connection.check();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void connectSocket() {
|
|
|
|
|
try{
|
|
|
|
|
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
|
|
|
|
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
|
|
|
|
lobbyWrapper.setVisible(false);
|
|
|
|
|
parent.enterLobby(socket);
|
|
|
|
|
} catch (IOException e) { /* Never reached */ }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AnchorPane startWrapper(){
|
|
|
|
|
|