Updated host to show the hosted address and port. Fixed css issue with lobby text field.

#story[1087]
This commit is contained in:
David Wu
2017-07-27 13:12:39 +12:00
parent f4eb03e79e
commit 2b8b334486
6 changed files with 57 additions and 25 deletions
@@ -33,11 +33,6 @@ public class HostController extends Controller {
@FXML
AnchorPane hostWrapper;
@FXML
TextField gameAddressFld;
@FXML
TextField gamePortFld;
@Override
public void initialize(URL location, ResourceBundle resources) {
@@ -46,12 +41,8 @@ public class HostController extends Controller {
public void hostGamePressed() throws IOException{
try {
Event game = Event.getEvent();
gameAddressFld.textProperty().set(game.getAddress());
gamePortFld.textProperty().set(Integer.toString(game.getPort()));
System.out.println(gameAddressFld.textProperty().getValue());
System.out.println(gamePortFld.textProperty().getValue());
game.start();
connectSocket(gameAddressFld.textProperty().getValue(), Integer.parseInt(gamePortFld.textProperty().getValue()));
connectSocket("localhost", 4942);
} catch (InvalidRaceDataException e) {
e.printStackTrace();
} catch (XMLReaderException e) {
@@ -60,8 +51,6 @@ public class HostController extends Controller {
e.printStackTrace();
} catch (InvalidRegattaDataException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
@@ -6,6 +6,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import visualiser.model.RaceConnection;
@@ -32,6 +33,10 @@ public class LobbyController extends Controller {
private TableColumn<RaceConnection, String> statusColumn;
@FXML
private Button joinGameBtn;
@FXML
private TextField addressFld;
@FXML
private TextField portFld;
private ObservableList<RaceConnection> connections;
@@ -39,7 +44,7 @@ public class LobbyController extends Controller {
@Override
public void initialize(URL location, ResourceBundle resources) {
connections = FXCollections.observableArrayList();
connections.add(new RaceConnection("localhost", 4942, "Local Game"));
//connections.add(new RaceConnection("localhost", 4942, "Local Game"));
lobbyTable.setItems(connections);
@@ -62,8 +67,12 @@ public class LobbyController extends Controller {
public void refreshBtnPressed(){
for(RaceConnection connection: connections) {
connection.check();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
try {
if (lobbyTable.getSelectionModel().getSelectedItem().statusProperty().getValue().equals("Ready")) {
joinGameBtn.setDisable(false);
@@ -84,6 +93,22 @@ public class LobbyController extends Controller {
}
}
/**
* adds a new connection
*/
public void addConnectionPressed(){
String hostName = addressFld.getText();
String portString = portFld.getText();
try{
int port = Integer.parseInt(portString);
connections.add(new RaceConnection(hostName, port, "Boat Game"));
addressFld.clear();
portFld.clear();
}catch(NumberFormatException e){
System.err.println("Port number entered is not a number");
}
}
public AnchorPane startWrapper(){
return lobbyWrapper;
}