Set up controller classes for lobby and host. Made changes to TitleController and MainController. Title screen can now enter lobby and host.

#story[1087]
This commit is contained in:
David Wu
2017-07-25 16:15:32 +12:00
parent 913946265d
commit 9159e16a21
10 changed files with 211 additions and 78 deletions
@@ -0,0 +1,46 @@
package visualiser.Controllers;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import mock.app.App;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by zwu18 on 25/07/17.
*/
public class HostController extends Controller {
@FXML
TextField gameNameField;
@FXML
TextField hostNameField;
@FXML
AnchorPane hostWrapper;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
public void hostGamePressed() throws IOException{
System.out.println("TODO: Run mock");
}
public AnchorPane startWrapper(){
return hostWrapper;
}
public void hostGame(){
hostWrapper.setVisible(true);
System.out.println("Reacted hostGame");
}
}
@@ -0,0 +1,29 @@
package visualiser.Controllers;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by zwu18 on 25/07/17.
*/
public class LobbyController extends Controller {
@FXML
AnchorPane lobbyWrapper;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
public AnchorPane startWrapper(){
return lobbyWrapper;
}
public void enterLobby(){
lobbyWrapper.setVisible(true);
}
}
@@ -20,7 +20,9 @@ public class MainController extends Controller {
@FXML private RaceController raceController;
@FXML private ConnectionController connectionController;
@FXML private FinishController finishController;
@FXML private TitleController titleController;
@FXML private HostController hostController;
@FXML private LobbyController lobbyController;
/**
@@ -56,6 +58,21 @@ public class MainController extends Controller {
finishController.enterFinish(boats);
}
/**
* Transitions into the title screen
*/
public void enterTitle(){ titleController.enterTitle(); }
/**
* Transitions into lobby screen
*/
public void enterLobby(){ lobbyController.enterLobby(); }
/**
* Transitions into host game screen
*/
public void hostGame(){ hostController.hostGame(); }
/**
* Main Controller for the applications will house the menu and the displayed pane.
*
@@ -69,6 +86,10 @@ public class MainController extends Controller {
raceController.setParent(this);
connectionController.setParent(this);
finishController.setParent(this);
titleController.setParent(this);
hostController.setParent(this);
lobbyController.setParent(this);
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0);
@@ -6,9 +6,12 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller for the opening title window.
@@ -16,8 +19,11 @@ import java.io.IOException;
* burger-boat and comic sans styling to allure and entice users into playing
* the game.
*/
public class TitleController {
@FXML Button btnJoin;
public class TitleController extends Controller {
@FXML
Button btnJoin;
@FXML
AnchorPane titleWrapper;
/**
* Method called when the 'host a game' button is pressed.
@@ -27,7 +33,7 @@ public class TitleController {
*/
public void hostAGame() throws IOException {
// load up the main window
Stage stage = new Stage();
/*Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/visualiser/scenes/main.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 1200, 800);
@@ -40,7 +46,14 @@ public class TitleController {
// close title screen
Stage stageOld = (Stage)btnJoin.getScene().getWindow();
stageOld.close();
stageOld.close();*/
titleWrapper.setVisible(false);
parent.hostGame();
}
public void enterTitle(){
titleWrapper.setVisible(true);
}
/**
@@ -48,6 +61,12 @@ public class TitleController {
* games a player can join. Place holder method for now!
*/
public void joinAGame() {
System.out.println("You can't join a game yet ;)");
titleWrapper.setVisible(false);
parent.enterLobby();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}