Merge branch 'master' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into controllerSplit

# Conflicts:
#	racevisionGame/src/main/java/visualiser/Controllers/HostGameController.java
#	racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java
#	racevisionGame/src/main/java/visualiser/Controllers/StartController.java
#	racevisionGame/src/main/java/visualiser/Controllers/hostgame.fxml
#	racevisionGame/src/main/java/visualiser/Controllers/lobbyHosting.fxml
#	racevisionGame/src/main/java/visualiser/Controllers/main.fxml
#	racevisionGame/src/main/java/visualiser/Controllers/raceView.fxml
This commit is contained in:
Jessica Syder
2017-09-11 20:05:24 +12:00
31 changed files with 679 additions and 521 deletions
@@ -1,127 +0,0 @@
package visualiser.Controllers;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
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;
//TODO it appears this view/controller was replaced by Lobby.fxml. Remove?
/**
* Controls the connection that the Visualiser can connect to.
*/
public class ConnectionController extends Controller {
@FXML AnchorPane connectionWrapper;
@FXML TableView<RaceConnection> connectionTable;
@FXML TableColumn<RaceConnection, String> hostnameColumn;
@FXML TableColumn<RaceConnection, String> statusColumn;
@FXML Button connectButton;
@FXML TextField urlField;
@FXML TextField portField;
/*Title Screen fxml items*/
@FXML
private Button hostGameTitleBtn;
@FXML
private Button connectGameBtn;
@FXML
private RadioButton nightRadioBtn;
@FXML
private RadioButton dayRadioButton;
/*Lobby fxml items*/
@FXML
private TableView lobbyTable;
@FXML
private TableColumn gameNameColumn;
@FXML
private TableColumn hostNameColumn;
@FXML
private TableColumn playerCountColumn;
@FXML
private TextField playerNameField;
@FXML
private Button joinGameBtn;
/*Host game fxml items*/
@FXML
private TextField gameNameField;
@FXML
private TextField hostNameField;
@FXML
private TextField hostGameBtn;
private ObservableList<RaceConnection> connections;
public void initialize(URL location, ResourceBundle resources) {
// TODO - replace with config file
connections = FXCollections.observableArrayList();
connectionTable.setItems(connections);
hostnameColumn.setCellValueFactory(cellData -> cellData.getValue().hostnameProperty());
statusColumn.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
connectionTable.getSelectionModel().selectedItemProperty().addListener((obs, prev, curr) -> {
if (curr != null && curr.check()) connectButton.setDisable(false);
else connectButton.setDisable(true);
});
connectButton.setDisable(true);
}
/**
* Sets current status of all connections.
*/
public void checkConnections() {
for(RaceConnection connection: connections) {
connection.check();
}
}
public AnchorPane startWrapper(){
return connectionWrapper;
}
/**
* Connects to host currently selected in table. Button enabled only if host is ready.
*/
public void connectSocket() {
try{
RaceConnection connection = connectionTable.getSelectionModel().getSelectedItem();
Socket socket = new Socket(connection.getHostname(), connection.getPort());
socket.setKeepAlive(true);
connectionWrapper.setVisible(false);
//parent.enterLobby(socket);
} catch (IOException e) { /* Never reached */ }
}
/**
* adds a new connection
*/
public void addConnection(){
String hostName = urlField.getText();
String portString = portField.getText();
try{
int port = Integer.parseInt(portString);
connections.add(new RaceConnection(hostName, port, null));
}catch(NumberFormatException e){
System.err.println("Port number entered is not a number");
}
}
}
@@ -0,0 +1,141 @@
package visualiser.Controllers;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import mock.app.Event;
import mock.exceptions.EventConstructionException;
import visualiser.app.App;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller for Hosting a game.
*/
public class HostController extends Controller {
private @FXML ImageView imageView;
private @FXML AnchorPane imagePane;
private @FXML SplitPane splitPane;
private @FXML AnchorPane specPane;
@FXML ImageView mapImage;
private ArrayList<Image> listOfMaps;
private int currentMapIndex = 0;
@FXML TextField gameNameField;
@FXML TextField hostNameField;
@FXML Button previousButton;
@FXML Button nextButton;
public void initialize() {
Image ac35Map = new Image(getClass().getClassLoader().getResourceAsStream("images/AC35_Racecourse_MAP.png"));
Image oMap = new Image(getClass().getClassLoader().getResourceAsStream("images/oMapLayout.png"));
Image iMap = new Image(getClass().getClassLoader().getResourceAsStream("images/iMapLayout.png"));
Image mMap = new Image(getClass().getClassLoader().getResourceAsStream("images/mMapLayout.png"));
listOfMaps = new ArrayList(Arrays.asList(ac35Map, oMap, iMap, mMap));
// mapImage.setImage(listOfMaps.get(currentMapIndex));
Platform.runLater(() -> {
mapImage.setImage(listOfMaps.get(currentMapIndex));
});
hostGame();
// mapImage..addListener(
// (observable, oldValue, newValue) -> Platform
// .runLater(() -> ));
}
/**
* Hosts a game
*/
public void hostGamePressed() {
try {
App.game = new Event(false, currentMapIndex);
connectSocket("localhost", 4942);
} catch (EventConstructionException e) {
Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e);
throw new RuntimeException(e);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Connect to a socket
* @param address address of the server
* @param port port that the server is run off
*/
public void connectSocket(String address, int port) throws IOException {
Socket socket = new Socket(address, port);
RaceStartController rsc = (RaceStartController)loadScene("raceStart.fxml");
rsc.enterLobby(socket, true);
}
/**
* Hosts a game.
*/
public void hostGame(){
// 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());
Platform.runLater(() -> {
mapImage.fitWidthProperty()
.bind(((Stage)mapImage.getScene().getWindow()).widthProperty().multiply(0.6));
});
// mapImage.fitWidthProperty().bind(((Stage) mapImage.getScene().getWindow()).widthProperty().multiply(0.6));
}
/**
* Menu button pressed. Prompt alert then return to menu
*/
public void menuBtnPressed() throws Exception {
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){
loadTitleScreen();
}}
/**
* 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");
hostGamePressed();
}
public void nextImage(){
increaseIndex();
mapImage.setImage(listOfMaps.get(currentMapIndex));
}
public void previousImage(){
decreaseIndex();
mapImage.setImage(listOfMaps.get(currentMapIndex));
}
private void increaseIndex(){
currentMapIndex = (currentMapIndex + 1)%listOfMaps.size();
}
private void decreaseIndex(){
currentMapIndex = ((((currentMapIndex - 1)%listOfMaps.size())+listOfMaps.size())%listOfMaps.size());
}
}
@@ -1,127 +0,0 @@
package visualiser.Controllers;
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
import javafx.animation.AnimationTimer;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.SplitPane;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.shape.MeshView;
import mock.app.Event;
import mock.exceptions.EventConstructionException;
import visualiser.app.App;
import visualiser.layout.Subject3D;
import visualiser.layout.View3D;
import java.io.IOException;
import java.net.Socket;
import java.net.URL;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller for Hosting a game.
*/
public class LobbyHostingController extends Controller {
private @FXML ImageView imageView;
private @FXML AnchorPane imagePane;
private @FXML SplitPane splitPane;
private @FXML AnchorPane specPane;
private @FXML GridPane playerContainer;
private View3D view3D;
public void initialize() {
hostGame();
ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
view3D = new View3D();
view3D.setItems(subjects);
playerContainer.add(view3D, 0,0);
URL asset = LobbyHostingController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
StlMeshImporter importer = new StlMeshImporter();
importer.read(asset);
Subject3D subject = new Subject3D(new MeshView(importer.getImport()));
subjects.add(subject);
view3D.setPivot(subject);
view3D.setDistance(50);
view3D.setYaw(45);
view3D.setPitch(20);
AnimationTimer rotate = new AnimationTimer() {
@Override
public void handle(long now) {
subject.setHeading(subject.getHeading() + 0.1);
}
};
rotate.start();
}
/**
* Hosts a game
*/
public void hostGamePressed() {
try {
App.game = new Event(false);
connectSocket("localhost", 4942);
} catch (EventConstructionException e) {
Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e);
throw new RuntimeException(e);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Connect to a socket
* @param address address of the server
* @param port port that the server is run off
*/
public void connectSocket(String address, int port) throws IOException {
Socket socket = new Socket(address, port);
RaceStartController rsc = (RaceStartController)loadScene("raceStart.fxml");
rsc.enterLobby(socket, true);
}
/**
* Hosts a game.
*/
public void hostGame(){
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());
}
/**
* Menu button pressed. Prompt alert then return to menu
*/
public void menuBtnPressed() throws Exception {
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){
loadTitleScreen();
}
}
/**
* 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");
hostGamePressed();
}
}