aboutsummaryrefslogtreecommitdiff
path: root/src/gui/Driver.java
blob: 59002c22826a4c03ee9755cdea719b3a20951dbc (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gui;

import java.util.HashMap;

import javafx.application.Application;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Driver extends Application 
{

    static Stage primaryStage;
    static HashMap<String,Pane> menus = new HashMap<String,Pane>();
    static Pane primaryPane = new Pane();

    public static void main(String[] args) 
    {
        launch(args);
    }
    
    @Override
    public void start(Stage newPrimaryStage) 
    {
        primaryStage = newPrimaryStage;
        menus.put("MainMenu", new MainMenu());
        menus.put("LevelSelector", new LevelSelector());
        menus.put("Settings", new Settings());
        menus.put("Leaderboard", new Leaderboard());

        for (Pane value : menus.values()) {
            value.minWidthProperty().bind(primaryStage.widthProperty()); 
            value.minHeightProperty().bind(primaryStage.heightProperty());
        }

        Scene primaryScene = new Scene(primaryPane, 800, 600);
        primaryScene.getStylesheets().add("gui/style.css");

        primaryStage.setScene(primaryScene);
        primaryStage.setTitle("NPE Hero");

        setMenu("MainMenu");
        setBackground("assets/water.png");

        primaryStage.show();
    }


    public static void setMenu(String name)
    {
        if (! primaryPane.getChildren().isEmpty())
        {
            primaryPane.getChildren().remove(0);
        }
        primaryPane.getChildren().add(menus.get(name));
        primaryPane.requestFocus();
    }

    public static void setCustomMenu(Pane pane)
    {
        if (! primaryPane.getChildren().isEmpty())
        {
            primaryPane.getChildren().remove(0);
        }
        pane.minWidthProperty().bind(primaryStage.widthProperty()); 
        pane.minHeightProperty().bind(primaryStage.heightProperty());
        primaryPane.getChildren().add(pane);
        primaryPane.requestFocus();
    }

    public static void setBackground(String url)
    {
        primaryPane.setBackground(new Background(
            new BackgroundImage(
                    new Image(url),
                    BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT,
                    new BackgroundPosition(Side.LEFT, 0, true, Side.BOTTOM, 0, true),
                    new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, false, true)
            )));
    }
}