diff --git a/cosmos_client/assets/cosmos/lang/settings/en_us.lang b/cosmos_client/assets/cosmos/lang/settings/en_us.lang index 97aa0a2ff..c248f4247 100644 --- a/cosmos_client/assets/cosmos/lang/settings/en_us.lang +++ b/cosmos_client/assets/cosmos/lang/settings/en_us.lang @@ -1,3 +1,4 @@ cosmos:brightness=Brightness cosmos:sensitivity=Mouse Sensitivity -cosmos:fov=Field of View \ No newline at end of file +cosmos:fov=Field of View +cosmos:music_volume=Music Volume diff --git a/cosmos_client/src/audio/music/mod.rs b/cosmos_client/src/audio/music/mod.rs index d6bec514b..a077533e5 100644 --- a/cosmos_client/src/audio/music/mod.rs +++ b/cosmos_client/src/audio/music/mod.rs @@ -3,8 +3,11 @@ use bevy::prelude::*; use bevy_inspector_egui::prelude::*; use bevy_kira_audio::prelude::*; +use cosmos_core::registry::Registry; use dynamic_music::MusicAtmosphere; +use crate::settings::{Setting, SettingsRegistry, SettingsSet}; + pub mod dynamic_music; #[derive(Resource)] @@ -18,14 +21,14 @@ pub struct VolumeSetting(#[inspector(min = 0.0, max = 1.0)] f64); impl VolumeSetting { /// Returns the volume as a decimal percent [0.0, 1.0] pub fn percent(&self) -> f64 { - self.0 + self.0.powf(2.0) * 0.2 // 1.0 is way too loud } } impl Default for VolumeSetting { - /// Initializes the volume to 0.2 (20%). + /// Initializes the volume to 1.0 (100%). fn default() -> Self { - Self(0.2) // 1.0 is way too loud - in the future introduce a global volume + Self(1.0) } } @@ -50,7 +53,7 @@ fn adjust_volume( return; }; - instance.set_volume(volume.0, AudioTween::default()); + instance.set_volume(volume.percent(), AudioTween::default()); } #[derive(Event)] @@ -60,6 +63,10 @@ pub struct PlayMusicEvent { pub atmosphere: MusicAtmosphere, } +fn load_volume(settings: Res>, mut music_volume: ResMut) { + music_volume.0 = settings.i32_or("cosmos:music_volume", 100) as f64 / 100.0; +} + pub(super) fn register(app: &mut App) { dynamic_music::register(app); @@ -77,4 +84,6 @@ pub(super) fn register(app: &mut App) { .init_resource::() .register_type::() .add_event::(); + + app.add_systems(Update, (load_volume).in_set(SettingsSet::LoadSettings)); } diff --git a/cosmos_client/src/settings/mod.rs b/cosmos_client/src/settings/mod.rs index 57ad0fca2..bda7b649b 100644 --- a/cosmos_client/src/settings/mod.rs +++ b/cosmos_client/src/settings/mod.rs @@ -26,6 +26,8 @@ pub enum SettingCategory { Graphics, /// Mouse Mouse, + /// Audio + Audio, } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] @@ -199,6 +201,13 @@ fn register_settings(mut registry: ResMut>) { SettingCategory::Graphics, Some(SettingConstraint::I32 { min: 30, max: 120 }), )); + + registry.register(Setting::new( + "cosmos:music_volume", + SettingData::I32(100), + SettingCategory::Audio, + Some(SettingConstraint::I32 { min: 0, max: 100 }), + )); } #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Resource, Default)] diff --git a/cosmos_client/src/ui/settings/mod.rs b/cosmos_client/src/ui/settings/mod.rs index 41fd62064..0e4266f9b 100644 --- a/cosmos_client/src/ui/settings/mod.rs +++ b/cosmos_client/src/ui/settings/mod.rs @@ -126,6 +126,7 @@ fn create_settings_screen( let category_display_name = match category { SettingCategory::Graphics => "Graphics", SettingCategory::Mouse => "Mouse", + SettingCategory::Audio => "Audio", }; p.spawn(TextBundle {