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 0e100e8..33f38e5 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 @@ -7,21 +7,25 @@ package pp.battleship.client; -import com.simsilica.lemur.Button; -import com.simsilica.lemur.Checkbox; -import com.simsilica.lemur.Label; -import com.simsilica.lemur.style.ElementId; -import pp.dialog.Dialog; -import pp.dialog.StateCheckboxModel; -import pp.dialog.TextInputDialog; - import java.io.File; import java.io.IOException; import java.util.prefs.Preferences; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.Checkbox; +import com.simsilica.lemur.Label; +import com.simsilica.lemur.style.ElementId; + import static pp.battleship.Resources.lookup; +import pp.battleship.client.gui.BgMusic; +import pp.battleship.client.gui.VolumeSlider; +import pp.dialog.Dialog; +import pp.dialog.StateCheckboxModel; +import pp.dialog.TextInputDialog; import static pp.util.PreferencesUtils.getPreferences; + + /** * The Menu class represents the main menu in the Battleship game application. * It extends the Dialog class and provides functionalities for loading, saving, @@ -33,6 +37,7 @@ class Menu extends Dialog { private final BattleshipApp app; private final Button loadButton = new Button(lookup("menu.map.load")); private final Button saveButton = new Button(lookup("menu.map.save")); + private final VolumeSlider slider; /** * Constructs the Menu dialog for the Battleship application. @@ -42,9 +47,16 @@ class Menu extends Dialog { public Menu(BattleshipApp app) { super(app.getDialogManager()); this.app = app; + slider = new VolumeSlider(app.getStateManager().getState(BgMusic.class)); addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS - addChild(new Checkbox(lookup("menu.sound-enabled"), - new StateCheckboxModel(app, GameSound.class))); + // addChild(new Checkbox(lookup("menu.sound-enabled"), + // new StateCheckboxModel(app, GameSound.class))); + addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class))); + + addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, BgMusic.class))); + + addChild(slider); + addChild(loadButton) .addClickCommands(s -> ifTopDialog(this::loadDialog)); addChild(saveButton) @@ -64,6 +76,10 @@ class Menu extends Dialog { loadButton.setEnabled(app.getGameLogic().mayLoadMap()); saveButton.setEnabled(app.getGameLogic().maySaveMap()); } + @Override + public void update(float delta) { + slider.update(); + } /** * As an escape action, this method closes the menu if it is the top dialog. 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..2772afd --- /dev/null +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java @@ -0,0 +1,25 @@ +package pp.battleship.client.gui; + +import com.simsilica.lemur.Slider; + +public class VolumeSlider extends Slider { + + private final BgMusic music; + + private double vol; + + public VolumeSlider(BgMusic music) { + super(); + this.music = music; + vol = BgMusic.volumeInPreferences(); + getModel().setPercent(vol); + } + + public void update() { + if (vol != getModel().getPercent()) { + vol = getModel().getPercent(); + music.setVolume( (float) vol); + } + } + +}