ajout de slider pour regler le volume des effets sonores dans les parametres et le menu pause

This commit is contained in:
Bastien NOEL 2020-05-08 16:18:56 +02:00
parent abacff2a17
commit 5ac8589818
5 changed files with 132 additions and 106 deletions

View File

@ -6,6 +6,7 @@ import java.io.InputStream;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip; import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
public class EffetSonore { public class EffetSonore {
@ -13,6 +14,8 @@ public class EffetSonore {
public InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav"); public InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav");
public InputStream fileSound2 = getClass().getResourceAsStream("/ihm/ressources/musique/BeepError.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) { public static void playSoundEffect(InputStream path) {
@ -29,6 +32,10 @@ public class EffetSonore {
AudioInputStream audioInput = AudioSystem.getAudioInputStream(bufferedIn); AudioInputStream audioInput = AudioSystem.getAudioInputStream(bufferedIn);
Clip clipSound = AudioSystem.getClip(); Clip clipSound = AudioSystem.getClip();
clipSound.open(audioInput); clipSound.open(audioInput);
volumeEffet = (FloatControl) clipSound.getControl(FloatControl.Type.MASTER_GAIN);
volumeEffet.setValue(lvVolumeEffet);
clipSound.start(); clipSound.start();
} else { } else {
@ -40,7 +47,6 @@ public class EffetSonore {
} }
} }
} }
public static boolean isSoundOK() { public static boolean isSoundOK() {
@ -51,10 +57,8 @@ public class EffetSonore {
EffetSonore.soundOK = soundOK; EffetSonore.soundOK = soundOK;
} }
public static void setVolumeEffets(double dValeur) {
lvVolumeEffet = (float) (dValeur);
}
} }

View File

@ -31,21 +31,23 @@ public class ParametreController implements Initializable {
private ComboBox<String> langues; private ComboBox<String> langues;
@FXML @FXML
private Slider sliderMusique; private Slider sliderMusique;
@FXML
private Slider sliderEffets;
public static boolean cbMusiqueCoche = false; // verifi si la checbox musical est coche public static boolean cbMusiqueCoche = false; // verifi si la checbox musical est coche
public static boolean cbSonCoche = false; public static boolean cbSonCoche = false;
public static boolean cbClair = false; public static boolean cbClair = false;
public static double slideValue; public static double slideValue;
public static double slideValueEffets;
public static String langueChoisi; public static String langueChoisi;
boolean MusiqueLancee = false; // verifi si la musique a déja été lancé une première fois 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 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"); InputStream fileMusique = getClass().getResourceAsStream("/ihm/ressources/musique/The_Red_Fox_Tavern.wav");
File repertoire = new File("src//ihm//ressources"); File repertoire = new File("src//ihm//ressources");
File repertoire2; File repertoire2;
String liste[] = repertoire.list(); String liste[] = repertoire.list();
@ -57,7 +59,9 @@ public class ParametreController implements Initializable {
cbEffetSonore.setSelected(cbSonCoche); cbEffetSonore.setSelected(cbSonCoche);
clair.setSelected(cbClair); clair.setSelected(cbClair);
sliderMusique.setValue(slideValue); sliderMusique.setValue(slideValue);
sliderEffets.setValue(slideValueEffets);
System.out.println("slidevalueeffet init = "+ slideValueEffets);
langues.getItems().add("Anglais"); langues.getItems().add("Anglais");
langues.getItems().add("Allemand"); langues.getItems().add("Allemand");
@ -110,44 +114,38 @@ public class ParametreController implements Initializable {
System.out.println(EffetSonore.isSoundOK()); System.out.println(EffetSonore.isSoundOK());
} }
// Pour la couleur du theme // Pour la couleur du theme
if (clair.isSelected()) { if (clair.isSelected()) {
//Pane root = FXMLLoader.load(getClass().getResource("../ressources/menu.fxml")); // Pane root =
// FXMLLoader.load(getClass().getResource("../ressources/menu.fxml"));
rootPane.setStyle("-fx-background-color: white;"); rootPane.setStyle("-fx-background-color: white;");
rootPane.applyCss(); rootPane.applyCss();
} }
rootPane.setStyle("-fx-background-color: white;"); rootPane.setStyle("-fx-background-color: white;");
rootPane.applyCss(); rootPane.applyCss();
/*if (liste != null) { /*
for (int i = 0; i < liste.length; i++) { * if (liste != null) { for (int i = 0; i < liste.length; i++) {
*
System.out.println(liste[i]); * System.out.println(liste[i]); System.out.println(i); repertoire2 = new
System.out.println(i); * File("../ressources/" + liste[i]);
repertoire2 = new File("../ressources/" + liste[i]); *
* if (repertoire.isDirectory() == false) { if (liste[i] == "Plateau.fxml") {
if (repertoire.isDirectory() == false) { * Pane root1 = FXMLLoader.load(getClass().getResource("../ressources/" +
if (liste[i] == "Plateau.fxml") { * liste[i])); root1.setStyle("../ressources/style/plateau.css");
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"); } }
} *
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 EffetSonore.playSoundEffect(fileSound1); // emet un bruit sur le bouton si les effets sonores sont activés
System.out.println("slidevalueeffet enregistre = "+ slideValueEffets);
// Quitter les paramètres // Quitter les paramètres
final URL fxmlURL = getClass().getResource("/ihm/ressources/Menu.fxml"); final URL fxmlURL = getClass().getResource("/ihm/ressources/Menu.fxml");
@ -158,8 +156,6 @@ public class ParametreController implements Initializable {
rootPane.getChildren().setAll(pane); rootPane.getChildren().setAll(pane);
} }
@FXML @FXML
@ -170,23 +166,22 @@ public class ParametreController implements Initializable {
slideValue = sliderMusique.getValue(); slideValue = sliderMusique.getValue();
} }
}
public void slideVolumeEffet(MouseEvent mouseEvent) throws IOException {
EffetSonore.setVolumeEffets(sliderEffets.getValue());
slideValueEffets = sliderEffets.getValue();
}
/* /*
*
@FXML * @FXML public void monterVolume(MouseEvent mouseEvent) throws IOException{
public void monterVolume(MouseEvent mouseEvent) throws IOException{ * Musique.volumeUp(5.f); System.out.println("on monte le son"); }
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"); }
@FXML
public void baisserVolume(MouseEvent mouseEvent) throws IOException{
Musique.volumeDown(5.f);
System.out.println("on baisse le son");
}
*/ */
}
} }

View File

@ -26,13 +26,16 @@ public class PauseController implements Initializable {
private CheckBox cbEffet; private CheckBox cbEffet;
@FXML @FXML
private Slider sliderMusiquePause; private Slider sliderMusiquePause;
@FXML
private Slider sliderEffetsPause;
String filepathMusique = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"; String filepathMusique = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav";
InputStream fileMusique = getClass().getResourceAsStream("/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 MusiqueLancee = ParametreController.cbMusiqueCoche;
boolean SonLance = ParametreController.cbSonCoche; boolean SonLance = ParametreController.cbSonCoche;
public static double slideValuePause; public static double slideValueMusiquePause;
public static double slideValueEffetPause;
@Override @Override
public void initialize(URL arg0, ResourceBundle arg1) { public void initialize(URL arg0, ResourceBundle arg1) {
@ -40,6 +43,7 @@ public class PauseController implements Initializable {
cbMusique.setSelected(ParametreController.cbMusiqueCoche); cbMusique.setSelected(ParametreController.cbMusiqueCoche);
cbEffet.setSelected(ParametreController.cbSonCoche); cbEffet.setSelected(ParametreController.cbSonCoche);
sliderMusiquePause.setValue(ParametreController.slideValue); sliderMusiquePause.setValue(ParametreController.slideValue);
sliderEffetsPause.setValue(ParametreController.slideValueEffets);
} }
@FXML @FXML
@ -83,7 +87,8 @@ public class PauseController implements Initializable {
ParametreController.cbSonCoche = cbEffet.isSelected(); ParametreController.cbSonCoche = cbEffet.isSelected();
ParametreController.cbMusiqueCoche = cbMusique.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 EffetSonore.playSoundEffect(fileSound1); // met un bruit sur le bouton si les effets sonores sont activés
@ -122,13 +127,22 @@ public class PauseController implements Initializable {
if (Musique.musiqueEnCours == true) { if (Musique.musiqueEnCours == true) {
System.out.println("slide"); System.out.println("slide");
Musique.setVolume(sliderMusiquePause.getValue()); Musique.setVolume(sliderMusiquePause.getValue());
slideValuePause = sliderMusiquePause.getValue(); slideValueMusiquePause = sliderMusiquePause.getValue();
}else { }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 @FXML
public void monterVolume(MouseEvent mouseEvent) throws IOException { public void monterVolume(MouseEvent mouseEvent) throws IOException {

View File

@ -48,7 +48,7 @@
</HBox> </HBox>
<HBox prefHeight="0.0" prefWidth="540.0"> <HBox prefHeight="0.0" prefWidth="540.0">
<children> <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> </children>
</HBox> </HBox>
<HBox alignment="CENTER_LEFT"> <HBox alignment="CENTER_LEFT">
@ -64,6 +64,11 @@
<CheckBox fx:id="cbEffet" mnemonicParsing="false" /> <CheckBox fx:id="cbEffet" mnemonicParsing="false" />
</children> </children>
</HBox> </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"> <Label style="-fx-border-width: 0 0 0.5 0; -fx-border-color: #e2e2e2;" text="Jeux">
<VBox.margin> <VBox.margin>
<Insets top="50.0" /> <Insets top="50.0" />

View File

@ -15,12 +15,20 @@
<children> <children>
<HBox alignment="TOP_CENTER" layoutX="146.0" layoutY="171.0" prefHeight="242.0" prefWidth="507.0" spacing="10.0"> <HBox alignment="TOP_CENTER" layoutX="146.0" layoutY="171.0" prefHeight="242.0" prefWidth="507.0" spacing="10.0">
<children> <children>
<VBox prefHeight="348.0" prefWidth="195.0" spacing="40.0"> <VBox prefHeight="348.0" prefWidth="195.0" spacing="35.0">
<children> <children>
<CheckBox fx:id="clair" mnemonicParsing="false" styleClass="checkBox" text="%mode.claire" /> <CheckBox fx:id="clair" mnemonicParsing="false" styleClass="checkBox" text="%mode.claire" />
<CheckBox fx:id="cmusique" mnemonicParsing="false" styleClass="checkBox" text="%musique" /> <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" /> <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"> <VBox prefHeight="86.0" prefWidth="195.0" spacing="10.0">
<children> <children>
<Label styleClass="titre" text="%langue"> <Label styleClass="titre" text="%langue">