-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.java
170 lines (145 loc) · 6.41 KB
/
MainPage.java
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
public class MainPage extends Pane{
//Constants
private final String PLAY_ICON = "/img/PLAY.png";
private final String HOW_TO_ICON = "/img/HOW_TO.png";
private final String DASHBOARD_ICON = "/img/DASHBOARD.png";
private final String SETTINGS_ICON = "/img/SETTINGS.png";
private final String CREDITS_ICON = "/img/credButton.png";
private final String SOUND_ICON = "/img/soundIcon.png";
private final String COPYRIGHT_LABEL = "Developed by Royal Flush";
private final String GAME_TITLE = "Rush Hour";
private final double WIDTH = 1080;
private final double HEIGHT = 720;
private final double COPYRIGHT_PANEL_SIZE = 60;
private final double BUTTON_X = WIDTH / 2 - 125;
private final double BUTTON_Y = 125;
private final double BUTTON_WIDTH = 250;
private final double BUTTON_HEIGHT = 75;
private final int ICON_SIZE = 64;
//Variables
private Label copyRightLabel;
private Label name;
private Label version;
private Button[] frameButtons;
private Button soundButton;
private Pane copyRightPanel;
private ImageView soundImage;
public MainPage() {
super();
initialize();
}
public void initialize(){
//Creating middle panel
this.setMinHeight(HEIGHT - COPYRIGHT_PANEL_SIZE);
this.setMinWidth(WIDTH);
//Creating copyright panel
copyRightPanel = new Pane();
copyRightPanel.setMinHeight(COPYRIGHT_PANEL_SIZE);
copyRightPanel.setMinWidth(WIDTH);
//Copyright label
copyRightLabel = new Label(COPYRIGHT_LABEL);
//Version label
version = new Label("Version b0.1");
version.setLayoutX(WIDTH - 100);
//Name of the game label
name = new Label("");
name.setStyle("-fx-font-weight: bold;");
ImageView tmp = new ImageView("/img/rushhour.png");
tmp.setFitWidth(780);
tmp.setFitHeight(160);
tmp.setLayoutY(90);
name.setGraphic(tmp);
name.setMaxSize(450,75);
name.setFont(new Font("American Typewriter", 75));
name.setLayoutX(150 );
name.setLayoutY(40);
//Creating main buttons
int space = 0;
frameButtons = new Button[5];
for ( int i = 0; i < 5; i++){
space = space + 80;
frameButtons[i] = new Button();
frameButtons[i].setMinSize(BUTTON_WIDTH, BUTTON_HEIGHT);
frameButtons[i].setLayoutX(BUTTON_X);
frameButtons[i].setLayoutY(BUTTON_Y + space);
frameButtons[i].setStyle("-fx-background-color: transparent");
}
ImageView playIcon = new ImageView(new Image(PLAY_ICON));
playIcon.setFitHeight(BUTTON_HEIGHT);
playIcon.setFitWidth(BUTTON_WIDTH);
frameButtons[0].setGraphic(playIcon);
ImageView howToIcon = new ImageView(new Image(HOW_TO_ICON));
howToIcon.setFitHeight(BUTTON_HEIGHT);
howToIcon.setFitWidth(BUTTON_WIDTH);
frameButtons[1].setGraphic(howToIcon);
ImageView dashboardIcon = new ImageView(new Image(DASHBOARD_ICON));
dashboardIcon.setFitHeight(BUTTON_HEIGHT);
dashboardIcon.setFitWidth(BUTTON_WIDTH);
frameButtons[2].setGraphic(dashboardIcon);
ImageView settingsIcon = new ImageView(new Image(SETTINGS_ICON));
settingsIcon.setFitHeight(BUTTON_HEIGHT);
settingsIcon.setFitWidth(BUTTON_WIDTH);
frameButtons[3].setGraphic(settingsIcon);
ImageView creditsIcon = new ImageView(new Image(CREDITS_ICON));
creditsIcon.setFitHeight(BUTTON_HEIGHT);
creditsIcon.setFitWidth(BUTTON_WIDTH);
frameButtons[4].setGraphic(creditsIcon);
//Sound button
soundImage = new ImageView(new Image(SOUND_ICON));
soundImage.setFitWidth(ICON_SIZE);
soundImage.setFitHeight(ICON_SIZE);
soundButton = new Button();
soundButton.setGraphic(soundImage);
soundButton.setStyle("-fx-background-color: transparent");
soundButton.setMinSize(ICON_SIZE, ICON_SIZE);
soundButton.setLayoutX(WIDTH - 100);
soundButton.setLayoutY(25);
//Add animation to the buttons
addAnimation(10);
//Adding buttons to middle panel
this.getChildren().addAll(name, frameButtons[0], frameButtons[1], frameButtons[2], frameButtons[3],frameButtons[4], soundButton);
//Adding labels to panel
copyRightPanel.getChildren().add(copyRightLabel);
copyRightPanel.getChildren().add(version);
//Default theme
setCurrentColor(null);
}
public void setCurrentColor(String colorCSS){
if (colorCSS == null){
this.setStyle("-fx-background-color: rgba(22,24,23,0.94);");
}else{
this.setStyle(colorCSS);
}
}
public void addHandler( GameManager.ButtonListener e) {
frameButtons[0].addEventHandler(MouseEvent.MOUSE_CLICKED, e);
GameManager.ButtonListener newE = e.clone();
newE.setIndex(2);
frameButtons[1].addEventHandler(MouseEvent.MOUSE_CLICKED, newE);
GameManager.ButtonListener dashboard = e.clone();
dashboard.setIndex(3);
frameButtons[2].addEventHandler(MouseEvent.MOUSE_CLICKED, dashboard);
GameManager.ButtonListener settings = e.clone();
settings.setIndex(4);
frameButtons[3].addEventHandler(MouseEvent.MOUSE_CLICKED, settings);
GameManager.ButtonListener credits = e.clone();
credits.setIndex(5);
frameButtons[4].addEventHandler(MouseEvent.MOUSE_CLICKED, credits);
}
public void addAnimation(int factor) {
for ( int i = 0; i < 5; i++ ) {
frameButtons[i].setOnMouseEntered(new GameManager.Animation(frameButtons[i], factor, true));
frameButtons[i].setOnMouseExited(new GameManager.Animation(frameButtons[i], factor, false));
}
soundButton.setOnMouseEntered(new GameManager.Animation(soundButton, factor, true));
soundButton.setOnMouseExited(new GameManager.Animation(soundButton, factor, false));
}
}