Merge branch 'DaforLynx/combat-music-toggle' into 'master'

Combat music toggle

See merge request veloren/veloren!4048
This commit is contained in:
DaforLynx 2023-07-30 08:10:37 +00:00
commit 05c9ca22a5
8 changed files with 65 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -58,6 +58,8 @@ pub struct AudioFrontend {
pub subtitles_enabled: bool,
pub subtitles: VecDeque<Subtitle>,
pub combat_music_enabled: bool,
mtm: AssetHandle<MusicTransitionManifest>,
}
@ -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,
}
}

View File

@ -255,29 +255,31 @@ impl MusicMgr {
let groups = ecs.read_component::<Group>();
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);
}
}
}

View File

@ -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))

View File

@ -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()),
};

View File

@ -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());

View File

@ -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,
}
}
}