From 3e487c00d5fc16ae2f3dbabbcd0e4c4b9782a37c Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 24 Nov 2024 23:29:59 +0100 Subject: [PATCH] accidentally deleted volumeSlider --- .../main/java/pp/battleship/client/Menu.java | 2 +- .../battleship/client/gui/VolumeSlider.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java index 231776d..12afb6d 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java @@ -21,7 +21,7 @@ import pp.battleship.client.gui.GameMusic; import pp.dialog.Dialog; import pp.dialog.StateCheckboxModel; import pp.dialog.TextInputDialog; -import pp.monopoly.client.gui.VolumeSlider; +import pp.battleship.client.gui.VolumeSlider; import static pp.util.PreferencesUtils.getPreferences; diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java new file mode 100644 index 0000000..70f9097 --- /dev/null +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java @@ -0,0 +1,36 @@ +package pp.battleship.client.gui; + +import com.simsilica.lemur.Slider; + +/** + * The VolumeSlider class represents the Volume Slider in the Menu. + * It extends the Slider class and provides functionalities for setting the music volume, + * with the help of the Slider in the GUI + */ +public class VolumeSlider extends Slider { + + private final GameMusic music; + private double vol; + + /** + * Constructs the Volume Slider for the Menu dialog + * @param music the music instance + */ + public VolumeSlider(GameMusic music) { + super(); + this.music = music; + vol = GameMusic.volumeInPreferences(); + getModel().setPercent(vol); + } + + /** + * when triggered it updates the volume to the value set with the slider + */ + public void update() { + if (vol != getModel().getPercent()) { + vol = getModel().getPercent(); + music.setVolume( (float) vol); + } + } + +}