aboutsummaryrefslogtreecommitdiff
path: root/src/gui/MainMenu.java
blob: fe26054a776c18a49ebeaefb922d3fefc31a05c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gui;

import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;


public class MainMenu extends Pane
{
    /*
     * this class is a layout class, most of its purpose is to place UI elements like Buttons within Panes like VBoxes.
     * the creation of these UI elements are mostly not commented due to their repetitive and self explanatory nature.
     * style classes are defined in the style.css file.
     */
    public MainMenu()
    {
        DropShadow dropShadow = new DropShadow();
        dropShadow.setRadius(50.0);
        dropShadow.setColor(Color.WHITE);
        dropShadow.setBlurType(BlurType.GAUSSIAN);

        Text title = new Text();
        title.setText("NPE Hero");
        title.getStyleClass().add("t0");
        title.setEffect(dropShadow);

        Button play = new Button();
        play.setText("Play");
        play.setOnAction(e -> Driver.setMenu(new LevelSelector()));

        Button settings = new Button();
        settings.setText("Settings");
        settings.setOnAction(e -> Driver.setMenu(new Settings()));

        Button exit = new Button();
        exit.setText("Quit");
        exit.setOnAction(e -> Driver.quit());

        VBox buttonBox = new VBox();
        buttonBox.getChildren().addAll(play, settings, exit);
        buttonBox.setAlignment(Pos.CENTER);
        buttonBox.setSpacing(10);

        VBox centerBox = new VBox();
        centerBox.setAlignment(Pos.CENTER);
        centerBox.getChildren().addAll(title, buttonBox);
        centerBox.setSpacing(10);

        VBox rootBox = new VBox();
        rootBox.prefWidthProperty().bind(super.prefWidthProperty()); 
        rootBox.prefHeightProperty().bind(super.prefHeightProperty());
        rootBox.setAlignment(Pos.CENTER);
        rootBox.getChildren().add(centerBox);

        super.getChildren().add(rootBox);
    }
}