-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIngameMenu.java
More file actions
135 lines (108 loc) · 3.15 KB
/
IngameMenu.java
File metadata and controls
135 lines (108 loc) · 3.15 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.geometry.Side;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
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.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
public class IngameMenu extends Application {
private static final Font FONT = Font.font("", FontWeight.BOLD, 20);
final FileChooser fileChooser = new FileChooser();
private VBox menuBox;
private int currentItem = 0;
public static void main(String[] args) {
launch(args);
}
public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.TRANSPARENT);
stage.setAlwaysOnTop(true);
Scene scene = new Scene(createContent());
stage.setScene(scene);
stage.show();
}
public Parent createContent() {
StackPane root = new StackPane();
root.setPrefSize(200, 300);
MenuItem exit = new MenuItem("EXIT");
MenuItem menu = new MenuItem("MENU");
MenuItem sandbox = new MenuItem("SANDBOX MODE");
MenuItem options = new MenuItem("OPTIONS");
menuBox = new VBox(30, menu, sandbox, options, exit);
menuBox.setAlignment(Pos.CENTER);
getMenuItem(0).setActive(true);
root.getChildren().addAll(menuBox);
return root;
}
private static class MenuItem extends HBox {
private Text text;
private String name;
public MenuItem(String name) {
// constructor for distance between sprite and text
super(15);
this.name = name;
setAlignment(Pos.CENTER_LEFT);
text = new Text(name);
text.setFont(FONT);
getChildren().addAll(text);
setActive(false);
}
public String getMenuName() {
return name;
}
public void setActive(boolean b) {
text.setFill(b ? Color.WHITE : Color.BISQUE);
}
}
public void moveItem(int code, Stage stage) throws Exception {
if(code == 1) {
if (currentItem > 0) {
getMenuItem(currentItem).setActive(false);
getMenuItem(--currentItem).setActive(true);
}
}
if (code == -1) {
if (currentItem < menuBox.getChildren().size() - 1) {
getMenuItem(currentItem).setActive(false);
getMenuItem(++currentItem).setActive(true);
}
}
if (code == 0) {
switch (getMenuItem(currentItem).getMenuName()) {
case "MENU" :
Menu m = new Menu();
m.start(stage);
case "OPTIONS":
break;
case "EXIT":
System.exit(0);
}
}
}
private MenuItem getMenuItem(int index) {
if (index < 0)
return null;
return (MenuItem) menuBox.getChildren().get(index);
}
}