ajout de slider pour regler le volume des effets sonores dans les parametres et le menu pause
This commit is contained in:
parent
abacff2a17
commit
5ac8589818
@ -6,29 +6,36 @@ import java.io.InputStream;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.sound.sampled.FloatControl;
|
||||
|
||||
public class EffetSonore {
|
||||
|
||||
static boolean soundOK;
|
||||
|
||||
public InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav");
|
||||
public InputStream fileSound2 = getClass().getResourceAsStream("/ihm/ressources/musique/BeepError.wav");
|
||||
|
||||
|
||||
static boolean soundOK;
|
||||
|
||||
public InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav");
|
||||
public InputStream fileSound2 = getClass().getResourceAsStream("/ihm/ressources/musique/BeepError.wav");
|
||||
public static FloatControl volumeEffet;
|
||||
public static float lvVolumeEffet;
|
||||
|
||||
public static void playSoundEffect(InputStream path) {
|
||||
|
||||
|
||||
if (soundOK == true) {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
InputStream soundPath = path;
|
||||
|
||||
if (soundPath!=null) {
|
||||
if (soundPath != null) {
|
||||
|
||||
InputStream bufferedIn = new BufferedInputStream(soundPath);
|
||||
|
||||
|
||||
AudioInputStream audioInput = AudioSystem.getAudioInputStream(bufferedIn);
|
||||
Clip clipSound = AudioSystem.getClip();
|
||||
clipSound.open(audioInput);
|
||||
|
||||
volumeEffet = (FloatControl) clipSound.getControl(FloatControl.Type.MASTER_GAIN);
|
||||
volumeEffet.setValue(lvVolumeEffet);
|
||||
|
||||
clipSound.start();
|
||||
|
||||
} else {
|
||||
@ -40,7 +47,6 @@ public class EffetSonore {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static boolean isSoundOK() {
|
||||
@ -51,10 +57,8 @@ public class EffetSonore {
|
||||
EffetSonore.soundOK = soundOK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void setVolumeEffets(double dValeur) {
|
||||
lvVolumeEffet = (float) (dValeur);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,20 +31,22 @@ public class ParametreController implements Initializable {
|
||||
private ComboBox<String> langues;
|
||||
@FXML
|
||||
private Slider sliderMusique;
|
||||
|
||||
|
||||
|
||||
@FXML
|
||||
private Slider sliderEffets;
|
||||
|
||||
public static boolean cbMusiqueCoche = false; // verifi si la checbox musical est coche
|
||||
public static boolean cbSonCoche = false;
|
||||
public static boolean cbClair = false;
|
||||
public static double slideValue;
|
||||
public static double slideValueEffets;
|
||||
public static String langueChoisi;
|
||||
|
||||
boolean MusiqueLancee = false; //verifi si la musique a déja été lancé une première fois
|
||||
|
||||
String filepathMusique = "/ihm/ressources/musique/The_Red_Fox_Tavern.wav"; // lien vers la musique : https://www.youtube.com/watch?v=LBpKUIyOHdo
|
||||
InputStream fileMusique = getClass().getResourceAsStream("/ihm/ressources/musique/The_Red_Fox_Tavern.wav");
|
||||
|
||||
boolean MusiqueLancee = false; // verifi si la musique a déja été lancé une première fois
|
||||
|
||||
String filepathMusique = "/ihm/ressources/musique/The_Red_Fox_Tavern.wav"; // lien vers la musique :
|
||||
// https://www.youtube.com/watch?v=LBpKUIyOHdo
|
||||
InputStream fileMusique = getClass().getResourceAsStream("/ihm/ressources/musique/The_Red_Fox_Tavern.wav");
|
||||
|
||||
File repertoire = new File("src//ihm//ressources");
|
||||
File repertoire2;
|
||||
@ -57,7 +59,9 @@ public class ParametreController implements Initializable {
|
||||
cbEffetSonore.setSelected(cbSonCoche);
|
||||
clair.setSelected(cbClair);
|
||||
sliderMusique.setValue(slideValue);
|
||||
|
||||
sliderEffets.setValue(slideValueEffets);
|
||||
|
||||
System.out.println("slidevalueeffet init = "+ slideValueEffets);
|
||||
|
||||
langues.getItems().add("Anglais");
|
||||
langues.getItems().add("Allemand");
|
||||
@ -68,125 +72,116 @@ public class ParametreController implements Initializable {
|
||||
|
||||
@FXML
|
||||
public void enregistre(MouseEvent mouseEvent) throws IOException, Exception {
|
||||
|
||||
InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav");
|
||||
//Pour la musique
|
||||
if (fileMusique!=null) {
|
||||
|
||||
InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav");
|
||||
// Pour la musique
|
||||
if (fileMusique != null) {
|
||||
|
||||
if (cmusique.isSelected() == true) {
|
||||
cbMusiqueCoche = true;
|
||||
if (Musique.clipTimePosition == 0 && MusiqueLancee == false && Musique.musiqueEnCours != true) { // si la musique n'a jamais été lancé
|
||||
if (Musique.clipTimePosition == 0 && MusiqueLancee == false && Musique.musiqueEnCours != true) { //si la musique n'a jamais été lancé
|
||||
Musique.playMusique(fileMusique);
|
||||
Musique.musiqueEnCours = true;
|
||||
MusiqueLancee = true;
|
||||
|
||||
} else if (Musique.musiqueEnCours != true) {
|
||||
Musique.resumeMusique(Musique.clip); // si elle a deja été lancé mais mis en pause, reprend a partir du point d'arret
|
||||
Musique.musiqueEnCours = true;
|
||||
Musique.musiqueEnCours = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (cbMusiqueCoche == true) {
|
||||
cbMusiqueCoche = false;
|
||||
Musique.pauseMusique(Musique.clip); //met en pause la musique
|
||||
Musique.pauseMusique(Musique.clip); // met en pause la musique
|
||||
Musique.musiqueEnCours = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Pour les effets sonores
|
||||
|
||||
// Pour les effets sonores
|
||||
if (cbEffetSonore.isSelected() == true) {
|
||||
EffetSonore.setSoundOK(true);
|
||||
cbSonCoche = true;
|
||||
|
||||
|
||||
System.out.println(EffetSonore.isSoundOK());
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
EffetSonore.setSoundOK(false);
|
||||
cbSonCoche = false;
|
||||
System.out.println(EffetSonore.isSoundOK());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Pour la couleur du theme
|
||||
|
||||
if (clair.isSelected()) {
|
||||
// Pane root =
|
||||
// FXMLLoader.load(getClass().getResource("../ressources/menu.fxml"));
|
||||
|
||||
rootPane.setStyle("-fx-background-color: white;");
|
||||
rootPane.applyCss();
|
||||
}
|
||||
rootPane.setStyle("-fx-background-color: white;");
|
||||
rootPane.applyCss();
|
||||
/*
|
||||
* if (liste != null) { for (int i = 0; i < liste.length; i++) {
|
||||
*
|
||||
* System.out.println(liste[i]); System.out.println(i); repertoire2 = new
|
||||
* File("../ressources/" + liste[i]);
|
||||
*
|
||||
* if (repertoire.isDirectory() == false) { if (liste[i] == "Plateau.fxml") {
|
||||
* Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" +
|
||||
* liste[i])); root1.setStyle("../ressources/style/plateau.css");
|
||||
*
|
||||
* } Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" +
|
||||
* liste[i])); root1.setStyle("../ressources/style/menuLight.css"); } }
|
||||
*
|
||||
* }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
EffetSonore.playSoundEffect(fileSound1); // emet un bruit sur le bouton si les effets sonores sont activés
|
||||
|
||||
|
||||
if (clair.isSelected()) {
|
||||
//Pane root = FXMLLoader.load(getClass().getResource("../ressources/menu.fxml"));
|
||||
|
||||
rootPane.setStyle("-fx-background-color: white;");
|
||||
rootPane.applyCss();
|
||||
}
|
||||
rootPane.setStyle("-fx-background-color: white;");
|
||||
rootPane.applyCss();
|
||||
/*if (liste != null) {
|
||||
for (int i = 0; i < liste.length; i++) {
|
||||
System.out.println("slidevalueeffet enregistre = "+ slideValueEffets);
|
||||
|
||||
System.out.println(liste[i]);
|
||||
System.out.println(i);
|
||||
repertoire2 = new File("../ressources/" + liste[i]);
|
||||
|
||||
if (repertoire.isDirectory() == false) {
|
||||
if (liste[i] == "Plateau.fxml") {
|
||||
Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" + liste[i]));
|
||||
root1.setStyle("../ressources/style/plateau.css");
|
||||
|
||||
}
|
||||
Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" + liste[i]));
|
||||
root1.setStyle("../ressources/style/menuLight.css");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
EffetSonore.playSoundEffect(fileSound1); //emet un bruit sur le bouton si les effets sonores sont activés
|
||||
|
||||
|
||||
// Quitter les paramètres
|
||||
final URL fxmlURL = getClass().getResource("/ihm/ressources/Menu.fxml");
|
||||
// Quitter les paramètres
|
||||
final URL fxmlURL = getClass().getResource("/ihm/ressources/Menu.fxml");
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle("domaine.properties.langue", Locale.FRANCE);
|
||||
|
||||
|
||||
final FXMLLoader fxmlLoader = new FXMLLoader(fxmlURL, bundle);
|
||||
Pane pane = fxmlLoader.load();
|
||||
|
||||
rootPane.getChildren().setAll(pane);
|
||||
|
||||
|
||||
rootPane.getChildren().setAll(pane);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
public void slideVolumeMusique(MouseEvent mouseEvent) throws IOException{
|
||||
|
||||
if(Musique.musiqueEnCours == true) {
|
||||
public void slideVolumeMusique(MouseEvent mouseEvent) throws IOException {
|
||||
|
||||
if (Musique.musiqueEnCours == true) {
|
||||
Musique.setVolume(sliderMusique.getValue());
|
||||
slideValue = sliderMusique.getValue();
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
@FXML
|
||||
public void monterVolume(MouseEvent mouseEvent) throws IOException{
|
||||
Musique.volumeUp(5.f);
|
||||
System.out.println("on monte le son");
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void baisserVolume(MouseEvent mouseEvent) throws IOException{
|
||||
Musique.volumeDown(5.f);
|
||||
System.out.println("on baisse le son");
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void slideVolumeEffet(MouseEvent mouseEvent) throws IOException {
|
||||
|
||||
EffetSonore.setVolumeEffets(sliderEffets.getValue());
|
||||
slideValueEffets = sliderEffets.getValue();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* @FXML public void monterVolume(MouseEvent mouseEvent) throws IOException{
|
||||
* Musique.volumeUp(5.f); System.out.println("on monte le son"); }
|
||||
*
|
||||
* @FXML public void baisserVolume(MouseEvent mouseEvent) throws IOException{
|
||||
* Musique.volumeDown(5.f); System.out.println("on baisse le son"); }
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -26,13 +26,16 @@ public class PauseController implements Initializable {
|
||||
private CheckBox cbEffet;
|
||||
@FXML
|
||||
private Slider sliderMusiquePause;
|
||||
@FXML
|
||||
private Slider sliderEffetsPause;
|
||||
|
||||
String filepathMusique = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav";
|
||||
InputStream fileMusique = getClass().getResourceAsStream("/ihm/ressources/musique/The_Red_Fox_Tavern.wav");
|
||||
|
||||
boolean MusiqueLancee = ParametreController.cbMusiqueCoche;
|
||||
boolean SonLance = ParametreController.cbSonCoche;
|
||||
public static double slideValuePause;
|
||||
public static double slideValueMusiquePause;
|
||||
public static double slideValueEffetPause;
|
||||
|
||||
@Override
|
||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||
@ -40,6 +43,7 @@ public class PauseController implements Initializable {
|
||||
cbMusique.setSelected(ParametreController.cbMusiqueCoche);
|
||||
cbEffet.setSelected(ParametreController.cbSonCoche);
|
||||
sliderMusiquePause.setValue(ParametreController.slideValue);
|
||||
sliderEffetsPause.setValue(ParametreController.slideValueEffets);
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -83,7 +87,8 @@ public class PauseController implements Initializable {
|
||||
|
||||
ParametreController.cbSonCoche = cbEffet.isSelected();
|
||||
ParametreController.cbMusiqueCoche = cbMusique.isSelected();
|
||||
ParametreController.slideValue = slideValuePause;
|
||||
ParametreController.slideValue = slideValueMusiquePause;
|
||||
ParametreController.slideValueEffets = slideValueEffetPause;
|
||||
|
||||
EffetSonore.playSoundEffect(fileSound1); // met un bruit sur le bouton si les effets sonores sont activés
|
||||
|
||||
@ -122,12 +127,21 @@ public class PauseController implements Initializable {
|
||||
if (Musique.musiqueEnCours == true) {
|
||||
System.out.println("slide");
|
||||
Musique.setVolume(sliderMusiquePause.getValue());
|
||||
slideValuePause = sliderMusiquePause.getValue();
|
||||
slideValueMusiquePause = sliderMusiquePause.getValue();
|
||||
|
||||
}else {
|
||||
System.out.println("probleme");
|
||||
System.out.println("probleme de slider musique");
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void slideVolumeEffets(MouseEvent mouseEvent) throws IOException {
|
||||
|
||||
System.out.println("slide effet");
|
||||
EffetSonore.setVolumeEffets(sliderEffetsPause.getValue());
|
||||
slideValueEffetPause = sliderEffetsPause.getValue();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@FXML
|
||||
|
@ -48,7 +48,7 @@
|
||||
</HBox>
|
||||
<HBox prefHeight="0.0" prefWidth="540.0">
|
||||
<children>
|
||||
<Slider fx:id="sliderMusiquePause" blockIncrement="1.0" majorTickUnit="1.0" max="1.0" minorTickCount="10" onMouseClicked="#slideVolumeMusique" prefHeight="14.0" prefWidth="194.0" showTickLabels="true" showTickMarks="true" value="0.1" />
|
||||
<Slider fx:id="sliderMusiquePause" blockIncrement="1.0" majorTickUnit="1.0" max="1.0" minorTickCount="10" onMouseClicked="#slideVolumeMusique" prefHeight="14.0" prefWidth="194.0" value="0.1" />
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT">
|
||||
@ -64,6 +64,11 @@
|
||||
<CheckBox fx:id="cbEffet" mnemonicParsing="false" />
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox prefHeight="0.0" prefWidth="540.0">
|
||||
<children>
|
||||
<Slider fx:id="sliderEffetsPause" blockIncrement="1.0" majorTickUnit="1.0" max="0.0" min="-20.0" minorTickCount="10" onMouseClicked="#slideVolumeEffets" prefHeight="14.0" prefWidth="194.0" />
|
||||
</children>
|
||||
</HBox>
|
||||
<Label style="-fx-border-width: 0 0 0.5 0; -fx-border-color: #e2e2e2;" text="Jeux">
|
||||
<VBox.margin>
|
||||
<Insets top="50.0" />
|
||||
|
@ -15,12 +15,20 @@
|
||||
<children>
|
||||
<HBox alignment="TOP_CENTER" layoutX="146.0" layoutY="171.0" prefHeight="242.0" prefWidth="507.0" spacing="10.0">
|
||||
<children>
|
||||
<VBox prefHeight="348.0" prefWidth="195.0" spacing="40.0">
|
||||
<VBox prefHeight="348.0" prefWidth="195.0" spacing="35.0">
|
||||
<children>
|
||||
<CheckBox fx:id="clair" mnemonicParsing="false" styleClass="checkBox" text="%mode.claire" />
|
||||
<CheckBox fx:id="cmusique" mnemonicParsing="false" styleClass="checkBox" text="%musique" />
|
||||
<Slider fx:id="sliderMusique" blockIncrement="1.0" majorTickUnit="1.0" max="1.0" minorTickCount="10" onMouseClicked="#slideVolumeMusique" showTickLabels="true" showTickMarks="true" value="0.1" />
|
||||
<Slider fx:id="sliderMusique" blockIncrement="1.0" majorTickUnit="1.0" max="1.0" minorTickCount="10" onMouseClicked="#slideVolumeMusique" value="0.1">
|
||||
<padding>
|
||||
<Insets top="-20.0" />
|
||||
</padding></Slider>
|
||||
<CheckBox fx:id="cbEffetSonore" mnemonicParsing="false" styleClass="checkBox" text="%effet" />
|
||||
<Slider fx:id="sliderEffets" blockIncrement="1.0" layoutX="10.0" layoutY="125.0" majorTickUnit="1.0" max="0.0" min="-20.0" minorTickCount="10" onMouseClicked="#slideVolumeEffet" value="-10.0">
|
||||
<padding>
|
||||
<Insets top="-20.0" />
|
||||
</padding>
|
||||
</Slider>
|
||||
<VBox prefHeight="86.0" prefWidth="195.0" spacing="10.0">
|
||||
<children>
|
||||
<Label styleClass="titre" text="%langue">
|
||||
|
Loading…
x
Reference in New Issue
Block a user