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); + } + } + +}