|
| 1 | +package com.dinosaur.dinosaurexploder.view; |
| 2 | + |
| 3 | +import com.almasb.fxgl.app.scene.FXGLMenu; |
| 4 | +import com.almasb.fxgl.app.scene.MenuType; |
| 5 | +import com.almasb.fxgl.dsl.FXGL; |
| 6 | +import com.almasb.fxgl.ui.FontType; |
| 7 | +import javafx.scene.Node; |
| 8 | +import javafx.scene.control.Button; |
| 9 | +import javafx.scene.layout.Pane; |
| 10 | +import javafx.scene.layout.StackPane; |
| 11 | +import javafx.scene.paint.Color; |
| 12 | +import javafx.scene.shape.Rectangle; |
| 13 | + |
| 14 | +public class DinosaurMenu extends FXGLMenu { |
| 15 | + |
| 16 | + public DinosaurMenu() { |
| 17 | + super(MenuType.MAIN_MENU); |
| 18 | + |
| 19 | + var bg = new Rectangle(getAppWidth(), getAppHeight(), Color.BLACK); |
| 20 | + |
| 21 | + var title = FXGL.getUIFactoryService().newText("Dinosaur Exploder", Color.LIME, FontType.MONO, 35); |
| 22 | + var startButton = new Button("Start Game"); |
| 23 | + var quitButton = new Button("Quit"); |
| 24 | + |
| 25 | + startButton.setMinSize(200, 100); |
| 26 | + quitButton.setMinSize(200, 100); |
| 27 | + |
| 28 | + title.setTranslateY(100); |
| 29 | + title.setTranslateX(getAppWidth() / 2 - 175); |
| 30 | + |
| 31 | + startButton.setTranslateY(350); |
| 32 | + startButton.setTranslateX(getAppWidth() / 2 - 100); |
| 33 | + startButton.setStyle("-fx-font-size:20"); |
| 34 | + |
| 35 | + quitButton.setTranslateY(490); |
| 36 | + quitButton.setTranslateX(getAppWidth() / 2 - 100); |
| 37 | + quitButton.setStyle("-fx-font-size:20"); |
| 38 | + |
| 39 | + startButton.setOnAction(event -> fireNewGame()); |
| 40 | + quitButton.setOnAction(event -> fireExit()); |
| 41 | + |
| 42 | + getContentRoot().getChildren().addAll( |
| 43 | + bg, title, startButton, quitButton |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments