diff --git a/src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java b/src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java index 9d41397..f347e70 100644 --- a/src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java +++ b/src/main/java/com/dinosaur/dinosaurexploder/view/DinosaurMenu.java @@ -3,6 +3,7 @@ import com.almasb.fxgl.app.scene.FXGLMenu; import com.almasb.fxgl.app.scene.MenuType; import com.almasb.fxgl.dsl.FXGL; +import com.almasb.fxgl.scene.Scene; import com.almasb.fxgl.ui.FontType; import com.dinosaur.dinosaurexploder.model.GameConstants; import javafx.scene.control.Button; @@ -24,12 +25,13 @@ import java.io.FileNotFoundException; public class DinosaurMenu extends FXGLMenu { + private MediaPlayer mainMenuSound; public DinosaurMenu() { super(MenuType.MAIN_MENU); Media media = new Media(getClass().getResource(GameConstants.MAINMENU_SOUND).toExternalForm()); - MediaPlayer mainMenuSound = new MediaPlayer(media); + mainMenuSound = new MediaPlayer(media); mainMenuSound.play(); mainMenuSound.setCycleCount(MediaPlayer.INDEFINITE); @@ -38,7 +40,7 @@ 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); @@ -53,13 +55,14 @@ public void changed(ObservableValue observable, Number oldValu volumeLabel.setText(String.format("Volume: %.0f%%", newValue.doubleValue() * 100)); } }); - - + + try { FileInputStream fileInputStream = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png"); FileInputStream mutemusic_button = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/silent.png"); + FileInputStream audioOnButton = new FileInputStream("../dinosaur-exploder/src/main/resources/assets/textures/playing.png"); // image for dino in main menu Image image = new Image(fileInputStream); @@ -71,16 +74,21 @@ public void changed(ObservableValue observable, Number oldValu imageView.setPreserveRatio(true); //adding image to manually mute music - Image mute = new Image(mutemusic_button); - ImageView imageView_mute = new ImageView(mute); - imageView_mute.setFitHeight(40); - imageView_mute.setFitWidth(50); - imageView_mute.setX(490); - imageView_mute.setY(20); - imageView_mute.setPreserveRatio(true); + + + Image audioOn = new Image(audioOnButton); + ImageView imageViewPlaying = new ImageView(audioOn); + imageViewPlaying.setFitHeight(40); + imageViewPlaying.setFitWidth(50); + imageViewPlaying.setX(490); + imageViewPlaying.setY(20); + imageViewPlaying.setPreserveRatio(true); + startButton.setMinSize(50, 50); + startButton.setPrefSize(140,60); + quitButton.setMinSize(140, 50); title.setTranslateY(100); @@ -93,7 +101,7 @@ public void changed(ObservableValue observable, Number oldValu quitButton.setTranslateY(500); quitButton.setTranslateX(getAppWidth() / 2 - 50); quitButton.setStyle("-fx-font-size:20"); - + BorderPane root = new BorderPane(); root.setTop(title); BorderPane.setAlignment(title, Pos.CENTER); @@ -113,22 +121,31 @@ public void changed(ObservableValue observable, Number oldValu mainMenuSound.stop(); }); - imageView_mute.setOnMouseClicked(event -> { - if (mainMenuSound.getStatus() == MediaPlayer.Status.PLAYING) { - mainMenuSound.pause(); - } else { - mainMenuSound.play(); - } + imageViewPlaying.setOnMouseClicked(mouseEvent -> { + if (mainMenuSound.isMute()){ + mainMenuSound.setMute(false); + imageViewPlaying.setImage(audioOn); + } else { + mainMenuSound.setMute(true); + imageViewPlaying.setImage(mute); + } }); + quitButton.setOnAction(event -> fireExit()); getContentRoot().getChildren().addAll( - bg, title, startButton, quitButton, imageView, imageView_mute,volumeSlider, volumeLabel + bg, title, startButton, quitButton, imageView, imageViewPlaying, volumeSlider, volumeLabel ); } catch (FileNotFoundException e){ - System.out.println("File not found" + e.getMessage()); + System.out.println("File not found" + e.getMessage()); } } + @Override + public void onEnteredFrom(Scene prevState) { + super.onEnteredFrom(prevState); + FXGL.getAudioPlayer().stopAllSounds(); + mainMenuSound.play(); + } -} +} \ No newline at end of file diff --git a/src/main/resources/assets/textures/playing.png b/src/main/resources/assets/textures/playing.png new file mode 100644 index 0000000..a9c9012 Binary files /dev/null and b/src/main/resources/assets/textures/playing.png differ