Merge remote-tracking branch 'remotes/origin/story77_lobby' into story77

# Conflicts:
#	racevisionGame/src/main/java/visualiser/Controllers/HostController.java
This commit is contained in:
hba56
2017-09-08 13:34:48 +12:00
12 changed files with 576 additions and 106 deletions
@@ -0,0 +1,209 @@
package visualiser.Controllers;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.fxml.FXML;
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 mock.app.Event;
import network.Messages.Enums.RaceStatusEnum;
import network.Messages.Enums.RequestToJoinEnum;
import visualiser.gameController.ControllerClient;
import visualiser.model.View3D;
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.logging.Level;
import java.util.logging.Logger;
/**
* Controller for Hosting a game.
*/
public class InGameLobby extends Controller {
// @FXML
// TextField gameNameField;
//
// @FXML
// TextField hostNameField;
@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;
@FXML
private Button startButton;
@FXML
private Label countdownLable;
private Event game;
private View3D fancyStuff;
private VisualiserRaceEvent visualiserRaceEvent;
private boolean isHost;
private ControllerClient controllerClient;
@Override
public void initialize(URL location, ResourceBundle resources) {
fancyStuff = new View3D();
playerPane4.getChildren().add(fancyStuff);
//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);
fancyStuff.spinBox();
}
/**
* Starts the race.
*/
private void startRace() {
initialiseRaceClock(this.visualiserRaceEvent.getVisualiserRaceState());
//Starts the race countdown timer.
countdownTimer();
}
/**
* Initialises the race clock/timer labels for the start time, current time, and remaining time.
* @param visualiserRace The race to get data from.
*/
private void initialiseRaceClock(VisualiserRaceState visualiserRace) {
//Remaining time.
initialiseRaceClockDuration(visualiserRace);
}
/**
* Initialises the race duration label.
* @param visualiserRace The race to get data from.
*/
private void initialiseRaceClockDuration(VisualiserRaceState visualiserRace) {
visualiserRace.getRaceClock().durationProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
countdownLable.setText(newValue);
});
});
}
/**
* Countdown timer until race starts.
*/
private void countdownTimer() {
new AnimationTimer() {
@Override
public void handle(long arg0) {
//Get the current race status.
RaceStatusEnum raceStatus = visualiserRaceEvent.getVisualiserRaceState().getRaceStatusEnum();
//If the race has reached the preparatory phase, or has started...
if (raceStatus == RaceStatusEnum.PREPARATORY || raceStatus == RaceStatusEnum.STARTED) {
//Stop this timer.
stop();
//Hide this, and display the race controller.
gameLobbyWrapper.setVisible(false);
parent.beginRace(visualiserRaceEvent, controllerClient, isHost);
}
}
}.start();
}
/**
* 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);
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);
}
}
/**
* Menu button pressed. Prompt alert then return to menu
*/
public void menuBtnPressed(){
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Quitting race");
alert.setContentText("Do you wish to quit the race?");
alert.setHeaderText("You are about to quit the race");
Optional<ButtonType> result = alert.showAndWait();
if(result.get() == ButtonType.OK){
gameLobbyWrapper.setVisible(false);
parent.enterTitle();
}
}
/**
* Start button pressed. Currently only prints out start
*/
public void startBtnPressed(){
System.out.println("Should start the race. This button is only visible for the host");
}
public void joinSpecPressed(){
System.out.println("Spectator list pressed. Joining spectators");
}
public void joinRacePressed(){
System.out.println("Empty race user pane pressed. Joining racers");
}
}
@@ -29,7 +29,7 @@ import java.util.ResourceBundle;
public class LobbyController extends Controller {
@FXML
AnchorPane lobbyWrapper;
private AnchorPane lobbyWrapper;
@FXML
private TableView<RaceConnection> lobbyTable;
@FXML
@@ -81,7 +81,6 @@ public class TitleController extends Controller {
@Override
public void initialize(URL location, ResourceBundle resources) {
}
/**