Positionning on the screen
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: Anthony Debucquoy <debucquoy.anthony@gmail.com>
This commit is contained in:
Debucquoy Anthony 2023-05-04 13:14:10 +02:00
parent 94be15100d
commit a796fbf504
Signed by: tonitch
GPG Key ID: A78D6421F083D42E

View File

@ -2,26 +2,27 @@ package school_project;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import school_project.Utils.MatrixShape;
import java.io.FileNotFoundException;
public class GameUI extends BorderPane {
public class GameUI extends Group{
public final static int SEGMENT_SIZE = 50;
public final static int SPACE_SIZE = 5;
public GameUI(Map level) throws FileNotFoundException {
super();
MatrixShape grid = new MatrixShape(level);
grid.setAlignment(Pos.CENTER);
grid.setColor(Color.WHITE);
grid.setLayoutX(Screen.getPrimary().getBounds().getWidth()/2 - grid.boundary_size.x/2);
grid.setLayoutY(Screen.getPrimary().getBounds().getHeight()/2 - grid.boundary_size.y/2);
HBox pieces = new HBox();
pieces.setSpacing(10);
Group pieces = new Group();
for (Piece p : level.getPieces()) {
MatrixShape _piece = new MatrixShape(p);
_piece.setOnMouseClicked(event -> {
@ -30,10 +31,13 @@ public class GameUI extends BorderPane {
_piece.update();
}
});
_piece.setOnMouseDragged(event -> {
_piece.setLayoutX(event.getSceneX());
_piece.setLayoutY(event.getSceneY());
});
pieces.getChildren().add(_piece);
}
setCenter(grid);
setBottom(pieces);
getChildren().addAll(grid, pieces);
}
}