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