Skip to content

Commit

Permalink
Merge branch 'main' into Fixingmusicandsoundbutton
Browse files Browse the repository at this point in the history
  • Loading branch information
jvondermarck authored Aug 26, 2024
2 parents 5e7b0f7 + 57c7e8a commit 14e54ed
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

Expand All @@ -33,6 +40,23 @@ public DinosaurMenu() {
var title = FXGL.getUIFactoryService().newText(GameConstants.GAME_NAME, Color.LIME, FontType.MONO, 35);
var startButton = new Button("Start Game");
var quitButton = new Button("Quit");

Slider volumeSlider = new Slider(0, 1, 1);
volumeSlider.setShowTickLabels(true);
volumeSlider.setShowTickMarks(true);
volumeSlider.setBlockIncrement(0.01);

Label volumeLabel = new Label("Volume: 100%");

volumeSlider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
mainMenuSound.setVolume(newValue.doubleValue());
volumeLabel.setText(String.format("Volume: %.0f%%", newValue.doubleValue() * 100));
}
});


try {


Expand Down Expand Up @@ -78,15 +102,30 @@ public DinosaurMenu() {
quitButton.setTranslateX(getAppWidth() / 2 - 50);
quitButton.setStyle("-fx-font-size:20");

BorderPane root = new BorderPane();
root.setTop(title);
BorderPane.setAlignment(title, Pos.CENTER);

BorderPane volumePane = new BorderPane();
volumePane.setLeft(volumeLabel);
volumePane.setCenter(volumeSlider);
volumePane.setStyle("-fx-padding: 10;");

root.setCenter(volumePane);
root.setBottom(new BorderPane(startButton, null, quitButton, null, null));
BorderPane.setAlignment(startButton, Pos.CENTER);
BorderPane.setAlignment(quitButton, Pos.BOTTOM_CENTER);

startButton.setOnAction(event -> {
fireNewGame();
mainMenuSound.stop();
});

imageViewPlaying.setOnMouseClicked(mouseEvent -> {
if (mainMenuSound.isMute()){
mainMenuSound.setMute(false);
imageViewPlaying.setImage(audioOn);
}else{
} else {
mainMenuSound.setMute(true);
imageViewPlaying.setImage(mute);
}
Expand All @@ -95,7 +134,7 @@ public DinosaurMenu() {
quitButton.setOnAction(event -> fireExit());

getContentRoot().getChildren().addAll(
bg, title, startButton, quitButton, imageView, imageViewPlaying
bg, title, startButton, quitButton, imageView, imageViewPlaying, volumeSlider, volumeLabel
);
}
catch (FileNotFoundException e){
Expand All @@ -109,4 +148,4 @@ public void onEnteredFrom(Scene prevState) {
mainMenuSound.play();
}

}
}

0 comments on commit 14e54ed

Please sign in to comment.