From 32f3437fb0136b05b1f070ec524b6e58fd66a5e7 Mon Sep 17 00:00:00 2001 From: DaforLynx Date: Sun, 30 Jul 2023 08:10:36 +0000 Subject: [PATCH] Combat music toggle --- CHANGELOG.md | 1 + assets/voxygen/i18n/en/hud/settings.ftl | 1 + voxygen/src/audio/mod.rs | 5 +++ voxygen/src/audio/music.rs | 46 ++++++++++++------------ voxygen/src/hud/settings_window/sound.rs | 28 ++++++++++++++- voxygen/src/main.rs | 1 + voxygen/src/session/settings_change.rs | 4 +++ voxygen/src/settings/audio.rs | 2 ++ 8 files changed, 65 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7323dc2cf4..51a077f3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Recipe for twigs from wooden logs - First version of multisalvage that allows to obtain more than one piece of material from salvage - Axe +- Combat music toggle ### Changed diff --git a/assets/voxygen/i18n/en/hud/settings.ftl b/assets/voxygen/i18n/en/hud/settings.ftl index 35c7b78511..098892d2e4 100644 --- a/assets/voxygen/i18n/en/hud/settings.ftl +++ b/assets/voxygen/i18n/en/hud/settings.ftl @@ -127,6 +127,7 @@ hud-settings-inactive_master_volume_perc = Inactive Window Volume hud-settings-music_volume = Music Volume hud-settings-sound_effect_volume = Sound Effects Volume hud-settings-ambience_volume = Ambience Volume +hud-settings-combat_music = Combat Music hud-settings-music_spacing = Music Spacing hud-settings-audio_device = Audio Device hud-settings-reset_sound = Reset to Defaults diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 533ad6a47b..4ee26a485c 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -58,6 +58,8 @@ pub struct AudioFrontend { pub subtitles_enabled: bool, pub subtitles: VecDeque, + pub combat_music_enabled: bool, + mtm: AssetHandle, } @@ -68,6 +70,7 @@ impl AudioFrontend { num_sfx_channels: usize, num_ui_channels: usize, subtitles: bool, + combat_music_enabled: bool, ) -> Self { // Commented out until audio device switcher works //let audio_device = get_device_raw(&dev); @@ -118,6 +121,7 @@ impl AudioFrontend { mtm: AssetExt::load_expect("voxygen.audio.music_transition_manifest"), subtitles: VecDeque::new(), subtitles_enabled: subtitles, + combat_music_enabled, } } @@ -143,6 +147,7 @@ impl AudioFrontend { mtm: AssetExt::load_expect("voxygen.audio.music_transition_manifest"), subtitles: VecDeque::new(), subtitles_enabled: false, + combat_music_enabled: false, } } diff --git a/voxygen/src/audio/music.rs b/voxygen/src/audio/music.rs index c331b98fb5..29499a264e 100644 --- a/voxygen/src/audio/music.rs +++ b/voxygen/src/audio/music.rs @@ -255,29 +255,31 @@ impl MusicMgr { let groups = ecs.read_component::(); let mtm = audio.mtm.read(); - if let Some(player_pos) = positions.get(player) { - // TODO: `group::ENEMY` will eventually be moved server-side with an - // alignment/faction rework, so this will need an alternative way to measure - // "in-combat-ness" - let num_nearby_entities: u32 = (&entities, &positions, &healths, &groups) - .join() - .map(|(entity, pos, health, group)| { - if entity != player - && group == &ENEMY - && (player_pos.0 - pos.0).magnitude_squared() - < mtm.combat_nearby_radius.powf(2.0) - { - (health.maximum() / mtm.combat_health_factor).ceil() as u32 - } else { - 0 - } - }) - .sum(); + if audio.combat_music_enabled { + if let Some(player_pos) = positions.get(player) { + // TODO: `group::ENEMY` will eventually be moved server-side with an + // alignment/faction rework, so this will need an alternative way to measure + // "in-combat-ness" + let num_nearby_entities: u32 = (&entities, &positions, &healths, &groups) + .join() + .map(|(entity, pos, health, group)| { + if entity != player + && group == &ENEMY + && (player_pos.0 - pos.0).magnitude_squared() + < mtm.combat_nearby_radius.powf(2.0) + { + (health.maximum() / mtm.combat_health_factor).ceil() as u32 + } else { + 0 + } + }) + .sum(); - if num_nearby_entities >= mtm.combat_nearby_high_thresh { - activity_state = MusicActivity::Combat(CombatIntensity::High); - } else if num_nearby_entities >= mtm.combat_nearby_low_thresh { - activity_state = MusicActivity::Combat(CombatIntensity::Low); + if num_nearby_entities >= mtm.combat_nearby_high_thresh { + activity_state = MusicActivity::Combat(CombatIntensity::High); + } else if num_nearby_entities >= mtm.combat_nearby_low_thresh { + activity_state = MusicActivity::Combat(CombatIntensity::Low); + } } } diff --git a/voxygen/src/hud/settings_window/sound.rs b/voxygen/src/hud/settings_window/sound.rs index f5320c19ee..7967d70240 100644 --- a/voxygen/src/hud/settings_window/sound.rs +++ b/voxygen/src/hud/settings_window/sound.rs @@ -45,6 +45,8 @@ widget_ids! { //audio_device_list, //audio_device_text, reset_sound_button, + combat_music_toggle_label, + combat_music_toggle_button, } } @@ -431,6 +433,30 @@ impl<'a> Widget for Sound<'a> { .color(TEXT_COLOR) .set(state.ids.music_spacing_number, ui); + // Combat music toggle + let audio = &self.global_state.audio; + + Text::new(&self.localized_strings.get_msg("hud-settings-combat_music")) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .down_from(state.ids.music_spacing_slider, 10.0) + .x_align_to(state.ids.music_spacing_text, Align::Start) + .color(TEXT_COLOR) + .set(state.ids.combat_music_toggle_label, ui); + + let combat_music_enabled = ToggleButton::new( + audio.combat_music_enabled, + self.imgs.checkbox, + self.imgs.checkbox_checked, + ) + .w_h(18.0, 18.0) + .right_from(state.ids.combat_music_toggle_label, 10.0) + .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo) + .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) + .set(state.ids.combat_music_toggle_button, ui); + + events.push(ToggleCombatMusic(combat_music_enabled)); + // Audio Device Selector // -------------------------------------------- // let device = &self.global_state.audio.device; @@ -463,7 +489,7 @@ impl<'a> Widget for Sound<'a> { .w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .down_from(state.ids.music_spacing_slider, 12.0) + .down_from(state.ids.combat_music_toggle_button, 12.0) .x_align_to(state.ids.ambience_volume_text, Align::Start) .label(&self.localized_strings.get_msg("hud-settings-reset_sound")) .label_font_size(self.fonts.cyri.scale(14)) diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index f8e0ed9622..e68bae2282 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -140,6 +140,7 @@ fn main() { settings.audio.num_sfx_channels, settings.audio.num_ui_channels, settings.audio.subtitles, + settings.audio.combat_music_enabled, ), // AudioOutput::Device(ref dev) => Some(dev.clone()), }; diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index ad1688ddd8..42222e184a 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -30,6 +30,7 @@ pub enum Audio { AdjustAmbienceVolume(f32), MuteAmbienceVolume(bool), AdjustMusicSpacing(f32), + ToggleCombatMusic(bool), //ChangeAudioDevice(String), ResetAudioSettings, } @@ -286,6 +287,9 @@ impl SettingsChange { settings.audio.music_spacing = multiplier; }, + Audio::ToggleCombatMusic(combat_music_enabled) => { + global_state.audio.combat_music_enabled = combat_music_enabled + }, //Audio::ChangeAudioDevice(name) => { // global_state.audio.set_device(name.clone()); diff --git a/voxygen/src/settings/audio.rs b/voxygen/src/settings/audio.rs index 4275555600..dfe53f442d 100644 --- a/voxygen/src/settings/audio.rs +++ b/voxygen/src/settings/audio.rs @@ -48,6 +48,7 @@ pub struct AudioSettings { pub num_ui_channels: usize, pub music_spacing: f32, pub subtitles: bool, + pub combat_music_enabled: bool, /// Audio Device that Voxygen will use to play audio. pub output: AudioOutput, @@ -66,6 +67,7 @@ impl Default for AudioSettings { music_spacing: 1.0, subtitles: false, output: AudioOutput::Automatic, + combat_music_enabled: true, } } }