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