Merge branch 'Test_Branch' into 'Latice_Console_2.0'

added player name input window + working latice console

See merge request odabasioglu1/latice!5
master
Odabasioglu Cemal 2022-05-30 17:40:36 +00:00
commit a5c0bd9b5d
4 changed files with 176 additions and 27 deletions

View File

@ -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<Tile> listOfTile = new ArrayList<Tile>();
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane alignment="CENTER" hgap="50.0" prefHeight="300.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="latice.controller.PlayerNameInputController">
<children>
<Label alignment="TOP_LEFT" text="Nom joueur 1 : ">
<GridPane.margin>
<Insets left="35.0" />
</GridPane.margin>
</Label>
<Label text="Nom joueur 2 : " GridPane.columnIndex="1">
<GridPane.margin>
<Insets left="35.0" />
</GridPane.margin>
</Label>
<TextField fx:id="nomJoueur1" GridPane.rowIndex="1" />
<TextField fx:id="nomJoueur2" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button fx:id="validBtn" mnemonicParsing="false" onMouseClicked="#validBtnClicked" text="Valider" GridPane.columnIndex="1" GridPane.rowIndex="2">
<GridPane.margin>
<Insets left="100.0" top="50.0" />
</GridPane.margin>
</Button>
</children>
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="39.99999389648437" minHeight="22.40001831054687" prefHeight="25.599999999999994" />
<RowConstraints maxHeight="25.59998168945313" minHeight="8.00000610351563" prefHeight="22.400000000000006" />
<RowConstraints maxHeight="25.59998168945313" minHeight="10.0" prefHeight="30.0" />
</rowConstraints>
</GridPane>