You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.6 KiB

package visualiser.Controllers;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import visualiser.gameController.ControllerClient;
import visualiser.model.VisualiserBoat;
import visualiser.model.VisualiserRaceEvent;
import visualiser.network.MatchBrowserInterface;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller that everything is overlayed onto. This makes it so that changing scenes does not resize your stage.
*/
public class MainController extends Controller {
@FXML private StartController startController;
@FXML private RaceController raceController;
@FXML private ConnectionController connectionController;
@FXML private FinishController finishController;
@FXML private TitleController titleController;
@FXML private HostController hostController;
@FXML private LobbyController lobbyController;
@FXML private InGameLobbyController inGameLobbyController;
private MatchBrowserInterface matchBrowserInterface;
private DatagramSocket udpSocket;
/**
* Ctor.
*/
public MainController() {
this.matchBrowserInterface = new MatchBrowserInterface();
try{
this.udpSocket = matchBrowserInterface.setupMatchBrowserConnection();
}catch (IOException e){
System.err.println("Error in setting up connection with match browser");
}
}
/**
* Transitions from the StartController screen (displays pre-race information) to the RaceController (displays the actual race).
* @param visualiserRace The object modelling the race.
* @param controllerClient Socket Client that manipulates the controller.
* @param isHost if the client is the host of a race or not.
*/
public void beginRace(VisualiserRaceEvent visualiserRace, ControllerClient controllerClient, Boolean isHost) {
raceController.startRace(visualiserRace, controllerClient, isHost);
}
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.
* @param isHost is connection a host
*/
public void enterLobby(Socket socket, Boolean isHost) {
startController.enterLobby(socket, isHost);
}
/**
* Transitions from the {@link RaceController} screen to the {@link FinishController} screen.
* @param boats The boats to display on the finish screen.
*/
public void enterFinish(ObservableList<VisualiserBoat> boats) {
finishController.enterFinish(boats);
}
/**
* Transitions into the title screen
*/
public void enterTitle() {
titleController.enterTitle();
}
/**
* Transitions into lobby screen
*/
public void enterLobby(){ lobbyController.enterLobby(udpSocket); }
/**
* Transitions into host game screen
*/
public void hostGame(){ hostController.hostGame(udpSocket); }
/**
* Sets up the css for the start of the program
*/
public void startCss(){titleController.setDayMode();}
/**
* Main Controller for the applications will house the menu and the displayed pane.
*
* @param location of resources
* @param resources bundle
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
startController.setParent(this);
raceController.setParent(this);
connectionController.setParent(this);
finishController.setParent(this);
titleController.setParent(this);
hostController.setParent(this);
lobbyController.setParent(this);
inGameLobbyController.setParent(this);
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);
AnchorPane.setLeftAnchor(lobbyController.startWrapper(), 0.0);
AnchorPane.setRightAnchor(lobbyController.startWrapper(), 0.0);
AnchorPane.setTopAnchor(hostController.startWrapper(), 0.0);
AnchorPane.setBottomAnchor(hostController.startWrapper(), 0.0);
AnchorPane.setLeftAnchor(hostController.startWrapper(), 0.0);
AnchorPane.setRightAnchor(hostController.startWrapper(), 0.0);
AnchorPane.setTopAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setBottomAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setLeftAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setRightAnchor(finishController.finishWrapper, 0.0);
AnchorPane.setTopAnchor(titleController.titleWrapper, 0.0);
AnchorPane.setBottomAnchor(titleController.titleWrapper, 0.0);
AnchorPane.setLeftAnchor(titleController.titleWrapper, 0.0);
AnchorPane.setRightAnchor(titleController.titleWrapper, 0.0);
}
}