diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index bbe20e028f..e6c85494ee 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -76,4 +76,8 @@ impl AudioFrontend { self.play_music(music[i]) } } + + pub fn set_volume(&mut self, volume: f32) { + self.stream.set_volume(volume.min(1.0).max(0.0)) + } } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 97ddf8071d..388d5a5525 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -91,6 +91,7 @@ font_ids! { pub enum Event { SendMessage(String), AdjustViewDistance(u32), + AdjustVolume(f32), Logout, Quit, } @@ -210,6 +211,7 @@ pub struct Hud { force_ungrab: bool, // TODO: move to settings current_vd: u32, + current_volume: f32, } impl Hud { @@ -247,6 +249,7 @@ impl Hud { settings, force_ungrab: false, current_vd: 5, + current_volume: 0.5, } } @@ -376,8 +379,14 @@ impl Hud { // Settings if let Windows::Settings = self.show.open_windows { - for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, self.current_vd) - .set(self.ids.settings_window, ui_widgets) + for event in SettingsWindow::new( + &self.show, + &self.imgs, + &self.fonts, + self.current_vd, + self.current_volume, + ) + .set(self.ids.settings_window, ui_widgets) { match event { settings_window::Event::ToggleHelp => self.show.toggle_help(), @@ -390,6 +399,10 @@ impl Hud { self.current_vd = view_distance; events.push(Event::AdjustViewDistance(view_distance)); } + settings_window::Event::AdjustVolume(volume) => { + self.current_volume = volume; + events.push(Event::AdjustVolume(volume)); + } } } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 3f340ebe4b..0f290cea71 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -1,11 +1,10 @@ -use super::{img_ids::Imgs, Fonts, TEXT_COLOR}; -use crate::{hud::Show, ui::ToggleButton}; +use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR}; use crate::{ render::Renderer, ui::{ self, img_ids::{ImageGraphic, VoxelGraphic}, - ImageSlider, ScaleMode, Ui, + ImageSlider, ScaleMode, ToggleButton, Ui, }, window::Window, }; @@ -44,6 +43,8 @@ widget_ids! { video, vd_slider, vd_slider_text, + audio_volume_slider, + audio_volume_text, } } @@ -63,18 +64,26 @@ pub struct SettingsWindow<'a> { fonts: &'a Fonts, current_vd: u32, + current_volume: f32, #[conrod(common_builder)] common: widget::CommonBuilder, } impl<'a> SettingsWindow<'a> { - pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts, current_vd: u32) -> Self { + pub fn new( + show: &'a Show, + imgs: &'a Imgs, + fonts: &'a Fonts, + current_vd: u32, + current_volume: f32, + ) -> Self { Self { show, imgs, fonts, current_vd, + current_volume, common: widget::CommonBuilder::default(), } } @@ -92,6 +101,7 @@ pub enum Event { ToggleDebug, Close, AdjustViewDistance(u32), + AdjustVolume(f32), } impl<'a> Widget for SettingsWindow<'a> { @@ -312,6 +322,8 @@ impl<'a> Widget for SettingsWindow<'a> { Toggle Help Window\n\ Toggle Interface\n\ Toggle FPS and Debug Info\n\ + Take Screenshot\n\ + Toggle Fullscreen\n\ \n\ \n\ Move Forward\n\ @@ -378,6 +390,8 @@ impl<'a> Widget for SettingsWindow<'a> { F1\n\ F2\n\ F3\n\ + F4\n\ + F11\n\ \n\ \n\ W\n\ @@ -489,7 +503,7 @@ impl<'a> Widget for SettingsWindow<'a> { .pad_track((5.0, 5.0)) .set(state.ids.vd_slider, ui) { - events.push(Event::AdjustViewDistance(new_val as u32)); + events.push(Event::AdjustViewDistance(new_val)); } } // 5 Sound @@ -519,6 +533,32 @@ impl<'a> Widget for SettingsWindow<'a> { { state.update(|s| s.settings_tab = SettingsTab::Sound); } + // Contents + if let SettingsTab::Sound = state.settings_tab { + Text::new("Volume") + .top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0) + .font_size(14) + .font_id(self.fonts.opensans) + .color(TEXT_COLOR) + .set(state.ids.audio_volume_text, ui); + + if let Some(new_val) = ImageSlider::continuous( + self.current_volume, + 0.0, + 1.0, + self.imgs.slider_indicator, + self.imgs.slider, + ) + .w_h(104.0, 22.0) + .down_from(state.ids.audio_volume_text, 10.0) + .track_breadth(12.0) + .slider_length(10.0) + .pad_track((5.0, 5.0)) + .set(state.ids.audio_volume_slider, ui) + { + events.push(Event::AdjustVolume(new_val)); + } + } events } diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 76f99a94d4..643674e135 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -165,6 +165,10 @@ fn main() { audio: AudioFrontend::new(), }; + // TODO: Remove this when the volume setting can be saved + // Lower the volume to 50% + global_state.audio.set_volume(0.5); + // Set up the initial play state. let mut states: Vec> = vec![Box::new(MainMenuState::new(&mut global_state))]; states diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 6f7993be2b..de75d9bb4d 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -193,6 +193,9 @@ impl PlayState for SessionState { HudEvent::AdjustViewDistance(view_distance) => { self.client.borrow_mut().set_view_distance(view_distance) } + HudEvent::AdjustVolume(volume) => { + global_state.audio.set_volume(volume); + } } } diff --git a/voxygen/src/ui/widgets/image_slider.rs b/voxygen/src/ui/widgets/image_slider.rs index 160ab72f1a..daa33d9721 100644 --- a/voxygen/src/ui/widgets/image_slider.rs +++ b/voxygen/src/ui/widgets/image_slider.rs @@ -119,7 +119,10 @@ impl ImageSlider { } } -impl ImageSlider { +impl ImageSlider +where + T: Float, +{ pub fn continuous( value: T, min: T, @@ -131,7 +134,10 @@ impl ImageSlider { } } -impl ImageSlider { +impl ImageSlider +where + T: Integer, +{ pub fn discrete( value: T, min: T,