Updated host to show the hosted address and port. Fixed css issue with lobby text field.
#story[1087]
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
/* Fix derived prompt color for text fields */
|
||||
.text-input {
|
||||
-fx-prompt-text-fill: derive(-fx-control-inner-background, +0%);
|
||||
-fx-background-color: #a9a9a9 , black , black;
|
||||
-fx-background-color: #a9a9a9, black, grey;
|
||||
}
|
||||
|
||||
/* Keep prompt invisible when focused (above color fix overrides it) */
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
/* Fix derived prompt color for text fields */
|
||||
.text-input {
|
||||
-fx-prompt-text-fill: derive(-fx-control-inner-background, +0%);
|
||||
-fx-background-color: #a9a9a9 , white , white;
|
||||
-fx-background-color: #a9a9a9 , grey, grey;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,21 @@
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<TextField fx:id="gameNameField" disable="true" promptText="Enter game name" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="TOP" />
|
||||
<TextField fx:id="hostNameField" disable="true" promptText="Enter host name" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="BOTTOM" />
|
||||
<Button fx:id="hostGameBtn" mnemonicParsing="false" onAction="#hostGamePressed" text="Host Game" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<Button fx:id="hostGameBtn" mnemonicParsing="false" onAction="#hostGamePressed" text="Start Game" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Label text="Address: 127.0.0.1" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
|
||||
<font>
|
||||
<Font size="17.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label text="Port: 4942" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||
<font>
|
||||
<Font size="17.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
|
||||
@@ -35,11 +35,6 @@
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<TextField fx:id="playerNameField" prefHeight="25.0" prefWidth="315.0" promptText="Enter player name" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<Button fx:id="joinGameBtn" mnemonicParsing="false" onAction="#connectSocket" text="Connect to Game" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets right="50.0" />
|
||||
@@ -47,7 +42,22 @@
|
||||
</Button>
|
||||
<Button mnemonicParsing="false" onAction="#refreshBtnPressed" text="Refresh" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="80.0" />
|
||||
<Insets left="120.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
<TextField fx:id="addressFld" promptText="Address" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="50.0" right="150.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="portFld" promptText="Port Number" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="270.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<Button mnemonicParsing="false" onAction="#addConnectionPressed" text="Add" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="40.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
</children>
|
||||
|
||||
Reference in New Issue
Block a user