added background and few design adjustments

master
Cemal Odabasioglu 2022-05-19 15:41:17 +02:00
parent 2e34cb91b4
commit 6ca85066db
4 changed files with 50 additions and 38 deletions

View File

@ -31,6 +31,7 @@ import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.ImagePattern; import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font; import javafx.scene.text.Font;
@ -45,9 +46,21 @@ import latice.model.Tile;
public class LaticeApplicationWindow extends Application { public class LaticeApplicationWindow extends Application {
private static final int NUMBER_OF_BOX_ON_ONE_LINE = 9;
private static final int RECTANGLE_HEIGHT = 50;
private static final int RECTANGLE_WIDTH = 50;
private static final int Y_CENTER = 37;
private static final int X_CENTER = 355;
private static final int BOX_WIDTH = 52;
javafx.scene.paint.Color realColor = new javafx.scene.paint.Color(0, 0, 0, 0); javafx.scene.paint.Color realColor = new javafx.scene.paint.Color(0, 0, 0, 0);
Image image = new Image("laticePlateau.png"); Image image = new Image("backgroundLatice.png");
ImageView imageView = new ImageView(image); ImageView imageView = new ImageView(image);
Tile blueBird = new Tile(Color.NAVYBLUE, Shape.BIRD); Tile blueBird = new Tile(Color.NAVYBLUE, Shape.BIRD);
@ -58,7 +71,7 @@ public class LaticeApplicationWindow extends Application {
ArrayList<Image> listTileImage = Rack.getRackTileImage(); ArrayList<Image> listTileImage = Rack.getRackTileImage();
ArrayList<Tile> listOfTile = new ArrayList<Tile>(); ArrayList<Tile> listOfTile = new ArrayList<Tile>();
Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>(); Map<Rectangle, Tile> assocRectangleTile = new HashMap<Rectangle, Tile>();
static BorderPane rootLayout; static StackPane rootLayout;
public static int indexTileClicked; public static int indexTileClicked;
@ -79,6 +92,9 @@ public class LaticeApplicationWindow extends Application {
Parent loader = FXMLLoader.load(getClass().getResource("../view/MainScreen.fxml")); Parent loader = FXMLLoader.load(getClass().getResource("../view/MainScreen.fxml"));
Scene menu = new Scene(loader, 1280, 720); Scene menu = new Scene(loader, 1280, 720);
MainScreenController MSC = new MainScreenController(); MainScreenController MSC = new MainScreenController();
//StackPane for background image + BorderPane root onto it
StackPane stackPane = new StackPane();
//root layout //root layout
BorderPane root = new BorderPane(); BorderPane root = new BorderPane();
@ -93,17 +109,17 @@ public class LaticeApplicationWindow extends Application {
BackgroundImage myBG= new BackgroundImage(image, BackgroundImage myBG= new BackgroundImage(image,
BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
BackgroundSize.DEFAULT); BackgroundSize.DEFAULT);
pane.setBackground(new Background(myBG)); stackPane.setBackground(new Background(myBG));
//Creating rectangle for tiles placement //Creating rectangle for tiles placement
Rectangle[][] r = new Rectangle[9][9]; Rectangle[][] r = new Rectangle[9][9];
int counterI = 0; int counterI = 0;
int counterJ = 0; int counterJ = 0;
for (int i=1; i<10 ; i++) { for (int i=1; i<=NUMBER_OF_BOX_ON_ONE_LINE ; i++) {
for (int j=1; j < 10 ; j++) { for (int j=1; j <= NUMBER_OF_BOX_ON_ONE_LINE ; j++) {
r[counterI][counterJ] = new Rectangle(i*52+307,j*52+3,50,50); r[counterI][counterJ] = new Rectangle(i*BOX_WIDTH+X_CENTER,j*BOX_WIDTH+Y_CENTER,RECTANGLE_WIDTH,RECTANGLE_HEIGHT);
r[counterI][counterJ].setFill(realColor.TRANSPARENT); r[counterI][counterJ].setFill(realColor.TRANSPARENT);
pane.getChildren().add(r[counterI][counterJ]); pane.getChildren().add(r[counterI][counterJ]);
System.out.println(r[counterI][counterJ]); System.out.println(r[counterI][counterJ]);
@ -148,18 +164,11 @@ public class LaticeApplicationWindow extends Application {
//deck.displayListTile(); //deck.displayListTile();
//With Image
Rack rack2 = new Rack(deck);
HBox rackImage = rack2.createImageTileOfRack();
root.setBottom(rackImage);
//Confirm Button //Confirm Button
Image checkMark = new Image("checkMark.png"); Image checkMark = new Image("checkMark.png");
ImageView checkMarkView = new ImageView(checkMark); ImageView checkMarkView = new ImageView(checkMark);
Button confirmButton = new Button("Confirm", checkMarkView); Button confirmButton = new Button("Confirm", checkMarkView);
root.setAlignment(confirmButton, Pos.BOTTOM_LEFT);
confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() { confirmButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override @Override
@ -170,8 +179,12 @@ public class LaticeApplicationWindow extends Application {
}); });
//With Image
root.setRight(confirmButton); Rack rack2 = new Rack(deck);
HBox rackImage = rack2.createTileImage();
rackImage.getChildren().add(confirmButton);
rackImage.setMargin(rackImage.getChildren().get(4), new Insets(0,150,0,0));
root.setBottom(rackImage);
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -200,8 +213,8 @@ public class LaticeApplicationWindow extends Application {
ImagePattern imagePattern = new ImagePattern(listTileImage.get(getIndexTileClicked())); ImagePattern imagePattern = new ImagePattern(listTileImage.get(getIndexTileClicked()));
//Setting drag & drop on rectangles //Setting drag & drop on rectangles
for(int i=0; i<9; i++) { for(int i=0; i<NUMBER_OF_BOX_ON_ONE_LINE; i++) {
for(int j=0; j<9; j++) { for(int j=0; j<NUMBER_OF_BOX_ON_ONE_LINE; j++) {
int a = i; int a = i;
int b = j; int b = j;
@ -212,7 +225,6 @@ public class LaticeApplicationWindow extends Application {
if (arg0.getDragboard().hasString()){ if (arg0.getDragboard().hasString()){
Dragboard dragboard = arg0.getDragboard(); Dragboard dragboard = arg0.getDragboard();
System.out.println("got files :" + dragboard.getFiles());
r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked()))); r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked())));
} }
arg0.consume(); arg0.consume();
@ -245,7 +257,6 @@ public class LaticeApplicationWindow extends Application {
System.out.println("entered"); System.out.println("entered");
Dragboard dragboard = arg0.getDragboard(); Dragboard dragboard = arg0.getDragboard();
System.out.println("got files :" + dragboard.getFiles());
r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked()))); r[a][b].setFill(new ImagePattern(listTileImage.get(getIndexTileClicked())));
arg0.setDropCompleted(true); arg0.setDropCompleted(true);
assocRectangleTile.put(r[a][b], listRackTile.get(getIndexTileClicked())); assocRectangleTile.put(r[a][b], listRackTile.get(getIndexTileClicked()));
@ -262,7 +273,8 @@ public class LaticeApplicationWindow extends Application {
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
setRootLayout(root); setRootLayout(stackPane);
stackPane.getChildren().add(root);
primaryStage.setResizable(false); primaryStage.setResizable(false);
primaryStage.setTitle("Latice"); primaryStage.setTitle("Latice");
@ -270,10 +282,10 @@ public class LaticeApplicationWindow extends Application {
primaryStage.show(); primaryStage.show();
} }
public static void setRootLayout(BorderPane root) { public static void setRootLayout(StackPane root) {
rootLayout = root; rootLayout = root;
} }
public static BorderPane getRootLayout() { public static StackPane getRootLayout() {
return rootLayout; return rootLayout;
} }

View File

@ -5,7 +5,7 @@ import javafx.fxml.FXML;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.stage.Stage; import javafx.stage.Stage;
import latice.application.LaticeApplicationWindow; import latice.application.LaticeApplicationWindow;
@ -23,7 +23,7 @@ public class MainScreenController extends LaticeApplicationWindow{
public void playButtonClicked(MouseEvent event) { public void playButtonClicked(MouseEvent event) {
System.out.println("playButtonClicked"); System.out.println("playButtonClicked");
Stage stage = (Stage) ((Node) event.getTarget()).getScene().getWindow(); Stage stage = (Stage) ((Node) event.getTarget()).getScene().getWindow();
BorderPane root = getRootLayout(); StackPane root = getRootLayout();
Scene scene = new Scene(root, 1280, 720); Scene scene = new Scene(root, 1280, 720);
stage.setScene(scene); stage.setScene(scene);
} }

View File

@ -47,7 +47,7 @@ public class Rack {
public HBox createImageTileOfRack() { public HBox createTileImage() {
Image image; Image image;
ImageView imageView; ImageView imageView;
Tile tile; Tile tile;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB