Voxygen: Add inactive window volume

This commit is contained in:
João Capucho 2021-04-18 19:30:22 +01:00
parent 1d605c2dc8
commit fd302b6975
No known key found for this signature in database
GPG Key ID: 1AD5CE7CCAEBDA21
2 changed files with 11 additions and 0 deletions

View File

@ -61,6 +61,15 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) {
},
winit::event::Event::WindowEvent { event, .. } => {
span!(_guard, "Handle WindowEvent");
if let winit::event::WindowEvent::Focused(focused) = event {
global_state.audio.set_master_volume(if focused {
global_state.settings.audio.master_volume
} else {
global_state.settings.audio.inactive_master_volume
});
}
global_state
.window
.handle_window_event(event, &mut global_state.settings)

View File

@ -21,6 +21,7 @@ impl AudioOutput {
#[serde(default)]
pub struct AudioSettings {
pub master_volume: f32,
pub inactive_master_volume: f32,
pub music_volume: f32,
pub sfx_volume: f32,
pub max_sfx_channels: usize,
@ -33,6 +34,7 @@ impl Default for AudioSettings {
fn default() -> Self {
Self {
master_volume: 1.0,
inactive_master_volume: 0.5,
music_volume: 0.4,
sfx_volume: 0.6,
max_sfx_channels: 30,