package sample;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
public class Main extends Application {
public static ArrayList<Vodiy> vodii = new ArrayList<>();
public static Stage mainWindow = null;
public static AnchorPane root;
@Override public void start(Stage stage) {
vodii.add(new Vodiy("dfg", "fsdf", 32, 23));
vodii.add(new ExperiencedVodiy("dfg", "fsdf", 32, 23));
vodii.add(new Vodiy3("dfg", "fsdf", 32, 23));
root = new AnchorPane();
root.setBackground(new Background(new BackgroundImage(new Image(getClass().getResourceAsStream("back.jpg")), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT)));
Scene scene = new Scene(root, 1272, 785);
for(Vodiy x: vodii) {
root.getChildren().add(x.getGroup());
x.getGroup().setLayoutX(x.posis.x);
x.getGroup().setLayoutY(x.posis.y);
}
scene.setOnKeyPressed(event -> {
KeyCode keyCode = event.getCode();
for(Vodiy x: vodii) {
if(x.isActive()) {
Group act = x.getGroup();
switch (keyCode) {
case W:
act.setLayoutY(act.getLayoutY() - 20);
break;
case S:
act.setLayoutY(act.getLayoutY() + 20);
break;
case A:
act.setLayoutX(act.getLayoutX() - 20);
break;
case D:
act.setLayoutX(act.getLayoutX() + 20);
break;
case ESCAPE:
active();
break;
case DELETE:
root.getChildren().remove(x.getGroup());
break;
}
}
}
if (event.getCode().equals(KeyCode.INSERT))
{
if( NewVodiy.display("Створення нового водія","Введіть данні"))
{
if( NewVodiy.level == 0)
{
Vodiy vodiy = new Vodiy(NewVodiy.name, NewVodiy.auto, NewVodiy.year, NewVodiy.stag);
vodii.add(vodiy);
root.getChildren().add(vodiy.getGroup());
if(NewVodiy.select){
vodiy.active = NewVodiy.select;
vodiy.bodyImg.setImage(vodiy.img1);
vodiy.nameLabel.setTextFill(Color.YELLOW);
vodiy.activeLabel.setText("Активний");
vodiy.activeLabel.setTextFill(Color.YELLOW);
vodiy.bodyImg.setImage(vodiy.img1);
}
else{
vodiy.nameLabel.setTextFill(Color.WHITE);
vodiy.activeLabel.setText("");
vodiy.activeLabel.setTextFill(Color.WHITE);
vodiy.bodyImg.setImage(vodiy.img);}
vodiy.getGroup().setLayoutX(vodiy.posis.x);
vodiy.getGroup().setLayoutY(vodiy.posis.y);
NewVodiy.level =0;
}
else if (NewVodiy.level == 1){
ExperiencedVodiy vodiy = new ExperiencedVodiy(NewVodiy.name, NewVodiy.auto, NewVodiy.year, NewVodiy.stag);
vodii.add(vodiy);
root.getChildren().add(vodiy.getGroup());
if(NewVodiy.select){
vodiy.active = NewVodiy.select;
vodiy.nameLabel.setTextFill(Color.YELLOW);
vodiy.activeLabel.setText("Активний");
vodiy.activeLabel.setTextFill(Color.YELLOW);
vodiy.bodyImg.setImage(vodiy.img1);
}
else{
vodiy.nameLabel.setTextFill(Color.WHITE);
vodiy.activeLabel.setText("");
vodiy.activeLabel.setTextFill(Color.WHITE);
vodiy.bodyImg.setImage(vodiy.img);
}
vodiy.getGroup().setLayoutX(vodiy.posis.x);
vodiy.getGroup().setLayoutY(vodiy.posis.y);
NewVodiy.level =0;
}
else if (NewVodiy.level == 2){
Vodiy3 vodiy = new Vodiy3(NewVodiy.name, NewVodiy.auto, NewVodiy.year, NewVodiy.stag);
vodii.add(vodiy);
root.getChildren().add(vodiy.getGroup());
if(NewVodiy.select){
vodiy.active = NewVodiy.select;
vodiy.nameLabel.setTextFill(Color.YELLOW);
vodiy.activeLabel.setText("Активний");
vodiy.activeLabel.setTextFill(Color.YELLOW);
vodiy.bodyImg.setImage(vodiy.img1);
}
else{
vodiy.nameLabel.setTextFill(Color.WHITE);
vodiy.activeLabel.setText("");
vodiy.activeLabel.setTextFill(Color.WHITE);
vodiy.bodyImg.setImage(vodiy.img);
}
vodiy.getGroup().setLayoutX(vodiy.posis.x);
vodiy.getGroup().setLayoutY(vodiy.posis.y);
NewVodiy.level =0;
}
}
}
});
stage.setTitle("Лабораторна №3 Пацалюк В. С");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
public void active() {
for(Vodiy x: vodii) {
if(x.isActive()) {
boolean ativ =x.active;
ativ =!ativ;
x.active = ativ;
if(x.active){
x.nameLabel.setTextFill(Color.YELLOW);
x.activeLabel.setText("Активний");
x.activeLabel.setTextFill(Color.YELLOW);
x.bodyImg.setImage(x.img1);
}
else{
x.nameLabel.setTextFill(Color.WHITE);
x.activeLabel.setText("");
x.activeLabel.setTextFill(Color.WHITE);
x.bodyImg.setImage(x.img);
}
}
}
}
public static void main(String[] args) {
launch(args);
}
}