mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Continue implementing audio device selection
Former-commit-id: 6b92cbdb2e93653f43c0ed4d04e1b8fc35cfe8cf
This commit is contained in:
parent
8dc35b8609
commit
ee6ec2d299
@ -210,16 +210,10 @@ pub struct Hud {
|
||||
to_focus: Option<Option<widget::Id>>,
|
||||
settings: Settings,
|
||||
force_ungrab: bool,
|
||||
// TODO: move to settings
|
||||
current_vd: u32,
|
||||
current_volume: f32,
|
||||
audio_devices: Vec<String>,
|
||||
current_audio_device: String,
|
||||
}
|
||||
|
||||
impl Hud {
|
||||
pub fn new(window: &mut Window, settings: Settings) -> Self {
|
||||
let settings = global_state.settings;
|
||||
let mut ui = Ui::new(window).unwrap();
|
||||
// TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality.
|
||||
ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into()));
|
||||
@ -252,8 +246,6 @@ impl Hud {
|
||||
to_focus: None,
|
||||
settings,
|
||||
force_ungrab: false,
|
||||
current_vd: 5,
|
||||
current_volume: 0.5,
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,16 +375,8 @@ 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,
|
||||
self.current_volume,
|
||||
self.audio_devices,
|
||||
self.current_audio_device,
|
||||
)
|
||||
.set(self.ids.settings_window, ui_widgets)
|
||||
for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, &self.settings)
|
||||
.set(self.ids.settings_window, ui_widgets)
|
||||
{
|
||||
match event {
|
||||
settings_window::Event::ToggleHelp => self.show.toggle_help(),
|
||||
@ -402,15 +386,15 @@ impl Hud {
|
||||
settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug,
|
||||
settings_window::Event::Close => self.show.open_windows = Windows::None,
|
||||
settings_window::Event::AdjustViewDistance(view_distance) => {
|
||||
self.current_vd = view_distance;
|
||||
self.settings.graphics.view_distance = view_distance;
|
||||
events.push(Event::AdjustViewDistance(view_distance));
|
||||
}
|
||||
settings_window::Event::AdjustVolume(volume) => {
|
||||
self.current_volume = volume;
|
||||
self.settings.audio.music_volume = volume;
|
||||
events.push(Event::AdjustVolume(volume));
|
||||
}
|
||||
settings_window::Event::ChangeAudioDevice(name) => {
|
||||
self.current_audio_device = name;
|
||||
self.settings.audio.audio_device = name.clone();
|
||||
events.push(Event::ChangeAudioDevice(name));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use crate::{
|
||||
ImageSlider, ScaleMode, ToggleButton, Ui,
|
||||
},
|
||||
window::Window,
|
||||
Settings,
|
||||
};
|
||||
use conrod_core::{
|
||||
color,
|
||||
@ -65,33 +66,19 @@ pub struct SettingsWindow<'a> {
|
||||
imgs: &'a Imgs,
|
||||
fonts: &'a Fonts,
|
||||
|
||||
current_vd: u32,
|
||||
current_volume: f32,
|
||||
audio_devices: Vec<String>,
|
||||
current_audio_device: String,
|
||||
settings: &'a Settings,
|
||||
|
||||
#[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,
|
||||
current_volume: f32,
|
||||
audio_devices: Vec<String>,
|
||||
current_audio_device: String,
|
||||
) -> Self {
|
||||
pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts, settings: &'a Settings) -> Self {
|
||||
Self {
|
||||
show,
|
||||
imgs,
|
||||
fonts,
|
||||
current_vd,
|
||||
current_volume,
|
||||
audio_devices,
|
||||
current_audio_device,
|
||||
settings,
|
||||
common: widget::CommonBuilder::default(),
|
||||
}
|
||||
}
|
||||
@ -499,7 +486,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.set(state.ids.vd_slider_text, ui);
|
||||
|
||||
if let Some(new_val) = ImageSlider::discrete(
|
||||
self.current_vd,
|
||||
self.settings.graphics.view_distance,
|
||||
1,
|
||||
25,
|
||||
self.imgs.slider_indicator,
|
||||
@ -553,7 +540,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.set(state.ids.audio_volume_text, ui);
|
||||
|
||||
if let Some(new_val) = ImageSlider::continuous(
|
||||
self.current_volume,
|
||||
self.settings.audio.music_volume,
|
||||
0.0,
|
||||
1.0,
|
||||
self.imgs.slider_indicator,
|
||||
@ -578,7 +565,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.set(state.ids.audio_device_text, ui);
|
||||
|
||||
// TODO: Draw scroll bar or remove it.
|
||||
let (mut items, scrollbar) = List::flow_down(self.audio_devices.len())
|
||||
let (mut items, scrollbar) = List::flow_down(self.settings.audio.audio_devices.len())
|
||||
.down_from(state.ids.audio_device_text, 10.0)
|
||||
.w_h(400.0, 300.0)
|
||||
.scrollbar_next_to()
|
||||
@ -588,12 +575,12 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
|
||||
while let Some(item) = items.next(ui) {
|
||||
let mut text = "".to_string();
|
||||
if &self.audio_devices[item.i] == &self.current_audio_device {
|
||||
if &self.settings.audio.audio_devices[item.i] == &self.settings.audio.audio_device {
|
||||
text.push_str("* ")
|
||||
} else {
|
||||
text.push_str(" ")
|
||||
}
|
||||
text.push_str(&self.audio_devices[item.i]);
|
||||
text.push_str(&self.settings.audio.audio_devices[item.i]);
|
||||
|
||||
// TODO: Use buttons to allow changing audio devices
|
||||
item.set(
|
||||
|
@ -166,7 +166,9 @@ fn main() {
|
||||
};
|
||||
|
||||
// Load volume from audio file
|
||||
global_state.audio.set_volume(settings.audio.music_volume);
|
||||
global_state
|
||||
.audio
|
||||
.set_volume(global_state.settings.audio.music_volume);
|
||||
|
||||
global_state.settings.audio.audio_devices = global_state.audio.get_devices();
|
||||
|
||||
@ -175,7 +177,7 @@ fn main() {
|
||||
if global_state.settings.audio.audio_device != "" {
|
||||
global_state
|
||||
.audio
|
||||
.set_device(global_state.settings.audio.audio_device);
|
||||
.set_device(global_state.settings.audio.audio_device.clone());
|
||||
} else {
|
||||
global_state.settings.audio.audio_device = global_state.audio.get_device();
|
||||
global_state.settings.save_to_file();
|
||||
|
@ -196,6 +196,9 @@ impl PlayState for SessionState {
|
||||
HudEvent::AdjustVolume(volume) => {
|
||||
global_state.audio.set_volume(volume);
|
||||
}
|
||||
HudEvent::ChangeAudioDevice(name) => {
|
||||
global_state.audio.set_device(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ pub struct Settings {
|
||||
pub controls: ControlSettings,
|
||||
pub networking: NetworkingSettings,
|
||||
pub log: Log,
|
||||
pub graphics: GraphicsSettings,
|
||||
pub audio: AudioSettings,
|
||||
}
|
||||
|
||||
@ -53,6 +54,11 @@ pub struct Log {
|
||||
pub file: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct GraphicsSettings {
|
||||
pub view_distance: u32,
|
||||
}
|
||||
|
||||
/// AudioSettings controls the volume of different audio subsystems and which
|
||||
/// which device is used.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@ -104,6 +110,7 @@ impl Default for Settings {
|
||||
log: Log {
|
||||
file: "voxygen.log".into(),
|
||||
},
|
||||
graphics: GraphicsSettings { view_distance: 5 },
|
||||
audio: AudioSettings {
|
||||
music_volume: 0.5,
|
||||
sfx_volume: 0.5,
|
||||
|
Loading…
Reference in New Issue
Block a user