Skip to content
Snippets Groups Projects
Commit bd8dba41 authored by Tran Peter's avatar Tran Peter
Browse files

update(settings): add sfx volume slider and refactor 'options' to 'settings #61'

parent d57c1638
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!10Mergin ui into development,!9Merging ui into development
......@@ -30,7 +30,7 @@ public class MainMenuController implements Initializable {
switchScene("Statistics");
}
public void optionsScene() {
public void settingsScene() {
switchScene("Options");
}
......
......@@ -11,13 +11,13 @@ import java.net.URL;
import java.util.Objects;
import java.util.ResourceBundle;
public class OptionsController implements Initializable {
public class SettingsController implements Initializable {
@FXML
private VBox parent;
@FXML
private Slider volumeSlider;
private Slider musicVolume, sfxVolume;
SceneLoader sceneLoader = new SceneLoader();
public double volume;
public double music;
MusicPlayerSingleton musicPlayer = MusicPlayerSingleton.getInstance();
public void creditScene() throws IOException {
......@@ -32,15 +32,21 @@ public class OptionsController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
setVolume();
setMusicVolume();
}
private void setVolume() {
private void setMusicVolume() {
// need a runtime database to save volume
volumeSlider.valueProperty().addListener((observableValue, oldValue, newValue) -> {
volume = newValue.doubleValue() / 100;
musicPlayer.getMediaPlayer().setVolume(volume);
System.out.println(volume);
musicVolume.valueProperty().addListener((observableValue, oldValue, newValue) -> {
setMusic(musicVolume);
System.out.println(music);
});
}
private void setMusic(Slider slider) {
slider.valueProperty().addListener(((observableValue, oldValue, newValue) -> {
music = newValue.doubleValue() / 100;
musicPlayer.getMediaPlayer().setVolume(music);
}));
}
}
......@@ -17,7 +17,7 @@
</Button>
<Button mnemonicParsing="false" text="Map Creator" VBox.vgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#statisticsScene" text="Statistics" VBox.vgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#optionsScene" text="Options" />
<Button mnemonicParsing="false" onAction="#settingsScene" text="Settings" />
<Button fx:id="exitButton" alignment="CENTER" mnemonicParsing="false" onAction="#exit" text="Exit" />
<Pane VBox.vgrow="ALWAYS" />
<Pane layoutX="10.0" layoutY="395.0" VBox.vgrow="ALWAYS" />
......
......@@ -6,15 +6,24 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<VBox fx:id="parent" alignment="CENTER" prefHeight="400.0" prefWidth="600.0" spacing="20.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.OptionsController">
<VBox fx:id="parent" alignment="CENTER" prefHeight="400.0" prefWidth="600.0" spacing="20.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.SettingsController">
<children>
<HBox alignment="CENTER">
<children>
<VBox alignment="TOP_CENTER" spacing="10.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Volume:" />
<Slider fx:id="volumeSlider" blockIncrement="25.0" majorTickUnit="100.0" minorTickCount="1" prefHeight="14.0" prefWidth="480.0" showTickLabels="true" value="75.0" VBox.vgrow="NEVER" />
<VBox alignment="CENTER" VBox.vgrow="ALWAYS">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Music volume:" />
<Slider fx:id="musicVolume" blockIncrement="25.0" majorTickUnit="100.0" minorTickCount="1" prefHeight="14.0" prefWidth="480.0" showTickLabels="true" value="75.0" VBox.vgrow="NEVER" />
</children>
</VBox>
<VBox alignment="CENTER" VBox.vgrow="ALWAYS">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="SFX volume:" />
<Slider fx:id="sfxVolume" blockIncrement="25.0" majorTickUnit="100.0" minorTickCount="1" prefHeight="14.0" prefWidth="480.0" showTickLabels="true" value="75.0" />
</children>
</VBox>
</children>
</VBox>
</children>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment