From 8cf6546decee2084aafac6e5c983c5ddd368c3e4 Mon Sep 17 00:00:00 2001 From: Shane Handley Date: Wed, 25 Sep 2019 01:18:09 +0900 Subject: [PATCH] Add an additional SFX Volume control to the in-game settings dialog and supporting events. --- voxygen/src/audio/mod.rs | 9 +++++-- voxygen/src/hud/mod.rs | 10 +++++--- voxygen/src/hud/settings_window.rs | 39 ++++++++++++++++++++++++++---- voxygen/src/session.rs | 11 ++++++--- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 3fee3119e1..308fe743b6 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -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 diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 19567bf182..e8b589c74f 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -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)); diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 682eb3dfd9..abc2aaa105 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -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) diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 029d5fe67d..9e9f216e5b 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -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) => {