mirror of https://github.com/FreeCol/freecol.git
Reintroducing separate volume sliders for music and sound effects.
This commit is contained in:
parent
fda26e7afa
commit
cc4254b397
|
@ -370,9 +370,15 @@
|
|||
<!-- Which mixer to use by default. -->
|
||||
<audioMixerOption id="model.option.audioMixer"
|
||||
defaultValue="AUTO" />
|
||||
<!-- The default volume percent. -->
|
||||
<percentageOption id="model.option.audioVolume"
|
||||
|
||||
<!--The music volume -->
|
||||
<percentageOption id="model.option.musicVolume"
|
||||
defaultValue="100" previewEnabled="true"/>
|
||||
|
||||
<!--The sound effects volume -->
|
||||
<percentageOption id="model.option.soundEffectsVolume"
|
||||
defaultValue="100" previewEnabled="true"/>
|
||||
|
||||
<!-- Play an alert sound on message arrival. -->
|
||||
<booleanOption id="model.option.audioAlerts"
|
||||
defaultValue="false"/>
|
||||
|
|
|
@ -1255,8 +1255,10 @@ clientOptions.audio.shortDescription=Audio Settings
|
|||
clientOptions.audio.audioMixer.automatic=Autodetect audio output
|
||||
model.option.audioMixer.name=Audio Output
|
||||
model.option.audioMixer.shortDescription=The device to be used when playing audio.
|
||||
model.option.audioVolume.name=Audio Volume
|
||||
model.option.audioVolume.shortDescription=Audio Volume
|
||||
model.option.musicVolume.name=Music Volume
|
||||
model.option.musicVolume.shortDescription=Music Volume
|
||||
model.option.soundEffectsVolume.name=Sound Effects Volume
|
||||
model.option.soundEffectsVolume.shortDescription=Sound Effects Volume
|
||||
model.option.audioAlerts.name=Audio Alerts
|
||||
model.option.audioAlerts.shortDescription=Turn on Audio Alerts
|
||||
|
||||
|
|
|
@ -509,6 +509,14 @@ public class ClientOptions extends OptionGroup {
|
|||
/** The volume level to set. */
|
||||
public static final String AUDIO_VOLUME
|
||||
= "model.option.audioVolume";
|
||||
|
||||
/** The volume level to set for the music. */
|
||||
public static final String MUSIC_VOLUME
|
||||
= "model.option.musicVolume";
|
||||
|
||||
/** The volume level to set. */
|
||||
public static final String SOUND_EFFECTS_VOLUME
|
||||
= "model.option.soundEffectsVolume";
|
||||
|
||||
/** Play an alert sound on message arrival. */
|
||||
public static final String AUDIO_ALERTS
|
||||
|
@ -855,11 +863,26 @@ public class ClientOptions extends OptionGroup {
|
|||
addBooleanOption(DISPLAY_FOG_OF_WAR, MAPCONTROLS_GROUP, false);
|
||||
// end @compat 0.11.6
|
||||
// @compat 0.12.0
|
||||
/* Gone after 0.13.0:
|
||||
final PercentageOption volumeOption = getOption(AUDIO_VOLUME, PercentageOption.class);
|
||||
volumeOption.setPreviewEnabled(true);
|
||||
*/
|
||||
addRangeOption(GRAPHICS_QUALITY, DISPLAY_GROUP, 20, graphicsQualityChoices);
|
||||
addBooleanOption(USE_TERRAIN_ANIMATIONS, DISPLAY_GROUP, true);
|
||||
// end @compat 0.12.0
|
||||
// @compat 0.13.0
|
||||
addPercentageOption(MUSIC_VOLUME, AUDIO_GROUP, 100);
|
||||
addPercentageOption(SOUND_EFFECTS_VOLUME, AUDIO_GROUP, 100);
|
||||
// end @compat 0.13.0
|
||||
}
|
||||
|
||||
private void addPercentageOption(String id, String gr, int val) {
|
||||
if (!hasOption(id, PercentageOption.class)) {
|
||||
PercentageOption op = new PercentageOption(id, null);
|
||||
op.setGroup(gr);
|
||||
op.setValue(val);
|
||||
add(op);
|
||||
}
|
||||
}
|
||||
|
||||
private void addBooleanOption(String id, String gr, boolean val) {
|
||||
|
|
|
@ -64,21 +64,17 @@ public class SoundController {
|
|||
} catch (Exception ex) {
|
||||
logger.warning(ex.getMessage());
|
||||
}
|
||||
PercentageOption vo = null;
|
||||
try {
|
||||
vo = opts.getOption(ClientOptions.AUDIO_VOLUME,
|
||||
PercentageOption.class);
|
||||
} catch (Exception ex) {
|
||||
logger.warning(ex.getMessage());
|
||||
|
||||
if (amo == null) {
|
||||
return;
|
||||
}
|
||||
if (amo == null || vo == null) return;
|
||||
// Unless totally disabled, the sound player is always
|
||||
// created, but if it has a bad mixer sound output will be
|
||||
// suspended. The hope is that the user will change the
|
||||
// mixer option to one that works.
|
||||
logger.info("Create sound player with " + amo + "/" + vo);
|
||||
this.soundPlayer = new SoundPlayer(amo, vo);
|
||||
this.musicPlayer = new SoundPlayer(amo, vo);
|
||||
logger.info("Create sound player with " + amo);
|
||||
this.soundPlayer = new SoundPlayer(amo, opts.getOption(ClientOptions.SOUND_EFFECTS_VOLUME, PercentageOption.class));
|
||||
this.musicPlayer = new SoundPlayer(amo, opts.getOption(ClientOptions.MUSIC_VOLUME, PercentageOption.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,6 +128,8 @@ public final class SoundPlayer {
|
|||
* @exception IOException if unable to read or write the sound data.
|
||||
*/
|
||||
private boolean playSound(File sound) throws IOException {
|
||||
setVolume(volumeOption.getValue());
|
||||
|
||||
boolean ret = false;
|
||||
PropertyChangeListener volumeListener = null;
|
||||
try (AudioInputStream in = getAudioInputStream(sound)) {
|
||||
|
@ -142,7 +144,6 @@ public final class SoundPlayer {
|
|||
};
|
||||
volumeOption.addPropertyChangeListener(volumeListener);
|
||||
changeVolume(line, getVolume());
|
||||
|
||||
try {
|
||||
this.playDone = false;
|
||||
int rd;
|
||||
|
|
|
@ -41,7 +41,7 @@ public class SoundTest extends FreeColTestCase {
|
|||
co.load(FreeColDirectories.getBaseClientOptionsFile());
|
||||
final AudioMixerOption amo = co.getOption(ClientOptions.AUDIO_MIXER,
|
||||
AudioMixerOption.class);
|
||||
final PercentageOption po = co.getOption(ClientOptions.AUDIO_VOLUME,
|
||||
final PercentageOption po = co.getOption(ClientOptions.MUSIC_VOLUME,
|
||||
PercentageOption.class);
|
||||
po.setValue(10); // 10% volume
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue