mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-28 18:59:47 +01:00
refactor and documentation
This commit is contained in:
parent
133921cfbb
commit
5cca8f5c05
@ -283,7 +283,7 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches the game sound state and sets its initial enabled state.
|
||||
* Attaches the background music state and sets its initial enabled state.
|
||||
*/
|
||||
private void attachGameMusic() {
|
||||
final GameMusic gameSound = new GameMusic();
|
||||
|
@ -34,7 +34,7 @@ public class GameMusic extends AbstractAppState{
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
* @return //TODO
|
||||
* @return float to which the volume is set
|
||||
*/
|
||||
public static float volumeInPreferences() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
|
||||
@ -78,7 +78,7 @@ public class GameMusic extends AbstractAppState{
|
||||
return null;
|
||||
}
|
||||
|
||||
/** TODO
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
*
|
||||
@ -87,11 +87,15 @@ public class GameMusic extends AbstractAppState{
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
else if(!isEnabled() && enabled) {
|
||||
if (music != null) music.play();
|
||||
} else if (isEnabled() && !enabled) {
|
||||
if (music != null) music.stop();
|
||||
|
||||
if (music != null) {
|
||||
if (enabled) {
|
||||
music.play();
|
||||
} else {
|
||||
music.stop();
|
||||
}
|
||||
}
|
||||
|
||||
super.setEnabled(enabled);
|
||||
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
|
||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||
@ -104,6 +108,10 @@ public class GameMusic extends AbstractAppState{
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume of music
|
||||
* @param vol the volume to which the music should be set
|
||||
*/
|
||||
public void setVolume(float vol){
|
||||
music.setVolume(vol);
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
|
@ -1,13 +1,20 @@
|
||||
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;
|
||||
@ -15,6 +22,9 @@ public class VolumeSlider extends Slider {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user