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

#story[1087]
main
David Wu 9 years ago
parent 913946265d
commit 9159e16a21

@ -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 RaceController raceController;
@FXML private ConnectionController connectionController; @FXML private ConnectionController connectionController;
@FXML private FinishController finishController; @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); 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. * 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); raceController.setParent(this);
connectionController.setParent(this); connectionController.setParent(this);
finishController.setParent(this); finishController.setParent(this);
titleController.setParent(this);
hostController.setParent(this);
lobbyController.setParent(this);
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0); AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
AnchorPane.setBottomAnchor(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.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/** /**
* Controller for the opening title window. * 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 * burger-boat and comic sans styling to allure and entice users into playing
* the game. * the game.
*/ */
public class TitleController { public class TitleController extends Controller {
@FXML Button btnJoin; @FXML
Button btnJoin;
@FXML
AnchorPane titleWrapper;
/** /**
* Method called when the 'host a game' button is pressed. * Method called when the 'host a game' button is pressed.
@ -27,7 +33,7 @@ public class TitleController {
*/ */
public void hostAGame() throws IOException { public void hostAGame() throws IOException {
// load up the main window // load up the main window
Stage stage = new Stage(); /*Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/visualiser/scenes/main.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("/visualiser/scenes/main.fxml"));
Parent root = loader.load(); Parent root = loader.load();
Scene scene = new Scene(root, 1200, 800); Scene scene = new Scene(root, 1200, 800);
@ -40,7 +46,14 @@ public class TitleController {
// close title screen // close title screen
Stage stageOld = (Stage)btnJoin.getScene().getWindow(); 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! * games a player can join. Place holder method for now!
*/ */
public void joinAGame() { 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) {
} }
} }

@ -9,6 +9,7 @@ import javafx.scene.Scene;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.WindowEvent; import javafx.stage.WindowEvent;
import visualiser.Controllers.MainController;
public class App extends Application { public class App extends Application {
@ -35,9 +36,11 @@ public class App extends Application {
} }
}); });
FXMLLoader loader = new FXMLLoader(getClass().getResource FXMLLoader loader = new FXMLLoader(getClass().getResource
("/visualiser/scenes/titleScreen.fxml")); ("/visualiser/scenes/main.fxml"));
Parent root = loader.load(); Parent root = loader.load();
stage.setResizable(false); stage.setResizable(false);
MainController mc = (MainController) loader.getController();
mc.enterTitle();
Scene scene = new Scene(root); Scene scene = new Scene(root);
stage.setScene(scene); stage.setScene(scene);

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
<children> <children>
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

@ -7,7 +7,7 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController"> <AnchorPane fx:id="hostWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.HostController">
<children> <children>
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>
@ -23,7 +23,7 @@
<children> <children>
<TextField fx:id="gameNameField" promptText="Enter game name" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="TOP" /> <TextField fx:id="gameNameField" promptText="Enter game name" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="TOP" />
<TextField fx:id="hostNameField" promptText="Enter host name" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="BOTTOM" /> <TextField fx:id="hostNameField" promptText="Enter host name" GridPane.columnIndex="1" GridPane.rowIndex="1" GridPane.valignment="BOTTOM" />
<Button fx:id="hostGameBtn" mnemonicParsing="false" text="Host Game" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2"> <Button fx:id="hostGameBtn" mnemonicParsing="false" onAction="#hostGamePressed" text="Host Game" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>

@ -7,7 +7,7 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController"> <AnchorPane fx:id="lobbyWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.LobbyController">
<children> <children>
<GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <GridPane fx:id="connection" prefHeight="600.0" prefWidth="780.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>

@ -7,5 +7,8 @@
<fx:include fx:id="start" source="start.fxml" /> <fx:include fx:id="start" source="start.fxml" />
<fx:include fx:id="connection" source="connect.fxml" /> <fx:include fx:id="connection" source="connect.fxml" />
<fx:include fx:id="finish" source="finish.fxml" /> <fx:include fx:id="finish" source="finish.fxml" />
<fx:include fx:id="host" source="hostgame.fxml" />
<fx:include fx:id="title" source="titleScreen.fxml" />
<fx:include fx:id="lobby" source="lobby.fxml" />
</children> </children>
</AnchorPane> </AnchorPane>

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.image.Image?> <?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?> <?import javafx.scene.image.ImageView?>
@ -10,7 +15,9 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController"> <AnchorPane fx:id="titleWrapper" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController">
<children>
<GridPane layoutY="39.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
@ -80,4 +87,6 @@
</children> </children>
</Pane> </Pane>
</children> </children>
</GridPane> </GridPane>
</children>
</AnchorPane>

Loading…
Cancel
Save