blob: 77b9f276d960a3140d4bd393a77693450ef79a39 (
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
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
|
package gui;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow;
import main.Level;
import main.ScoreController;
public class LevelDetails extends VBox
{
/**
* 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.
*
* @param level: the selected level on the right side
*/
public LevelDetails(Level level)
{
VBox rightBox = new VBox();
rightBox.prefWidthProperty().bind(super.prefWidthProperty());
rightBox.prefHeightProperty().bind(super.prefHeightProperty().multiply(0.75));
rightBox.setMinWidth(275);
rightBox.getStyleClass().add("box");
Button play = new Button();
play.setDisable(true);
play.setText("Play");
if (level == null) //if no level is selected from the list on the left
{
Text desc = new Text();
desc.setText("Select a level from the left pane");
desc.getStyleClass().add("t3");
desc.wrappingWidthProperty().bind(super.prefWidthProperty().subtract(10));
desc.setTextAlignment(TextAlignment.CENTER);
rightBox.setAlignment(Pos.CENTER);
rightBox.getChildren().addAll(desc);
}
else
{
VBox details = new VBox();
ScrollPane detailsScroll = new ScrollPane(details);
detailsScroll.prefHeightProperty().bind(rightBox.prefHeightProperty());
detailsScroll.prefWidthProperty().bind(rightBox.prefWidthProperty());
detailsScroll.getStyleClass().remove("scroll-pane");
Text title = new Text();
title.setText(level.title);
title.getStyleClass().add("t1");
Text artist = new Text();
artist.setText(level.aritst);
artist.getStyleClass().add("t2");
Text desc = new Text();
desc.setText(level.desc);
desc.getStyleClass().add("t3");
ImageView previewView = new ImageView();
Image preview = level.preview;
previewView.setImage(preview);
previewView.fitWidthProperty().bind(super.prefWidthProperty().multiply(0.5));
previewView.setPreserveRatio(true);
FlowPane diffSelector = new FlowPane();
diffSelector.setAlignment(Pos.CENTER);
ToggleGroup diffToggleGroup = new ToggleGroup(); //allows only one to be selected at a time
for (String diff : level.diffList) //adds a button for each diff
{
RadioButton temp = new RadioButton();
temp.getStyleClass().remove("radio-button"); //makes the buttons not look like a radio button and instead a normal button
temp.getStyleClass().add("button");
temp.setText(diff);
temp.setUserData(diff); //allows the data and text to be seperate
diffToggleGroup.getToggles().add(temp);
diffSelector.getChildren().add(temp);
}
play.disableProperty().bind(diffToggleGroup.selectedToggleProperty().isNull()); //disables play button when no difficulty is selected
play.setOnAction(e -> Driver.setMenu(new LevelSurround(level, (String)diffToggleGroup.getSelectedToggle().getUserData(), Driver.getMenu())));
HBox diffBox = new HBox();
diffSelector.prefWidthProperty().bind(diffBox.widthProperty());
diffBox.getChildren().add(diffSelector);
details.setSpacing(10);
details.getChildren().addAll(new TextFlow(title), new TextFlow(artist), new TextFlow(desc), previewView, diffBox);
detailsScroll.setFitToWidth(true);
rightBox.getChildren().add(detailsScroll);
rightBox.setPadding(new Insets(5));
}
VBox rightSide = new VBox();
rightSide.setAlignment(Pos.CENTER_RIGHT);
rightSide.setSpacing(10);
rightSide.getChildren().addAll(rightBox,play);
super.setAlignment(Pos.CENTER_RIGHT);
super.getChildren().add(rightSide);
}
}
|