diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 108a9ce..2bde023 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -16,6 +16,7 @@ import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.ClipboardContent; @@ -38,6 +39,7 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; import latice.controller.MainScreenController; +import latice.controller.PlayerNameInputController; import latice.model.Color; import latice.model.Deck; import latice.model.Rack; @@ -72,10 +74,18 @@ public class LaticeApplicationWindow extends Application { ArrayList listOfTile = new ArrayList(); Map assocRectangleTile = new HashMap(); static StackPane rootLayout; + private Label namePlayer1 = new Label(); + private Label namePlayer2 = new Label(); - public static int indexTileClicked; + //root layout + BorderPane root = new BorderPane(); + + //StackPane for background image + BorderPane root onto it + StackPane stackPane = new StackPane(); + static Stage primaryStageCopy; + @@ -92,11 +102,8 @@ public class LaticeApplicationWindow extends Application { Parent loader = FXMLLoader.load(getClass().getResource("../view/MainScreen.fxml")); Scene menu = new Scene(loader, 1280, 720); MainScreenController MSC = new MainScreenController(); + - //StackPane for background image + BorderPane root onto it - StackPane stackPane = new StackPane(); - //root layout - BorderPane root = new BorderPane(); //Title Text title = new Text("Latice"); @@ -276,10 +283,10 @@ public class LaticeApplicationWindow extends Application { } } - - + root.setLeft(namePlayer1); //-------------------------------------------------------------------------------------- + setPrimaryStage(primaryStage); setRootLayout(stackPane); stackPane.getChildren().add(root); @@ -302,9 +309,9 @@ public class LaticeApplicationWindow extends Application { public static int getIndexTileClicked() { return indexTileClicked; } - - - + public void setPrimaryStage(Stage primaryStage) { + this.primaryStageCopy = primaryStage; + } //Setter to set the mouse clicked tile @@ -312,6 +319,23 @@ public class LaticeApplicationWindow extends Application { LaticeApplicationWindow.indexTileClicked = indexTileClicked; } + //player names setters + public void setNamePlayer1(String namePlayer1) { + this.namePlayer1.setText(namePlayer1); + } + + public void setNamePlayer2(String namePlayer2) { + this.namePlayer2.setText(namePlayer2); + } + public void playerNamesEntered() { + System.out.println("entered playNamesEntered()" + namePlayer1 + " VS " + namePlayer2); + HBox scoreHbox = new HBox(); + scoreHbox.getChildren().add(namePlayer1); + scoreHbox.getChildren().add(namePlayer2); + Text working = new Text("Working"); + root.setLeft(working); + primaryStageCopy.show(); + } } diff --git a/src/main/java/latice/controller/MainScreenController.java b/src/main/java/latice/controller/MainScreenController.java index 99da2bb..2ebb3b7 100644 --- a/src/main/java/latice/controller/MainScreenController.java +++ b/src/main/java/latice/controller/MainScreenController.java @@ -1,12 +1,16 @@ package latice.controller; +import java.io.IOException; + import javafx.animation.Interpolator; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Platform; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.scene.Node; +import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; @@ -29,28 +33,22 @@ public class MainScreenController extends LaticeApplicationWindow{ private StackPane parentStackPane; @FXML private BorderPane menuBorderPane; + public static Stage mainStage; + private static StackPane parentStackPaneStock; // Event Listener on Rectangle[#playButton].onMouseClicked @FXML - public void playButtonClicked(MouseEvent event) { + public void playButtonClicked(MouseEvent event) throws IOException { + System.out.println(parentStackPane); + parentStackPaneStock = parentStackPane; System.out.println("playButtonClicked"); - Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); - StackPane root = getRootLayout(); - root.translateYProperty().set(primaryStage.getHeight()); - parentStackPane.getChildren().add(root); - - //parameters of the animation - Timeline timeline = new Timeline(); - KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); - KeyFrame kf = new KeyFrame(Duration.seconds(1), kv); - timeline.getKeyFrames().add(kf); - - //when the animation is finished we're removing the main screen - timeline.setOnFinished(t -> { - parentStackPane.getChildren().remove(menuBorderPane); - }); - timeline.play(); + mainStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); + System.out.println(mainStage); + if (!PlayerNameInputController.btnClicked) { + playerNamesInput(event); + } } + // Event Listener on Rectangle[#rulesButton].onMouseClicked @FXML public void rulesButtonClicked(MouseEvent event) { @@ -86,4 +84,52 @@ public class MainScreenController extends LaticeApplicationWindow{ System.out.println("exitButtonClicked"); Platform.exit(); } + + public void playerNamesInput(MouseEvent event) throws IOException { + Parent loader = FXMLLoader.load(getClass().getResource("../view/PlayerNameInput.fxml")); + Scene nameInputScene = new Scene(loader, 600, 300); + Stage primaryStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); + + // New window (Stage) + Stage nameInputStage = new Stage(); + nameInputStage.setTitle("Names"); + nameInputStage.setScene(nameInputScene); + + // Specifies the modality for new window + nameInputStage.initModality(Modality.WINDOW_MODAL); + + // Specifies the owner window + nameInputStage.initOwner(primaryStage); + + // Set position of window + nameInputStage.setX(primaryStage.getX() + 300); + nameInputStage.setY(primaryStage.getY() + 175); + + nameInputStage.show(); + } + + public void startGameInstruction() { + startGame(mainStage); + } + + public void startGame(Stage stage) { + parentStackPane = parentStackPaneStock; + StackPane root = getRootLayout(); + root.translateYProperty().set(stage.getHeight()); + System.out.println(parentStackPane); + System.out.println(parentStackPaneStock); + parentStackPane.getChildren().add(root); + + //parameters of the animation + Timeline timeline = new Timeline(); + KeyValue kv = new KeyValue(root.translateYProperty(), 0, Interpolator.EASE_IN); + KeyFrame kf = new KeyFrame(Duration.seconds(1), kv); + timeline.getKeyFrames().add(kf); + + //when the animation is finished we're removing the main screen + timeline.setOnFinished(t -> { + parentStackPane.getChildren().remove(menuBorderPane); + }); + timeline.play(); + } } diff --git a/src/main/java/latice/controller/PlayerNameInputController.java b/src/main/java/latice/controller/PlayerNameInputController.java new file mode 100644 index 0000000..6d181b4 --- /dev/null +++ b/src/main/java/latice/controller/PlayerNameInputController.java @@ -0,0 +1,39 @@ +package latice.controller; + +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.scene.Node; +import javafx.scene.control.Button; + +import javafx.scene.control.TextField; +import javafx.scene.input.MouseEvent; +import javafx.stage.Stage; +import latice.application.LaticeApplicationWindow; + +public class PlayerNameInputController { + @FXML + private TextField nomJoueur1; + @FXML + private TextField nomJoueur2; + @FXML + public Button btnValid; + public static boolean btnClicked = false; + MainScreenController mainScreenController = new MainScreenController(); + LaticeApplicationWindow laticeApplicationWindow = new LaticeApplicationWindow(); + + @FXML + public void validBtnClicked(MouseEvent event) { + System.out.println("valid Button Clicked"); + Stage nameInputStage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); + //setting player names + String name1 = nomJoueur1.getText(); + String name2 = nomJoueur2.getText(); + laticeApplicationWindow.setNamePlayer1(name1); + laticeApplicationWindow.setNamePlayer2(name2); + btnClicked = true; + nameInputStage.close(); + laticeApplicationWindow.playerNamesEntered(); + mainScreenController.startGameInstruction(); + } + +} diff --git a/src/main/java/latice/view/PlayerNameInput.fxml b/src/main/java/latice/view/PlayerNameInput.fxml new file mode 100644 index 0000000..294994e --- /dev/null +++ b/src/main/java/latice/view/PlayerNameInput.fxml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +