@@ -78,7 +78,7 @@ public class HostController extends Controller {
|
||||
try{
|
||||
Socket socket = new Socket(address, port);
|
||||
hostWrapper.setVisible(false);
|
||||
parent.enterLobby(socket, true);
|
||||
parent.enterGameLobby(socket, true);
|
||||
} catch (IOException e) { /* Never reached */ }
|
||||
}
|
||||
|
||||
|
||||
@@ -2,73 +2,71 @@ package visualiser.Controllers;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.shape.Box;
|
||||
import mock.app.Event;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import network.Messages.Enums.RequestToJoinEnum;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.model.View3D;
|
||||
import visualiser.layout.Subject3D;
|
||||
import visualiser.layout.View3D;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRaceEvent;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Controller for Hosting a game.
|
||||
*/
|
||||
public class InGameLobby extends Controller {
|
||||
|
||||
|
||||
// @FXML
|
||||
// TextField gameNameField;
|
||||
//
|
||||
// @FXML
|
||||
// TextField hostNameField;
|
||||
|
||||
public class InGameLobbyController extends Controller {
|
||||
@FXML
|
||||
private ImageView imageView;
|
||||
|
||||
@FXML
|
||||
AnchorPane gameLobbyWrapper;
|
||||
|
||||
@FXML
|
||||
AnchorPane imagePane;
|
||||
|
||||
@FXML
|
||||
SplitPane splitPane;
|
||||
|
||||
@FXML
|
||||
AnchorPane specPane;
|
||||
|
||||
@FXML
|
||||
GridPane playerContainer;
|
||||
|
||||
@FXML
|
||||
private Pane playerPane;
|
||||
|
||||
@FXML
|
||||
private Pane playerPane4;
|
||||
private Label playerLabel;
|
||||
|
||||
@FXML
|
||||
private Button startButton;
|
||||
private Label playerLabel2;
|
||||
|
||||
@FXML
|
||||
private Label countdownLable;
|
||||
private Label playerLabel3;
|
||||
|
||||
@FXML
|
||||
private Label playerLabel4;
|
||||
|
||||
@FXML
|
||||
private Label playerLabel5;
|
||||
|
||||
@FXML
|
||||
private Label playerLabel6;
|
||||
|
||||
@FXML
|
||||
private Label countdownLabel;
|
||||
|
||||
private Event game;
|
||||
|
||||
private View3D fancyStuff;
|
||||
private View3D playerBoat;
|
||||
|
||||
private VisualiserRaceEvent visualiserRaceEvent;
|
||||
|
||||
@@ -76,28 +74,82 @@ public class InGameLobby extends Controller {
|
||||
|
||||
private ControllerClient controllerClient;
|
||||
|
||||
private ArrayList<Label> allPlayerLabels;
|
||||
|
||||
private ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
fancyStuff = new View3D();
|
||||
playerPane4.getChildren().add(fancyStuff);
|
||||
allPlayerLabels = new ArrayList(Arrays.asList(playerLabel, playerLabel2,
|
||||
playerLabel3,
|
||||
playerLabel4,
|
||||
playerLabel5,
|
||||
playerLabel6));
|
||||
}
|
||||
|
||||
//centering the 3d object
|
||||
fancyStuff.layoutXProperty().bind(playerPane4.widthProperty().subtract(fancyStuff.widthProperty()).divide(2));
|
||||
fancyStuff.layoutYProperty().bind(playerPane4.heightProperty().subtract(fancyStuff.heightProperty()).divide(2));
|
||||
//playerContainer.add(fancyStuff, 0,0);
|
||||
private void populatePlayers(ListChangeListener.Change change){
|
||||
Platform.runLater(
|
||||
() -> {
|
||||
while (change.next()){
|
||||
if (change.wasAdded()){
|
||||
try{
|
||||
int count = 0;
|
||||
int row = 0;
|
||||
for (VisualiserBoat boat :this.visualiserRaceEvent.getVisualiserRaceState().getBoats()) {
|
||||
View3D playerBoatToSet = new View3D();
|
||||
playerBoatToSet.setItems(subjects);
|
||||
playerContainer.add(playerBoatToSet, (count % 3) , row);
|
||||
playerContainer.setMargin(playerBoatToSet, new Insets(10, 10, 10, 10));
|
||||
|
||||
fancyStuff.spinBox();
|
||||
Subject3D subject = new Subject3D(new Box());
|
||||
subjects.add(subject);
|
||||
|
||||
playerBoatToSet.setDistance(50);
|
||||
playerBoatToSet.setYaw(45);
|
||||
playerBoatToSet.setPitch(20);
|
||||
|
||||
|
||||
|
||||
AnimationTimer rotate = new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(subject.getHeading() + 0.1);
|
||||
}
|
||||
};
|
||||
rotate.start();
|
||||
|
||||
allPlayerLabels.get(count).setText("Player: " + boat.getSourceID());
|
||||
allPlayerLabels.get(count).toFront();
|
||||
count += 1;
|
||||
if (count > 2){
|
||||
row = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ConcurrentModificationException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the race.
|
||||
*/
|
||||
private void startRace() {
|
||||
//Initialises the race clock.
|
||||
initialiseRaceClock(this.visualiserRaceEvent.getVisualiserRaceState());
|
||||
|
||||
|
||||
//Starts the race countdown timer.
|
||||
countdownTimer();
|
||||
}
|
||||
|
||||
public AnchorPane gameLobbyWrapper(){
|
||||
return gameLobbyWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the race clock/timer labels for the start time, current time, and remaining time.
|
||||
* @param visualiserRace The race to get data from.
|
||||
@@ -117,7 +169,7 @@ public class InGameLobby extends Controller {
|
||||
|
||||
visualiserRace.getRaceClock().durationProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Platform.runLater(() -> {
|
||||
countdownLable.setText(newValue);
|
||||
countdownLabel.setText(newValue);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -153,23 +205,20 @@ public class InGameLobby extends Controller {
|
||||
* Hosts a game.
|
||||
*/
|
||||
public void enterGameLobby(Socket socket, boolean isHost){
|
||||
splitPane.setResizableWithParent(specPane, false);
|
||||
splitPane.lookupAll(".split-pane-divider").stream().forEach(div -> div.setMouseTransparent(true));
|
||||
imageView.fitWidthProperty().bind(imagePane.widthProperty());
|
||||
imageView.fitHeightProperty().bind(imagePane.heightProperty());
|
||||
this.isHost = isHost;
|
||||
this.controllerClient = visualiserRaceEvent.getControllerClient();
|
||||
|
||||
if (!isHost){
|
||||
startButton.setVisible(false);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
this.visualiserRaceEvent = new VisualiserRaceEvent(socket, RequestToJoinEnum.PARTICIPANT);
|
||||
this.isHost = isHost;
|
||||
this.controllerClient = visualiserRaceEvent.getControllerClient();
|
||||
|
||||
|
||||
this.visualiserRaceEvent.getVisualiserRaceState().getBoats().addListener((ListChangeListener<? super VisualiserBoat>) c ->{
|
||||
populatePlayers(c);
|
||||
});
|
||||
|
||||
|
||||
gameLobbyWrapper.setVisible(true);
|
||||
startRace();
|
||||
|
||||
} catch (IOException e) {
|
||||
//TODO should probably let this propagate, so that we only enter this scene if everything works
|
||||
Logger.getGlobal().log(Level.WARNING, "Could not connect to server.", e);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class LobbyController extends Controller {
|
||||
RaceConnection connection = lobbyTable.getSelectionModel().getSelectedItem();
|
||||
Socket socket = new Socket(connection.getHostname(), connection.getPort());
|
||||
lobbyWrapper.setVisible(false);
|
||||
parent.enterLobby(socket, false);
|
||||
parent.enterGameLobby(socket, false);
|
||||
} catch (IOException e) { /* Never reached */
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class MainController extends Controller {
|
||||
@FXML private TitleController titleController;
|
||||
@FXML private HostController hostController;
|
||||
@FXML private LobbyController lobbyController;
|
||||
@FXML private InGameLobbyController inGameLobbyController;
|
||||
|
||||
private MatchBrowserInterface matchBrowserInterface;
|
||||
private DatagramSocket udpSocket;
|
||||
@@ -57,6 +58,15 @@ public class MainController extends Controller {
|
||||
|
||||
public void endEvent() throws IOException { hostController.endEvent(); }
|
||||
|
||||
/**
|
||||
* Transitions from the server selection screen to the pre-race lobby for a given server.
|
||||
* @param socket The server to read data from.
|
||||
* @param isHost is connection a host
|
||||
*/
|
||||
public void enterGameLobby(Socket socket, Boolean isHost) {
|
||||
inGameLobbyController.enterGameLobby(socket, isHost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transitions from the server selection screen to the pre-race lobby for a given server.
|
||||
* @param socket The server to read data from.
|
||||
@@ -112,12 +122,13 @@ public class MainController extends Controller {
|
||||
titleController.setParent(this);
|
||||
hostController.setParent(this);
|
||||
lobbyController.setParent(this);
|
||||
inGameLobbyController.setParent(this);
|
||||
|
||||
|
||||
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setTopAnchor(inGameLobbyController.gameLobbyWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(inGameLobbyController.gameLobbyWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(inGameLobbyController.gameLobbyWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(inGameLobbyController.gameLobbyWrapper(), 0.0);
|
||||
|
||||
AnchorPane.setTopAnchor(lobbyController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(lobbyController.startWrapper(), 0.0);
|
||||
|
||||
Reference in New Issue
Block a user