Add an additional SFX Volume control to the in-game settings dialog and supporting events.

This commit is contained in:
Shane Handley 2019-09-25 01:18:09 +09:00
parent d33671f9c1
commit 8cf6546dec
4 changed files with 56 additions and 13 deletions

View File

@ -93,7 +93,7 @@ impl AudioFrontend {
let id = self.next_channel_id;
self.next_channel_id += 1;
let volume = self.music_volume;
let sfx_volume = self.sfx_volume;
if let Some(_) = &self.audio_device {
let calc_pos = ((pos - self.listener_pos) * FALLOFF).into_array();
@ -105,7 +105,7 @@ impl AudioFrontend {
if let Some(channel) = self.get_channel() {
channel.set_id(id);
channel.set_volume(volume);
channel.set_volume(sfx_volume);
channel.set_emitter_position(calc_pos);
channel.set_left_ear_position(left_ear);
channel.set_right_ear_position(right_ear);
@ -145,14 +145,19 @@ impl AudioFrontend {
let id = self.next_channel_id;
self.next_channel_id += 1;
let music_volume = self.music_volume;
if let Some(_) = &self.audio_device {
let file = assets::load_file(&sound, &["ogg"]).unwrap();
let sound = Decoder::new(file).unwrap();
if let Some(channel) = self.get_channel() {
channel.set_id(id);
channel.set_volume(music_volume);
channel.play(sound);
}
} else {
log::warn!("No available channels!");
}
id

View File

@ -152,7 +152,8 @@ pub enum Event {
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustViewDistance(u32),
AdjustVolume(f32),
AdjustSfxVolume(f32),
AdjustMusicVolume(f32),
ChangeAudioDevice(String),
ChangeMaxFPS(u32),
ChangeFOV(u16),
@ -788,8 +789,11 @@ impl Hud {
settings_window::Event::CrosshairTransp(crosshair_transp) => {
events.push(Event::CrosshairTransp(crosshair_transp));
}
settings_window::Event::AdjustVolume(volume) => {
events.push(Event::AdjustVolume(volume));
settings_window::Event::AdjustMusicVolume(volume) => {
events.push(Event::AdjustMusicVolume(volume));
}
settings_window::Event::AdjustSfxVolume(volume) => {
events.push(Event::AdjustSfxVolume(volume));
}
settings_window::Event::MaximumFPS(max_fps) => {
events.push(Event::ChangeMaxFPS(max_fps));

View File

@ -78,6 +78,8 @@ widget_ids! {
fov_value,
audio_volume_slider,
audio_volume_text,
sfx_volume_slider,
sfx_volume_text,
audio_device_list,
audio_device_text,
hotbar_title,
@ -151,7 +153,8 @@ pub enum Event {
AdjustMouseZoom(u32),
AdjustViewDistance(u32),
AdjustFOV(u16),
AdjustVolume(f32),
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
ChangeAudioDevice(String),
MaximumFPS(u32),
CrosshairTransp(f32),
@ -1225,7 +1228,8 @@ impl<'a> Widget for SettingsWindow<'a> {
// Contents
if let SettingsTab::Sound = self.show.settings_tab {
Text::new("Volume")
// Music Volume -----------------------------------------------------
Text::new("Music Volume")
.top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
@ -1246,14 +1250,39 @@ impl<'a> Widget for SettingsWindow<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.audio_volume_slider, ui)
{
events.push(Event::AdjustVolume(new_val));
events.push(Event::AdjustMusicVolume(new_val));
}
// SFX Volume -------------------------------------------------------
Text::new("Sound Effects Volume")
.down_from(state.ids.audio_volume_slider, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.sfx_volume_text, ui);
if let Some(new_val) = ImageSlider::continuous(
self.global_state.settings.audio.sfx_volume,
0.0,
1.0,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
.down_from(state.ids.sfx_volume_text, 10.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.sfx_volume_slider, ui)
{
events.push(Event::AdjustSfxVolume(new_val));
}
// Audio Device Selector --------------------------------------------
let device = &self.global_state.audio.device;
let device_list = &self.global_state.audio.device_list;
Text::new("Volume")
.down_from(state.ids.audio_volume_slider, 10.0)
Text::new("Audio Volume")
.down_from(state.ids.sfx_volume_slider, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)

View File

@ -408,11 +408,16 @@ impl PlayState for SessionState {
self.hud.scale_change(scale_change);
global_state.settings.save_to_file_warn();
}
HudEvent::AdjustMusicVolume(music_volume) => {
global_state.audio.set_music_volume(music_volume);
HudEvent::AdjustVolume(volume) => {
global_state.audio.set_music_volume(volume);
global_state.settings.audio.music_volume = music_volume;
global_state.settings.save_to_file_warn();
}
HudEvent::AdjustSfxVolume(sfx_volume) => {
global_state.audio.set_sfx_volume(sfx_volume);
global_state.settings.audio.music_volume = volume;
global_state.settings.audio.sfx_volume = sfx_volume;
global_state.settings.save_to_file_warn();
}
HudEvent::ChangeAudioDevice(name) => {