mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-06 02:35:38 +02:00
added effect sound slider
This commit is contained in:
@@ -34,7 +34,7 @@ public class GameMusic extends AbstractAppState{
|
||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
* @return float to which the volume is set
|
||||
|
@@ -30,6 +30,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
private static final Logger LOGGER = System.getLogger(GameSound.class.getName());
|
||||
private static final Preferences PREFERENCES = getPreferences(GameSound.class);
|
||||
private static final String ENABLED_PREF = "enabled"; //NON-NLS
|
||||
private static final String VOLUME_PREF = "volume"; //NON-NLS
|
||||
|
||||
private AudioNode passStartSound;
|
||||
private AudioNode eventCardSound;
|
||||
@@ -59,6 +60,15 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
* @return float to which the volume is set
|
||||
*/
|
||||
public static float volumeInPreferences() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
@@ -92,7 +102,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
tradeAcceptedSound = loadSound(app, "Sound/Effects/tradeAccepted.ogg");
|
||||
tradeRejectedSound = loadSound(app, "Sound/Effects/tradeRejected.ogg");
|
||||
winnerSound = loadSound(app, "Sound/Effects/winner.ogg");
|
||||
looserSound = loadSound(app, "Sound/Effects/looser.ogg");
|
||||
looserSound = loadSound(app, "Sound/Effects/loser.ogg");
|
||||
buttonSound = loadSound(app, "Sound/Effects/button.ogg");
|
||||
}
|
||||
|
||||
@@ -193,6 +203,25 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
||||
if (isEnabled() && buttonSound != null)
|
||||
buttonSound.playInstance();
|
||||
}
|
||||
/**
|
||||
* Sets the volume of the sounds
|
||||
* @param vol the volume to which the sounds should be set
|
||||
*/
|
||||
public void setVolume(float vol){
|
||||
passStartSound.setVolume(vol);
|
||||
eventCardSound.setVolume(vol);
|
||||
gulagSound.setVolume(vol);
|
||||
diceRollSound.setVolume(vol);
|
||||
moneyCollectSound.setVolume(vol);
|
||||
moneyLostSound.setVolume(vol);
|
||||
tradeAcceptedSound.setVolume(vol);
|
||||
tradeRejectedSound.setVolume(vol);
|
||||
winnerSound.setVolume(vol);
|
||||
looserSound.setVolume(vol);
|
||||
buttonSound.setVolume(vol);
|
||||
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(SoundEvent event) {
|
||||
|
@@ -31,7 +31,8 @@ public class SettingsMenu extends Dialog {
|
||||
private static final Preferences PREFERENCES = getPreferences(SettingsMenu.class);
|
||||
private static final String LAST_PATH = "last.file.path";
|
||||
private final MonopolyApp app;
|
||||
private final VolumeSlider slider;
|
||||
private final VolumeSlider musicSlider;
|
||||
private final SoundSlider soundSlider;
|
||||
|
||||
/**
|
||||
* Constructs the Menu dialog for the Battleship application.
|
||||
@@ -41,18 +42,22 @@ public class SettingsMenu extends Dialog {
|
||||
public SettingsMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
addChild(new Label("Einstellungen", new ElementId("header"))); //NON-NLS
|
||||
musicSlider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
soundSlider = new SoundSlider(app.getStateManager().getState(GameSound.class));
|
||||
addChild(new Label("Einstellungen", new ElementId("settings-title"))); //NON-NLS
|
||||
addChild(new Label("Sound Effekte", new ElementId("label"))); //NON-NLS
|
||||
|
||||
addChild(soundSlider);
|
||||
|
||||
addChild(new Checkbox("Soundeffekte an / aus", new StateCheckboxModel(app, GameSound.class)));
|
||||
|
||||
addChild(new Label("Hintergrund Musik", new ElementId("label"))); //NON-NLS
|
||||
addChild(new Checkbox("Musik an / aus", new StateCheckboxModel(app, GameMusic.class)));
|
||||
|
||||
addChild(slider);
|
||||
addChild(musicSlider);
|
||||
|
||||
addChild(new Button("Zurück zum Spiel")).addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button("Beenden")).addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button("Beenden", new ElementId("button"))).addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
|
||||
update();
|
||||
}
|
||||
@@ -66,7 +71,8 @@ public class SettingsMenu extends Dialog {
|
||||
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
slider.update();
|
||||
musicSlider.update();
|
||||
soundSlider.update();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,32 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.simsilica.lemur.Slider;
|
||||
import pp.monopoly.client.GameMusic;
|
||||
import pp.monopoly.client.GameSound;
|
||||
|
||||
public class SoundSlider extends Slider {
|
||||
|
||||
private final pp.monopoly.client.GameSound sound;
|
||||
private double vol;
|
||||
|
||||
/**
|
||||
* Constructs the Volume Slider for the Menu dialog
|
||||
* @param sound the Effects sound instance
|
||||
*/
|
||||
public SoundSlider(GameSound sound) {
|
||||
super();
|
||||
this.sound = sound;
|
||||
vol = GameSound.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();
|
||||
sound.setVolume( (float) vol);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user